MCPcopy Create free account
hub / github.com/easyp-tech/server / TestUpstreamError_OnProviderFailure

Function TestUpstreamError_OnProviderFailure

internal/connect/api_test.go:935–973  ·  view source on GitHub ↗

TestUpstreamError_OnProviderFailure pins the 502 mapping: when the back-end provider (artifactory/git/...) fails, the proxy must surface that as a 502 Bad Gateway, not 500 Internal Server Error, so clients can tell "we are broken" from "they are broken".

(t *testing.T)

Source from the content-addressed store, hash-verified

933// that as a 502 Bad Gateway, not 500 Internal Server Error, so clients
934// can tell "we are broken" from "they are broken".
935func TestUpstreamError_OnProviderFailure(t *testing.T) {
936 p := &mockProvider{
937 meta: content.Meta{Commit: "deadbeef", DefaultBranch: "main"},
938 files: []content.File{
939 {Path: "a.proto", Data: []byte("syntax = \"proto3\";"), Hash: shake256.Hash{}},
940 },
941 err: errUpstream,
942 }
943 mux := testMux(p)
944 server := httptest.NewServer(mux)
945 defer server.Close()
946
947 body := buildGetCommitsRequest("owner", "repo")
948 resp, err := http.Post(
949 server.URL+"/buf.registry.module.v1.CommitService/GetCommits",
950 "application/proto",
951 bytes.NewReader(body),
952 )
953 if err != nil {
954 t.Fatalf("request failed: %v", err)
955 }
956 defer resp.Body.Close()
957
958 if resp.StatusCode != http.StatusBadGateway {
959 respBody, _ := io.ReadAll(resp.Body)
960 t.Fatalf("status = %d, want 502; body: %s", resp.StatusCode, respBody)
961 }
962 respBody, _ := io.ReadAll(resp.Body)
963 // Body should describe which owner/repo failed so an operator can
964 // identify the request from client-side logs, but the raw upstream
965 // error message must NOT leak into the body — it goes into the
966 // structured server log only (as the "upstream_error" attribute).
967 if !bytes.Contains(respBody, []byte("owner/repo")) {
968 t.Errorf("body %q does not identify failing module", respBody)
969 }
970 if bytes.Contains(respBody, []byte(errUpstream.Error())) {
971 t.Errorf("body %q leaks internal upstream error — should be in logs only", respBody)
972 }
973}
974
975// TestHandlerError_IncludesServer pins the funnel-level addition of the
976// "server" attribute. Every error log emitted via logHandlerError must

Callers

nothing calls this directly

Calls 3

testMuxFunction · 0.85
buildGetCommitsRequestFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected