-
Notifications
You must be signed in to change notification settings - Fork 522
OCPBUGS-112043: Preserve proxy environment vars #6424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,6 +111,7 @@ func TestSysContextBuilder(t *testing.T) { | |
| name string | ||
| secret *corev1.Secret | ||
| controllerConfig *mcfgv1.ControllerConfig | ||
| proxy *configv1.ProxyStatus | ||
| registriesConfig *sysregistriesv2.V2RegistriesConf | ||
| expectTempDir bool | ||
| expectAuthFile bool | ||
|
|
@@ -171,16 +172,16 @@ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuOSW8w== | |
| expectCerts: true, | ||
| }, | ||
| { | ||
| name: "WithControllerConfig only - proxy", | ||
| name: "WithControllerConfig only - proxy in controllerconfig does not set DockerProxyURL", | ||
| controllerConfig: &mcfgv1.ControllerConfig{ | ||
| Spec: mcfgv1.ControllerConfigSpec{ | ||
| Proxy: &configv1.ProxyStatus{ | ||
| HTTPSProxy: "https://proxy.example.com:3128", | ||
| }, | ||
| }, | ||
| }, | ||
| expectTempDir: false, // Proxy doesn't need temp dir | ||
| expectProxy: true, | ||
| expectTempDir: false, | ||
| expectProxy: false, | ||
|
Comment on lines
+175
to
+184
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Resolve the reported The supplied static analysis reports repeated Also applies to: 338-342 🧰 Tools🪛 golangci-lint (2.12.2)[error] 179-179: string (goconst) 🤖 Prompt for AI AgentsSource: Linters/SAST tools |
||
| }, | ||
| { | ||
| name: "WithControllerConfig only - just rootCA", | ||
|
|
@@ -220,15 +221,18 @@ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuOSW8w== | |
| -----END CERTIFICATE-----`), | ||
| }, | ||
| }, | ||
| Proxy: &configv1.ProxyStatus{ | ||
| HTTPSProxy: "https://proxy.example.com:3128", | ||
| }, | ||
| }, | ||
| }, | ||
| expectTempDir: true, | ||
| expectAuthFile: true, | ||
| expectCerts: true, | ||
| expectProxy: true, | ||
| }, | ||
| { | ||
| name: "WithProxy sets DockerProxyURL", | ||
| proxy: &configv1.ProxyStatus{ | ||
| HTTPSProxy: "https://proxy.example.com:3128", | ||
| }, | ||
| expectProxy: true, | ||
| }, | ||
| } | ||
|
|
||
|
|
@@ -244,6 +248,10 @@ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuOSW8w== | |
| builder.WithControllerConfig(tc.controllerConfig) | ||
| } | ||
|
|
||
| if tc.proxy != nil { | ||
| builder.WithProxy(tc.proxy) | ||
| } | ||
|
|
||
| if tc.registriesConfig != nil { | ||
| builder.WithRegistriesConfig(tc.registriesConfig) | ||
| } | ||
|
|
@@ -320,7 +328,7 @@ func TestSysContextBuilderWithProxy(t *testing.T) { | |
| name string | ||
| httpProxy string | ||
| httpsProxy string | ||
| skipProxy bool | ||
| useProxy bool | ||
| expectedScheme string | ||
| expectedHost string | ||
| expectedUsername string | ||
|
|
@@ -329,18 +337,21 @@ func TestSysContextBuilderWithProxy(t *testing.T) { | |
| { | ||
| name: "HTTPS proxy with complete URL", | ||
| httpsProxy: "https://proxy.example.com:3128", | ||
| useProxy: true, | ||
| expectedScheme: "https", | ||
| expectedHost: "proxy.example.com:3128", | ||
| }, | ||
| { | ||
| name: "HTTP proxy with complete URL", | ||
| httpProxy: "http://proxy.example.com:8080", | ||
| useProxy: true, | ||
| expectedScheme: "http", | ||
| expectedHost: "proxy.example.com:8080", | ||
| }, | ||
| { | ||
| name: "HTTPS proxy with authentication", | ||
| httpsProxy: "https://user:password@proxy.example.com:3128", | ||
| useProxy: true, | ||
| expectedScheme: "https", | ||
| expectedHost: "proxy.example.com:3128", | ||
| expectedUsername: "user", | ||
|
|
@@ -349,67 +360,57 @@ func TestSysContextBuilderWithProxy(t *testing.T) { | |
| { | ||
| name: "HTTP proxy with authentication", | ||
| httpProxy: "http://proxyuser:proxypass@proxy.example.com:8080", | ||
| useProxy: true, | ||
| expectedScheme: "http", | ||
| expectedHost: "proxy.example.com:8080", | ||
| expectedUsername: "proxyuser", | ||
| expectedPassword: "proxypass", | ||
| }, | ||
| { | ||
| name: "Both proxies - HTTPS preferred with auth", | ||
| httpProxy: "http://httpuser:httppass@http-proxy.example.com:8080", | ||
| httpsProxy: "https://httpsuser:httpspass@https-proxy.example.com:3128", | ||
| expectedScheme: "https", | ||
| expectedHost: "https-proxy.example.com:3128", | ||
| expectedUsername: "httpsuser", | ||
| expectedPassword: "httpspass", | ||
| name: "Different HTTP and HTTPS proxies falls back to env vars", | ||
| httpProxy: "http://httpuser:httppass@http-proxy.example.com:8080", | ||
| httpsProxy: "https://httpsuser:httpspass@https-proxy.example.com:3128", | ||
| useProxy: true, | ||
| }, | ||
| { | ||
| name: "HTTPS proxy without port", | ||
| httpsProxy: "https://proxy.example.com", | ||
| useProxy: true, | ||
| expectedScheme: "https", | ||
| expectedHost: "proxy.example.com", | ||
| }, | ||
| { | ||
| name: "HTTPS proxy with special characters in password", | ||
| httpsProxy: "https://user:p@ssw0rd!@proxy.example.com:3128", | ||
| useProxy: true, | ||
| expectedScheme: "https", | ||
| expectedHost: "proxy.example.com:3128", | ||
| expectedUsername: "user", | ||
| expectedPassword: "p@ssw0rd!", | ||
| }, | ||
| { | ||
| name: "WithoutProxy skips proxy even when configured", | ||
| httpsProxy: "https://proxy.example.com:3128", | ||
| httpProxy: "http://proxy.example.com:8080", | ||
| skipProxy: true, | ||
| name: "No explicit proxy leaves DockerProxyURL nil", | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range testCases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| cc := &mcfgv1.ControllerConfig{ | ||
| Spec: mcfgv1.ControllerConfigSpec{ | ||
| Proxy: &configv1.ProxyStatus{ | ||
| HTTPProxy: tc.httpProxy, | ||
| HTTPSProxy: tc.httpsProxy, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| builder := NewSysContextBuilder(). | ||
| WithSecret(secret). | ||
| WithControllerConfig(cc) | ||
| if tc.skipProxy { | ||
| builder.WithoutProxy() | ||
| WithSecret(secret) | ||
| if tc.useProxy { | ||
| builder.WithProxy(&configv1.ProxyStatus{ | ||
| HTTPProxy: tc.httpProxy, | ||
| HTTPSProxy: tc.httpsProxy, | ||
| }) | ||
| } | ||
|
|
||
| sysCtx, err := builder.Build() | ||
| require.NoError(t, err, "SysContextBuilder.Build should not fail") | ||
| require.NotNil(t, sysCtx, "SysContext wrapper should not be nil") | ||
| require.NotNil(t, sysCtx.SysContext, "Underlying SystemContext should not be nil") | ||
|
|
||
| if tc.skipProxy { | ||
| assert.Nil(t, sysCtx.SysContext.DockerProxyURL, "DockerProxyURL should be nil when proxy is skipped") | ||
| if tc.expectedScheme == "" { | ||
| assert.Nil(t, sysCtx.SysContext.DockerProxyURL, "DockerProxyURL should be nil") | ||
| } else { | ||
| require.NotNil(t, sysCtx.SysContext.DockerProxyURL, "DockerProxyURL should not be nil") | ||
| assert.Equal(t, tc.expectedScheme, sysCtx.SysContext.DockerProxyURL.Scheme, "Proxy scheme should match") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: It would be nice for this to be tied to a Jira card if possible.