Files
mesh-delivery/modules/mesh-grants/internal/grants/grantskept_test.go
T

42 lines
1.4 KiB
Go

package grants
import (
"testing"
"mesh-grants/internal/buscompose"
)
// Design 47 G A-364: the grants part's own account carries the right to create each kept event stream of the seat list, such as
// SEAT_git_branch-moved, composed from the same records as every other account.
func TestTheGrantsAccountMayCreateEachKeptEventStream(t *testing.T) {
const stream, subject = "SEAT_git_branch-moved", "mesh.seat.git.event.branch-moved"
for _, c := range []struct {
name string
kept []buscompose.KeptEvent
may bool
}{
{"a kept event of the seat list", []buscompose.KeptEvent{{Seat: "git", Event: "branch-moved", Stream: stream, Filter: subject}}, true},
{"no kept event", nil, false},
} {
t.Run(c.name, func(t *testing.T) {
users, err := buscompose.Users(buscompose.Records{Nodes: []string{"ace"}, Kept: c.kept,
Assigned: map[string][]buscompose.Declared{"ace": {{Module: buscompose.GrantsModule}}}})
if err != nil {
t.Fatal(err)
}
for _, u := range users {
if u.Kind != buscompose.KindModule || u.Module != buscompose.GrantsModule {
continue
}
perms, err := buscompose.PermissionsFor(u)
if err != nil {
t.Fatal(err)
}
if got := buscompose.MayPublish(perms, "$JS.API.STREAM.CREATE."+stream); got != c.may {
t.Errorf("the grants account may create %s: %v, want %v", stream, got, c.may)
}
}
})
}
}