|
28 | 28 | import com.cloudbees.plugins.credentials.SystemCredentialsProvider; |
29 | 29 | import hudson.ProxyConfiguration; |
30 | 30 | import hudson.util.Secret; |
| 31 | +import io.fabric8.kubernetes.client.Config; |
31 | 32 | import io.fabric8.kubernetes.client.KubernetesClient; |
32 | | -import io.fabric8.kubernetes.client.utils.HttpClientUtils; |
33 | 33 | import org.jenkinsci.plugins.kubernetes.auth.KubernetesAuthException; |
34 | 34 | import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl; |
35 | 35 | import org.junit.After; |
|
39 | 39 | import org.jvnet.hudson.test.Issue; |
40 | 40 | import org.jvnet.hudson.test.JenkinsRule; |
41 | 41 |
|
42 | | -import java.net.MalformedURLException; |
43 | 42 | import java.util.HashMap; |
44 | 43 | import java.util.Map; |
45 | 44 |
|
|
55 | 54 | import static org.junit.Assert.assertArrayEquals; |
56 | 55 | import static org.junit.Assert.assertEquals; |
57 | 56 | import static org.junit.Assert.assertFalse; |
58 | | -import static org.junit.Assert.assertNotNull; |
59 | | -import static org.junit.Assert.assertNull; |
60 | 57 | import static org.junit.Assert.assertTrue; |
61 | 58 |
|
62 | 59 | /** |
@@ -176,32 +173,57 @@ public void autoConfigWithAuth() throws Exception { |
176 | 173 |
|
177 | 174 | @Test |
178 | 175 | @Issue("JENKINS-70563") |
179 | | - public void jenkinsProxyConfiguration() throws KubernetesAuthException, MalformedURLException { |
| 176 | + public void jenkinsProxyConfiguration() throws KubernetesAuthException { |
180 | 177 |
|
181 | 178 | j.jenkins.setProxy(new ProxyConfiguration("proxy.com", 123, PROXY_USERNAME, PROXY_PASSWORD, "*acme.com\n*acme*.com\n*.example.com|192.168.*")); |
182 | 179 | KubernetesFactoryAdapter factory = new KubernetesFactoryAdapter("http://acme.com", null, null, null, false, 15, 5, 32, true); |
183 | | - try(KubernetesClient client = factory.createClient()) { |
184 | | - assertNull(HttpClientUtils.getProxyUrl(client.getConfiguration())); |
| 180 | + try (KubernetesClient client = factory.createClient()) { |
| 181 | + Config configuration = client.getConfiguration(); |
| 182 | + assertEquals("http://proxy.com:123", configuration.getHttpProxy()); |
| 183 | + assertEquals(PROXY_USERNAME, configuration.getProxyUsername()); |
| 184 | + assertEquals(PROXY_PASSWORD, configuration.getProxyPassword()); |
| 185 | + assertArrayEquals(new String[] {"acme.com", ".example.com|192.168."}, configuration.getNoProxy()); |
| 186 | + assertEquals("http://proxy.com:123", configuration.getHttpsProxy()); |
185 | 187 | } |
186 | 188 |
|
187 | 189 | j.jenkins.setProxy(new ProxyConfiguration("proxy.com", 123, PROXY_USERNAME, PROXY_PASSWORD, "*acme.com")); |
188 | 190 | factory = new KubernetesFactoryAdapter("http://acme.com", null, null, null, false, 15, 5, 32, true); |
189 | | - try(KubernetesClient client = factory.createClient()) { |
190 | | - assertNull(HttpClientUtils.getProxyUrl(client.getConfiguration())); |
| 191 | + try (KubernetesClient client = factory.createClient()) { |
| 192 | + Config configuration = client.getConfiguration(); |
| 193 | + assertEquals("http://proxy.com:123", configuration.getHttpProxy()); |
| 194 | + assertEquals(PROXY_USERNAME, configuration.getProxyUsername()); |
| 195 | + assertEquals(PROXY_PASSWORD, configuration.getProxyPassword()); |
| 196 | + assertArrayEquals(new String[] {"acme.com"}, configuration.getNoProxy()); |
| 197 | + assertEquals("http://proxy.com:123", configuration.getHttpsProxy()); |
191 | 198 | } |
192 | 199 | factory = new KubernetesFactoryAdapter("http://k8s.acme.com", null, null, null, false, 15, 5, 32, true); |
193 | | - try(KubernetesClient client = factory.createClient()) { |
194 | | - assertNull(HttpClientUtils.getProxyUrl(client.getConfiguration())); |
| 200 | + try (KubernetesClient client = factory.createClient()) { |
| 201 | + Config configuration = client.getConfiguration(); |
| 202 | + assertEquals("http://proxy.com:123", configuration.getHttpProxy()); |
| 203 | + assertEquals(PROXY_USERNAME, configuration.getProxyUsername()); |
| 204 | + assertEquals(PROXY_PASSWORD, configuration.getProxyPassword()); |
| 205 | + assertArrayEquals(new String[] {"acme.com"}, configuration.getNoProxy()); |
| 206 | + assertEquals("http://proxy.com:123", configuration.getHttpsProxy()); |
195 | 207 | } |
196 | 208 |
|
197 | 209 | j.jenkins.setProxy(new ProxyConfiguration("proxy.com", 123, PROXY_USERNAME, PROXY_PASSWORD, "*.acme.com")); |
198 | 210 | factory = new KubernetesFactoryAdapter("http://acme.com", null, null, null, false, 15, 5, 32, true); |
199 | | - try(KubernetesClient client = factory.createClient()) { |
200 | | - assertNotNull(HttpClientUtils.getProxyUrl(client.getConfiguration())); |
| 211 | + try (KubernetesClient client = factory.createClient()) { |
| 212 | + Config configuration = client.getConfiguration(); |
| 213 | + assertEquals("http://proxy.com:123", configuration.getHttpProxy()); |
| 214 | + assertEquals(PROXY_USERNAME, configuration.getProxyUsername()); |
| 215 | + assertEquals(PROXY_PASSWORD, configuration.getProxyPassword()); |
| 216 | + assertArrayEquals(new String[] {".acme.com"}, configuration.getNoProxy()); |
| 217 | + assertEquals("http://proxy.com:123", configuration.getHttpsProxy()); |
201 | 218 | } |
202 | 219 | factory = new KubernetesFactoryAdapter("http://k8s.acme.com", null, null, null, false, 15, 5, 32, true); |
203 | | - try(KubernetesClient client = factory.createClient()) { |
204 | | - assertNull(HttpClientUtils.getProxyUrl(client.getConfiguration())); |
| 220 | + try (KubernetesClient client = factory.createClient()) { |
| 221 | + Config configuration = client.getConfiguration(); |
| 222 | + assertEquals("http://proxy.com:123", configuration.getHttpProxy()); |
| 223 | + assertEquals(PROXY_USERNAME, configuration.getProxyUsername()); |
| 224 | + assertEquals(PROXY_PASSWORD, configuration.getProxyPassword()); |
| 225 | + assertArrayEquals(new String[] {".acme.com"}, configuration.getNoProxy()); |
| 226 | + assertEquals("http://proxy.com:123", configuration.getHttpsProxy()); |
205 | 227 | } |
206 | 228 | } |
207 | 229 | } |
0 commit comments