Skip to content
Myr

test_auth.py

This file

Path

tests/client/test_auth.py

379 lines · 12.3 KiB · Python

Last changed by

Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15

History of this file

Take it

The walk stopped after 200 commits: lines older than 3065dd6 point at it.

Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d

line 1why, one step back
1import hashlib

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 2–3why, one step back
2import json
3import os

Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15

line 4why, one step back
4import typing

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 5–7why, one step back
5
6import pytest7

Tighten up top-level API to only expose public API (#608)Tom Christiebefore adoptiond15dc0b

lines 8–10why, one step back
8from httpx import URL, Client, DigestAuth, ProtocolError, Request, Response
9from httpx.config import CertTypes, TimeoutTypes, VerifyTypes10from httpx.dispatch.base import Dispatcher

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 11–12why, one step back
11
12

Drop sync (#544)Tom Christiebefore adoption206c537

line 13why, one step back
13class MockDispatch(Dispatcher):

Additional DigestAuth tests (#334)Yeray Diaz Diazbefore adoption1cd9156

lines 14–17why, one step back
14 def __init__(self, auth_header: str = "", status_code: int = 200) -> None:
15 self.auth_header = auth_header16 self.status_code = status_code17

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 18–19why, one step back
18 async def send(
19 self,

Drop sync (#544)Tom Christiebefore adoption206c537

line 20why, one step back
20 request: Request,

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 21–23why, one step back
21 verify: VerifyTypes = None,
22 cert: CertTypes = None,23 timeout: TimeoutTypes = None,

Drop sync (#544)Tom Christiebefore adoption206c537

line 24why, one step back
24 ) -> Response:

Additional DigestAuth tests (#334)Yeray Diaz Diazbefore adoption1cd9156

line 25why, one step back
25 headers = [("www-authenticate", self.auth_header)] if self.auth_header else []

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

line 26why, one step back
26 body = json.dumps({"auth": request.headers.get("Authorization")}).encode()

Drop sync (#544)Tom Christiebefore adoption206c537

line 27why, one step back
27 return Response(

Additional DigestAuth tests (#334)Yeray Diaz Diazbefore adoption1cd9156

lines 28–29why, one step back
28 self.status_code, headers=headers, content=body, request=request
29 )

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 30–31why, one step back
30
31

Drop sync (#544)Tom Christiebefore adoption206c537

line 32why, one step back
32class MockDigestAuthDispatch(Dispatcher):

Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d

lines 33–47why, one step back
33 def __init__(
34 self,35 algorithm: str = "SHA-256",36 send_response_after_attempt: int = 1,37 qop: str = "auth",38 regenerate_nonce: bool = True,39 ) -> None:40 self.algorithm = algorithm41 self.send_response_after_attempt = send_response_after_attempt42 self.qop = qop43 self._regenerate_nonce = regenerate_nonce44 self._response_count = 04546 async def send(47 self,

Drop sync (#544)Tom Christiebefore adoption206c537

line 48why, one step back
48 request: Request,

Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d

lines 49–51why, one step back
49 verify: VerifyTypes = None,
50 cert: CertTypes = None,51 timeout: TimeoutTypes = None,

Drop sync (#544)Tom Christiebefore adoption206c537

line 52why, one step back
52 ) -> Response:

Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d

lines 53–56why, one step back
53 if self._response_count < self.send_response_after_attempt:
54 return self.challenge_send(request)5556 body = json.dumps({"auth": request.headers.get("Authorization")}).encode()

Drop sync (#544)Tom Christiebefore adoption206c537

line 57why, one step back
57 return Response(200, content=body, request=request)

Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d

line 58why, one step back
58

Drop sync (#544)Tom Christiebefore adoption206c537

line 59why, one step back
59 def challenge_send(self, request: Request) -> Response:

Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d

lines 60–83why, one step back
60 self._response_count += 1
61 nonce = (62 hashlib.sha256(os.urandom(8)).hexdigest()63 if self._regenerate_nonce64 else "ee96edced2a0b43e4869e96ebe27563f369c1205a049d06419bb51d8aeddf3d3"65 )66 challenge_data = {67 "nonce": nonce,68 "qop": self.qop,69 "opaque": (70 "ee6378f3ee14ebfd2fff54b70a91a7c9390518047f242ab2271380db0e14bda1"71 ),72 "algorithm": self.algorithm,73 "stale": "FALSE",74 }75 challenge_str = ", ".join(76 '{}="{}"'.format(key, value)77 for key, value in challenge_data.items()78 if value79 )8081 headers = [82 ("www-authenticate", 'Digest realm="httpx@example.org", ' + challenge_str)83 ]

Drop sync (#544)Tom Christiebefore adoption206c537

line 84why, one step back
84 return Response(401, headers=headers, content=b"", request=request)

Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d

lines 85–86why, one step back
85
86

Drop sync (#544)Tom Christiebefore adoption206c537

line 87why, one step back
87@pytest.mark.asyncio

Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15

line 88why, one step back
88async def test_basic_auth() -> None:

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 89–91why, one step back
89 url = "https://example.org/"
90 auth = ("tomchristie", "password123")91

Drop sync (#544)Tom Christiebefore adoption206c537

lines 92–93why, one step back
92 client = Client(dispatch=MockDispatch())
93 response = await client.get(url, auth=auth)

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 94–98why, one step back
94
95 assert response.status_code == 20096 assert response.json() == {"auth": "Basic dG9tY2hyaXN0aWU6cGFzc3dvcmQxMjM="}9798

Drop sync (#544)Tom Christiebefore adoption206c537

line 99why, one step back
99@pytest.mark.asyncio

Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15

line 100why, one step back
100async def test_basic_auth_in_url() -> None:

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 101–102why, one step back
101 url = "https://tomchristie:password123@example.org/"
102

Drop sync (#544)Tom Christiebefore adoption206c537

lines 103–104why, one step back
103 client = Client(dispatch=MockDispatch())
104 response = await client.get(url)

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 105–109why, one step back
105
106 assert response.status_code == 200107 assert response.json() == {"auth": "Basic dG9tY2hyaXN0aWU6cGFzc3dvcmQxMjM="}108109

Drop sync (#544)Tom Christiebefore adoption206c537

line 110why, one step back
110@pytest.mark.asyncio

Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15

line 111why, one step back
111async def test_basic_auth_on_session() -> None:

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 112–114why, one step back
112 url = "https://example.org/"
113 auth = ("tomchristie", "password123")114

Drop sync (#544)Tom Christiebefore adoption206c537

lines 115–116why, one step back
115 client = Client(dispatch=MockDispatch(), auth=auth)
116 response = await client.get(url)

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 117–121why, one step back
117
118 assert response.status_code == 200119 assert response.json() == {"auth": "Basic dG9tY2hyaXN0aWU6cGFzc3dvcmQxMjM="}120121

Drop sync (#544)Tom Christiebefore adoption206c537

line 122why, one step back
122@pytest.mark.asyncio

Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15

line 123why, one step back
123async def test_custom_auth() -> None:

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 124–125why, one step back
124 url = "https://example.org/"
125

Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15

line 126why, one step back
126 def auth(request: Request) -> Request:

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 127–129why, one step back
127 request.headers["Authorization"] = "Token 123"
128 return request129

Drop sync (#544)Tom Christiebefore adoption206c537

lines 130–131why, one step back
130 client = Client(dispatch=MockDispatch())
131 response = await client.get(url, auth=auth)

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 132–136why, one step back
132
133 assert response.status_code == 200134 assert response.json() == {"auth": "Token 123"}135136

Drop sync (#544)Tom Christiebefore adoption206c537

line 137why, one step back
137@pytest.mark.asyncio

Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15

line 138why, one step back
138async def test_netrc_auth() -> None:

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 139–141why, one step back
139 os.environ["NETRC"] = "tests/.netrc"
140 url = "http://netrcexample.org"141

Drop sync (#544)Tom Christiebefore adoption206c537

lines 142–143why, one step back
142 client = Client(dispatch=MockDispatch())
143 response = await client.get(url)

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 144–150why, one step back
144
145 assert response.status_code == 200146 assert response.json() == {147 "auth": "Basic ZXhhbXBsZS11c2VybmFtZTpleGFtcGxlLXBhc3N3b3Jk"148 }149150

Drop sync (#544)Tom Christiebefore adoption206c537

line 151why, one step back
151@pytest.mark.asyncio

Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15

line 152why, one step back
152async def test_auth_header_has_priority_over_netrc() -> None:

Ensure Authorization header has priority over .netrcTom Christiebefore adoption43331cf

lines 153–163why, one step back
153 os.environ["NETRC"] = "tests/.netrc"
154 url = "http://netrcexample.org"155156 client = Client(dispatch=MockDispatch())157 response = await client.get(url, headers={"Authorization": "Override"})158159 assert response.status_code == 200160 assert response.json() == {"auth": "Override"}161162163@pytest.mark.asyncio

Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15

line 164why, one step back
164async def test_trust_env_auth() -> None:

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 165–167why, one step back
165 os.environ["NETRC"] = "tests/.netrc"
166 url = "http://netrcexample.org"167

No I/O auth (#644)Tom Christiebefore adoption6c69e09

lines 168–169why, one step back
168 client = Client(dispatch=MockDispatch(), trust_env=False)
169 response = await client.get(url)

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 170–173why, one step back
170
171 assert response.status_code == 200172 assert response.json() == {"auth": None}173

No I/O auth (#644)Tom Christiebefore adoption6c69e09

lines 174–175why, one step back
174 client = Client(dispatch=MockDispatch(), trust_env=True)
175 response = await client.get(url)

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 176–182why, one step back
176
177 assert response.status_code == 200178 assert response.json() == {179 "auth": "Basic ZXhhbXBsZS11c2VybmFtZTpleGFtcGxlLXBhc3N3b3Jk"180 }181182

Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15

line 183why, one step back
183def test_auth_hidden_url() -> None:

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 184–189why, one step back
184 url = "http://example-username:example-password@example.org/"
185 expected = "URL('http://example-username:[secure]@example.org/')"186 assert url == URL(url)187 assert expected == repr(URL(url))188189

Drop sync (#544)Tom Christiebefore adoption206c537

line 190why, one step back
190@pytest.mark.asyncio

Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15

line 191why, one step back
191async def test_auth_hidden_header() -> None:

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 192–194why, one step back
192 url = "https://example.org/"
193 auth = ("example-username", "example-password")194

Drop sync (#544)Tom Christiebefore adoption206c537

lines 195–196why, one step back
195 client = Client(dispatch=MockDispatch())
196 response = await client.get(url, auth=auth)

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 197–200why, one step back
197
198 assert "'authorization': '[secure]'" in str(response.request.headers)199200

Drop sync (#544)Tom Christiebefore adoption206c537

line 201why, one step back
201@pytest.mark.asyncio

Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15

line 202why, one step back
202async def test_auth_invalid_type() -> None:

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

line 203why, one step back
203 url = "https://example.org/"

Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15

lines 204–206why, one step back
204 client = Client(
205 dispatch=MockDispatch(), auth="not a tuple, not a callable", # type: ignore206 )

Drop sync (#544)Tom Christiebefore adoption206c537

lines 207–208why, one step back
207 with pytest.raises(TypeError):
208 await client.get(url)

Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d

lines 209–210why, one step back
209
210

Drop sync (#544)Tom Christiebefore adoption206c537

line 211why, one step back
211@pytest.mark.asyncio

Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15

line 212why, one step back
212async def test_digest_auth_returns_no_auth_if_no_digest_header_in_response() -> None:

Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d

lines 213–215why, one step back
213 url = "https://example.org/"
214 auth = DigestAuth(username="tomchristie", password="password123")215

Drop sync (#544)Tom Christiebefore adoption206c537

lines 216–217why, one step back
216 client = Client(dispatch=MockDispatch())
217 response = await client.get(url, auth=auth)

Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d

lines 218–222why, one step back
218
219 assert response.status_code == 200220 assert response.json() == {"auth": None}221222

Drop sync (#544)Tom Christiebefore adoption206c537

line 223why, one step back
223@pytest.mark.asyncio

Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15

line 224why, one step back
224async def test_digest_auth_200_response_including_digest_auth_header() -> None:

Additional DigestAuth tests (#334)Yeray Diaz Diazbefore adoption1cd9156

lines 225–228why, one step back
225 url = "https://example.org/"
226 auth = DigestAuth(username="tomchristie", password="password123")227 auth_header = 'Digest realm="realm@host.com",qop="auth",nonce="abc",opaque="xyz"'228

Drop sync (#544)Tom Christiebefore adoption206c537

lines 229–230why, one step back
229 client = Client(dispatch=MockDispatch(auth_header=auth_header, status_code=200))
230 response = await client.get(url, auth=auth)

Additional DigestAuth tests (#334)Yeray Diaz Diazbefore adoption1cd9156

lines 231–235why, one step back
231
232 assert response.status_code == 200233 assert response.json() == {"auth": None}234235

Drop sync (#544)Tom Christiebefore adoption206c537

line 236why, one step back
236@pytest.mark.asyncio

Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15

line 237why, one step back
237async def test_digest_auth_401_response_without_digest_auth_header() -> None:

Additional DigestAuth tests (#334)Yeray Diaz Diazbefore adoption1cd9156

lines 238–240why, one step back
238 url = "https://example.org/"
239 auth = DigestAuth(username="tomchristie", password="password123")240

Drop sync (#544)Tom Christiebefore adoption206c537

lines 241–242why, one step back
241 client = Client(dispatch=MockDispatch(auth_header="", status_code=401))
242 response = await client.get(url, auth=auth)

Additional DigestAuth tests (#334)Yeray Diaz Diazbefore adoption1cd9156

lines 243–247why, one step back
243
244 assert response.status_code == 401245 assert response.json() == {"auth": None}246247

Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d

lines 248–260why, one step back
248@pytest.mark.parametrize(
249 "algorithm,expected_hash_length,expected_response_length",250 [251 ("MD5", 64, 32),252 ("MD5-SESS", 64, 32),253 ("SHA", 64, 40),254 ("SHA-SESS", 64, 40),255 ("SHA-256", 64, 64),256 ("SHA-256-SESS", 64, 64),257 ("SHA-512", 64, 128),258 ("SHA-512-SESS", 64, 128),259 ],260)

Drop sync (#544)Tom Christiebefore adoption206c537

line 261why, one step back
261@pytest.mark.asyncio

Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15

lines 262–264why, one step back
262async def test_digest_auth(
263 algorithm: str, expected_hash_length: int, expected_response_length: int264) -> None:

Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d

lines 265–267why, one step back
265 url = "https://example.org/"
266 auth = DigestAuth(username="tomchristie", password="password123")267

Drop sync (#544)Tom Christiebefore adoption206c537

lines 268–269why, one step back
268 client = Client(dispatch=MockDigestAuthDispatch(algorithm=algorithm))
269 response = await client.get(url, auth=auth)

Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d

lines 270–271why, one step back
270
271 assert response.status_code == 200

Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15

lines 272–274why, one step back
272 authorization = typing.cast(dict, response.json())["auth"]
273 scheme, _, fields = authorization.partition(" ")274 assert scheme == "Digest"

Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d

line 275why, one step back
275

Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15

line 276why, one step back
276 response_fields = [field.strip() for field in fields.split(",")]

Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d

lines 277–290why, one step back
277 digest_data = dict(field.split("=") for field in response_fields)
278279 assert digest_data["username"] == '"tomchristie"'280 assert digest_data["realm"] == '"httpx@example.org"'281 assert "nonce" in digest_data282 assert digest_data["uri"] == '"/"'283 assert len(digest_data["response"]) == expected_response_length + 2 # extra quotes284 assert len(digest_data["opaque"]) == expected_hash_length + 2285 assert digest_data["algorithm"] == algorithm286 assert digest_data["qop"] == "auth"287 assert digest_data["nc"] == "00000001"288 assert len(digest_data["cnonce"]) == 16 + 2289290

Drop sync (#544)Tom Christiebefore adoption206c537

line 291why, one step back
291@pytest.mark.asyncio

Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15

line 292why, one step back
292async def test_digest_auth_no_specified_qop() -> None:

Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d

lines 293–295why, one step back
293 url = "https://example.org/"
294 auth = DigestAuth(username="tomchristie", password="password123")295

Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15

line 296why, one step back
296 client = Client(dispatch=MockDigestAuthDispatch(qop=""))

Drop sync (#544)Tom Christiebefore adoption206c537

line 297why, one step back
297 response = await client.get(url, auth=auth)

Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d

lines 298–299why, one step back
298
299 assert response.status_code == 200

Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15

lines 300–302why, one step back
300 authorization = typing.cast(dict, response.json())["auth"]
301 scheme, _, fields = authorization.partition(" ")302 assert scheme == "Digest"

Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d

line 303why, one step back
303

Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15

line 304why, one step back
304 response_fields = [field.strip() for field in fields.split(",")]

Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d

lines 305–318why, one step back
305 digest_data = dict(field.split("=") for field in response_fields)
306307 assert "qop" not in digest_data308 assert "nc" not in digest_data309 assert "cnonce" not in digest_data310 assert digest_data["username"] == '"tomchristie"'311 assert digest_data["realm"] == '"httpx@example.org"'312 assert len(digest_data["nonce"]) == 64 + 2 # extra quotes313 assert digest_data["uri"] == '"/"'314 assert len(digest_data["response"]) == 64 + 2315 assert len(digest_data["opaque"]) == 64 + 2316 assert digest_data["algorithm"] == "SHA-256"317318

Additional DigestAuth tests (#334)Yeray Diaz Diazbefore adoption1cd9156

line 319why, one step back
319@pytest.mark.parametrize("qop", ("auth, auth-int", "auth,auth-int", "unknown,auth"))

Drop sync (#544)Tom Christiebefore adoption206c537

line 320why, one step back
320@pytest.mark.asyncio

Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15

line 321why, one step back
321async def test_digest_auth_qop_including_spaces_and_auth_returns_auth(qop: str) -> None:

Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d

lines 322–324why, one step back
322 url = "https://example.org/"
323 auth = DigestAuth(username="tomchristie", password="password123")324

Drop sync (#544)Tom Christiebefore adoption206c537

lines 325–326why, one step back
325 client = Client(dispatch=MockDigestAuthDispatch(qop=qop))
326 await client.get(url, auth=auth)

Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d

lines 327–328why, one step back
327
328

Drop sync (#544)Tom Christiebefore adoption206c537

line 329why, one step back
329@pytest.mark.asyncio

Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15

line 330why, one step back
330async def test_digest_auth_qop_auth_int_not_implemented() -> None:

Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d

lines 331–332why, one step back
331 url = "https://example.org/"
332 auth = DigestAuth(username="tomchristie", password="password123")

Drop sync (#544)Tom Christiebefore adoption206c537

line 333why, one step back
333 client = Client(dispatch=MockDigestAuthDispatch(qop="auth-int"))

Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d

lines 334–335why, one step back
334
335 with pytest.raises(NotImplementedError):

Drop sync (#544)Tom Christiebefore adoption206c537

line 336why, one step back
336 await client.get(url, auth=auth)

Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d

lines 337–338why, one step back
337
338

Drop sync (#544)Tom Christiebefore adoption206c537

line 339why, one step back
339@pytest.mark.asyncio

Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15

line 340why, one step back
340async def test_digest_auth_qop_must_be_auth_or_auth_int() -> None:

Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d

lines 341–342why, one step back
341 url = "https://example.org/"
342 auth = DigestAuth(username="tomchristie", password="password123")

Drop sync (#544)Tom Christiebefore adoption206c537

line 343why, one step back
343 client = Client(dispatch=MockDigestAuthDispatch(qop="not-auth"))

Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d

lines 344–345why, one step back
344
345 with pytest.raises(ProtocolError):

Drop sync (#544)Tom Christiebefore adoption206c537

line 346why, one step back
346 await client.get(url, auth=auth)

Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d

lines 347–348why, one step back
347
348

Drop sync (#544)Tom Christiebefore adoption206c537

line 349why, one step back
349@pytest.mark.asyncio

Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15

line 350why, one step back
350async def test_digest_auth_incorrect_credentials() -> None:

Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d

lines 351–353why, one step back
351 url = "https://example.org/"
352 auth = DigestAuth(username="tomchristie", password="password123")353

Drop sync (#544)Tom Christiebefore adoption206c537

lines 354–355why, one step back
354 client = Client(dispatch=MockDigestAuthDispatch(send_response_after_attempt=2))
355 response = await client.get(url, auth=auth)

Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d

lines 356–369why, one step back
356
357 assert response.status_code == 401358359360@pytest.mark.parametrize(361 "auth_header",362 [363 'Digest realm="httpx@example.org", qop="auth"', # missing fields364 'realm="httpx@example.org", qop="auth"', # not starting with Digest365 'DigestZ realm="httpx@example.org", qop="auth"'366 'qop="auth,auth-int",nonce="abc",opaque="xyz"',367 'Digest realm="httpx@example.org", qop="auth,au', # malformed fields list368 ],369)

Drop sync (#544)Tom Christiebefore adoption206c537

line 370why, one step back
370@pytest.mark.asyncio

Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15

lines 371–373why, one step back
371async def test_digest_auth_raises_protocol_error_on_malformed_header(
372 auth_header: str,373) -> None:

Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d

lines 374–375why, one step back
374 url = "https://example.org/"
375 auth = DigestAuth(username="tomchristie", password="password123")

Drop sync (#544)Tom Christiebefore adoption206c537

line 376why, one step back
376 client = Client(dispatch=MockDispatch(auth_header=auth_header, status_code=401))

Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d

lines 377–378why, one step back
377
378 with pytest.raises(ProtocolError):

Drop sync (#544)Tom Christiebefore adoption206c537

line 379why, one step back
379 await client.get(url, auth=auth)