AutomatedTester / browsermob-proxy-py

A python wrapper for Browsermob Proxy
http://oss.theautomatedtester.co.uk/browsermob-proxy-py
236 stars 104 forks source link

Trusting all Servers and bypassing Basic Authentication #86

Closed ghost closed 6 years ago

ghost commented 6 years ago

I am using Windows + Python + Selenium (latest) + Browsermob-proxy-py + Chrome, FF, IE.

After following the installation instructions and the example provided by the documentation, my code looks like this:

@pytest.fixture(scope="session", autouse=True)
def selenium_proxy():
    proxy = Client("localhost:9090")
    proxy.trustAllServers(True)
    proxy.basic_authentication("", HTACCESS_USERNAME, HTACCESS_PASSWORD)

    yield proxy.selenium_proxy()

    proxy.close()
# I defined this method in browsermob-proxy-py/client.py 
def trustAllServers(self, value):
    r = requests.post(url='%s/proxy' % (self.host),
                      data=json.dumps({'trustAllServers': value}),
                      headers={'content-type': 'application/json'})
    return r.status_code

I am running the browsermob proxy standalone version like this: java -jar browsermob-dist-2.1.4.jar --port 9090

I did this by following the official browsermob-proxy documentation, which can be found here

Printing the response code for both methods: trustAllServers (Returns 200) and basic_authentication (Returns 404) <- Why?

The main issue is: when I try to load an URL with selenium the browser will say that the page cannot be loaded. If I run my tests with internet explorer, some weird unwanted windows configurations will take place and I will have to manually deactivate the LAN Proxy configuration in the Internet Options in order to recover my internet connection.

The console logs informs two main Problems:

...
Caused by: javax.net.ssl.SSLHandshakeException: General SSLEngine problem
...

and

...
Caused by: java.security.cert.CertificateException: No subject alternative DNS name matching <host> found.
...

I've been reading for hours and the solution I always end up finding is trusting all servers, which "I am already doing" with the trustAllServers method I defined. Maybe I am doing something wrong?

Edit: I am trying to do something like this https://www.softensity.com/browsermob-proxy-qa/

ghost commented 6 years ago

Installing this Certificate to Trusted Root Certification Authorities on Windows solved most of my issues.

Now the remaining issue is handling the alert dialog window of any domain with the basic_authentication method. Giving "*" as domain-parameter returns 200 response status code. However, the alert window appears anyway.

ghost commented 6 years ago

I wasn't able to match all domains with a generic expression (empty string or *). But you can match all subdomains by just giving "domain.com". This solves my issue for now.