61 lines
2.4 KiB
Go
61 lines
2.4 KiB
Go
package broker
|
|
|
|
import (
|
|
"slices"
|
|
"testing"
|
|
)
|
|
|
|
// 1155/AC1: a module whose manifest reads mesh-controller.checks-running may watch and get every key of the bucket and
|
|
// write none.
|
|
func TestAModuleReadingChecksRunningReadsAndWritesNone(t *testing.T) { // 1155/AC1
|
|
if !slices.Contains(ControllerMirrors(), "checks-running") || BucketName(ControllerSeat, "checks-running") != CheckRunningBucket {
|
|
t.Fatalf("a module cannot name %s in `reads`: %v", CheckRunningBucket, ControllerMirrors())
|
|
}
|
|
perms, err := PermissionsFor(Principal{Kind: KindModule, Node: "one", Module: "mesh-delivery-watchman", PasswordHash: "x",
|
|
Reads: []string{"mesh-controller.checks-running"}})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
stream := "KV_" + CheckRunningBucket
|
|
has(t, perms.Publish, "$JS.API.STREAM.INFO."+stream)
|
|
has(t, perms.Publish, "$JS.API.DIRECT.GET."+stream+".>")
|
|
has(t, perms.Publish, "$JS.API.CONSUMER.CREATE."+stream+".>")
|
|
for _, p := range perms.Publish {
|
|
if SubjectsOverlap(p, "$KV."+CheckRunningBucket+".any.key") {
|
|
t.Errorf("the reading module may write %s through %q", CheckRunningBucket, p)
|
|
}
|
|
}
|
|
}
|
|
|
|
// 1155/AC3: the writers table names checks-running's writer as the build seat's holders, and the rule that a mirror is
|
|
// written by the controller alone names it as the exception, with its reason.
|
|
func TestChecksRunningIsAMirrorWrittenByTheBuildSeatsHolders(t *testing.T) { // 1155/AC3
|
|
why := MirrorsWrittenByAnother["checks-running"]
|
|
if why == "" {
|
|
t.Fatal("the mirrors written by another do not name checks-running with a reason")
|
|
}
|
|
subject := "$KV." + CheckRunningBucket + ".novox.a.7"
|
|
var rows int
|
|
for _, row := range WritersTable {
|
|
for _, s := range row.Subjects {
|
|
if s != "$KV."+CheckRunningBucket+".>" {
|
|
continue
|
|
}
|
|
rows++
|
|
holder := Principal{Kind: KindModule, Module: "builder", Node: "one", Holds: []Seat{{Name: TheBuildSeat}}}
|
|
other := Principal{Kind: KindModule, Module: "mesh-delivery-watchman", Node: "one"}
|
|
if row.Writes == nil || !row.Writes(holder, subject) || row.Writes(other, subject) {
|
|
t.Errorf("%q is not written by the build seat's holders alone", row.State)
|
|
}
|
|
}
|
|
}
|
|
if rows != 1 {
|
|
t.Fatalf("%d rows of the writers table write %s, want one", rows, CheckRunningBucket)
|
|
}
|
|
for m := range MirrorsWrittenByAnother {
|
|
if m != "checks-running" {
|
|
t.Errorf("the mirror %q is written by another and is not checks-running", m)
|
|
}
|
|
}
|
|
}
|