Files
mesh-controller/internal/broker/witness_grants_test.go
T
jochen d9289ef6d4 Gate a release plan's first machine and roll a failed build back there (hq ADR 0236)
A build that reported applied was sent everywhere; one that then did nothing, served
no tools or broke its machine's word reached every machine. Now the first machine is
judged by the component's health (the core's definitions, as doctor probes H-*, or a
module's own) three times over two minutes within ten; a failing gate puts the previous
build back there once, marks the build, and says it as a condition and an event.
Upgrades roll out by default; the bus is a planned step; a module deleted at its
source is not built (the public-acme plan failure).
2026-10-06 18:56:54 +02:00

38 lines
1.1 KiB
Go

package broker
import (
"slices"
"testing"
)
// Every machine's node-engine may ask its own node tools PING; the one running the controller may read
// the lease's key, and nothing else of the bucket (novox/hq ADR 0236).
func TestTheWitnessIsGrantedWhatItReadsAndNoMore(t *testing.T) {
users, err := Users(Records{Nodes: []string{"control", "edge"},
Assigned: map[string][]Declared{"control": {{Module: "mesh-controller"}}}})
if err != nil {
t.Fatal(err)
}
lease := "$JS.API.DIRECT.GET.KV_mesh-controller_lease.$KV.mesh-controller_lease.holder"
for _, u := range users {
if u.Kind != KindNode {
continue
}
perms, err := PermissionsFor(u)
if err != nil {
t.Fatal(err)
}
if !slices.Contains(perms.Publish, "$SRV.PING.node-tools."+u.Node) {
t.Errorf("%s may not ask its node tools: %v", u.Node, perms.Publish)
}
if got := slices.Contains(perms.Publish, lease); got != (u.Node == "control") {
t.Errorf("%s may read the lease: %v", u.Node, got)
}
for _, p := range perms.Publish {
if p == "$KV.mesh-controller_lease.>" || p == "$KV.mesh-controller_lease.holder" {
t.Errorf("%s may write the lease", u.Node)
}
}
}
}