Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

test: no guard pins that a capability-gated route refuses on the bridge front, which is why the same screencast gap has now been produced twice (PIN-245)

Luigi Agosti5beab47cd38c
diff --git a/internal/handlers/handlers_routes_test.go b/internal/handlers/handlers_routes_test.go
index cd321dab..3477405c 100644
--- a/internal/handlers/handlers_routes_test.go
+++ b/internal/handlers/handlers_routes_test.go
@@ -147,10 +147,26 @@ func gatedCatalogRoutes(t *testing.T) []routes.Endpoint {
seen[ep.Capability] = true
}
- // Vacuity floors, both derived. The count floor is the smaller of the two claims: it
- // catches an enumeration that silently stopped matching. The capability cross-check comes
- // from a DIFFERENT accessor, so a Core() that lost its capability field entirely cannot
- // leave this passing on a shrunken set.
+ // THREE FLOORS, and each catches a different thing — stated exactly, because a guard whose
+ // comment overstates its own coverage is what stops the next reader strengthening it.
+ //
+ // 1. The count floor is a HAND-PICKED number. It catches an enumeration that stopped
+ // matching wholesale. It cannot catch a population that shrinks by a few routes, and
+ // it is not evidence of anything above that number.
+ // 2. CapabilityEndpoints() is a different FUNCTION but not a different SOURCE: it walks
+ // the same coreEndpoints slice through the same Capability != CapNone predicate. So it
+ // only bites when a capability loses ALL of its routes — de-declare one route of three
+ // and both this and the count floor stay green.
+ // 3. endpointSecurityStates() is the genuinely independent one: a hand-maintained
+ // capability -> paths map that /health reports to operators. A route de-declared in the
+ // catalogue disappears from 1 and 2 together and is still listed here, so it reds by
+ // name. That was the measured evasion — setting two record routes to CapNone and
+ // reverting their handler guards left this guard green on floors 1 and 2 alone.
+ //
+ // The cross-check is ONE-DIRECTIONAL by design: it asks whether everything /health calls
+ // gated is actually driven here. Deleting a route from BOTH lists still passes, because
+ // then no source claims it is gated — that is a decision to stop gating a route, not a
+ // drift between two records of the same decision, and it is not this guard's question.
if len(gated) < 20 {
t.Fatalf("only %d capability-gated routes in the catalogue; the enumeration has stopped matching and this guard would pass over almost nothing", len(gated))
}
@@ -159,12 +175,63 @@ func gatedCatalogRoutes(t *testing.T) []routes.Endpoint {
t.Errorf("capability %q gates endpoints but no catalogue route carries it, so nothing here drives it", capability)
}
}
+ assertHealthGatedRoutesArePresent(t, gated)
return gated
}
+// assertHealthGatedRoutesArePresent cross-checks the enumerated population against the routes
+// /health tells operators are gated. The two lists are maintained independently — one is the
+// catalogue's Capability field, the other a literal map in security.go — so a route that loses
+// its declaration in one is still named by the other.
+//
+// Only ROOT forms are compared: the health map also lists /tabs/{id}/ and /instances/ spellings,
+// which this guard drives through their root form or not at all. The pairing is by SETTING, not
+// by the map's key names, so an entry with no catalogue capability behind it — clipboard, whose
+// gate is local — excludes itself rather than needing an exemption.
+func assertHealthGatedRoutesArePresent(t *testing.T, gated []routes.Endpoint) {
+ t.Helper()
+
+ driven := map[string]bool{}
+ for _, ep := range gated {
+ driven[ep.Route()] = true
+ }
+
+ settingCapability := map[string]routes.Capability{}
+ for capability := range routes.CapabilityEndpoints() {
+ if meta, ok := routes.Meta(capability); ok && meta.Setting != "" {
+ settingCapability[meta.Setting] = capability
+ }
+ }
+ if len(settingCapability) == 0 {
+ t.Fatal("no capability reports a setting, so this cross-check would compare against nothing")
+ }
+
+ h := New(&mockBridge{}, &config.RuntimeConfig{}, nil, nil, nil)
+ checked := 0
+ for name, state := range h.endpointSecurityStates() {
+ if _, ok := settingCapability[state.Setting]; !ok {
+ continue
+ }
+ for _, path := range state.Paths {
+ if strings.Contains(path, "/tabs/{id}/") || strings.Contains(path, "/instances/") {
+ continue
+ }
+ checked++
+ if !driven[path] {
+ t.Errorf("/health reports %q as gated under %q, but the catalogue no longer declares a capability for it, so this guard does not drive it — re-declare the route's capability, or remove it from endpointSecurityStates if it genuinely stopped being gated", path, name)
+ }
+ }
+ }
+ if checked == 0 {
+ t.Fatal("no root-form path was cross-checked; the health map or its path spellings changed and this floor would pass over nothing")
+ }
+}
+
// driveBridgeRoute issues one request through the REAL bridge mux and returns what a client
-// would receive. reached=false means the handler ran past the gate and then failed on the
-// mock bridge, which is still an answer to "was it refused".
+// would receive. answered=false means the handler ran past the gate and then panicked on the
+// mock bridge, so there is no response to judge — but getting that far is itself proof it was
+// not refused, which is why the negative control treats it as a pass and the disabled run does
+// not: there the recorder is still at 200 and the row fails on the status.
//
// The request runs under a deadline because an unguarded handler must FAIL this guard rather
// than hang it: with no browser behind the mock, a route that blocks would otherwise stall
@@ -178,13 +245,13 @@ func driveBridgeRoute(t *testing.T, cfg *config.RuntimeConfig, ep routes.Endpoin
method, path, _ := strings.Cut(ep.Route(), " ")
w := httptest.NewRecorder()
- reached := true
+ answered := true
done := make(chan struct{})
go func() {
defer close(done)
defer func() {
if recover() != nil {
- reached = false
+ answered = false
}
}()
mux.ServeHTTP(w, httptest.NewRequest(method, concreteRoutePath(path), strings.NewReader("{}")))
@@ -194,7 +261,7 @@ func driveBridgeRoute(t *testing.T, cfg *config.RuntimeConfig, ep routes.Endpoin
case <-time.After(5 * time.Second):
t.Fatalf("%s did not answer within the deadline; a capability gate answers before any browser work, so this route is reaching for one", ep.Route())
}
- return w.Code, w.Body.String(), reached
+ return w.Code, w.Body.String(), answered
}
// concreteRoutePath substitutes a value for each wildcard segment, so the guard sends what a
@@ -250,7 +317,8 @@ func TestEveryCapabilityGatedRouteRefusesOnTheBridgeFrontWhenDisabled(t *testing
// The negative control: the gate has to be a gate, not a removal. With the capability on, no
// route in the same population answers the capability refusal. A handler that panics on the
-// mock bridge counts as reached — it got past the gate, which is the whole claim here.
+// mock bridge got past the gate, which is the whole claim here, so it has nothing to judge and
+// is not a failure.
func TestNoCapabilityGatedRouteRefusesWhenTheCapabilityIsEnabled(t *testing.T) {
enabled := &config.RuntimeConfig{
AllowEvaluate: true,
@@ -266,8 +334,8 @@ func TestNoCapabilityGatedRouteRefusesWhenTheCapabilityIsEnabled(t *testing.T) {
for _, ep := range gatedCatalogRoutes(t) {
t.Run(ep.Route(), func(t *testing.T) {
meta, _ := routes.Meta(ep.Capability)
- status, body, reached := driveBridgeRoute(t, enabled, ep)
- if !reached {
+ status, body, answered := driveBridgeRoute(t, enabled, ep)
+ if !answered {
return
}
if status == http.StatusForbidden && strings.Contains(body, meta.DisabledCode) {