| new file mode 100644 |
| index 000000000..5b174770e |
| --- /dev/null |
| +++ b/internal/console/hunt_H4-M8_test.go |
| @@ -0,0 +1,60 @@ |
| +package console |
| + |
| +// Hunt H4-M8 (verifier, opus): the app's /.carlos/instances answer is a |
| +// redirect, and the console's instance fetcher (production wiring: cmd never |
| +// sets Config.AppClient, so newInstanceFetcher's default http.Client is used) |
| +// follows it to a host the tenant chose. Here the target is a second loopback |
| +// server standing in for a service on the console host's own network. |
| +// |
| +// The assertion is the SECURE behaviour: the internal service is never hit. |
| + |
| +import ( |
| + "net/http" |
| + "net/http/httptest" |
| + "strings" |
| + "sync/atomic" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/registry" |
| +) |
| + |
| +func TestHunt_H4_M8_InstanceReportFollowsRedirect(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + c := signInPaul(t, fx) |
| + |
| + // The "internal" service: it records every hit, and answers in the one |
| + // shape the fetcher reflects onto the page. |
| + var internalHits atomic.Int64 |
| + var internalPath atomic.Value |
| + internal := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + internalHits.Add(1) |
| + internalPath.Store(r.URL.RequestURI()) |
| + w.Write([]byte(`[{"slug":"internal-secret-row","detail":"served by the internal service"}]`)) |
| + })) |
| + t.Cleanup(internal.Close) |
| + |
| + // The tenant's app: its report endpoint redirects into the internal one. |
| + app := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + if r.URL.Path != InstancesPath { |
| + http.NotFound(w, r) |
| + return |
| + } |
| + http.Redirect(w, r, internal.URL+"/admin/anything?probe=1", http.StatusFound) |
| + })) |
| + t.Cleanup(app.Close) |
| + host := strings.TrimPrefix(app.URL, "http://") |
| + fx.addRoute(t, registry.Route{Host: host, Kind: "instance", Status: "ready", App: "kass"}) |
| + |
| + status, _, body := get(t, c, fx.u("/apps/kass/instances")) |
| + if status != http.StatusOK { |
| + t.Fatalf("instances page = %d", status) |
| + } |
| + if n := internalHits.Load(); n != 0 { |
| + p, _ := internalPath.Load().(string) |
| + t.Errorf("H4-M8: the console followed the app's redirect and hit the internal service %d time(s) (GET %s); want 0", |
| + n, p) |
| + } |
| + if strings.Contains(body, "internal-secret-row") { |
| + t.Errorf("H4-M8: the internal service's slug-shaped answer was rendered on the tenant's instances page") |
| + } |
| +} |