(
browser_factory: "Callable[..., asyncio.Future[Browser]]", server: Server
)
| 107 | |
| 108 | |
| 109 | async def test_should_authenticate( |
| 110 | browser_factory: "Callable[..., asyncio.Future[Browser]]", server: Server |
| 111 | ) -> None: |
| 112 | def handler(req: TestServerRequest) -> None: |
| 113 | auth = req.getHeader("proxy-authorization") |
| 114 | if not auth: |
| 115 | req.setHeader( |
| 116 | b"Proxy-Authenticate", b'Basic realm="Access to internal site"' |
| 117 | ) |
| 118 | req.setResponseCode(407) |
| 119 | else: |
| 120 | req.write(f"<html><title>{auth}</title></html>".encode("utf-8")) |
| 121 | req.finish() |
| 122 | |
| 123 | server.set_route("/target.html", handler) |
| 124 | |
| 125 | browser = await browser_factory( |
| 126 | proxy={ |
| 127 | "server": f"localhost:{server.PORT}", |
| 128 | "username": "user", |
| 129 | "password": "secret", |
| 130 | } |
| 131 | ) |
| 132 | page = await browser.new_page() |
| 133 | await page.goto("http://non-existent.com/target.html") |
| 134 | assert await page.title() == "Basic " + base64.b64encode(b"user:secret").decode( |
| 135 | "utf-8" |
| 136 | ) |
| 137 | |
| 138 | |
| 139 | async def test_should_authenticate_with_empty_password( |
nothing calls this directly
no test coverage detected