Files
tenant-registry/internal/scopes/scopes_test.go
T
sharang 97284b5008
ci / shared (push) Successful in 14s
ci / test (push) Successful in 25m3s
ci / image (push) Successful in 39s
feat(api-keys): Scope catalogue, kinds, expiry and sha256 keys (#70)
2026-10-13 21:21:16 +00:00

48 lines
1.5 KiB
Go

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)
}
}