1

So I'm using browsermob proxy to login selenium tests to get passed IAP for Google Cloud. But that just gets the user to the site, they still need to login to the site using some firebase login form. IAP has me adding Authorization header through browsermob so you can get to the site itself but the when you try to login through the firebase form you get a 401 error message: "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential..

I thought I could get around this using the whitelist or blacklist feature to just not apply those headers to urls related to the firebase login, but it seems that whitelist and blacklist just return status codes and empty responses for calls that match the regex.

Is there a way to just passthrough certain calls based on the host? Or on the off chance I'm doing something wrong, let me know. Code below:

class ExampleTest(unittest.TestCase):

    def setUp(self):
        server = Server("env/bin/browsermob-proxy/bin/browsermob-proxy")
        server.start()
        proxy = server.create_proxy()
        bearer_header = {}
        bearer_header['Authorization'] = 'Bearer xxxxxxxxexamplexxxxxxxx'
        proxy.headers({"Authorization": bearer_header["Authorization"]})
        profile  = webdriver.FirefoxProfile()
        proxy_info = proxy.selenium_proxy()
        profile.set_proxy(proxy_info)
        proxy.whitelist('.*googleapis.*, .*google.com.*', 200) # This fakes 200 from urls on regex match
        # proxy.blacklist('.*googleapis.*', 200) # This fakes 200 from urls if not regex match
        self.driver = webdriver.Firefox(firefox_profile=profile)
        proxy.new_har("file-example")


    def test_wait(self):
        self.driver.get("https://example.com/login/")
        time.sleep(3)


    def tearDown(self):
        self.driver.close()
Cynic
  • 4,282
  • 1
  • 21
  • 42

1 Answers1

0

Figured this out a bit later. There isn't anything built into the BrowserMob proxy/client to do this. But you can achieve it through webdriver's proxy settings.

Chrome

    self.chrome_options = webdriver.ChromeOptions()
    proxy_address = '{}:{}'.format(server.host, proxy.port)
    self.chrome_options.add_argument('--proxy-server=%s' % proxy_address)
    no_proxy_string = ''
    for item in no_proxy:
        no_proxy_string += '*' + item + ';'
    self.chrome_options.add_argument('--proxy-bypass-list=%s' % no_proxy_string)
    self.desired_capabilities = webdriver.DesiredCapabilities.CHROME
    self.desired_capabilities['acceptInsecureCerts'] = True

Firefox

    self.desired_capabilities = webdriver.DesiredCapabilities.FIREFOX
    proxy_address = '{}:{}'.format(server.host, proxy.port)
    self.desired_capabilities['proxy'] = {
        'proxyType': "MANUAL",
        'httpProxy': proxy_address,
        'sslProxy': proxy_address,
        'noProxy': ['google.com', 'example.com']
    }
    self.desired_capabilities['acceptInsecureCerts'] = True
Cynic
  • 4,282
  • 1
  • 21
  • 42