package grants import ( "slices" "testing" "mesh-grants/internal/buscompose" ) // Design 47 G A-383, A-384: a runner's account kept from the list in force gains the rights of hearing new events and the streams' // names, and loses nothing; every account may ask any seat (principle 6); a ledger's account gains none of them. func TestAKeptRunnerGainsWhatEveryRunnerCarries(t *testing.T) { own := map[string][]string{"novox.node-tools": buscompose.NewEventGrants([]string{"EVENTS"})} kept := map[string]User{"novox.node-tools": {User: "novox.node-tools", Publish: []string{"a"}}, "ledger.novox.m": {User: "ledger.novox.m", Publish: []string{"b"}}} users, kept := withEveryAccountsRights([]User{{User: "novox.node-tools", Publish: []string{"a"}}}, kept, own) if !slices.Contains(kept["novox.node-tools"].Publish, buscompose.AnySeatSubject) { t.Errorf("the kept runner may not ask a seat: %v", kept["novox.node-tools"].Publish) } for _, u := range []User{users[0], kept["novox.node-tools"]} { for _, want := range []string{"a", buscompose.StreamNamesSubject, "$JS.API.CONSUMER.CREATE.EVENTS.*", "$JS.FC.EVENTS.>"} { if !slices.Contains(u.Publish, want) { t.Errorf("the runner lacks %s: %v", want, u.Publish) } } } if got := kept["ledger.novox.m"].Publish; !slices.Equal(got, []string{"b"}) { t.Errorf("a ledger's account = %v", got) } } // Principle 6 (the operator, 2026-11-15): a module's account kept from the list in force may put an ask on any seat, named by any // asker (a composed one has it from buscompose.PermissionsFor); an enrolling node's account gains none. func TestAKeptModuleAccountMayAskAnySeat(t *testing.T) { kept := map[string]User{"novox.mesh-delivery-pipeline": {User: "novox.mesh-delivery-pipeline", Publish: []string{"x"}}, "enrol.ace": {User: "enrol.ace", Publish: []string{"y"}}} _, kept = withEveryAccountsRights(nil, kept, nil) if !slices.Contains(kept["novox.mesh-delivery-pipeline"].Publish, buscompose.AnySeatSubject) { t.Errorf("a kept module account may not ask a seat: %v", kept["novox.mesh-delivery-pipeline"].Publish) } if got := kept["enrol.ace"].Publish; !slices.Equal(got, []string{"y"}) { t.Errorf("an enrolling node's account = %v", got) } }