write and update the netrc with safe perms

This commit is contained in:
Abel Luck 2026-02-26 11:25:20 +01:00
parent a3991af0ae
commit e0c0cb6f32
2 changed files with 28 additions and 1 deletions

View file

@ -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)
}
}