A-383 kept-accounts-gain-the-right-every-account-carries: a kept or held account of the list in force gains the streams' names, as every composed one does

Builds: design 47 G A-383 (G-22-lead-answers-2.md)

Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
2026-11-14 00:23:49 +01:00
parent 0ad09c7382
commit 968e1b7493
3 changed files with 88 additions and 0 deletions
+56
View File
@@ -5346,3 +5346,59 @@ func TestWithheldIsAnsweredWhileTheListIsAnObject(t *testing.T) {
t.Errorf("withheld from the tools = %+v, %v", got, err)
}
}
// Design 47 G A-383: a right every account carries (the streams' names, A-382) is written to every account of a list, one kept or held
// from the list in force included: a held module's account of a pass before the catalog half is read gains it and loses nothing.
func TestAKeptAccountGainsTheRightEveryAccountCarries(t *testing.T) {
const names = "$JS.API.STREAM.NAMES"
b := fixture()
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{}
p.Compose()
first, _, _ := p.Sealed()
if first.Digest == "" {
t.Fatal("no list in force sealed")
}
// The list in force lacks the right for b.mod-y (written before the rule).
key := grants.SealedUserKey(first.Digest, "b.mod-y")
var u grants.User
if err := json.Unmarshal(b.own[grants.StateUserList][key], &u); err != nil {
t.Fatal(err)
}
u.Publish = slices.DeleteFunc(slices.Clone(u.Publish), func(s string) bool { return s == names })
b.own[grants.StateUserList][key], _ = json.Marshal(u)
// Its manifest is now held, the catalog half is unread, and the list changes (mod-x runs on b too).
b.refuse("mod-y", yManifest, "held for the test")
b.mu.Lock()
b.catalogWaited = []string{"the catalog half of the branch main"}
b.mu.Unlock()
b.assign("b", "mod-x")
p.Compose()
next, _, _ := p.Sealed()
if next.Digest == first.Digest {
t.Fatal("the list did not change: the pass kept the list in force")
}
var got grants.User
if err := json.Unmarshal(b.own[grants.StateUserList][grants.SealedUserKey(next.Digest, "b.mod-y")], &got); err != nil {
t.Fatal(err)
}
if !slices.Contains(got.Publish, names) {
t.Errorf("the kept account b.mod-y lacks %s: %v", names, got.Publish)
}
for _, s := range u.Publish {
if !slices.Contains(got.Publish, s) {
t.Errorf("the kept account lost %s", s)
}
}
}
@@ -399,6 +399,9 @@ func (p *Part) Compose() Result {
res.KeptLoaded = sortedKeys(union)
}
}
// A right every account carries is written to every account of the list, one kept or held from the list in force included
// (design 47 G A-383); the pass only adds.
users, kept = withEveryAccountsRights(users, kept)
users = WithHashes(users, in.Hashes)
st.Digest, st.Users = Digest(users), len(users)
st.Compare = Compare(users, loaded, Placed(in)).Excusing(ExcusedBy(MultiHeld(listRecs)))
@@ -137,3 +137,32 @@ func (p *Part) sayPrincipalsRefused(refused map[string]string, kept map[string]U
p.refusedSaid, p.refusedKnown = why, true
}
}
// withEveryAccountsRights gives each account a right every account of its kind carries (buscompose.StreamNamesSubject, design 47 G
// A-382) that it lacks, in users and in kept: a user kept from the list in force or held is copied whole, so it would never gain it. An
// account of a ledger, an enrolling node, a person or a provisioner publishes on a few subjects alone and gets none. It only adds.
func withEveryAccountsRights(users []User, kept map[string]User) ([]User, map[string]User) {
add := func(u User) User {
for _, alone := range []string{"ledger.", "enrol.", "person.", "provisioner."} {
if strings.HasPrefix(u.User, alone) {
return u
}
}
if !slices.Contains(u.Publish, buscompose.StreamNamesSubject) {
u.Publish = append(slices.Clone(u.Publish), buscompose.StreamNamesSubject)
}
return u
}
out := make([]User, len(users))
for i, u := range users {
out[i] = add(u)
}
var withKept map[string]User
if kept != nil {
withKept = make(map[string]User, len(kept))
for k, u := range kept {
withKept[k] = add(u)
}
}
return out, withKept
}