networkmanager: the whole test's runtime publishes only what the membership lists
The stand-in tool runner refuses a subject the module's membership does not list, as the runtime's mayPublish does: the module's held seat's own-node events, read from its manifest and the nodeuplink contract (MembershipFor's rule at mesh-delivery ef8dd120). Another node's subject is refused and stays kept. Builds: design 08 sign-in-page §4a, §25; lead answer C-1
This commit is contained in:
@@ -62,6 +62,35 @@ type runtime struct {
|
||||
in io.Writer
|
||||
next int
|
||||
pending map[string]chan json.RawMessage
|
||||
// mayPublish is every subject the module's membership lets it say, as the runtime's mayPublish reads it.
|
||||
mayPublish map[string]bool
|
||||
}
|
||||
|
||||
// membershipPublish is what the module's membership lists it may publish on node: a held seat's own-node machine
|
||||
// events, the rule mesh-grants' MembershipFor holds (mesh-delivery ef8dd120), read here from the shared contract and the
|
||||
// module's own manifest, never from mesh-grants' code.
|
||||
func membershipPublish(t *testing.T, node string) map[string]bool {
|
||||
t.Helper()
|
||||
raw, err := os.ReadFile(filepath.Join(moduleDir, "module.json"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var m struct {
|
||||
Claims []struct {
|
||||
Name string `json:"name"`
|
||||
} `json:"claims"`
|
||||
}
|
||||
if err := json.Unmarshal(raw, &m); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
out := map[string]bool{}
|
||||
for _, c := range m.Claims {
|
||||
if c.Name == nodeuplink.Seat {
|
||||
out[nodeuplink.SubjectSignInAsked(node)] = true
|
||||
out[nodeuplink.SubjectSignInEnded(node)] = true
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (r *runtime) send(m map[string]any) {
|
||||
@@ -117,6 +146,10 @@ func (r *runtime) handle(id json.RawMessage, method string, params json.RawMessa
|
||||
ID string `json:"id"`
|
||||
}
|
||||
json.Unmarshal(params, &p)
|
||||
if !r.mayPublish[p.Subject] {
|
||||
r.answer(id, nil, fmt.Errorf("%s may not publish %s: its membership does not list it", Module, p.Subject))
|
||||
return
|
||||
}
|
||||
_, err := r.js.Publish(r.ctx, p.Subject, p.Body, jetstream.WithMsgID(Module+"."+p.ID))
|
||||
r.answer(id, map[string]any{}, err)
|
||||
case "mesh/ask":
|
||||
@@ -283,7 +316,8 @@ func TestNetworkManagerWhole(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { in.Close(); cmd.Wait() })
|
||||
r := &runtime{t: t, ctx: ctx, nc: nc, js: js, in: in, pending: map[string]chan json.RawMessage{}}
|
||||
r := &runtime{t: t, ctx: ctx, nc: nc, js: js, in: in, pending: map[string]chan json.RawMessage{},
|
||||
mayPublish: membershipPublish(t, "home-server")}
|
||||
go r.serve(out)
|
||||
|
||||
select {
|
||||
@@ -344,4 +378,19 @@ func TestNetworkManagerWhole(t *testing.T) {
|
||||
if left, _ := f.pending(); len(left) != 0 {
|
||||
t.Fatalf("left in pending/: %+v", left)
|
||||
}
|
||||
|
||||
// Another node's subject is not the module's to say: the runtime refuses it and it stays kept.
|
||||
if _, err := f.keep(eventAsked, nodeuplink.SubjectSignInAsked("other-node"), map[string]string{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if text := r.call("uplink_publish_again"); !strings.Contains(text, `"waiting":1`) ||
|
||||
!strings.Contains(text, "its membership does not list it") {
|
||||
t.Fatalf("another node's subject: uplink_publish_again answered %s", text)
|
||||
}
|
||||
if left, _ := f.pending(); len(left) != 1 {
|
||||
t.Fatalf("the refused event is not kept: %+v", left)
|
||||
}
|
||||
if info, err := stream.Info(ctx); err != nil || info.State.Msgs != 3 {
|
||||
t.Fatalf("the stream holds %v messages (%v), not the 3 published", info.State.Msgs, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user