Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions internal/api/handlers/management/api_tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,13 +649,7 @@ func (h *Handler) apiCallTransport(auth *coreauth.Auth) http.RoundTripper {
}
}

transport, ok := http.DefaultTransport.(*http.Transport)
if !ok || transport == nil {
return &http.Transport{Proxy: nil}
}
clone := transport.Clone()
clone.Proxy = nil
return clone
return http.DefaultTransport
}

func buildProxyTransport(proxyStr string) *http.Transport {
Expand Down
55 changes: 55 additions & 0 deletions internal/api/handlers/management/api_tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,61 @@ func TestAPICallTransportInvalidAuthFallsBackToGlobalProxy(t *testing.T) {
t.Fatalf("proxy URL = %v, want http://global-proxy.example.com:8080", proxyURL)
}
}
func TestAPICallTransport_InheritsEnvironmentProxyWhenNoExplicitProxyConfigured(t *testing.T) {
t.Setenv("HTTP_PROXY", "http://127.0.0.1:18080")
t.Setenv("HTTPS_PROXY", "http://127.0.0.1:18443")
t.Setenv("NO_PROXY", "")

h := &Handler{
cfg: &config.Config{
SDKConfig: sdkconfig.SDKConfig{ProxyURL: ""},
},
}

rt := h.apiCallTransport(&coreauth.Auth{ProxyURL: ""})
transport, ok := rt.(*http.Transport)
if ok && transport.Proxy != nil {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Fail test when apiCallTransport does not expose env proxy

This guard makes the new regression test pass even when apiCallTransport returns the wrong transport (for example, a non-*http.Transport or a transport with Proxy == nil), because execution falls through to checking http.ProxyFromEnvironment directly instead of asserting on rt. In that scenario, the test validates only the standard library behavior and would miss a real regression in apiCallTransport itself.

Useful? React with 👍 / 👎.

tests := []struct {
name string
raw string
want string
}{
{name: "http request uses HTTP_PROXY", raw: "http://example.com", want: "http://127.0.0.1:18080"},
{name: "https request uses HTTPS_PROXY", raw: "https://example.com", want: "http://127.0.0.1:18443"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
req, err := http.NewRequest("GET", tt.raw, nil)
if err != nil {
t.Fatalf("new request: %v", err)
}
proxyURL, err := transport.Proxy(req)
if err != nil {
t.Fatalf("proxy func returned error: %v", err)
}
if proxyURL == nil {
t.Fatal("expected environment proxy to be inherited, got nil")
}
if got := proxyURL.String(); got != tt.want {
t.Fatalf("expected proxy %q, got %q", tt.want, got)
}
})
}
return
}
req, err := http.NewRequest("GET", "https://example.com", nil)
if err != nil {
t.Fatalf("new request: %v", err)
}
proxyURL, err := http.ProxyFromEnvironment(req)
if err != nil {
t.Fatalf("ProxyFromEnvironment error: %v", err)
}
if proxyURL == nil || proxyURL.String() != "http://127.0.0.1:18443" {
t.Fatalf("expected environment proxy http://127.0.0.1:18443, got %v", proxyURL)
}
}


func TestAuthByIndexDistinguishesSharedAPIKeysAcrossProviders(t *testing.T) {
t.Parallel()
Expand Down
Loading