2424
2525package org .csanchez .jenkins .plugins .kubernetes ;
2626
27- import static org .junit .Assert .*;
28-
29- import java .util .HashMap ;
30- import java .util .Map ;
31-
27+ import hudson .ProxyConfiguration ;
28+ import io .fabric8 .kubernetes .client .KubernetesClient ;
29+ import io .fabric8 .kubernetes .client .utils .HttpClientUtils ;
30+ import org .jenkinsci .plugins .kubernetes .auth .KubernetesAuthException ;
3231import org .junit .After ;
3332import org .junit .Before ;
33+ import org .junit .Rule ;
3434import org .junit .Test ;
35+ import org .jvnet .hudson .test .Issue ;
36+ import org .jvnet .hudson .test .JenkinsRule ;
3537
36- import static io .fabric8 .kubernetes .client .Config .*;
37- import io .fabric8 .kubernetes .client .KubernetesClient ;
38+ import java .net .MalformedURLException ;
39+ import java .util .HashMap ;
40+ import java .util .Map ;
41+
42+ import static io .fabric8 .kubernetes .client .Config .KUBERNETES_HTTPS_PROXY ;
43+ import static io .fabric8 .kubernetes .client .Config .KUBERNETES_HTTP_PROXY ;
44+ import static io .fabric8 .kubernetes .client .Config .KUBERNETES_KUBECONFIG_FILE ;
45+ import static io .fabric8 .kubernetes .client .Config .KUBERNETES_NAMESPACE_FILE ;
46+ import static io .fabric8 .kubernetes .client .Config .KUBERNETES_NO_PROXY ;
47+ import static io .fabric8 .kubernetes .client .Config .KUBERNETES_PROXY_PASSWORD ;
48+ import static io .fabric8 .kubernetes .client .Config .KUBERNETES_PROXY_USERNAME ;
49+ import static org .junit .Assert .assertArrayEquals ;
50+ import static org .junit .Assert .assertEquals ;
51+ import static org .junit .Assert .assertNotNull ;
52+ import static org .junit .Assert .assertNull ;
3853
3954/**
4055 * Test the creation of clients
@@ -59,6 +74,9 @@ public class KubernetesFactoryAdapterTest {
5974
6075 private Map <String , String > systemProperties = new HashMap <>();
6176
77+ @ Rule
78+ public JenkinsRule j = new JenkinsRule ();
79+
6280 @ Before
6381 public void saveSystemProperties () {
6482 for (String key : SYSTEM_PROPERTY_NAMES ) {
@@ -117,4 +135,35 @@ public void autoConfigWithMasterUrl() throws Exception {
117135 assertEquals (PROXY_USERNAME , client .getConfiguration ().getProxyUsername ());
118136 assertEquals (PROXY_PASSWORD , client .getConfiguration ().getProxyPassword ());
119137 }
138+
139+ @ Test
140+ @ Issue ("JENKINS-70563" )
141+ public void jenkinsProxyConfiguration () throws KubernetesAuthException , MalformedURLException {
142+
143+ j .jenkins .setProxy (new ProxyConfiguration ("proxy.com" , 123 , PROXY_USERNAME , PROXY_PASSWORD , "*acme.com\n *acme*.com\n *.example.com|192.168.*" ));
144+ KubernetesFactoryAdapter factory = new KubernetesFactoryAdapter ("http://acme.com" , null , null , null , false , 15 , 5 , 32 , true );
145+ try (KubernetesClient client = factory .createClient ()) {
146+ assertNull (HttpClientUtils .getProxyUrl (client .getConfiguration ()));
147+ }
148+
149+ j .jenkins .setProxy (new ProxyConfiguration ("proxy.com" , 123 , PROXY_USERNAME , PROXY_PASSWORD , "*acme.com" ));
150+ factory = new KubernetesFactoryAdapter ("http://acme.com" , null , null , null , false , 15 , 5 , 32 , true );
151+ try (KubernetesClient client = factory .createClient ()) {
152+ assertNull (HttpClientUtils .getProxyUrl (client .getConfiguration ()));
153+ }
154+ factory = new KubernetesFactoryAdapter ("http://k8s.acme.com" , null , null , null , false , 15 , 5 , 32 , true );
155+ try (KubernetesClient client = factory .createClient ()) {
156+ assertNull (HttpClientUtils .getProxyUrl (client .getConfiguration ()));
157+ }
158+
159+ j .jenkins .setProxy (new ProxyConfiguration ("proxy.com" , 123 , PROXY_USERNAME , PROXY_PASSWORD , "*.acme.com" ));
160+ factory = new KubernetesFactoryAdapter ("http://acme.com" , null , null , null , false , 15 , 5 , 32 , true );
161+ try (KubernetesClient client = factory .createClient ()) {
162+ assertNotNull (HttpClientUtils .getProxyUrl (client .getConfiguration ()));
163+ }
164+ factory = new KubernetesFactoryAdapter ("http://k8s.acme.com" , null , null , null , false , 15 , 5 , 32 , true );
165+ try (KubernetesClient client = factory .createClient ()) {
166+ assertNull (HttpClientUtils .getProxyUrl (client .getConfiguration ()));
167+ }
168+ }
120169}
0 commit comments