()
| 67 | |
| 68 | |
| 69 | def test_digest_auth_with_401_nonce_counting(): |
| 70 | auth = httpx.DigestAuth(username="user", password="pass") |
| 71 | request = httpx.Request("GET", "https://www.example.com") |
| 72 | |
| 73 | # The initial request should not include an auth header. |
| 74 | flow = auth.sync_auth_flow(request) |
| 75 | request = next(flow) |
| 76 | assert "Authorization" not in request.headers |
| 77 | |
| 78 | # If a 401 response is returned, then a digest auth request is made. |
| 79 | headers = { |
| 80 | "WWW-Authenticate": 'Digest realm="...", qop="auth", nonce="...", opaque="..."' |
| 81 | } |
| 82 | response = httpx.Response( |
| 83 | content=b"Auth required", status_code=401, headers=headers, request=request |
| 84 | ) |
| 85 | first_request = flow.send(response) |
| 86 | assert first_request.headers["Authorization"].startswith("Digest") |
| 87 | |
| 88 | # Each subsequent request contains the digest header by default... |
| 89 | request = httpx.Request("GET", "https://www.example.com") |
| 90 | flow = auth.sync_auth_flow(request) |
| 91 | second_request = next(flow) |
| 92 | assert second_request.headers["Authorization"].startswith("Digest") |
| 93 | |
| 94 | # ... and the client nonce count (nc) is increased |
| 95 | first_nc = parse_keqv_list(first_request.headers["Authorization"].split(", "))["nc"] |
| 96 | second_nc = parse_keqv_list(second_request.headers["Authorization"].split(", "))[ |
| 97 | "nc" |
| 98 | ] |
| 99 | assert int(first_nc, 16) + 1 == int(second_nc, 16) |
| 100 | |
| 101 | # No other requests are made. |
| 102 | response = httpx.Response(content=b"Hello, world!", status_code=200) |
| 103 | with pytest.raises(StopIteration): |
| 104 | flow.send(response) |
| 105 | |
| 106 | |
| 107 | def set_cookies(request: httpx.Request) -> httpx.Response: |
nothing calls this directly
no test coverage detected