Xceptance / neodymium-library

A test automation library based on common other best practice open source libraries. It adds missing functionalities but does not reinvent the wheel. Just glues stuff together nicely and adds some sprinkles.
MIT License
80 stars 11 forks source link

Integrated proxy to manipulate headers #112

Closed occupant23 closed 4 years ago

occupant23 commented 4 years ago

Some modern browsers deprecate the usage of a Basic Authentication via URL. On the other side prevents/lacks the WebDriver spec any other method of passing the authentication credentials.

Recheck: https://github.com/w3c/webdriver/issues/385

occupant23 commented 4 years ago

Implementation proposal (PoC level):

<dependency>
    <groupId>com.browserup</groupId>
    <artifactId>browserup-proxy-core</artifactId>
    <version>2.0.1</version>
</dependency>
package com.xceptance.neodymium.tests;

import java.io.File;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

import com.browserup.bup.BrowserUpProxy;
import com.browserup.bup.BrowserUpProxyServer;
import com.browserup.bup.client.ClientUtil;
import com.browserup.bup.mitm.KeyStoreFileCertificateSource;
import com.browserup.bup.mitm.manager.ImpersonatingMitmManager;
import com.xceptance.neodymium.NeodymiumRunner;

@RunWith(NeodymiumRunner.class)
public class DevTest
{
    @Test
    public void testSomething() throws Exception
    {
        KeyStoreFileCertificateSource fileCertificateSource = new KeyStoreFileCertificateSource("PKCS12", new File("./config/Certificates.p12"), "MitmProxy", "xceptance");
        ImpersonatingMitmManager mitmManager = ImpersonatingMitmManager.builder().rootCertificateSource(fileCertificateSource).build();
        BrowserUpProxy proxy = new BrowserUpProxyServer();
        proxy.setMitmManager(mitmManager);
        proxy.start();

        // get the Selenium proxy object
        Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);

        // configure it as a desired capability
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.setAcceptInsecureCerts(true);
        chromeOptions.addArguments("-ignore-certificate-errors");
        chromeOptions.setProxy(seleniumProxy);

        // start the browser up

        WebDriver driver = new ChromeDriver(chromeOptions);
        proxy.autoAuthorization(domain, user, password, AuthType.BASIC);
        driver.get("http://" + domain);

        try
        {
            Thread.sleep(5000);
        }
        catch (InterruptedException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        driver.quit();

        Assert.assertTrue(true);
    }
}
occupant23 commented 4 years ago

Created follow up ticket to conclude this topic with the next version #117