fleet-routes-followups: e2e deferred minors (#457 1a, Task 13)
TestFleetAppServesThroughTheHub: - quieter first dial: the hub's pass (and so its reload, which loads box-1's token) runs before the box first dials, so the first dial is no longer refused 401 and retried; the test now fails if it is. - step 2 pins which edge drew the login form: the one GET is metered once on the hub and once on the box. - step 3 has an upper bound: 5 admitted, 6 at most with one refill. A mutation admitting two over a path rule's burst (7) passed the old lower-bound-only check and fails this one. - step 4's alias-pass inputs come through production folds: the owners from Registry.FleetOwners, and the report's Region from the BoxProvisionConfig the pass runs under (it was omitted). - step 6 asserts the instance catch-all's name (shop.shops.example.com) is refused at the handshake right after the trash, before the hub's alias pass runs again, with its admission checked just before the trash. A mutation keeping an alias's previous entry once its primary goes is caught only by this. Left as is: the fleetapi store door answers 404 to the box's alias-pass read of status/boxes/; a production fleet box would get the same answer.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+34
−14
fleet_public_routes_e2e_test.go+34 −14
diff --git a/fleet_public_routes_e2e_test.go b/fleet_public_routes_e2e_test.go| index 66ff7935f..ee030bdd9 100644 |
| --- a/fleet_public_routes_e2e_test.go |
| +++ b/fleet_public_routes_e2e_test.go |
| @@ -514,10 +514,12 @@ func TestFleetAppServesThroughTheHub(t *testing.T) { |
| t.Fatalf("box reload: %v", err) |
| } |
| } |
| + // The hub's pass reloads its edge, which loads box-1's token, before |
| + // the box first dials: a dial ahead of that reload is refused 401 and |
| + // retried, which only adds noise. |
| + hubPass() |
| stopBox := dial(boxToken[1]) |
| t.Cleanup(stopBox) |
| - |
| - hubPass() |
| boxPass() |
| // The hub admits the instance's name: a fresh connection's handshake |
| // with it as SNI succeeds only while hub.Allowed says yes. |
| @@ -562,12 +564,22 @@ func TestFleetAppServesThroughTheHub(t *testing.T) { |
| } |
| time.Sleep(100 * time.Millisecond) |
| } |
| + if strings.Contains(tap.String(), "box-1: tunnel dial: tunnel register: 401") { |
| + t.Fatalf("box-1's first dial was refused: the hub had not loaded its token yet; the log:\n%s", tap.String()) |
| + } |
| // --- step 2: the gate, through the hub's TLS listener ------------------- |
| + // The fleet edge draws the login form, not the hub: the one request is |
| + // metered on both edges, so it crossed the tunnel to be answered. |
| + hubMeter.Drain() |
| + boxMeter.Drain() |
| resp, page := hubURL.mustDo(http.MethodGet, shopHost, "/up", nil, nil) |
| if !isLoginForm(resp, page) { |
| t.Fatalf("GET /up = %d %q, want the fleet edge's login form", resp.StatusCode, page) |
| } |
| + if h, b := hubMeter.Drain()[shopHost], boxMeter.Drain()[shopHost]; h.Requests != 1 || b.Requests != 1 { |
| + t.Fatalf("the login form's request was metered %d times on the hub and %d on the box, want once on each: the box draws the form", h.Requests, b.Requests) |
| + } |
| resp, body := hubURL.login(shopHost, page, "not the password") |
| if resp.StatusCode != http.StatusUnauthorized || !strings.Contains(body, "That password is not right.") || len(resp.Cookies()) != 0 { |
| t.Fatalf("wrong password = %d %v %q, want the wrong-password page and no cookie", resp.StatusCode, resp.Cookies(), body) |
| @@ -604,8 +616,9 @@ func TestFleetAppServesThroughTheHub(t *testing.T) { |
| t.Fatalf("GET /limited %d = %d %q, want the app's 200 or the hub's 429", i+1, resp.StatusCode, body) |
| } |
| } |
| - if refused == nil || oks < 5 { |
| - t.Fatalf("%d answered before a refusal (%v), want the burst of 5 and then a 429", oks, refused != nil) |
| + // One token refills a second, so a slow loop may see a sixth; never more. |
| + if refused == nil || oks < 5 || oks > 6 { |
| + t.Fatalf("%d answered before a refusal (%v), want the burst of 5 (6 at most, with one refill) and then a 429", oks, refused != nil) |
| } |
| if refused.Header.Get("Retry-After") == "" || refused.Header.Get("Cache-Control") != "no-store" || |
| refusedBody != "Too many requests. Try again in a moment." { |
| @@ -622,21 +635,20 @@ func TestFleetAppServesThroughTheHub(t *testing.T) { |
| const parent = "shops.example.com" |
| mustCarlos("domains", "attach", "--app", "shop", "--account", owner, parent) |
| mustCarlos("domains", "attach", "--app", "shop", "--account", owner, "*."+parent) |
| - aliasPass := func(s release.Store, reg *registry.Registry, hubSide bool) domains.AliasReport { |
| + aliasPass := func(s release.Store, reg *registry.Registry, env func(string) string, hubSide bool) domains.AliasReport { |
| t.Helper() |
| // What the agent's alias pass (aliasPassReporting) hands the |
| - // domains package: the deployment's routes from the edges files, and |
| - // the edge's own fleet-arm refusals over the listing. |
| + // domains package: the deployment's routes from the edges files, |
| + // the box's region from the pass config it runs under, and the |
| + // edge's own fleet-arm refusals over the listing, judged by the |
| + // owners the edge reads (Registry.FleetOwners). |
| deploymentRoutes, whole := edgesfile.DeploymentRoutesComplete(ctx, s, time.Now()) |
| - fleets, err := reg.ListFleets() |
| + owners, err := reg.FleetOwners() |
| if err != nil { |
| t.Fatal(err) |
| } |
| - owners := map[string]string{} |
| - for _, f := range fleets { |
| - owners[f.Name] = f.Account |
| - } |
| rep := domains.AliasReport{DeploymentRoutesPartial: deploymentRoutes != nil && !whole, |
| + Region: host.BoxProvisionConfig(reg, env, nil, nil).Region, |
| FleetRefused: func(routes []registry.Route) map[string]string { |
| return edge.FleetArmVerdict(routes, owners, hubSide, hubSide).Refused |
| }} |
| @@ -646,12 +658,12 @@ func TestFleetAppServesThroughTheHub(t *testing.T) { |
| return rep |
| } |
| hubPass() |
| - aliasPass(store, hubReg, true) |
| + aliasPass(store, hubReg, hubEnv, true) |
| if err := hub.Reload(); err != nil { |
| t.Fatal(err) |
| } |
| boxPass() |
| - aliasPass(boxStore, boxReg, false) |
| + aliasPass(boxStore, boxReg, boxEnv, false) |
| if err := box.Reload(); err != nil { |
| t.Fatal(err) |
| } |
| @@ -710,6 +722,9 @@ func TestFleetAppServesThroughTheHub(t *testing.T) { |
| boxPass() // the box's pass runs over the door with its new token |
| // --- step 6: trash the app ---------------------------------------------- |
| + if err := hubURL.handshake(slugHost); err != nil { |
| + t.Fatalf("before the trash, a TLS handshake with SNI %s: %v, want it admitted (the catch-all's name serves)", slugHost, err) |
| + } |
| mustCarlos("apps", "delete", "--account", owner, "shop") |
| if rt, err := hubReg.Get(shopHost); err != nil || rt == nil || !rt.IsForward() { |
| t.Fatalf("before the hub's pass, the row at %s = %+v (%v), want the forward row still there: only the hub's pass retires it", shopHost, rt, err) |
| @@ -721,6 +736,11 @@ func TestFleetAppServesThroughTheHub(t *testing.T) { |
| if err := hubURL.handshake(shopHost); err == nil { |
| t.Fatalf("a fresh TLS handshake with SNI %s succeeded after the app was trashed, want it refused", shopHost) |
| } |
| + // The catch-all's name goes with its primary, at once: the hub's alias |
| + // pass has not run since, so its alias row still names the gone row. |
| + if err := hubURL.handshake(slugHost); err == nil { |
| + t.Fatalf("a fresh TLS handshake with SNI %s (the instance catch-all's name) succeeded after the app was trashed, want it refused", slugHost) |
| + } |
| // --- step 7: another account's record on this fleet --------------------- |
| // No row and no admission. Whether the host reaches the hub's edges file |