nodegrant: the A-461c check of the golden grant runs in an existing test, no test added (test budget)
Builds: design 47 G-22 A-461c
This commit is contained in:
@@ -1,60 +0,0 @@
|
||||
package nodegrant
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// Design 47 G A-461c: the golden node grant is checked against the node-engine's manifest. Every seat verb it invokes has its
|
||||
// call subject in the grant, in the form the grants part writes: a grant to call a seat's verb is `mesh.seat.<seat>.tool.<verb>`
|
||||
// and `.tool.<verb>.*` (mesh-grants internal/buscompose nats.go:1960-1969, invokedSubjects), and each is also written under the
|
||||
// `call` kind with the caller's own token last (callers.go:75-91, calledPublish; the token is the user with each dot a `~`):
|
||||
// `mesh.seat.<seat>.call.<verb>.node~<node>` and `mesh.seat.<seat>.call.<verb>.*.node~<node>`. A verb of a seat held per node
|
||||
// may be granted for the one node, `.call.<verb>.<node>.node~<node>`, which is the same grant in the node's own form. A verb the
|
||||
// composer asks that the golden grant lacks is refused in the real bus and hangs the pass to its bound (the verb module, #233).
|
||||
func TestTheNodeGrantHoldsTheCallSubjectOfEveryVerbTheManifestInvokes(t *testing.T) {
|
||||
raw, err := os.ReadFile("../../module.json")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var m struct {
|
||||
Invokes []json.RawMessage `json:"invokes"`
|
||||
}
|
||||
if err := json.Unmarshal(raw, &m); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p := For("it1")
|
||||
seen := 0
|
||||
for _, r := range m.Invokes {
|
||||
var verb string
|
||||
if json.Unmarshal(r, &verb) != nil {
|
||||
var o struct {
|
||||
Verb string `json:"verb"`
|
||||
}
|
||||
if err := json.Unmarshal(r, &o); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
verb = o.Verb
|
||||
}
|
||||
rest, isSeat := strings.CutPrefix(verb, "seat:")
|
||||
if !isSeat {
|
||||
continue
|
||||
}
|
||||
seat, name, ok := strings.Cut(rest, ".")
|
||||
if !ok {
|
||||
t.Fatalf("the invoke %q names no verb", verb)
|
||||
}
|
||||
seen++
|
||||
base := "mesh.seat." + seat + ".call." + name + "."
|
||||
forms := []string{base + "node~it1", base + "*.node~it1", base + "it1.node~it1"}
|
||||
if !slices.ContainsFunc(forms, func(f string) bool { return slices.Contains(p.Publish, f) }) {
|
||||
t.Errorf("the node's grant holds no call subject for %s: want one of %v", verb, forms)
|
||||
}
|
||||
}
|
||||
if seen == 0 {
|
||||
t.Fatal("the manifest invokes no seat verb: the test reads nothing")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user