Files
mesh-delivery/modules/mesh-grants/internal/buscompose/state_objects_test.go
T
jschoubben eb45c3c67c GR14: the keeper hears either finding stream form, each module publishing its own node's
A * emitter before a finding event reaches the stream a part asked for by the
template events (its finding-events) beside the old stream; a part's finding
stream is published on its own node's subjects alone.

Builds: design 47 G §386, §529, §515

Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
2026-11-12 06:05:07 +01:00

59 lines
2.4 KiB
Go

package buscompose
import (
"testing"
"git.novox.be/novox/mesh-sdk/go/catalogue"
"git.novox.be/novox/mesh-sdk/go/membership"
)
// Design 47 G §58, §59, §91, §124: a state's `<state>-objects` store is its owner's alone, and a sent store is read, never
// written, by the modules it is for.
func TestStateObjectsAndSentStores(t *testing.T) {
owner, err := PermissionsFor(Principal{Kind: KindModule, Node: "one", Module: "shop", Bound: []membership.BusBinding{
{Local: "orders", Storage: catalogue.StorageKeyValue, Template: catalogue.TemplateState, Bucket: "shop_orders", Objects: "shop_orders-objects"}}})
if err != nil {
t.Fatal(err)
}
other, err := PermissionsFor(Principal{Kind: KindModule, Node: "one", Module: "bank"})
if err != nil {
t.Fatal(err)
}
for _, subject := range []string{"$O.shop_orders-objects.C.x", "$O.shop_orders-objects.M.x", "$JS.API.DIRECT.GET.OBJ_shop_orders-objects.x"} {
if !MayPublish(owner, subject) {
t.Errorf("the owner may not publish %s", subject)
}
if MayPublish(other, subject) {
t.Errorf("another module may publish %s", subject)
}
}
reader, err := PermissionsFor(Principal{Kind: KindModule, Node: "one", Module: "bank", ReadsObjects: []string{"shop_sent-objects"}})
if err != nil {
t.Fatal(err)
}
if !MayPublish(reader, "$JS.API.DIRECT.GET.OBJ_shop_sent-objects.x") || MayPublish(reader, "$O.shop_sent-objects.C.x") ||
MayPublish(reader, "$JS.API.DIRECT.GET.OBJ_other_sent-objects.x") {
t.Error("a reader of a sent store reads that one and writes none")
}
}
// A part's finding stream is published on its own node's subjects alone (design 47 G §529): the machine is the subject's last
// token, and another machine's is refused.
func TestFindingEventsOnOwnNodeOnly(t *testing.T) {
bound := []membership.BusBinding{{Local: "finding-events", Storage: catalogue.StorageStream, Template: catalogue.TemplateEvents,
Stream: "shop_finding-events", Subject: "mesh.bus.shop.finding-events"}}
perms, err := PermissionsFor(Principal{Kind: KindModule, Node: "one", Module: "shop", Bound: bound})
if err != nil {
t.Fatal(err)
}
for subject, want := range map[string]bool{
"mesh.bus.shop.finding-events.finding-written.one": true,
"mesh.bus.shop.finding-events.finding-written.two": false,
"mesh.bus.shop.finding-events.findings-stated.two": false,
} {
if got := MayPublish(perms, subject); got != want {
t.Errorf("may publish %s: %v, want %v", subject, got, want)
}
}
}