A state of the field state had no <state>-objects store: the grants part made and granted object buckets from the manifest's objects alone, so the indexer's state inputs (A-237) had no inputs-objects, and every validation failed on a refused STREAM.INFO of OBJ_mesh-delivery-indexer_inputs-objects; the assigner's inputs likewise. objectsOf now gives each such state its store (its size, 16 MiB when it names none; none for a state only read), so the grants part creates it and grants it to its owner as the module's own bucket. And a state asked in requires by the template state: the bus module's process may now make its store too (the grants part's BusStateStreams names it, as mesh-sdk's does), and a kept binding's objects is among its streams. Builds: design 47 G §58, §607, A-237
76 lines
3.5 KiB
Go
76 lines
3.5 KiB
Go
package buscompose
|
|
|
|
import (
|
|
"slices"
|
|
"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)
|
|
}
|
|
}
|
|
// The bus module may make the store beside a state asked by the template state: it is among the streams it keeps.
|
|
if got := BusStateStreams("shop", catalogue.BusStateEntry{Name: "orders", Storage: catalogue.StorageKeyValue, Template: catalogue.TemplateState}); !slices.Contains(got, "OBJ_shop_orders-objects") {
|
|
t.Errorf("the bus module's streams of the state orders = %v, want its object store among them", got)
|
|
}
|
|
// A state of the field state has its store beside it too, its owner's (A-237: the indexer's and the assigner's inputs), as
|
|
// the grants part makes and grants a module's own object buckets.
|
|
stated, err := PermissionsFor(Principal{Kind: KindModule, Node: "novox", Module: "mesh-delivery-indexer", State: []string{"inputs"},
|
|
Objects: []string{"mesh-delivery-indexer_inputs-objects"}})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, subject := range []string{"$JS.API.STREAM.INFO.OBJ_mesh-delivery-indexer_inputs-objects", "$O.mesh-delivery-indexer_inputs-objects.C.x"} {
|
|
if !MayPublish(stated, subject) {
|
|
t.Errorf("the indexer may not 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)
|
|
}
|
|
}
|
|
}
|