package credentialform import ( "os" "path/filepath" "strings" "testing" ) func aCatalogue(t *testing.T, manifests map[string]string) string { t.Helper() root := t.TempDir() for module, body := range manifests { 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) } } return root } // A binder the provisioner does not read is refused and named; an offer that says no form is the judge's to refuse, not // this check's; a route received as a file is refused but for the module still moving off it; and the real catalogue is // clean. func TestNoBinderIsUnreadAndNoRouteIsReceivedAsAFile(t *testing.T) { root := aCatalogue(t, map[string]string{ "silent": `{"module":"silent","provides":[{"name":"thing","scope":"mesh"}]}`, "binder": `{"module":"binder","provides":[{"name":"d","credential":{"form":"pair"}}],"state":["bound"]}`, "mesh-provisioner": `{"module":"mesh-provisioner","reads":["other.bound"]}`, "says": `{"module":"says","provides":[{"name":"a","credential":{"form":"pair"}},{"name":"b","credential":{"form":"none"}},{"name":"c","credential":{"own":"jwt"}}]}`, // A route received as a file (issue 774, research 072 row 34): refused, naming every module still on it; the one // listed as still moving passes. "old-proxy": `{"module":"old-proxy","receives":{"route":"/var/lib/old-proxy/mesh.json"}}`, "route-adapter": `{"module":"route-adapter","receives":{"route":"/var/lib/route-adapter/mesh.json"}}`, }) got, err := Problems(root) if err != nil { t.Fatal(err) } if len(got) != 2 || !strings.Contains(got[0], "binder") || !strings.Contains(got[0], "mesh-provisioner") || !strings.HasPrefix(got[1], "old-proxy receives route") || !strings.Contains(got[1], "old-proxy, route-adapter") { t.Fatalf("refused %v, wanted the binder the provisioner does not read and the received route", got) } real, err := Problems(filepath.Join("..", "..")) if err != nil { t.Fatal(err) } if len(real) != 0 { t.Fatalf("the catalogue has binders or routes it must not:\n%s", strings.Join(real, "\n")) } }