Fix proxy tests on Windows
- commit
- a159f476ed3b182ce2fa95251dbc4300e185087a
- author
- patriceckhart · · 2026-08-06 06:08 UTC
- parent
- 43baf04
- signature
- unsigned
- refs
- tag: v0.3.35
1 file · +27 -6
M packages/agent/config_proxy_test.go +27 -6
| @@ -24,12 +24,14 @@ func TestApplyConfiguredHTTPProxy(t *testing.T) { | |||
| 24 | 24 | } | |
| 25 | 25 | } | |
| 26 | 26 | ||
| 27 | - | func TestApplyConfiguredHTTPProxyPreservesEnvironment(t *testing.T) { | |
| 27 | + | func TestApplyConfiguredHTTPProxyPreservesUppercaseEnvironment(t *testing.T) { | |
| 28 | 28 | t.Setenv("ZOT_HOME", t.TempDir()) | |
| 29 | - | t.Setenv("HTTP_PROXY", "http://http-env.example:8080") | |
| 29 | + | // Set lowercase first because environment variable names are | |
| 30 | + | // case-insensitive on Windows. | |
| 30 | 31 | t.Setenv("http_proxy", "") | |
| 31 | - | t.Setenv("HTTPS_PROXY", "") | |
| 32 | - | t.Setenv("https_proxy", "http://https-env.example:8080") | |
| 32 | + | t.Setenv("https_proxy", "") | |
| 33 | + | t.Setenv("HTTP_PROXY", "http://http-env.example:8080") | |
| 34 | + | t.Setenv("HTTPS_PROXY", "http://https-env.example:8080") | |
| 33 | 35 | if err := SaveConfig(Config{HTTPProxy: "http://config.example:8080"}); err != nil { | |
| 34 | 36 | t.Fatal(err) | |
| 35 | 37 | } | |
| @@ -39,8 +41,27 @@ func TestApplyConfiguredHTTPProxyPreservesEnvironment(t *testing.T) { | |||
| 39 | 41 | if got := getenvForTest("HTTP_PROXY"); got != "http://http-env.example:8080" { | |
| 40 | 42 | t.Fatalf("HTTP_PROXY = %q", got) | |
| 41 | 43 | } | |
| 42 | - | if got := getenvForTest("HTTPS_PROXY"); got != "" { | |
| 43 | - | t.Fatalf("HTTPS_PROXY = %q, want empty because lowercase environment setting takes precedence", got) | |
| 44 | + | if got := getenvForTest("HTTPS_PROXY"); got != "http://https-env.example:8080" { | |
| 45 | + | t.Fatalf("HTTPS_PROXY = %q", got) | |
| 46 | + | } | |
| 47 | + | } | |
| 48 | + | ||
| 49 | + | func TestApplyConfiguredHTTPProxyPreservesLowercaseEnvironment(t *testing.T) { | |
| 50 | + | t.Setenv("ZOT_HOME", t.TempDir()) | |
| 51 | + | // Set uppercase first because environment variable names are | |
| 52 | + | // case-insensitive on Windows. | |
| 53 | + | t.Setenv("HTTP_PROXY", "") | |
| 54 | + | t.Setenv("HTTPS_PROXY", "") | |
| 55 | + | t.Setenv("http_proxy", "http://http-env.example:8080") | |
| 56 | + | t.Setenv("https_proxy", "http://https-env.example:8080") | |
| 57 | + | if err := SaveConfig(Config{HTTPProxy: "http://config.example:8080"}); err != nil { | |
| 58 | + | t.Fatal(err) | |
| 59 | + | } | |
| 60 | + | ||
| 61 | + | applyConfiguredHTTPProxy() | |
| 62 | + | ||
| 63 | + | if got := getenvForTest("http_proxy"); got != "http://http-env.example:8080" { | |
| 64 | + | t.Fatalf("http_proxy = %q", got) | |
| 44 | 65 | } | |
| 45 | 66 | if got := getenvForTest("https_proxy"); got != "http://https-env.example:8080" { | |
| 46 | 67 | t.Fatalf("https_proxy = %q", got) | |
| @@ -24,12 +24,14 @@ func TestApplyConfiguredHTTPProxy(t *testing.T) { | |||||
| 24 | } | 24 | } | ||
| 25 | } | 25 | } | ||
| 26 | 26 | ||||
| 27 | - | func TestApplyConfiguredHTTPProxyPreservesEnvironment(t *testing.T) { | 27 | + | func TestApplyConfiguredHTTPProxyPreservesUppercaseEnvironment(t *testing.T) { |
| 28 | t.Setenv("ZOT_HOME", t.TempDir()) | 28 | t.Setenv("ZOT_HOME", t.TempDir()) | ||
| 29 | - | t.Setenv("HTTP_PROXY", "http://http-env.example:8080") | 29 | + | // Set lowercase first because environment variable names are |
| 30 | + | // case-insensitive on Windows. | |||
| 30 | t.Setenv("http_proxy", "") | 31 | t.Setenv("http_proxy", "") | ||
| 31 | - | t.Setenv("HTTPS_PROXY", "") | 32 | + | t.Setenv("https_proxy", "") |
| 32 | - | t.Setenv("https_proxy", "http://https-env.example:8080") | 33 | + | t.Setenv("HTTP_PROXY", "http://http-env.example:8080") |
| 34 | + | t.Setenv("HTTPS_PROXY", "http://https-env.example:8080") | |||
| 33 | if err := SaveConfig(Config{HTTPProxy: "http://config.example:8080"}); err != nil { | 35 | if err := SaveConfig(Config{HTTPProxy: "http://config.example:8080"}); err != nil { | ||
| 34 | t.Fatal(err) | 36 | t.Fatal(err) | ||
| 35 | } | 37 | } | ||
| @@ -39,8 +41,27 @@ func TestApplyConfiguredHTTPProxyPreservesEnvironment(t *testing.T) { | |||||
| 39 | if got := getenvForTest("HTTP_PROXY"); got != "http://http-env.example:8080" { | 41 | if got := getenvForTest("HTTP_PROXY"); got != "http://http-env.example:8080" { | ||
| 40 | t.Fatalf("HTTP_PROXY = %q", got) | 42 | t.Fatalf("HTTP_PROXY = %q", got) | ||
| 41 | } | 43 | } | ||
| 42 | - | if got := getenvForTest("HTTPS_PROXY"); got != "" { | 44 | + | if got := getenvForTest("HTTPS_PROXY"); got != "http://https-env.example:8080" { |
| 43 | - | t.Fatalf("HTTPS_PROXY = %q, want empty because lowercase environment setting takes precedence", got) | 45 | + | t.Fatalf("HTTPS_PROXY = %q", got) |
| 46 | + | } | |||
| 47 | + | } | |||
| 48 | + | ||||
| 49 | + | func TestApplyConfiguredHTTPProxyPreservesLowercaseEnvironment(t *testing.T) { | |||
| 50 | + | t.Setenv("ZOT_HOME", t.TempDir()) | |||
| 51 | + | // Set uppercase first because environment variable names are | |||
| 52 | + | // case-insensitive on Windows. | |||
| 53 | + | t.Setenv("HTTP_PROXY", "") | |||
| 54 | + | t.Setenv("HTTPS_PROXY", "") | |||
| 55 | + | t.Setenv("http_proxy", "http://http-env.example:8080") | |||
| 56 | + | t.Setenv("https_proxy", "http://https-env.example:8080") | |||
| 57 | + | if err := SaveConfig(Config{HTTPProxy: "http://config.example:8080"}); err != nil { | |||
| 58 | + | t.Fatal(err) | |||
| 59 | + | } | |||
| 60 | + | ||||
| 61 | + | applyConfiguredHTTPProxy() | |||
| 62 | + | ||||
| 63 | + | if got := getenvForTest("http_proxy"); got != "http://http-env.example:8080" { | |||
| 64 | + | t.Fatalf("http_proxy = %q", got) | |||
| 44 | } | 65 | } | ||
| 45 | if got := getenvForTest("https_proxy"); got != "http://https-env.example:8080" { | 66 | if got := getenvForTest("https_proxy"); got != "http://https-env.example:8080" { | ||
| 46 | t.Fatalf("https_proxy = %q", got) | 67 | t.Fatalf("https_proxy = %q", got) | ||