Grant the node-engine the subscription to its allowances-changed
Review round 1 (5): the node grant's stored copy had the allowed call subjects but not the event the engine consumes, which the grants part grants every machine's as a wildcard; the subtest of allowances-changed now checks the grant covers the node's subject. Builds: design 08 control-verbs §1, §3
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user