| index e8b5e4fee..cb74a1277 100644 |
| --- a/internal/edge/path_across_import_test.go |
| +++ b/internal/edge/path_across_import_test.go |
| @@ -1,12 +1,13 @@ |
| package edge |
| |
| // Path routes across boxes (#186) and the import gate (seeded-instances spec |
| -// §5.4; whole-branch review R1 P1-1). An uncommitted import is not a front |
| -// route (registry.PathFront), so no box selects its prefixes across boxes: |
| -// the front's own box keeps today's import gate over them, and every other |
| -// box sends the request there or refuses it. pathAcrossScene's boxes: the |
| -// hub (A, the gated front), the tenant (B, the prefix's target) and the |
| -// third (C, neither). |
| +// §5.4; spec §7.6, Paul's ruling of 2026-11-21). A front's import gate |
| +// covers its own route and its same-box prefixes, exactly as on one box |
| +// (TestImportGateCoversPathRoutes). A prefix whose target is a tenant app on |
| +// another box is a separate app: it keeps serving while the front imports. |
| +// pathAcrossScene's boxes: the hub (A, the gated front), the tenant (B, the |
| +// cross-box prefix's target) and the third (C, neither); A also serves |
| +// here.example, the target of a same-box prefix. |
| |
| import ( |
| "net/http" |
| @@ -16,6 +17,25 @@ import ( |
| "github.com/carlosframework/platform/internal/seeds" |
| ) |
| |
| +const ( |
| + acrossHere = "here.example" |
| + acrossHerePrefix = "here" |
| +) |
| + |
| +// addSameBoxPrefix homes here.example on A (published as a route of its |
| +// own) and adds the prefix here -> here.example to the hub's claim on every |
| +// box, as Task 3 derives the rows. |
| +func (s *pathAcrossScene) addSameBoxPrefix(t *testing.T) *acrossApp { |
| + t.Helper() |
| + here := newAcrossApp(t, "here-1") |
| + s.route(t, s.hub, acrossInstance(acrossHere, acrossAcct, "here", here.addr())) |
| + for _, be := range s.boxes() { |
| + s.path(t, be, acrossHub, acrossHerePrefix, acrossHere, acrossAcct, "hub") |
| + } |
| + s.publish(t, s.hub, acrossHere, acrossRouteEntry(acrossAcct, "here", 5)) |
| + return here |
| +} |
| + |
| // gateHubAcross swaps hub.example on A for a gated import row served by app, |
| // reloads A, and republishes A's edges-file row with the marks the shared |
| // predicates give the stored row, exactly as the edges-file writer does |
| @@ -53,68 +73,97 @@ func wantImportRefusal(t *testing.T, res acrossResp, what string) { |
| } |
| } |
| |
| -// The gated front's prefix is closed on every box, open gate and rollback's |
| -// closed gate alike: on A by A's own gate (no dial), on B and C by the |
| -// backhaul to A (the front's home) and A's gate; and a hop for it reaching |
| -// B is refused as stale, never served from the target. Nothing reaches the |
| -// target. Once the legacy row is restored the prefix crosses again. |
| -func TestImportGateCoversPathRoutesAcrossBoxes(t *testing.T) { |
| +// The ruling, open gate and rollback's closed gate alike: on the front's box |
| +// the front's own route and its same-box prefix are refused by the gate, as |
| +// on main (and from B and C, which send them to A); the cross-box prefix is served by its tenant from every box (case |
| +// 2 on A, case 3 on B, case 3 with a remote target on C), and never reaches |
| +// the import's row. After commit everything routes as normal. |
| +func TestImportGateLeavesCrossBoxPrefixesServing(t *testing.T) { |
| s := newPathAcrossScene(t) |
| + here := s.addSameBoxPrefix(t) |
| imported := newAcrossApp(t, "imported-1") |
| token := s.gateHubAcross(t, imported) |
| |
| + var tenantSeen []acrossSeen |
| verified := 0 |
| - closed := func(when string) { |
| + during := func(when string) { |
| t.Helper() |
| - for _, p := range []string{"/acme/x", "//acme/x", "/x/../acme/x"} { |
| - wantImportRefusal(t, s.get(t, s.hub, acrossHub, p), when+": front box "+p) |
| - wantImportRefusal(t, s.get(t, s.tenant, acrossHub, p), when+": target box "+p) |
| - wantImportRefusal(t, s.get(t, s.third, acrossHub, p), when+": third box "+p) |
| + // On the front's box: its own route and the same-box prefix stay |
| + // gated, every spelling. |
| + wantImportRefusal(t, s.get(t, s.hub, acrossHub, "/other"), when+": front's own route") |
| + for _, p := range []string{"/here/x", "//here/x", "/x/../here/x"} { |
| + wantImportRefusal(t, s.get(t, s.hub, acrossHub, p), when+": same-box prefix "+p) |
| } |
| - s.hop(t, s.tenant, acrossHub, "/acme/x", false).wantStale(t) |
| - s.hop(t, s.third, acrossHub, "/acme/x", false).wantStale(t) |
| - if n := s.dialsFrom(s.hub, acrossIPTenant); n != 0 { |
| - t.Fatalf("%s: the front box dialled the target's box %d times", when, n) |
| + // Landing elsewhere they reach the front's box, whose gate refuses |
| + // them. |
| + for _, be := range []*backhaulEdge{s.tenant, s.third} { |
| + wantImportRefusal(t, s.get(t, be, acrossHub, "/other"), when+": front's own route via "+be.box) |
| + wantImportRefusal(t, s.get(t, be, acrossHub, "/here/x"), when+": same-box prefix via "+be.box) |
| } |
| - if n := s.dialsFrom(s.third, acrossIPTenant); n != 0 { |
| - t.Fatalf("%s: the third box dialled the target's box %d times", when, n) |
| + here.wantSeen(t) |
| + // The cross-box prefix keeps serving, from every box. |
| + for _, be := range s.boxes() { |
| + for _, p := range []string{"/acme/x", "//acme/x"} { |
| + s.get(t, be, acrossHub, p).want(t, http.StatusOK, "tenant-1|"+acrossHub+"|"+p) |
| + tenantSeen = append(tenantSeen, acrossSeen{acrossHub, p}) |
| + } |
| } |
| - s.tenantApp.wantSeen(t) |
| + s.tenantApp.wantSeen(t, tenantSeen...) |
| + s.hubApp.wantSeen(t) |
| if n := len(imported.requests()); n != verified { |
| t.Fatalf("%s: the import's row was reached %d times, want only the %d verify requests", when, n, verified) |
| } |
| - s.hubApp.wantSeen(t) |
| } |
| - closed("open gate") |
| + during("open gate") |
| + if n := s.dialsFrom(s.hub, acrossIPTenant); n == 0 { |
| + t.Fatal("the front's box never sent the cross-box prefix to the target's box") |
| + } |
| |
| - // The verify token never opens the prefix's target: no box selects it, |
| - // so on every box the verify is the front's own request, which the |
| - // front's box admits to the import's own row and nothing else (as on |
| - // main, where a prefix naming another box's route fell through to the |
| - // host's own route). |
| - for _, be := range s.boxes() { |
| - req, err := http.NewRequest(http.MethodGet, "https://"+acrossHub+"/acme/x", nil) |
| - if err != nil { |
| - t.Fatal(err) |
| - } |
| - req.Header.Set(ImportVerifyHeader, token) |
| - s.do(t, be, req).want(t, http.StatusOK, "imported-1|"+acrossHub+"|/acme/x") |
| + // The verify token still opens only the import's own row, on the |
| + // front's box; the cross-box prefix is not the import's business. |
| + req, err := http.NewRequest(http.MethodGet, "https://"+acrossHub+"/up", nil) |
| + if err != nil { |
| + t.Fatal(err) |
| } |
| - s.tenantApp.wantSeen(t) |
| - imported.wantSeen(t, acrossSeen{acrossHub, "/acme/x"}, acrossSeen{acrossHub, "/acme/x"}, acrossSeen{acrossHub, "/acme/x"}) |
| - verified = 3 |
| + req.Header.Set(ImportVerifyHeader, token) |
| + s.do(t, s.hub, req).want(t, http.StatusOK, "imported-1|"+acrossHub+"|/up") |
| + verified = 1 |
| |
| - // Rollback, step 1: the gate closes; still closed everywhere. |
| + // Rollback's closed gate holds the same line. |
| if err := s.hub.reg.CloseImportGate(acrossHub, gateSeedID, 1); err != nil { |
| t.Fatal(err) |
| } |
| s.republishHub(t, 7) |
| - closed("closed gate") |
| + during("closed gate") |
| |
| - // Rollback, step 2: the legacy row is back and its prefix crosses again. |
| + // Restore the legacy row: everything routes as normal. |
| if err := s.hub.reg.RestoreImportRoute(acrossHub, gateSeedID); err != nil { |
| t.Fatal(err) |
| } |
| s.republishHub(t, 8) |
| + s.get(t, s.hub, acrossHub, "/other").want(t, http.StatusOK, "hub-1|"+acrossHub+"|/other") |
| + s.get(t, s.hub, acrossHub, "/here/x").want(t, http.StatusOK, "here-1|"+acrossHub+"|/here/x") |
| s.get(t, s.third, acrossHub, "/acme/x").want(t, http.StatusOK, "tenant-1|"+acrossHub+"|/acme/x") |
| } |
| + |
| +// After commit the front, its same-box prefix and its cross-box prefix all |
| +// route as normal, from every box. |
| +func TestImportCommitRoutesPathsAcrossBoxes(t *testing.T) { |
| + s := newPathAcrossScene(t) |
| + here := s.addSameBoxPrefix(t) |
| + imported := newAcrossApp(t, "imported-1") |
| + s.gateHubAcross(t, imported) |
| + s.get(t, s.hub, acrossHub, "/acme/x").want(t, http.StatusOK, "tenant-1|"+acrossHub+"|/acme/x") |
| + |
| + if err := s.hub.reg.CommitImport(acrossHub, gateSeedID); err != nil { |
| + t.Fatal(err) |
| + } |
| + s.republishHub(t, 7) |
| + s.get(t, s.hub, acrossHub, "/other").want(t, http.StatusOK, "imported-1|"+acrossHub+"|/other") |
| + s.get(t, s.hub, acrossHub, "/here/x").want(t, http.StatusOK, "here-1|"+acrossHub+"|/here/x") |
| + here.wantSeen(t, acrossSeen{acrossHub, "/here/x"}) |
| + for _, be := range s.boxes() { |
| + s.get(t, be, acrossHub, "/acme/y").want(t, http.StatusOK, "tenant-1|"+acrossHub+"|/acme/y") |
| + } |
| + s.hubApp.wantSeen(t) |
| +} |