TestFetchOriginPreservesSignedHeaders confirms the proxy forwards SigV4 headers verbatim (we can't verify against real S3 here, but we can verify the wire representation reaches the origin).
(t *testing.T)
| 857 | } |
| 858 | } |
| 859 | |
| 860 | func TestHandlePeerHasAndGet(t *testing.T) { |
| 861 | proxy := newTestProxy(t) |
| 862 | |
| 863 | key := strings.Repeat("c", 64) |
| 864 | body := []byte("peer-cached-payload") |
| 865 | if _, err := proxy.store.PutStream(key, bytes.NewReader(body)); err != nil { |
| 866 | t.Fatalf("seed PutStream: %v", err) |
| 867 | } |
| 868 | |
| 869 | // /cache/has → 200 for known key |
| 870 | req := httptest.NewRequest("GET", "/cache/has?key="+key, nil) |
| 871 | rec := httptest.NewRecorder() |
| 872 | proxy.HandlePeerHas(rec, req) |
| 873 | if rec.Code != http.StatusOK { |
| 874 | t.Errorf("HandlePeerHas known key: status = %d, want 200", rec.Code) |
| 875 | } |
| 876 | |
| 877 | // /cache/has → 404 for unknown key |
| 878 | missing := strings.Repeat("d", 64) |
| 879 | req = httptest.NewRequest("GET", "/cache/has?key="+missing, nil) |
| 880 | rec = httptest.NewRecorder() |
| 881 | proxy.HandlePeerHas(rec, req) |
| 882 | if rec.Code != http.StatusNotFound { |
| 883 | t.Errorf("HandlePeerHas missing key: status = %d, want 404", rec.Code) |
| 884 | } |
| 885 | |
| 886 | // /cache/get → 200 + body for known key |
| 887 | req = httptest.NewRequest("GET", "/cache/get?key="+key, nil) |
| 888 | rec = httptest.NewRecorder() |
| 889 | proxy.HandlePeerGet(rec, req) |
| 890 | if rec.Code != http.StatusOK { |
| 891 | t.Errorf("HandlePeerGet: status = %d, want 200", rec.Code) |
nothing calls this directly
no test coverage detected