Skip to content

Commit 46e44cb

Browse files
fix TestIntegrationWithBadProxy test
There was an update to how environment variables are used in DD. Make sure proxy environment variables are used.
1 parent 5a4e318 commit 46e44cb

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

pkg/desktop/raw_client.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"net"
1010
"net/http"
1111
"net/url"
12+
"os"
1213
"sync"
1314
"time"
1415
)
@@ -20,11 +21,22 @@ var (
2021
desktopProxyTransportInst http.RoundTripper
2122
)
2223

23-
// ProxyTransport returns an HTTP transport configured to use Docker Desktop's HTTP proxy socket
24-
// when Docker Desktop is running. If Docker Desktop is not running, it returns http.DefaultTransport.
24+
// ProxyTransport returns an HTTP transport configured to proxy HTTP requests.
25+
// If HTTP_PROXY/HTTPS_PROXY environment variables are set, they take precedence and
26+
// are respected via http.ProxyFromEnvironment. Otherwise, when Docker Desktop is running,
27+
// traffic is routed through Docker Desktop's HTTP proxy socket. If neither applies,
28+
// http.DefaultTransport is returned.
2529
// The transport is initialized once using sync.Once and cached for subsequent calls.
2630
func ProxyTransport() http.RoundTripper {
2731
desktopProxyTransportOnce.Do(func() {
32+
// Env proxy vars take precedence over Docker Desktop's proxy socket.
33+
if hasEnvProxyVars() {
34+
desktopProxyTransportInst = &http.Transport{
35+
Proxy: http.ProxyFromEnvironment,
36+
}
37+
return
38+
}
39+
2840
ctx := context.Background()
2941
if !IsRunningInDockerDesktop(ctx) {
3042
desktopProxyTransportInst = http.DefaultTransport
@@ -44,6 +56,16 @@ func ProxyTransport() http.RoundTripper {
4456
return desktopProxyTransportInst
4557
}
4658

59+
// hasEnvProxyVars returns true if any HTTP proxy environment variables are set.
60+
func hasEnvProxyVars() bool {
61+
for _, name := range []string{"HTTP_PROXY", "HTTPS_PROXY", "http_proxy", "https_proxy"} {
62+
if os.Getenv(name) != "" {
63+
return true
64+
}
65+
}
66+
return false
67+
}
68+
4769
func AvoidResourceSaverMode(ctx context.Context) {
4870
_ = ClientBackend.Post(ctx, "/idle/make-busy", nil, nil)
4971
}

pkg/proxy_integration_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ func TestIntegrationWithBadProxy(t *testing.T) {
6161
)
6262

6363
// Test catalog show command with bad proxy - should fail
64-
ctx, cancel := context.WithTimeout(t.Context(), 15*time.Second)
64+
ctx, cancel := context.WithTimeout(t.Context(), 5*time.Second)
6565
defer cancel()
6666

67-
cmd := exec.CommandContext(ctx, "docker", "mcp", "catalog", "show", "mcp/docker-mcp-catalog:latest", "--format=json")
67+
cmd := exec.CommandContext(ctx, "docker", "mcp", "catalog", "show", "mcp/docker-mcp-catalog:latest", "--pull=always", "--format=json")
6868
cmd.Env = env
6969

7070
err := cmd.Run()

0 commit comments

Comments
 (0)