MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestHandleProxyDoesNotCacheErrorResponses

Function TestHandleProxyDoesNotCacheErrorResponses

cmd/cache-proxy/proxy_test.go:713–740  ·  view source on GitHub ↗

TestHandleProxyDoesNotCacheErrorResponses: a transient origin error must not poison the cache. The next request for the same key has to hit the origin again — otherwise an ExpiredToken error would persist past the credential refresh that fixes it.

(t *testing.T)

Source from the content-addressed store, hash-verified

711 })
712 }
713}
714
715// TestHandleProxyForwardsOrigin400Verbatim is the case the user actually
716// hit: S3 returns 400 with an XML envelope (<Code>ExpiredToken</Code>) and
717// DuckDB needs to see *that* body and *that* status, not a generic 502 with
718// a Go-formatted error string. Without verbatim passthrough the error class
719// (4xx terminal vs 5xx retriable) is lost and httpfs retries non-retriable
720// auth failures.
721func TestHandleProxyForwardsOrigin400Verbatim(t *testing.T) {
722 proxy := newTestProxy(t)
723 const errBody = `<?xml version="1.0" encoding="UTF-8"?>
724<Error><Code>ExpiredToken</Code><Message>The provided token has expired.</Message></Error>`
725 _, originURL := newTestServer(t, func(w http.ResponseWriter, r *http.Request) {
726 w.Header().Set("Content-Type", "application/xml")
727 w.Header().Set("X-Amz-Request-Id", "TESTREQID123")
728 w.WriteHeader(http.StatusBadRequest)
729 _, _ = w.Write([]byte(errBody))
730 })
731 rec := doForwardProxyRequest(proxy, "GET", originURL+"/bucket/expired.parquet", http.Header{"Range": []string{"bytes=0-1023"}})
732
733 if rec.Code != http.StatusBadRequest {
734 t.Fatalf("status = %d, want 400 forwarded verbatim", rec.Code)
735 }
736 if got := rec.Body.String(); got != errBody {
737 t.Errorf("body mismatch:\n got = %q\nwant = %q", got, errBody)
738 }
739 if ct := rec.Header().Get("Content-Type"); ct != "application/xml" {
740 t.Errorf("Content-Type = %q, want application/xml so DuckLake parses it as an S3 error envelope", ct)
741 }
742 if rid := rec.Header().Get("X-Amz-Request-Id"); rid != "TESTREQID123" {
743 t.Errorf("X-Amz-Request-Id = %q, want TESTREQID123 (preserved for debugging)", rid)

Callers

nothing calls this directly

Calls 5

newTestProxyFunction · 0.85
newTestServerFunction · 0.85
doForwardProxyRequestFunction · 0.85
WriteMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected