write and update the netrc with safe perms
This commit is contained in:
parent
a3991af0ae
commit
e0c0cb6f32
2 changed files with 28 additions and 1 deletions
|
|
@ -173,3 +173,27 @@ func TestFilePermissions(t *testing.T) {
|
|||
t.Errorf("file permissions = %o, want 0600", perm)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilePermissionsCorrected(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
path := filepath.Join(dir, "netrc")
|
||||
|
||||
// Create file with overly permissive mode
|
||||
if err := os.WriteFile(path, []byte("machine old.host\npassword oldpass\n"), 0644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := Upsert(path, "cache.example.com", "token"); err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
info, err := os.Stat(path)
|
||||
if err != nil {
|
||||
t.Fatalf("stat error: %v", err)
|
||||
}
|
||||
|
||||
perm := info.Mode().Perm()
|
||||
if perm != 0600 {
|
||||
t.Errorf("file permissions = %o, want 0600", perm)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue