diff --git a/internal/nodegrant/testdata/node.json b/internal/nodegrant/testdata/node.json index d6b315e8..e31dcc1c 100644 --- a/internal/nodegrant/testdata/node.json +++ b/internal/nodegrant/testdata/node.json @@ -162,7 +162,8 @@ "mesh.seat.mesh-catalog.event.seat-definition-changed", "mesh.seat.mesh-catalog.event.seat-definition-removed", "mesh.seat.node-engine.call.*.NODE.*", - "mesh.seat.node-engine.tool.*.NODE" + "mesh.seat.node-engine.tool.*.NODE", + "mesh.seat.node-packet-filter.event.allowances-changed.*" ], "AllowResponses": true } diff --git a/internal/selfcompose/versions_test.go b/internal/selfcompose/versions_test.go index 76cf4bf8..9b2fa862 100644 --- a/internal/selfcompose/versions_test.go +++ b/internal/selfcompose/versions_test.go @@ -13,6 +13,7 @@ import ( "time" "github.com/novox/mesh-host/internal/agent" + "github.com/novox/mesh-host/internal/nodegrant" "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" @@ -248,6 +249,14 @@ func TestAModulesClaimsAreReadFromTheEntryOfItsWantsBuild(t *testing.T) { if own == nil || other != nil { t.Fatalf("heard %v, want the own node's allowances-changed and no other's", heard) } + // And the node's grant lets it subscribe there, as the grants part grants the consume (every machine's, as `*`). + granted := false + for _, f := range nodegrant.For("n1").Subscribe { + granted = granted || subjectCovers(f, nodepacketfilter.SubjectAllowancesChanged("n1")) + } + if !granted { + t.Errorf("the node's grant does not let it subscribe to %s", nodepacketfilter.SubjectAllowancesChanged("n1")) + } select { case own <- []byte(`{"node":"n1","change":"allowed"}`): case <-time.After(10 * time.Second): @@ -359,3 +368,17 @@ type storeAway struct{} func (storeAway) Error() string { return "artifact-store answered 503 Service Unavailable" } func (storeAway) StoreAnswered() bool { return false } + +// subjectCovers says whether the subject filter f matches the subject s, by NATS's wildcards (* one token, > the rest). +func subjectCovers(f, s string) bool { + ft, st := strings.Split(f, "."), strings.Split(s, ".") + for i, t := range ft { + if t == ">" { + return i < len(st) + } + if i >= len(st) || (t != "*" && t != st[i]) { + return false + } + } + return len(ft) == len(st) +}