【问题标题】:Set a passthrough using browsermob proxy?使用browsermob代理设置直通?
【发布时间】:2019-01-17 00:05:38
【问题描述】:

所以我使用 browsermob 代理登录 selenium 测试,以通过 Google Cloud 的 IAP。但这只是让用户访问该站点,他们仍然需要使用一些 Firebase 登录表单登录到该站点。 IAP 让我通过 browsermob 添加 Authorization 标头,这样您就可以访问网站本身,但是当您尝试通过 firebase 表单登录时,您会收到 401 错误message: "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential.

我认为我可以使用 whitelist 或黑名单功能解决此问题,只是不将这些标头应用于与 firebase 登录相关的 url,但似乎白名单和黑名单只是返回状态代码和匹配调用的空响应正则表达式。

有没有办法只通过基于主机的某些调用?或者如果我做错了什么,请告诉我。代码如下:

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()

【问题讨论】:

    标签: python-3.x browsermob-proxy browsermob


    【解决方案1】:

    后来想通了。 BrowserMob 代理/客户端中没有内置任何东西来执行此操作。不过可以通过webdriver's proxy settings实现。

        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
    

    火狐

        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
    

    【讨论】:

      猜你喜欢
      • 2015-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-23
      • 1970-01-01
      • 2015-07-24
      • 2014-10-25
      相关资源
      最近更新 更多