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 } // An offer that says no form is refused and named; one that says pair, none or an own secret passes; and the real // catalogue is clean. func TestEveryOfferSaysTheFormOfItsCredential(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"}}]}`, }) got, err := Problems(root) if err != nil { t.Fatal(err) } if len(got) != 2 || !strings.Contains(got[0], `silent provides "thing"`) || !strings.Contains(got[1], "binder") || !strings.Contains(got[1], "mesh-provisioner") { t.Fatalf("refused %v, wanted the silent offer and the binder the provisioner does not read", got) } real, err := Problems(filepath.Join("..", "..")) if err != nil { t.Fatal(err) } if len(real) != 0 { t.Fatalf("the catalogue has offers with no credential form:\n%s", strings.Join(real, "\n")) } }