MCPcopy Index your code
hub / github.com/microsoft/playwright-python / test_should_authenticate

Function test_should_authenticate

tests/async/test_proxy.py:109–136  ·  view source on GitHub ↗
(
    browser_factory: "Callable[..., asyncio.Future[Browser]]", server: Server
)

Source from the content-addressed store, hash-verified

107
108
109async 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
139async def test_should_authenticate_with_empty_password(

Callers

nothing calls this directly

Calls 5

browser_factoryFunction · 0.85
set_routeMethod · 0.80
new_pageMethod · 0.45
gotoMethod · 0.45
titleMethod · 0.45

Tested by

no test coverage detected