package scopes import ( "reflect" "testing" ) func TestCatalogueIsWellFormed(t *testing.T) { for _, s := range All() { if s.Product == "" || s.Description == "" { t.Errorf("%s: product and description are required", s.Name) } if _, ok := Lookup(s.Name); !ok { t.Errorf("%s: not found by Lookup", s.Name) } } } func TestValidate(t *testing.T) { got, err := Validate([]string{"pruefwerk:scans.run", " pruefwerk:findings.read", "pruefwerk:scans.run"}, "") if err != nil { t.Fatal(err) } if want := []string{"pruefwerk:findings.read", "pruefwerk:scans.run"}; !reflect.DeepEqual(got, want) { t.Fatalf("got %v, want %v", got, want) } if _, err := Validate([]string{"certifai:read"}, ""); err == nil { t.Error("unknown scope accepted") } if _, err := Validate([]string{"firmwerk:licence"}, "pruefwerk"); err == nil { t.Error("scope of another product accepted") } if _, err := Validate([]string{"werkbank:runner"}, "pruefwerk"); err != nil { t.Errorf("werkbank scopes belong to pruefwerk: %v", err) } } func TestProductsAndEffective(t *testing.T) { names := []string{"firmwerk:licence", "pruefwerk:findings.read", "werkbank:runner", "legacy:thing"} if got := Products(names); !reflect.DeepEqual(got, []string{"firmwerk", "pruefwerk"}) { t.Fatalf("Products = %v", got) } got := Effective(names, map[string]bool{"pruefwerk": true}) if want := []string{"pruefwerk:findings.read", "werkbank:runner", "legacy:thing"}; !reflect.DeepEqual(got, want) { t.Fatalf("Effective = %v, want %v", got, want) } }