The tool runner's bus account carried the heard grants, consumer and bind word of every module it runs, and every agent session on that machine reaches the bus as that account, so any session could pull a granted module's consumer on MAIL. Per ADR 0376 §1 the controller now composes a restricted stream's consumer, grants and bind word only for a module that declares runs-as; registration refuses a consumes of a restricted stream without runs-as (§2), and a grant that composes nothing is said in doctor (D-heard) and in the controller's log on every raise and send.
44 lines
1.6 KiB
Go
44 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/novox/mesh-controller/internal/broker"
|
|
"github.com/novox/mesh-controller/internal/conditions"
|
|
)
|
|
|
|
// A grant naming a module the tool runner carries composes nothing, and doctor says so in plain words, naming the
|
|
// module, the stream and the remedy (novox/hq ADR 0376 §2).
|
|
func TestAGrantThatComposesNothingIsSaid(t *testing.T) {
|
|
records := broker.Records{Nodes: []string{"ace"}, Assigned: map[string][]broker.Declared{"ace": {
|
|
{Module: broker.RuntimeModule},
|
|
{Module: "reader", Hears: []broker.Heard{{Stream: "MAIL", Emitter: "mesh-mail", Restricted: true,
|
|
Filters: []string{"mesh.stream.mesh-mail.event.mail.mesh.>"}}}},
|
|
{Module: "mailer", RunsAs: "mailer", Hears: []broker.Heard{{Stream: "MAIL", Emitter: "mesh-mail", Restricted: true,
|
|
Filters: []string{"mesh.stream.mesh-mail.event.mail.mesh.>"}}}},
|
|
}}}
|
|
found := withheldObservations(broker.WithheldOf(records))
|
|
if len(found) != 1 {
|
|
t.Fatalf("said %+v", found)
|
|
}
|
|
o := found[0]
|
|
if o.Kind != kindGrantComposesNothing || o.Machine != "ace" || !strings.Contains(o.Summary, "reader on ace") ||
|
|
!strings.Contains(o.Summary, "MAIL") || !strings.Contains(o.Summary, "runs-as") {
|
|
t.Fatalf("%+v", o)
|
|
}
|
|
w := plainWordings[kindGrantComposesNothing](o)
|
|
if why, ok := conditions.PlainWords(w, "ace"); !ok {
|
|
t.Fatalf("not plain: %s (%+v)", why, w)
|
|
}
|
|
registered := false
|
|
for _, p := range probeRegistry {
|
|
if p.ID == probeWithheldID && p.Kind == kindGrantComposesNothing && p.run != nil {
|
|
registered = true
|
|
}
|
|
}
|
|
if !registered {
|
|
t.Fatal("doctor does not run the probe of a grant that composes nothing")
|
|
}
|
|
}
|