package console import ( "errors" "fmt" "net/http" "net/http/httptest" "strings" "testing" "github.com/carlosframework/platform/internal/hostclaim" "github.com/carlosframework/platform/internal/hostops" ) func TestPlan9ClaimResponseDoesNotExposeInternalErrors(t *testing.T) { for _, tc := range []struct { err error status int }{ {fmt.Errorf("private-bucket/key: %w", hostops.ErrPending), http.StatusConflict}, {fmt.Errorf("private-bucket/key: %w", hostclaim.ErrConflict), http.StatusConflict}, {errors.New("private-bucket/key: secret backend failure"), http.StatusServiceUnavailable}, } { ref := claimResponseRefusal(tc.err) if ref.Status != tc.status || strings.Contains(ref.Msg, "private-bucket") || strings.Contains(ref.Msg, "secret") { t.Fatalf("unsafe response: %+v", ref) } } } func TestPlan9BrowserClaimAcceptanceIsHTML(t *testing.T) { fx := newConsoleFixture(t) r := httptest.NewRequest(http.MethodPost, "/apps/kass/domains/attach", nil) w := httptest.NewRecorder() fx.srv.renderClaimAccepted(w, r, "", "", "") if w.Code != http.StatusAccepted || !strings.HasPrefix(w.Header().Get("Content-Type"), "text/html") { t.Fatalf("response = %d %s", w.Code, w.Body.String()) } body := w.Body.String() if strings.Contains(body, "") || !strings.Contains(body, "<operation>") || w.Header().Get("Retry-After") != "2" { t.Fatalf("unsafe or unhelpful acceptance: %s", body) } }