| index f665415a6..6f8b2c3bb 100644 |
| --- a/internal/edge/replicaconsole_test.go |
| +++ b/internal/edge/replicaconsole_test.go |
| @@ -271,3 +271,56 @@ func TestReplicaConsoleAddrFromHostEnv(t *testing.T) { |
| t.Fatalf("good value: %v, configured %v", err, e.replicaConsole != nil) |
| } |
| } |
| + |
| +// TestHubRoutesFleetSeedsToConsole: the seeds door rides the same hub-to- |
| +// console hand-off as the replica door, POST only, clean paths only. |
| +func TestHubRoutesFleetSeedsToConsole(t *testing.T) { |
| + var hits atomic.Int32 |
| + console := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + hits.Add(1) |
| + w.Header().Set("X-Upstream-Path", r.URL.RequestURI()) |
| + _, _ = io.WriteString(w, `{}`) |
| + })) |
| + defer console.Close() |
| + reg := openReg(t) |
| + rt := registry.Route{Host: "console.test", App: "console", Unit: "console.service", Kind: "service", Addr: console.Listener.Addr().String(), Status: "ready", Version: "v-test"} |
| + if err := reg.Upsert(rt); err != nil { |
| + t.Fatal(err) |
| + } |
| + e, err := New(reg, nil) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + defer e.probers.Stop() |
| + e.EnableTunnels(NewTunnelHub("tunnel.test", nil)) |
| + const prefix = "/api/fleet/seeds/a/app/h/" |
| + for _, tc := range []struct { |
| + method, path string |
| + hit bool |
| + }{ |
| + {"POST", prefix + "placed", true}, |
| + {"POST", prefix + "failed", true}, |
| + {"GET", prefix + "placed", false}, |
| + {"POST", "/api/fleet/seeds", false}, |
| + {"POST", "/api/fleet/seeds-other/a", false}, |
| + {"POST", "/api/fleet/seeds/../../cli/apps/x", false}, |
| + {"POST", "//api/fleet/seeds/x", false}, |
| + {"POST", "/api/fleet/seeds/%2e%2e/x", false}, |
| + {"POST", "/api/fleet/seeds/a%2Fb/app/h/placed", false}, |
| + } { |
| + t.Run(tc.method+tc.path, func(t *testing.T) { |
| + ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) |
| + defer cancel() |
| + req := httptest.NewRequest(tc.method, "https://tunnel.test"+tc.path, strings.NewReader(`{}`)).WithContext(ctx) |
| + before := hits.Load() |
| + w := httptest.NewRecorder() |
| + e.ServeHTTP(w, req) |
| + if got := hits.Load() > before; got != tc.hit { |
| + t.Fatalf("console hit = %v, want %v (status %d)", got, tc.hit, w.Code) |
| + } |
| + if tc.hit && w.Header().Get("X-Upstream-Path") != tc.path { |
| + t.Fatalf("upstream path: %q", w.Header().Get("X-Upstream-Path")) |
| + } |
| + }) |
| + } |
| +} |