()
| 144 | |
| 145 | |
| 146 | def test_digest_auth_rfc_2069(): |
| 147 | # Example from https://datatracker.ietf.org/doc/html/rfc2069#section-2.4 |
| 148 | # with corrected response from https://www.rfc-editor.org/errata/eid749 |
| 149 | |
| 150 | auth = httpx.DigestAuth(username="Mufasa", password="CircleOfLife") |
| 151 | request = httpx.Request("GET", "https://www.example.com/dir/index.html") |
| 152 | |
| 153 | # The initial request should not include an auth header. |
| 154 | flow = auth.sync_auth_flow(request) |
| 155 | request = next(flow) |
| 156 | assert "Authorization" not in request.headers |
| 157 | |
| 158 | # If a 401 response is returned, then a digest auth request is made. |
| 159 | headers = { |
| 160 | "WWW-Authenticate": ( |
| 161 | 'Digest realm="testrealm@host.com", ' |
| 162 | 'nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", ' |
| 163 | 'opaque="5ccc069c403ebaf9f0171e9517f40e41"' |
| 164 | ) |
| 165 | } |
| 166 | response = httpx.Response( |
| 167 | content=b"Auth required", status_code=401, headers=headers, request=request |
| 168 | ) |
| 169 | request = flow.send(response) |
| 170 | assert request.headers["Authorization"].startswith("Digest") |
| 171 | assert 'username="Mufasa"' in request.headers["Authorization"] |
| 172 | assert 'realm="testrealm@host.com"' in request.headers["Authorization"] |
| 173 | assert ( |
| 174 | 'nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093"' in request.headers["Authorization"] |
| 175 | ) |
| 176 | assert 'uri="/dir/index.html"' in request.headers["Authorization"] |
| 177 | assert ( |
| 178 | 'opaque="5ccc069c403ebaf9f0171e9517f40e41"' in request.headers["Authorization"] |
| 179 | ) |
| 180 | assert ( |
| 181 | 'response="1949323746fe6a43ef61f9606e7febea"' |
| 182 | in request.headers["Authorization"] |
| 183 | ) |
| 184 | |
| 185 | # No other requests are made. |
| 186 | response = httpx.Response(content=b"Hello, world!", status_code=200) |
| 187 | with pytest.raises(StopIteration): |
| 188 | flow.send(response) |
| 189 | |
| 190 | |
| 191 | def test_digest_auth_rfc_7616_md5(monkeypatch): |
nothing calls this directly
no test coverage detected