Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BrowserUpProxy.addRequestFilter is not working on localhost when system under test is also on localhost #254

Closed
kroegr opened this issue Apr 16, 2020 · 1 comment

Comments

@kroegr
Copy link

kroegr commented Apr 16, 2020

I want to start the automated tests on localhost against my local system to check that the tests still green/functional after working on it.
The Webapplication is a Single-Page-Application and for security-reasons are HTTP-Header injected by a thirdparty-proxy for authentication. For the automated tests I use browserup-proxy to emulate that thirdparty-proxy and inject the HTTP-Header with the needed values for testing.

When I run the test locally against the DEV- or TEST-Stage, the proxy on localhost is working as expected - the header wil be injected.
When I run the test locally against my local environment, the proxy on localhost is not working as expected - there will be no headers set.

Here is the code for the configuration of the proxy:


    BrowserUpProxy proxy = new BrowserUpProxyServer();
        proxy.start();
        Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);

        // put our custom header to each request
        proxy.addRequestFilter((request, contents, messageInfo) -> {
            if (Host.isApiUrl(messageInfo.getUrl())) {
                request.headers().add("x-protect-authorization-user", "any_user");
            }
            System.err.println(messageInfo.getUrl());
            System.out.println(request.headers().entries().toString());
            return null;
        });

        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);

        String proxyOption = "--proxy-server=" + seleniumProxy.getHttpProxy();
        options.addArguments(proxyOption);

        options.setCapability(CapabilityType.PROXY, seleniumProxy);

On localhost against localhost the method proxy.addRequestFilter is not called, only on urls != localhost.

Versions that I am using:
com.browserup.browserup-proxy-core 2.1.0
org.seleniumhq.selenium.selenium-java 3.141.59
geckodriver 0.26.0

If more informations are needed or missing, please let me know.

What I have asked me: Is it even possible to run a proxy and the application under test on the same host or is this conflicting with the behavior of a proxy?

@kroegr
Copy link
Author

kroegr commented Apr 17, 2020

Good Morning!

I have found the solution, it's not a problem or bug with the proxy or anything else.

Firefox/geckodriver is per default configured to not allow any proxy hijack anything on localhost. It's possible to allow that.

        FirefoxOptions options = new FirefoxOptions();
        options.setHeadless(true);
        FirefoxProfile p = new FirefoxProfile();
        p.setPreference("network.proxy.allow_hijacking_localhost", true);

        options.setProfile(p);
        options.setLogLevel(FirefoxDriverLogLevel.INFO);
        driver = new FirefoxDriver(options);

@kroegr kroegr closed this as completed Apr 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant