Search in sources :

Example 1 with HttpClient

use of io.github.bonigarcia.wdm.HttpClient in project webdrivermanager by bonigarcia.

the class PhantomJsFilterTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() throws Exception {
    phatomJsManager = PhantomJsDriverManager.getInstance();
    Field field = WebDriverManager.class.getDeclaredField("httpClient");
    field.setAccessible(true);
    field.set(phatomJsManager, new HttpClient());
    Method method = WebDriverManager.class.getDeclaredMethod("getDrivers");
    method.setAccessible(true);
    driversUrls = (List<URL>) method.invoke(phatomJsManager);
}
Also used : Field(java.lang.reflect.Field) HttpClient(io.github.bonigarcia.wdm.HttpClient) Method(java.lang.reflect.Method) URL(java.net.URL) Before(org.junit.Before)

Example 2 with HttpClient

use of io.github.bonigarcia.wdm.HttpClient in project webdrivermanager by bonigarcia.

the class ProxyTest method testProxyCredentialsScope.

@Test
public void testProxyCredentialsScope() throws Exception {
    WebDriverManager.config().setProxy("myproxy:8081").setProxyUser("domain\\me").setProxyPass("pass");
    HttpClient wdmClient = new HttpClient();
    Field field = HttpClient.class.getDeclaredField("closeableHttpClient");
    field.setAccessible(true);
    CloseableHttpClient client = (CloseableHttpClient) field.get(wdmClient);
    field = client.getClass().getDeclaredField("credentialsProvider");
    field.setAccessible(true);
    BasicCredentialsProvider provider = (BasicCredentialsProvider) field.get(client);
    assertThat(provider.getCredentials(new AuthScope(ANY_HOST, ANY_PORT, ANY_REALM, NTLM)), instanceOf(NTCredentials.class));
    assertThat(provider.getCredentials(new AuthScope(ANY_HOST, ANY_PORT, ANY_REALM, BASIC)), instanceOf(UsernamePasswordCredentials.class));
    assertThat(provider.getCredentials(new AuthScope(ANY_HOST, ANY_PORT)), instanceOf(UsernamePasswordCredentials.class));
    assertThat(provider.getCredentials(new AuthScope(ANY_HOST, ANY_PORT, ANY_REALM, KERBEROS)), instanceOf(UsernamePasswordCredentials.class));
}
Also used : Field(java.lang.reflect.Field) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpClient(io.github.bonigarcia.wdm.HttpClient) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) AuthScope(org.apache.http.auth.AuthScope) NTCredentials(org.apache.http.auth.NTCredentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) Test(org.junit.Test)

Example 3 with HttpClient

use of io.github.bonigarcia.wdm.HttpClient in project webdrivermanager by bonigarcia.

the class ProxyTest method getProxy.

private Optional<Proxy> getProxy(WebDriverManager browserManager) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, MalformedURLException {
    Field httpClientField = WebDriverManager.class.getDeclaredField("httpClient");
    httpClientField.setAccessible(true);
    httpClientField.set(browserManager, new HttpClient());
    Field configField = WebDriverManager.class.getDeclaredField("config");
    configField.setAccessible(true);
    Config config = (Config) configField.get(browserManager);
    String proxy = config.getProxy();
    HttpClient wdmHttpClient = (HttpClient) httpClientField.get(browserManager);
    return wdmHttpClient.createProxy(proxy);
}
Also used : Field(java.lang.reflect.Field) Config(io.github.bonigarcia.wdm.Config) HttpClient(io.github.bonigarcia.wdm.HttpClient) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient)

Example 4 with HttpClient

use of io.github.bonigarcia.wdm.HttpClient in project webdrivermanager by bonigarcia.

the class ProxyTest method testProxyCredentials.

@Test
public void testProxyCredentials() throws Exception {
    WebDriverManager.config().setProxy("myproxy:8081").setProxyUser("domain\\me").setProxyPass("pass");
    HttpClient wdmClient = new HttpClient();
    Field field = HttpClient.class.getDeclaredField("closeableHttpClient");
    field.setAccessible(true);
    CloseableHttpClient client = (CloseableHttpClient) field.get(wdmClient);
    field = client.getClass().getDeclaredField("credentialsProvider");
    field.setAccessible(true);
    BasicCredentialsProvider provider = (BasicCredentialsProvider) field.get(client);
    NTCredentials ntcreds = (NTCredentials) provider.getCredentials(new AuthScope(ANY_HOST, ANY_PORT, ANY_REALM, NTLM));
    assertThat(ntcreds.getDomain(), equalTo("DOMAIN"));
    assertThat(ntcreds.getUserName(), equalTo("me"));
    assertThat(ntcreds.getPassword(), equalTo("pass"));
    UsernamePasswordCredentials creds = (UsernamePasswordCredentials) provider.getCredentials(new AuthScope(ANY_HOST, ANY_PORT));
    assertThat(creds.getUserName(), equalTo("domain\\me"));
    assertThat(creds.getPassword(), equalTo("pass"));
}
Also used : Field(java.lang.reflect.Field) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpClient(io.github.bonigarcia.wdm.HttpClient) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) AuthScope(org.apache.http.auth.AuthScope) NTCredentials(org.apache.http.auth.NTCredentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) Test(org.junit.Test)

Aggregations

HttpClient (io.github.bonigarcia.wdm.HttpClient)4 Field (java.lang.reflect.Field)4 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)3 AuthScope (org.apache.http.auth.AuthScope)2 NTCredentials (org.apache.http.auth.NTCredentials)2 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)2 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)2 Test (org.junit.Test)2 Config (io.github.bonigarcia.wdm.Config)1 Method (java.lang.reflect.Method)1 URL (java.net.URL)1 Before (org.junit.Before)1