package broker import ( "strings" "testing" ) func hasSubject(list []string, s string) bool { for _, x := range list { if x == s { return true } } return false } func composedFor(t *testing.T, module string) (pub, sub []string) { t.Helper() perms, err := PermissionsFor(Principal{Kind: KindModule, Node: "one", Module: module}) if err != nil { t.Fatal(err) } return perms.Publish, perms.Subscribe } func TestTheWatchmanIsGrantedNothingOnTheBuildSeats(t *testing.T) { // 1908: a waiting ask has no pulse pub, sub := composedFor(t, WatchmanModule) for _, s := range append(append([]string{}, pub...), sub...) { if strings.Contains(s, "node-build") || strings.Contains(s, "NODE_BUILD") { t.Errorf("the watchman is granted %s on a build seat", s) } } } func containsAny(list []string, sub string) bool { for _, x := range list { if strings.Contains(x, sub) { return true } } return false } func TestTheViewReadsTheBuildSeatsWorkersByNameAndPublishesNoAsk(t *testing.T) { // 1887/A8a pub, sub := composedFor(t, ViewModule) for _, s := range []string{ "$JS.API.STREAM.INFO.SEAT_NODE_BUILD_GO", "$JS.API.STREAM.MSG.GET.SEAT_NODE_BUILD_GO", "$JS.API.CONSUMER.INFO.SEAT_NODE_BUILD_GO.SEAT_NODE_BUILD_GO_CHECK_worker", "$JS.API.CONSUMER.INFO.SEAT_NODE_BUILD_NODE.SEAT_NODE_BUILD_NODE_RECHECK_worker", "$JS.API.CONSUMER.INFO.SEAT_NODE_BUILD_IMAGE.SEAT_NODE_BUILD_IMAGE_DELIVERY_worker", "$JS.API.STREAM.MSG.GET.SEAT_NODE_BUILD_IMAGE", } { if !hasSubject(pub, s) { t.Errorf("the view cannot request %s", s) } } for _, s := range append(append([]string{}, pub...), sub...) { if strings.Contains(s, "mesh.seat.node-build") || (strings.Contains(s, "NODE_BUILD") && (strings.Contains(s, "MSG.NEXT") || strings.Contains(s, "$JS.ACK") || strings.Contains(s, "CONSUMER.CREATE"))) { t.Errorf("the view may publish an ask or pull and acknowledge: %s", s) } } perms, _ := PermissionsFor(Principal{Kind: KindModule, Node: "one", Module: ViewModule}) for _, s := range []string{"mesh.seat.node-build-go.accept.check", "$JS.API.CONSUMER.MSG.NEXT.SEAT_NODE_BUILD_GO.SEAT_NODE_BUILD_GO_CHECK_worker"} { if MayPublish(perms, s) { t.Errorf("the view may publish %s", s) } } if other, _ := composedFor(t, "shop"); containsAny(other, "SEAT_NODE_BUILD") { t.Errorf("another module reads the build seats: %v", other) } }