fix(19.3-06): site-cache purge never follows redirects (WR-02)

- the purge client's CheckRedirect returns http.ErrUseLastResponse: a 3xx
  is logged as a failed purge with its status and the bearer token never
  reaches the Location
This commit is contained in:
Jakub Zych
2026-10-15 22:32:32 +02:00
parent d0a580c60c
commit 50a584c757
4 changed files with 32 additions and 5 deletions

View File

@@ -639,3 +639,24 @@ func TestSiteCacheFromApp(t *testing.T) {
t.Fatal("SiteCacheFromApp rebuilt a published purger")
}
}
func TestSiteCachePurgeNoRedirect(t *testing.T) {
logs := captureLogs(t)
target, targetHits := purgeReceiver(t, func(w http.ResponseWriter, _ *http.Request) { _, _ = w.Write([]byte(`{"purged":1}`)) })
srv, hits := purgeReceiver(t, func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Location", target.URL+"/api/__site__/cache/purge")
w.WriteHeader(http.StatusTemporaryRedirect)
})
newTestPurger(t, srv).Purge(context.Background(), "post", "moved")
if len(hits()) != 1 {
t.Fatalf("%d requests to the purge URL, want 1", len(hits()))
}
if got := targetHits(); len(got) != 0 {
t.Fatalf("the redirect target received %d requests: %#v", len(got), got)
}
lines := logs.lines()
if len(lines) != 1 || !strings.Contains(lines[0], "level=WARN") || !strings.Contains(lines[0], `msg="cooler: site cache purge failed"`) || !strings.Contains(lines[0], "status=307") {
t.Fatalf("log = %q, want one failed purge with status=307", lines)
}
assertNoToken(t, logs)
}