()
| 42 | |
| 43 | |
| 44 | def 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 | |
| 69 | def test_digest_auth_with_401_nonce_counting(): |
nothing calls this directly
no test coverage detected