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);
}
}
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());
}
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"));
}
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");
}
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));
}
Aggregations