package forge import ( "encoding/json" "os" "path/filepath" "reflect" "strings" "testing" ) func TestRepositoryNames(t *testing.T) { path := filepath.Join(t.TempDir(), "forge.json") must(t, os.WriteFile(path, []byte(`{"agent":"fixture~person@example.test","repositories":{"amadan.net/oficina/z":"canary-secret-z","amadan.net/oficina/a":{"api":"canary-secret-api","git":"canary-secret-git"}}}`), 0600)) names, err := (FileCredentials{Path: path}).RepositoryNames() must(t, err) if !reflect.DeepEqual(names, []string{"amadan.net/oficina/a", "amadan.net/oficina/z"}) { t.Fatal(names) } raw, err := json.Marshal(names) must(t, err) if strings.Contains(string(raw), "canary-secret") { t.Fatal("credential disclosed") } must(t, os.Chmod(path, 0644)) if _, err = (FileCredentials{Path: path}).RepositoryNames(); err == nil { t.Fatal("public credential file accepted") } must(t, os.Remove(path)) if _, err = (FileCredentials{Path: path}).RepositoryNames(); err == nil { t.Fatal("missing file accepted") } }