mesh-grants: a node seat's verb is also granted without the machine
Holders subscribe and callers publish on mesh.seat.<seat>.tool.<verb> (and its call form) beside the machine-named subject, so a verb asked of no machine is answered by any one holder in a queue group. Builds: lead answer A-393 (design 47 G) Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
@@ -137,3 +137,44 @@ func TestTheGrantsPartAlonePurgesTheNamedAsks(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Design 47 G, lead answer A-393: a verb of a node-scoped seat asked with no machine is answered by any one holder, so each
|
||||
// holder is granted the verb's subject without the machine (tool and call forms) beside its machine's, and a caller of the
|
||||
// verb may publish on it; a verb of a seat held once for the mesh gains nothing, and a stranger is granted nothing.
|
||||
func TestANodeSeatVerbIsAlsoGrantedWithoutTheMachine(t *testing.T) {
|
||||
build := Seat{Name: "node-build-go", Scope: "node", Serves: []string{"steps"},
|
||||
VerbCallers: map[string][]string{"steps": {"invokers"}}}
|
||||
holder := Principal{Kind: KindModule, Node: "shanks", Module: "mesh-build-go", Holds: []Seat{build}}
|
||||
caller := Principal{Kind: KindModule, Node: "shanks", Module: "an-indexer", Uses: []Seat{build},
|
||||
Invokes: []string{"seat:node-build-go.steps"}}
|
||||
stranger := Principal{Kind: KindModule, Node: "shanks", Module: "a-stranger", Uses: []Seat{build}}
|
||||
const tool = "mesh.seat.node-build-go.tool.steps"
|
||||
call := "mesh.seat.node-build-go.call.steps."
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
who Principal
|
||||
subject string
|
||||
sub bool
|
||||
want bool
|
||||
}{
|
||||
{"holder hears its machine's", holder, tool + ".shanks", true, true},
|
||||
{"holder hears the node-less tool", holder, tool, true, true},
|
||||
{"holder hears the node-less call", holder, call + "someone", true, true},
|
||||
{"caller asks the node-less tool", caller, tool, false, true},
|
||||
{"caller asks a machine's", caller, tool + ".shanks", false, true},
|
||||
{"caller asks the node-less call in its name", caller, call + CallerToken(caller.Username()), false, true},
|
||||
{"stranger asks the node-less tool", stranger, tool, false, false},
|
||||
} {
|
||||
perms, err := PermissionsFor(c.who)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := MayPublish(perms, c.subject)
|
||||
if c.sub {
|
||||
got = MaySubscribe(perms, c.subject)
|
||||
}
|
||||
if got != c.want {
|
||||
t.Errorf("%s: %v, want %v", c.name, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1112,7 +1112,7 @@ func permissionsFor(p Principal) (Permissions, error) {
|
||||
if s.isNewTraffic() {
|
||||
// Composed by SeatTrafficOf below, worker and all; only its tools are served here.
|
||||
for _, t := range s.Serves {
|
||||
sub = append(sub, seatToolSubject(s, t, p.Node))
|
||||
sub = append(sub, seatToolSubjects(s, t, p.Node)...)
|
||||
}
|
||||
continue
|
||||
}
|
||||
@@ -1141,7 +1141,7 @@ func permissionsFor(p Principal) (Permissions, error) {
|
||||
pub = append(pub, seatSubject(s, "event", e))
|
||||
}
|
||||
for _, t := range s.Serves {
|
||||
sub = append(sub, seatToolSubject(s, t, p.Node))
|
||||
sub = append(sub, seatToolSubjects(s, t, p.Node)...)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1155,7 +1155,7 @@ func permissionsFor(p Principal) (Permissions, error) {
|
||||
for _, t := range s.Serves {
|
||||
// Only a verb whose effective callers name this module (design 47 G A-179, §610).
|
||||
if callerOf(p, s, t) {
|
||||
pub = append(pub, seatToolSubject(s, t, "*"))
|
||||
pub = append(pub, seatToolSubjects(s, t, "*")...)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1218,7 +1218,7 @@ func permissionsFor(p Principal) (Permissions, error) {
|
||||
s.Serves = withoutActing(s.Serves)
|
||||
}
|
||||
for _, t := range s.Serves {
|
||||
sub = append(sub, seatToolSubject(s, t, p.Node))
|
||||
sub = append(sub, seatToolSubjects(s, t, p.Node)...)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1497,6 +1497,17 @@ func seatToolSubject(s Seat, verb, node string) string {
|
||||
return base
|
||||
}
|
||||
|
||||
// seatToolSubjects are seatToolSubject and, for a verb of a node-scoped seat, the subject without the machine, where a verb
|
||||
// asked of no machine is answered by any one holder in a queue group (design 47 G, lead answer A-393). Its call form
|
||||
// follows from the tool grant (callerNamed).
|
||||
func seatToolSubjects(s Seat, verb, node string) []string {
|
||||
out := []string{seatToolSubject(s, verb, node)}
|
||||
if s.Scope == "node" && node != "" {
|
||||
out = append(out, seatToolSubject(s, verb, ""))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// consumerStream and consumerDurable are the two halves of a consumer's identity, and they are
|
||||
// two functions because conflating them was a real bug.
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user