diff --git a/modules/mesh-grants/cmd/mesh-grants/integration_test.go b/modules/mesh-grants/cmd/mesh-grants/integration_test.go index 5aa60ab3..d84b24ee 100644 --- a/modules/mesh-grants/cmd/mesh-grants/integration_test.go +++ b/modules/mesh-grants/cmd/mesh-grants/integration_test.go @@ -35,6 +35,7 @@ import ( "git.novox.be/novox/mesh-sdk/go/seatlist" "git.novox.be/novox/mesh-sdk/go/views" + "mesh-grants/internal/buscompose" "mesh-grants/internal/grants" ) @@ -651,9 +652,19 @@ func TestTheGrantsPartWhole(t *testing.T) { }) // And what the part composes holds on a server that loads it (one integration test per module, the test budget). - t.Run("the composed grants hold on a server that loads them", theBusNodeFollowsTheSealedListUnderTheComposedGrants) - t.Run("the tool runner hears every event on a server that loads its grants", theToolRunnerHearsEveryEventOnTheBus) - t.Run("a runtime denied the marks is delivered no call on a marked subject", aRuntimeDeniedTheMarksHearsNoMarkedCall) + // These read each account's own subjects, which the part composes beneath the wide grant of every account (the unit tests' + // TestMain does the same): the mechanisms of the scoped grants are built whole all the same. + scoped := func(f func(*testing.T)) func(*testing.T) { + return func(t *testing.T) { + was := buscompose.EveryAccountMayDoEverything + buscompose.EveryAccountMayDoEverything = false + defer func() { buscompose.EveryAccountMayDoEverything = was }() + f(t) + } + } + t.Run("the composed grants hold on a server that loads them", scoped(theBusNodeFollowsTheSealedListUnderTheComposedGrants)) + t.Run("the tool runner hears every event on a server that loads its grants", scoped(theToolRunnerHearsEveryEventOnTheBus)) + t.Run("a runtime denied the marks is delivered no call on a marked subject", scoped(aRuntimeDeniedTheMarksHearsNoMarkedCall)) } // lockedLog is the part's log, read by the test while the part writes it. diff --git a/modules/mesh-grants/internal/buscompose/buscompose_test.go b/modules/mesh-grants/internal/buscompose/buscompose_test.go index d37475b0..683972e2 100644 --- a/modules/mesh-grants/internal/buscompose/buscompose_test.go +++ b/modules/mesh-grants/internal/buscompose/buscompose_test.go @@ -1698,6 +1698,11 @@ func TestEveryMeshAccountMayDoEverything(t *testing.T) { if err != nil || !slices.Equal(m.Publish, []string{AllSubjects}) || !slices.Equal(m.Subscribe, []string{AllSubjects}) { t.Fatalf("a module account = %v / %v (%v), want every subject both ways", m.Publish, m.Subscribe, err) } + // The wide grant leaves a module its consumer: its filters are its own events', never the grant's ">". + if c, ok := ConsumerFor(Principal{Kind: KindModule, Node: "a", Module: "plain", Consumes: []string{"nats.done"}}); !ok || slices.Contains(c.Filters, AllSubjects) || + !slices.Contains(c.Filters, "mesh.mod.nats.event.done") { + t.Errorf("a module's consumer under the wide grant = %v, %v, want its own event filters", c.Filters, ok) + } e, err := PermissionsFor(Principal{Kind: KindEnrolment, Node: "new"}) if err == nil && slices.Contains(e.Publish, AllSubjects) { t.Errorf("an enrolling node is granted every subject: %v", e.Publish) diff --git a/modules/mesh-grants/internal/buscompose/derived.go b/modules/mesh-grants/internal/buscompose/derived.go index ddc633d8..d0772c42 100644 --- a/modules/mesh-grants/internal/buscompose/derived.go +++ b/modules/mesh-grants/internal/buscompose/derived.go @@ -148,7 +148,9 @@ func ConsumerFor(p Principal) (Consumer, bool) { if p.Kind != KindModule || (len(p.Consumes) == 0 && len(p.Watches) == 0 && !hearsItsOwn && !hearsAStream) { return Consumer{}, false } - perms, err := PermissionsFor(p) + // The module's own subjects, never its account's grant: every account may subscribe to every subject (EveryAccountMayDoEverything), + // and a filter drawn from ">" names no event, so no consumer would be composed for any module. + perms, err := scopedPermissionsFor(p) if err != nil { return Consumer{}, false }