Search in sources :

Example 11 with ProxyConfiguration

use of hudson.ProxyConfiguration in project blueocean-plugin by jenkinsci.

the class HttpRequest method setClientProxyParams.

private void setClientProxyParams(String apiUrl, HttpClientBuilder clientBuilder) {
    try {
        URL url = new URL(apiUrl);
        ProxyConfiguration proxyConfig = Jenkins.get().proxy;
        Proxy proxy = proxyConfig != null ? proxyConfig.createProxy(url.getHost()) : Proxy.NO_PROXY;
        if (!proxy.equals(Proxy.NO_PROXY) && proxyConfig != null) {
            clientBuilder.setProxy(new HttpHost(proxyConfig.name, proxyConfig.port));
        }
    } catch (MalformedURLException e) {
        throw new ServiceException.UnexpectedErrorException("Invalid apiUrl: " + apiUrl, e);
    }
}
Also used : Proxy(java.net.Proxy) MalformedURLException(java.net.MalformedURLException) ProxyConfiguration(hudson.ProxyConfiguration) ServiceException(io.jenkins.blueocean.commons.ServiceException) HttpHost(org.apache.http.HttpHost) URL(java.net.URL)

Example 12 with ProxyConfiguration

use of hudson.ProxyConfiguration in project blueocean-plugin by jenkinsci.

the class GithubApiTest method proxyTest.

@Test
public void proxyTest() throws IOException {
    HttpURLConnection connection = HttpRequest.get(j.getURL().toString()).connect();
    Assert.assertFalse(connection.usingProxy());
    URL wiremockProxy = new URL(githubApiUrl);
    j.jenkins.proxy = new ProxyConfiguration(wiremockProxy.getHost(), wiremockProxy.getPort());
    connection = HttpRequest.get(j.getURL().toString()).connect();
    Assert.assertTrue(connection.usingProxy());
}
Also used : HttpURLConnection(java.net.HttpURLConnection) ProxyConfiguration(hudson.ProxyConfiguration) URL(java.net.URL) Test(org.junit.Test)

Example 13 with ProxyConfiguration

use of hudson.ProxyConfiguration in project configuration-as-code-plugin by jenkinsci.

the class ProxyConfiguratorTest method shouldSetProxyWithMinimumFields.

@Test
@ConfiguredWithCode("ProxyMinimal.yml")
public void shouldSetProxyWithMinimumFields() throws Exception {
    ProxyConfiguration proxy = j.jenkins.proxy;
    assertEquals(proxy.name, "proxyhost");
    assertEquals(proxy.port, 80);
    assertNull(proxy.getUserName());
    assertNull(proxy.getTestUrl());
    ConfiguratorRegistry registry = ConfiguratorRegistry.get();
    ConfigurationContext context = new ConfigurationContext(registry);
    final Configurator c = context.lookupOrFail(ProxyConfiguration.class);
    final CNode node = c.describe(proxy, context);
    assertNotNull(node);
    Mapping mapping = node.asMapping();
    assertEquals(2, node.asMapping().size());
    assertEquals("proxyhost", mapping.getScalarValue("name"));
    assertEquals("80", mapping.getScalarValue("port"));
}
Also used : CNode(io.jenkins.plugins.casc.model.CNode) ConfiguratorRegistry(io.jenkins.plugins.casc.ConfiguratorRegistry) ConfigurationContext(io.jenkins.plugins.casc.ConfigurationContext) ProxyConfiguration(hudson.ProxyConfiguration) Configurator(io.jenkins.plugins.casc.Configurator) Mapping(io.jenkins.plugins.casc.model.Mapping) Test(org.junit.Test) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode)

Example 14 with ProxyConfiguration

use of hudson.ProxyConfiguration in project configuration-as-code-plugin by jenkinsci.

the class ProxyConfiguratorTest method shouldSetProxyWithSecretInFields.

@Test
@Env(name = "PROXY_HOST", value = "proxyhost")
@Env(name = "PROXY_PORT", value = "80")
@Env(name = "PROXY_USER", value = "proxy_user")
@Env(name = "PROXY_PASSWORD", value = "proxy_password")
@Env(name = "PROXY_NOPROXY", value = "external.host")
@Env(name = "PROXY_TEST_URL", value = "http://google.com")
@ConfiguredWithCode("ProxyWithSecrets.yml")
public void shouldSetProxyWithSecretInFields() {
    ProxyConfiguration proxy = j.jenkins.proxy;
    assertEquals(proxy.name, "proxyhost");
    assertEquals(proxy.port, 80);
    assertEquals(proxy.getUserName(), "proxy_user");
    assertThat(proxy.getSecretPassword(), hasPlainText("proxy_password"));
    assertEquals(proxy.noProxyHost, "external.host");
    assertEquals(proxy.getTestUrl(), "http://google.com");
}
Also used : ProxyConfiguration(hudson.ProxyConfiguration) Test(org.junit.Test) ConfiguredWithCode(io.jenkins.plugins.casc.misc.ConfiguredWithCode) Env(io.jenkins.plugins.casc.misc.Env)

Example 15 with ProxyConfiguration

use of hudson.ProxyConfiguration in project configuration-as-code-plugin by jenkinsci.

the class ProxyTest method configure_proxy.

@Test
@ConfiguredWithReadme("proxy/README.md")
public void configure_proxy() {
    final ProxyConfiguration proxy = Jenkins.get().proxy;
    assertNotNull(proxy);
    assertThat(proxy.getSecretPassword(), hasPlainText("password"));
    assertThat(proxy.getTestUrl(), is("http://google.com"));
    assertThat(proxy.getUserName(), is("login"));
    assertThat(proxy.name, is("proxyhost"));
    assertThat(proxy.noProxyHost, is("externalhost"));
    assertThat(proxy.port, is(80));
}
Also used : ProxyConfiguration(hudson.ProxyConfiguration) Test(org.junit.Test) ConfiguredWithReadme(io.jenkins.plugins.casc.misc.ConfiguredWithReadme)

Aggregations

ProxyConfiguration (hudson.ProxyConfiguration)16 Test (org.junit.Test)8 Proxy (java.net.Proxy)5 URL (java.net.URL)5 ConfiguredWithCode (io.jenkins.plugins.casc.misc.ConfiguredWithCode)4 EnvVars (hudson.EnvVars)2 ConfigurationContext (io.jenkins.plugins.casc.ConfigurationContext)2 Configurator (io.jenkins.plugins.casc.Configurator)2 ConfiguratorRegistry (io.jenkins.plugins.casc.ConfiguratorRegistry)2 Env (io.jenkins.plugins.casc.misc.Env)2 CNode (io.jenkins.plugins.casc.model.CNode)2 Mapping (io.jenkins.plugins.casc.model.Mapping)2 HttpURLConnection (java.net.HttpURLConnection)2 MalformedURLException (java.net.MalformedURLException)2 HttpHost (org.apache.http.HttpHost)2 Issue (org.jvnet.hudson.test.Issue)2 ContrastSDK (com.contrastsecurity.sdk.ContrastSDK)1 ServiceException (io.jenkins.blueocean.commons.ServiceException)1 ConfiguredWithReadme (io.jenkins.plugins.casc.misc.ConfiguredWithReadme)1 KeenProject (io.keen.client.java.KeenProject)1