The three custom http.Transport instances built by the CLI (`internal/transport/client.go` MCP transport, `internal/apiclient/client.go` DingTalk OpenAPI client, `internal/app/legacy.go` IPv4-forcing registry client) all set DialContext / TLSClientConfig / timeouts but omit the Proxy field. Per Go's net/http contract, a non-nil Transport without an explicit Proxy means "no proxy" — env vars are silently ignored, breaking sandboxed or air-gapped deployments that route outbound through HTTP_PROXY / HTTPS_PROXY. Set Proxy: http.ProxyFromEnvironment on all three. Adds a regression test per package that pointer-compares the Transport's Proxy func against http.ProxyFromEnvironment (avoids flakiness from Go's envProxyOnce memoisation when running alongside tests that read proxy env early).
44 lines
1.6 KiB
Go
44 lines
1.6 KiB
Go
// Copyright 2026 Alibaba Group
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package apiclient
|
|
|
|
import (
|
|
"net/http"
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
// TestDefaultTransportHonoursHTTPProxyEnv is the regression guard for #236
|
|
// on the apiclient transport. Same rationale as transport/proxy_env_test.go:
|
|
// a custom Transport without an explicit Proxy field silently bypasses
|
|
// HTTP_PROXY/HTTPS_PROXY.
|
|
//
|
|
// We pointer-compare against http.ProxyFromEnvironment instead of invoking
|
|
// it, because http.ProxyFromEnvironment memoises the env on first call;
|
|
// other tests that read proxy env early would make a value-based assertion
|
|
// flaky.
|
|
func TestDefaultTransportHonoursHTTPProxyEnv(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tr := defaultTransport()
|
|
if tr.Proxy == nil {
|
|
t.Fatal("defaultTransport().Proxy is nil — HTTP_PROXY env will be ignored (regression of #236)")
|
|
}
|
|
wantPC := reflect.ValueOf(http.ProxyFromEnvironment).Pointer()
|
|
gotPC := reflect.ValueOf(tr.Proxy).Pointer()
|
|
if gotPC != wantPC {
|
|
t.Errorf("defaultTransport().Proxy is not http.ProxyFromEnvironment — env-var proxy may not be honoured (regression of #236)")
|
|
}
|
|
}
|