-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure that the .vault-token file writen by vault login
always has the correct permissions and ownership.
#8867
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,62 @@ | ||
package token | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
// TestCommand re-uses the existing Test function to ensure proper behavior of | ||
// the internal token helper | ||
func TestCommand(t *testing.T) { | ||
Test(t, &InternalTokenHelper{}) | ||
helper, err := NewInternalTokenHelper() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
Test(t, helper) | ||
} | ||
|
||
func TestInternalHelperFilePerms(t *testing.T) { | ||
tmpDir, err := ioutil.TempDir("", t.Name()) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer os.RemoveAll(tmpDir) | ||
|
||
helper, err := NewInternalTokenHelper() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
helper.homeDir = tmpDir | ||
|
||
tmpFile := filepath.Join(tmpDir, ".vault-token") | ||
f, err := os.Create(tmpFile) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer f.Close() | ||
|
||
fi, err := os.Stat(tmpFile) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if fi.Mode().Perm()&004 != 004 { | ||
t.Fatalf("expected world-readable/writable permission bits, got: %o", fi.Mode().Perm()) | ||
} | ||
|
||
err = helper.Store("bogus_token") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
fi, err = os.Stat(tmpFile) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if fi.Mode().Perm()&004 != 0 { | ||
t.Fatalf("expected no world-readable/writable permission bits, got: %o", fi.Mode().Perm()) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think we could use
f.WriteString(input)
here.