Skip to content

Commit 606a69b

Browse files
committed
Use config-based HTTP client in network check fallback path
When the workspace client is unavailable but config is resolved, the network check was falling back to http.DefaultClient. This ignores proxy and custom TLS settings from the SDK config, giving misleading results in enterprise environments. Use configuredNetworkHTTPClient(cfg) instead, which respects HTTPTransport and InsecureSkipVerify from the config.
1 parent d571c06 commit 606a69b

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

cmd/doctor/checks.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,10 @@ func checkNetwork(cmd *cobra.Command, cfg *config.Config, resolveErr error, w *d
236236
return checkNetworkWithHost(cmd, w.Config.Host, configuredNetworkHTTPClient(w.Config))
237237
}
238238

239-
log.Warnf(cmd.Context(), "workspace client unavailable for network check, falling back to default HTTP client")
240-
return checkNetworkWithHost(cmd, cfg.Host, http.DefaultClient)
239+
// Workspace client unavailable, but we can still build an HTTP client
240+
// from the resolved config to respect proxy and TLS settings.
241+
log.Warnf(cmd.Context(), "workspace client unavailable for network check, using config-based HTTP client")
242+
return checkNetworkWithHost(cmd, cfg.Host, configuredNetworkHTTPClient(cfg))
241243
}
242244

243245
func checkNetworkWithHost(cmd *cobra.Command, host string, client *http.Client) CheckResult {

cmd/doctor/doctor_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,33 @@ func TestCheckNetworkUsesWorkspaceClientTransport(t *testing.T) {
333333
assert.Contains(t, result.Message, "reachable")
334334
}
335335

336+
func TestCheckNetworkFallbackUsesConfigTransport(t *testing.T) {
337+
called := false
338+
cfg := &config.Config{
339+
Host: "https://example.com",
340+
Token: "test-token",
341+
HTTPTransport: roundTripFunc(func(r *http.Request) (*http.Response, error) {
342+
called = true
343+
assert.Equal(t, http.MethodHead, r.Method)
344+
return &http.Response{
345+
StatusCode: http.StatusOK,
346+
Body: http.NoBody,
347+
Header: make(http.Header),
348+
Request: r,
349+
}, nil
350+
}),
351+
}
352+
353+
ctx := cmdio.MockDiscard(t.Context())
354+
cmd := newTestCmd(ctx)
355+
356+
result := checkNetwork(cmd, cfg, nil, nil)
357+
assert.True(t, called, "expected config's HTTPTransport to be used")
358+
assert.Equal(t, "Network", result.Name)
359+
assert.Equal(t, statusPass, result.Status)
360+
assert.Contains(t, result.Message, "reachable")
361+
}
362+
336363
func TestCheckNetworkConfigResolutionFailure(t *testing.T) {
337364
clearConfigEnv(t)
338365

0 commit comments

Comments
 (0)