TestDDProxyFunc_BypassesLoopbackOnly exercises the proxy selection directly (rather than through ProxyTransport, which needs a live socket) so it runs on every platform, including Windows. This is the core of the docker/compose#13824 fix: loopback targets must connect directly instead of being force
(t *testing.T)
| 133 | // proxy, so Desktop keeps ownership of proxy decisions (docker/compose#13825 |
| 134 | // review). |
| 135 | func TestDDProxyFunc_BypassesLoopbackOnly(t *testing.T) { |
| 136 | // Set NO_PROXY to confirm it is deliberately NOT honored: registry.internal |
| 137 | // must still be proxied. |
| 138 | t.Setenv("NO_PROXY", "registry.internal") |
| 139 | t.Setenv("no_proxy", "registry.internal") |
| 140 | |
| 141 | proxyFunc := ddProxyFunc() |
| 142 | |
| 143 | cases := []struct { |
| 144 | name string |
| 145 | reqURL string |
| 146 | wantProxy bool |
| 147 | }{ |
| 148 | {"loopback name", "http://localhost:5000/v2/", false}, |
| 149 | {"loopback IPv4", "http://127.0.0.1:5000/v2/", false}, |
| 150 | {"loopback IPv4 subnet", "http://127.5.6.7:5000/v2/", false}, |
| 151 | {"loopback IPv6", "http://[::1]:5000/v2/", false}, |
| 152 | {"NO_PROXY host is not honored", "https://registry.internal/v2/", true}, |
| 153 | {"external https", "https://registry-1.docker.io/v2/", true}, |
| 154 | {"external http", "http://example.com/v2/", true}, |
| 155 | } |
| 156 | for _, tc := range cases { |
| 157 | t.Run(tc.name, func(t *testing.T) { |
| 158 | req, err := http.NewRequest(http.MethodGet, tc.reqURL, http.NoBody) |
| 159 | assert.NilError(t, err) |
| 160 | proxyURL, err := proxyFunc(req) |
| 161 | assert.NilError(t, err) |
| 162 | if tc.wantProxy { |
| 163 | assert.Assert(t, proxyURL != nil, "expected %s to route through the Docker Desktop proxy", tc.reqURL) |
| 164 | assert.Equal(t, proxyURL.Host, ddProxyHost) |
| 165 | } else { |
| 166 | assert.Assert(t, proxyURL == nil, "expected %s to bypass the proxy and connect directly", tc.reqURL) |
| 167 | } |
| 168 | }) |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | func mustTouch(t *testing.T, path string) { |
| 173 | t.Helper() |
nothing calls this directly
no test coverage detected