oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package forge
2
3import (
4 "encoding/json"
5 "os"
6 "path/filepath"
7 "reflect"
8 "strings"
9 "testing"
10)
11
12func TestRepositoryNames(t *testing.T) {
13 path := filepath.Join(t.TempDir(), "forge.json")
14 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))
15 names, err := (FileCredentials{Path: path}).RepositoryNames()
16 must(t, err)
17 if !reflect.DeepEqual(names, []string{"amadan.net/oficina/a", "amadan.net/oficina/z"}) {
18 t.Fatal(names)
19 }
20 raw, err := json.Marshal(names)
21 must(t, err)
22 if strings.Contains(string(raw), "canary-secret") {
23 t.Fatal("credential disclosed")
24 }
25 must(t, os.Chmod(path, 0644))
26 if _, err = (FileCredentials{Path: path}).RepositoryNames(); err == nil {
27 t.Fatal("public credential file accepted")
28 }
29 must(t, os.Remove(path))
30 if _, err = (FileCredentials{Path: path}).RepositoryNames(); err == nil {
31 t.Fatal("missing file accepted")
32 }
33}
34