Files
mesh-delivery/modules/mesh-grants/internal/grants/grantwaits_test.go
T
jschoubben 30f67f0471 mesh-grants: a grant waits only for what the loaded list does not allow
GrantWaits compared permissions by their text, so a composed subject or allow-responses counted as
missing though the loaded list's '>' already allowed it: all 182 grants waited on '1 permissions'
from 15:43 on 2026-11-16 and no want moved. A subject a loaded one covers is carried now, and
answering is carried where the loaded user may publish every subject.
2026-11-16 17:30:29 +01:00

33 lines
1.6 KiB
Go

package grants
import "testing"
// A grant is carried by what the loaded list allows, not by its text (2026-11-16: every grant waited on a permission the
// loaded `>` already gave).
func TestAGrantWaitsOnlyForWhatTheLoadedListDoesNotAllow(t *testing.T) {
all := User{User: "n.m", Publish: []string{">"}, Subscribe: []string{">"}}
for _, c := range []struct {
name string
composed, loaded User
waits bool
}{
{"everything covers a subject and answering", User{User: "n.m", Publish: []string{"mesh.a.b", ">"}, Subscribe: []string{"mesh.*.c"}, AllowResponses: true}, all, false},
{"a narrower loaded subject does not cover a wider one", User{User: "n.m", Publish: []string{"mesh.>"}}, User{User: "n.m", Publish: []string{"mesh.a.>"}}, true},
{"a star covers one token", User{User: "n.m", Subscribe: []string{"mesh.a.c"}}, User{User: "n.m", Subscribe: []string{"mesh.*.c"}}, false},
{"answering is not carried by a narrow publish", User{User: "n.m", Publish: []string{"mesh.a"}, AllowResponses: true}, User{User: "n.m", Publish: []string{"mesh.a"}}, true},
} {
got := GrantWaits([]string{"n.m"}, map[string]User{"n.m": c.composed}, map[string]User{"n.m": c.loaded}, "")
if (got != "") != c.waits {
t.Errorf("%s: waits %q, want waiting %v", c.name, got, c.waits)
}
}
for _, c := range []struct {
p, s string
want bool
}{{">", "a", true}, {">", "a.>", true}, {"a.>", "a", false}, {"a.*", "a.>", false}, {"a.*", "a.*", true}, {"a.b", "a.b", true}, {"a.b", "a.b.c", false}} {
if got := subjectCovers(c.p, c.s); got != c.want {
t.Errorf("subjectCovers(%q, %q) = %v, want %v", c.p, c.s, got, c.want)
}
}
}