package main import ( "os" "path/filepath" "testing" ) func manifest(t *testing.T, root, module, body string) { t.Helper() dir := filepath.Join(root, "modules", module) if err := os.MkdirAll(dir, 0o755); err != nil { t.Fatal(err) } if err := os.WriteFile(filepath.Join(dir, "module.json"), []byte(body), 0o644); err != nil { t.Fatal(err) } } func TestAnotherModuleNamingSSHIsRefused(t *testing.T) { root := t.TempDir() manifest(t, root, "ssh-client", `{"module":"ssh-client","resources":[{"path":"${machine:account-home}/.ssh/config"}]}`) manifest(t, root, "forge-account", `{"module":"forge-account","resources":[{"path":"${machine:account-home}/.ssh/config.d/20-forge"}]}`) manifest(t, root, "roster", `{"module":"roster","facts":{"hosts":{"path":".ssh/known_hosts"}}}`) manifest(t, root, "box", `{"module":"box","containers":[{"volumes":["~/.ssh:/root/.ssh:ro"]}]}`) manifest(t, root, "quiet", `{"module":"quiet","description":"reads ~/.ssh/config","resources":[{"path":"${machine:account-home}/.sshrc-not","template":"# see ~/.ssh/config"},{"path":"/etc/ssh/sshd_config"}]}`) found, err := Check(root) if err != nil { t.Fatal(err) } got := map[string]bool{} for _, f := range found { got[f.Module] = true } if len(found) != 3 || !got["forge-account"] || !got["roster"] || !got["box"] { t.Fatalf("refused %+v; want forge-account, roster and box", found) } } func TestTheCatalogueHasNone(t *testing.T) { found, err := Check("../..") if err != nil { t.Fatal(err) } if len(found) != 0 { t.Fatalf("the catalogue names paths under ~/.ssh outside ssh-client: %+v", found) } }