MCPcopy
hub / github.com/encode/httpx / test_digest_auth_with_401

Function test_digest_auth_with_401

tests/test_auth.py:44–66  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

42
43
44def test_digest_auth_with_401():
45 auth = httpx.DigestAuth(username="user", password="pass")
46 request = httpx.Request("GET", "https://www.example.com")
47
48 # The initial request should not include an auth header.
49 flow = auth.sync_auth_flow(request)
50 request = next(flow)
51 assert "Authorization" not in request.headers
52
53 # If a 401 response is returned, then a digest auth request is made.
54 headers = {
55 "WWW-Authenticate": 'Digest realm="...", qop="auth", nonce="...", opaque="..."'
56 }
57 response = httpx.Response(
58 content=b"Auth required", status_code=401, headers=headers, request=request
59 )
60 request = flow.send(response)
61 assert request.headers["Authorization"].startswith("Digest")
62
63 # No other requests are made.
64 response = httpx.Response(content=b"Hello, world!", status_code=200)
65 with pytest.raises(StopIteration):
66 flow.send(response)
67
68
69def test_digest_auth_with_401_nonce_counting():

Callers

nothing calls this directly

Calls 2

sync_auth_flowMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected