|
|
|
@@ -5666,3 +5666,76 @@ func TestAKeptRunnerCarriesAModuleKnownOnlyByItsBindings(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// A-386 live: a runner account left out for want of a manifest (the node's runner is another module's) is written as the union of the list in
|
|
|
|
|
// force and a carrying runner's grants.
|
|
|
|
|
func TestARunnerLeftOutForWantOfAManifestIsComposedAsACarryingRunner(t *testing.T) {
|
|
|
|
|
const runner = `{"module":"node-tools","version":"1","tool-runner":true,"own-secrets":{"broker":"/var/lib/nt/broker"}}`
|
|
|
|
|
b := fixture()
|
|
|
|
|
b.manifestOf("node-tools", runner)
|
|
|
|
|
b.assign("a", "node-tools")
|
|
|
|
|
b.assign("a", "mod-c")
|
|
|
|
|
busKey, err := seal.GenerateKeyPair()
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
b.put(grants.ReadHave, "a.nats", nodeengine.HaveByNodeModuleValue{V: keys.Version, Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthOK,
|
|
|
|
|
UserList: &nodeengine.UserListWritten{Source: grantsstate.GrantsUserListSource, Revision: 8, Wanted: "sha256:aa", Digest: "sha256:aa", Users: 5,
|
|
|
|
|
Key: busKey.PublicKey, Follows: grantsstate.FollowGrants}})
|
|
|
|
|
for _, u := range shadowOf(t, b) {
|
|
|
|
|
b.put(grants.ReadAccounts, u.User, map[string]any{"user": u.User, "hash": "$2a$10$x", "generation": 1, "fingerprint": "sha256:1"})
|
|
|
|
|
}
|
|
|
|
|
p := partOn(b)
|
|
|
|
|
p.Bus = grants.BusAddress{URL: "nats://a.mesh:4222", Fingerprint: "ab"}
|
|
|
|
|
p.Objects = &fakeObjects{}
|
|
|
|
|
binding := membership.BusBinding{Local: "records", Storage: "ledger", Template: "ledger", Stream: "mod-c_records", History: "mod-c_records",
|
|
|
|
|
Subject: "mesh.ledger.mod-c.records.history", State: "mod-c_records_state", Snapshot: "mesh.ledger.mod-c.records.snapshot"}
|
|
|
|
|
p.Compose() // the pass that learns the bus module is the broker
|
|
|
|
|
body, _ := json.Marshal(grants.BrokerEvent{V: 1, Module: "mod-c", Local: "records", Storage: "ledger", Template: "ledger", Binding: binding})
|
|
|
|
|
if _, err := p.HearBroker("mesh.seat.mesh-broker.event.created", body, p.Brokers()); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
p.Compose()
|
|
|
|
|
first, _, _ := p.Sealed()
|
|
|
|
|
key := grants.SealedUserKey(first.Digest, "a.node-tools")
|
|
|
|
|
var was grants.User
|
|
|
|
|
if err := json.Unmarshal(b.own[grants.StateUserList][key], &was); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
isLedger := func(s string) bool { return strings.Contains(s, "mod-c_records") }
|
|
|
|
|
was.Publish = append(slices.DeleteFunc(slices.Clone(was.Publish), isLedger), "mesh.control.a.tools-alive")
|
|
|
|
|
b.own[grants.StateUserList][key], _ = json.Marshal(was)
|
|
|
|
|
// Its manifest is gone, and another module placed on a says it is the tool runner: no kept runner by what runs, and the account
|
|
|
|
|
// of the list in force has no principal of the pass's.
|
|
|
|
|
delete(b.states[grants.ReadModules], "node-tools")
|
|
|
|
|
b.manifestOf("other-runner", strings.Replace(runner, "node-tools", "other-runner", 1))
|
|
|
|
|
b.assign("a", "other-runner")
|
|
|
|
|
b.assign("b", "mod-x")
|
|
|
|
|
p.Compose()
|
|
|
|
|
sealed, _, _ := p.Sealed()
|
|
|
|
|
if sealed.Digest == first.Digest {
|
|
|
|
|
t.Fatal("the list did not change")
|
|
|
|
|
}
|
|
|
|
|
var got grants.User
|
|
|
|
|
if err := json.Unmarshal(b.own[grants.StateUserList][grants.SealedUserKey(sealed.Digest, "a.node-tools")], &got); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
for _, want := range []string{
|
|
|
|
|
"$JS.API.STREAM.INFO.KV_mod-c_records_state", "$JS.API.DIRECT.GET.KV_mod-c_records_state.>", "$KV.mod-c_records_state.>",
|
|
|
|
|
"$JS.API.CONSUMER.CREATE.KV_mod-c_records_state.>", "$JS.API.DIRECT.GET.mod-c_records.>", "$JS.API.CONSUMER.CREATE.mod-c_records.>",
|
|
|
|
|
"$JS.API.DIRECT.GET.mod-c_records_snapshot.>"} {
|
|
|
|
|
if !slices.Contains(got.Publish, want) {
|
|
|
|
|
t.Errorf("the runner of a lacks %s", want)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for _, s := range was.Publish {
|
|
|
|
|
if !slices.Contains(got.Publish, s) {
|
|
|
|
|
t.Errorf("the kept runner lost %s", s)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for _, no := range []string{"mesh.ledger.mod-c.records.history.>", "mesh.ledger.mod-c.records.snapshot.>"} {
|
|
|
|
|
if slices.Contains(got.Publish, no) {
|
|
|
|
|
t.Errorf("the runner may publish on the ledger's %s", no)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|