test: proxy HTTP error branches (403/502) + revalidation upstream error

This commit is contained in:
2026-07-03 13:35:40 +10:00
parent 2658167346
commit 6029f19b86
2 changed files with 54 additions and 0 deletions
+26
View File
@@ -504,6 +504,32 @@ func TestServerVirtualLocalPyPIMerge(t *testing.T) {
}
}
func TestServerProxyErrors(t *testing.T) {
requireStack(t)
// Blocklisted path -> 403 propagated through handleProxy.
block := fmt.Sprintf(`{"name":"srv-block","package_type":"generic","repo_type":"remote","base_url":%q,"blocklist":["\\.secret$"],"stale_on_error":true}`, upstream.URL)
req(t, "POST", "/api/v2/remotes", block)
defer req(t, "DELETE", "/api/v2/remotes/srv-block", "")
if resp, _ := req(t, "GET", "/api/v1/remote/srv-block/x.secret", ""); resp.StatusCode != 403 {
t.Errorf("blocklisted GET = %d, want 403", resp.StatusCode)
}
rq, _ := http.NewRequest("HEAD", testTS.URL+"/v2/srv-block/x.secret", nil)
if resp, err := http.DefaultClient.Do(rq); err == nil {
resp.Body.Close()
if resp.StatusCode != 403 {
t.Errorf("blocklisted HEAD = %d, want 403", resp.StatusCode)
}
}
// Unreachable upstream, no stale copy -> 502 bad gateway.
dead := `{"name":"srv-dead","package_type":"generic","repo_type":"remote","base_url":"http://127.0.0.1:1","stale_on_error":false}`
req(t, "POST", "/api/v2/remotes", dead)
defer req(t, "DELETE", "/api/v2/remotes/srv-dead", "")
if resp, _ := req(t, "GET", "/api/v1/remote/srv-dead/x", ""); resp.StatusCode != 502 {
t.Errorf("dead upstream GET = %d, want 502", resp.StatusCode)
}
}
func TestServerNotFound(t *testing.T) {
requireStack(t)
if resp, _ := req(t, "GET", "/api/v2/remotes/does-not-exist", ""); resp.StatusCode != 404 {