test_auth.py
This file
Path
tests/client/test_auth.py
383 lines · 12.4 KiB · Python
Last changed by
Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
History of this fileTake 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 back1import hashlibSet Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 2–3why, one step back2import json3import osType-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
line 4why, one step back4import typingSet Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 5–7why, one step back56import pytest7Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 8why, one step back8from httpx import URL, AsyncClient, DigestAuth, ProtocolError, Request, ResponseTighten up top-level API to only expose public API (#608)Tom Christiebefore adoptiond15dc0b
lines 9–10why, one step back9from httpx.config import CertTypes, TimeoutTypes, VerifyTypes10from httpx.dispatch.base import DispatcherSet Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 11–12why, one step back1112Drop sync (#544)Tom Christiebefore adoption206c537
line 13why, one step back13class MockDispatch(Dispatcher):Additional DigestAuth tests (#334)Yeray Diaz Diazbefore adoption1cd9156
lines 14–17why, one step back14 def __init__(self, auth_header: str = "", status_code: int = 200) -> None:15 self.auth_header = auth_header16 self.status_code = status_code17Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 18–19why, one step back18 async def send(19 self,Drop sync (#544)Tom Christiebefore adoption206c537
line 20why, one step back20 request: Request,Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 21–23why, one step back21 verify: VerifyTypes = None,22 cert: CertTypes = None,23 timeout: TimeoutTypes = None,Drop sync (#544)Tom Christiebefore adoption206c537
line 24why, one step back24 ) -> Response:Additional DigestAuth tests (#334)Yeray Diaz Diazbefore adoption1cd9156
line 25why, one step back25 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 back26 body = json.dumps({"auth": request.headers.get("Authorization")}).encode()Drop sync (#544)Tom Christiebefore adoption206c537
line 27why, one step back27 return Response(Additional DigestAuth tests (#334)Yeray Diaz Diazbefore adoption1cd9156
lines 28–29why, one step back28 self.status_code, headers=headers, content=body, request=request29 )Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 30–31why, one step back3031Drop sync (#544)Tom Christiebefore adoption206c537
line 32why, one step back32class MockDigestAuthDispatch(Dispatcher):Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 33–47why, one step back33 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 back48 request: Request,Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 49–51why, one step back49 verify: VerifyTypes = None,50 cert: CertTypes = None,51 timeout: TimeoutTypes = None,Drop sync (#544)Tom Christiebefore adoption206c537
line 52why, one step back52 ) -> Response:Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 53–56why, one step back53 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 back57 return Response(200, content=body, request=request)Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
line 58why, one step back58Drop sync (#544)Tom Christiebefore adoption206c537
line 59why, one step back59 def challenge_send(self, request: Request) -> Response:Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 60–83why, one step back60 self._response_count += 161 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 back84 return Response(401, headers=headers, content=b"", request=request)Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 85–86why, one step back8586Drop sync (#544)Tom Christiebefore adoption206c537
line 87why, one step back87@pytest.mark.asyncioType-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
line 88why, one step back88async def test_basic_auth() -> None:Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 89–91why, one step back89 url = "https://example.org/"90 auth = ("tomchristie", "password123")91Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 92why, one step back92 client = AsyncClient(dispatch=MockDispatch())Drop sync (#544)Tom Christiebefore adoption206c537
line 93why, one step back93 response = await client.get(url, auth=auth)Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 94–98why, one step back9495 assert response.status_code == 20096 assert response.json() == {"auth": "Basic dG9tY2hyaXN0aWU6cGFzc3dvcmQxMjM="}9798Drop sync (#544)Tom Christiebefore adoption206c537
line 99why, one step back99@pytest.mark.asyncioType-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
line 100why, one step back100async def test_basic_auth_in_url() -> None:Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 101–102why, one step back101 url = "https://tomchristie:password123@example.org/"102Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 103why, one step back103 client = AsyncClient(dispatch=MockDispatch())Drop sync (#544)Tom Christiebefore adoption206c537
line 104why, one step back104 response = await client.get(url)Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 105–109why, one step back105106 assert response.status_code == 200107 assert response.json() == {"auth": "Basic dG9tY2hyaXN0aWU6cGFzc3dvcmQxMjM="}108109Drop sync (#544)Tom Christiebefore adoption206c537
line 110why, one step back110@pytest.mark.asyncioType-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
line 111why, one step back111async def test_basic_auth_on_session() -> None:Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 112–114why, one step back112 url = "https://example.org/"113 auth = ("tomchristie", "password123")114Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 115why, one step back115 client = AsyncClient(dispatch=MockDispatch(), auth=auth)Drop sync (#544)Tom Christiebefore adoption206c537
line 116why, one step back116 response = await client.get(url)Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 117–121why, one step back117118 assert response.status_code == 200119 assert response.json() == {"auth": "Basic dG9tY2hyaXN0aWU6cGFzc3dvcmQxMjM="}120121Drop sync (#544)Tom Christiebefore adoption206c537
line 122why, one step back122@pytest.mark.asyncioType-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
line 123why, one step back123async def test_custom_auth() -> None:Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 124–125why, one step back124 url = "https://example.org/"125Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
line 126why, one step back126 def auth(request: Request) -> Request:Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 127–129why, one step back127 request.headers["Authorization"] = "Token 123"128 return request129Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 130why, one step back130 client = AsyncClient(dispatch=MockDispatch())Drop sync (#544)Tom Christiebefore adoption206c537
line 131why, one step back131 response = await client.get(url, auth=auth)Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 132–136why, one step back132133 assert response.status_code == 200134 assert response.json() == {"auth": "Token 123"}135136Drop sync (#544)Tom Christiebefore adoption206c537
line 137why, one step back137@pytest.mark.asyncioType-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
line 138why, one step back138async def test_netrc_auth() -> None:Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 139–141why, one step back139 os.environ["NETRC"] = "tests/.netrc"140 url = "http://netrcexample.org"141Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 142why, one step back142 client = AsyncClient(dispatch=MockDispatch())Drop sync (#544)Tom Christiebefore adoption206c537
line 143why, one step back143 response = await client.get(url)Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 144–150why, one step back144145 assert response.status_code == 200146 assert response.json() == {147 "auth": "Basic ZXhhbXBsZS11c2VybmFtZTpleGFtcGxlLXBhc3N3b3Jk"148 }149150Drop sync (#544)Tom Christiebefore adoption206c537
line 151why, one step back151@pytest.mark.asyncioType-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
line 152why, one step back152async def test_auth_header_has_priority_over_netrc() -> None:Ensure Authorization header has priority over .netrcTom Christiebefore adoption43331cf
lines 153–155why, one step back153 os.environ["NETRC"] = "tests/.netrc"154 url = "http://netrcexample.org"155Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 156why, one step back156 client = AsyncClient(dispatch=MockDispatch())Ensure Authorization header has priority over .netrcTom Christiebefore adoption43331cf
lines 157–163why, one step back157 response = await client.get(url, headers={"Authorization": "Override"})158159 assert response.status_code == 200160 assert response.json() == {"auth": "Override"}161162163@pytest.mark.asyncioType-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
line 164why, one step back164async def test_trust_env_auth() -> None:Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 165–167why, one step back165 os.environ["NETRC"] = "tests/.netrc"166 url = "http://netrcexample.org"167Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 168why, one step back168 client = AsyncClient(dispatch=MockDispatch(), trust_env=False)No I/O auth (#644)Tom Christiebefore adoption6c69e09
line 169why, one step back169 response = await client.get(url)Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 170–173why, one step back170171 assert response.status_code == 200172 assert response.json() == {"auth": None}173Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 174why, one step back174 client = AsyncClient(dispatch=MockDispatch(), trust_env=True)No I/O auth (#644)Tom Christiebefore adoption6c69e09
line 175why, one step back175 response = await client.get(url)Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 176–182why, one step back176177 assert response.status_code == 200178 assert response.json() == {179 "auth": "Basic ZXhhbXBsZS11c2VybmFtZTpleGFtcGxlLXBhc3N3b3Jk"180 }181182Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
line 183why, one step back183def test_auth_hidden_url() -> None:Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 184–189why, one step back184 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))188189Drop sync (#544)Tom Christiebefore adoption206c537
line 190why, one step back190@pytest.mark.asyncioType-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
line 191why, one step back191async def test_auth_hidden_header() -> None:Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 192–194why, one step back192 url = "https://example.org/"193 auth = ("example-username", "example-password")194Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 195why, one step back195 client = AsyncClient(dispatch=MockDispatch())Drop sync (#544)Tom Christiebefore adoption206c537
line 196why, one step back196 response = await client.get(url, auth=auth)Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 197–200why, one step back197198 assert "'authorization': '[secure]'" in str(response.request.headers)199200Drop sync (#544)Tom Christiebefore adoption206c537
line 201why, one step back201@pytest.mark.asyncioType-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
line 202why, one step back202async def test_auth_invalid_type() -> None:Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
line 203why, one step back203 url = "https://example.org/"Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 204why, one step back204 client = AsyncClient(Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
lines 205–206why, one step back205 dispatch=MockDispatch(), auth="not a tuple, not a callable", # type: ignore206 )Drop sync (#544)Tom Christiebefore adoption206c537
lines 207–208why, one step back207 with pytest.raises(TypeError):208 await client.get(url)Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 209–210why, one step back209210Drop sync (#544)Tom Christiebefore adoption206c537
line 211why, one step back211@pytest.mark.asyncioType-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
line 212why, one step back212async 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 back213 url = "https://example.org/"214 auth = DigestAuth(username="tomchristie", password="password123")215Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 216why, one step back216 client = AsyncClient(dispatch=MockDispatch())Drop sync (#544)Tom Christiebefore adoption206c537
line 217why, one step back217 response = await client.get(url, auth=auth)Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 218–222why, one step back218219 assert response.status_code == 200220 assert response.json() == {"auth": None}221222Drop sync (#544)Tom Christiebefore adoption206c537
line 223why, one step back223@pytest.mark.asyncioType-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
line 224why, one step back224async def test_digest_auth_200_response_including_digest_auth_header() -> None:Additional DigestAuth tests (#334)Yeray Diaz Diazbefore adoption1cd9156
lines 225–228why, one step back225 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"'228Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
lines 229–231why, one step back229 client = AsyncClient(230 dispatch=MockDispatch(auth_header=auth_header, status_code=200)231 )Drop sync (#544)Tom Christiebefore adoption206c537
line 232why, one step back232 response = await client.get(url, auth=auth)Additional DigestAuth tests (#334)Yeray Diaz Diazbefore adoption1cd9156
lines 233–237why, one step back233234 assert response.status_code == 200235 assert response.json() == {"auth": None}236237Drop sync (#544)Tom Christiebefore adoption206c537
line 238why, one step back238@pytest.mark.asyncioType-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
line 239why, one step back239async def test_digest_auth_401_response_without_digest_auth_header() -> None:Additional DigestAuth tests (#334)Yeray Diaz Diazbefore adoption1cd9156
lines 240–242why, one step back240 url = "https://example.org/"241 auth = DigestAuth(username="tomchristie", password="password123")242Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 243why, one step back243 client = AsyncClient(dispatch=MockDispatch(auth_header="", status_code=401))Drop sync (#544)Tom Christiebefore adoption206c537
line 244why, one step back244 response = await client.get(url, auth=auth)Additional DigestAuth tests (#334)Yeray Diaz Diazbefore adoption1cd9156
lines 245–249why, one step back245246 assert response.status_code == 401247 assert response.json() == {"auth": None}248249Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 250–262why, one step back250@pytest.mark.parametrize(251 "algorithm,expected_hash_length,expected_response_length",252 [253 ("MD5", 64, 32),254 ("MD5-SESS", 64, 32),255 ("SHA", 64, 40),256 ("SHA-SESS", 64, 40),257 ("SHA-256", 64, 64),258 ("SHA-256-SESS", 64, 64),259 ("SHA-512", 64, 128),260 ("SHA-512-SESS", 64, 128),261 ],262)Drop sync (#544)Tom Christiebefore adoption206c537
line 263why, one step back263@pytest.mark.asyncioType-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
lines 264–266why, one step back264async def test_digest_auth(265 algorithm: str, expected_hash_length: int, expected_response_length: int266) -> None:Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 267–269why, one step back267 url = "https://example.org/"268 auth = DigestAuth(username="tomchristie", password="password123")269Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 270why, one step back270 client = AsyncClient(dispatch=MockDigestAuthDispatch(algorithm=algorithm))Drop sync (#544)Tom Christiebefore adoption206c537
line 271why, one step back271 response = await client.get(url, auth=auth)Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 272–273why, one step back272273 assert response.status_code == 200Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
lines 274–276why, one step back274 authorization = typing.cast(dict, response.json())["auth"]275 scheme, _, fields = authorization.partition(" ")276 assert scheme == "Digest"Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
line 277why, one step back277Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
line 278why, one step back278 response_fields = [field.strip() for field in fields.split(",")]Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 279–292why, one step back279 digest_data = dict(field.split("=") for field in response_fields)280281 assert digest_data["username"] == '"tomchristie"'282 assert digest_data["realm"] == '"httpx@example.org"'283 assert "nonce" in digest_data284 assert digest_data["uri"] == '"/"'285 assert len(digest_data["response"]) == expected_response_length + 2 # extra quotes286 assert len(digest_data["opaque"]) == expected_hash_length + 2287 assert digest_data["algorithm"] == algorithm288 assert digest_data["qop"] == "auth"289 assert digest_data["nc"] == "00000001"290 assert len(digest_data["cnonce"]) == 16 + 2291292Drop sync (#544)Tom Christiebefore adoption206c537
line 293why, one step back293@pytest.mark.asyncioType-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
line 294why, one step back294async def test_digest_auth_no_specified_qop() -> None:Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 295–297why, one step back295 url = "https://example.org/"296 auth = DigestAuth(username="tomchristie", password="password123")297Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 298why, one step back298 client = AsyncClient(dispatch=MockDigestAuthDispatch(qop=""))Drop sync (#544)Tom Christiebefore adoption206c537
line 299why, one step back299 response = await client.get(url, auth=auth)Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 300–301why, one step back300301 assert response.status_code == 200Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
lines 302–304why, one step back302 authorization = typing.cast(dict, response.json())["auth"]303 scheme, _, fields = authorization.partition(" ")304 assert scheme == "Digest"Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
line 305why, one step back305Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
line 306why, one step back306 response_fields = [field.strip() for field in fields.split(",")]Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 307–320why, one step back307 digest_data = dict(field.split("=") for field in response_fields)308309 assert "qop" not in digest_data310 assert "nc" not in digest_data311 assert "cnonce" not in digest_data312 assert digest_data["username"] == '"tomchristie"'313 assert digest_data["realm"] == '"httpx@example.org"'314 assert len(digest_data["nonce"]) == 64 + 2 # extra quotes315 assert digest_data["uri"] == '"/"'316 assert len(digest_data["response"]) == 64 + 2317 assert len(digest_data["opaque"]) == 64 + 2318 assert digest_data["algorithm"] == "SHA-256"319320Additional DigestAuth tests (#334)Yeray Diaz Diazbefore adoption1cd9156
line 321why, one step back321@pytest.mark.parametrize("qop", ("auth, auth-int", "auth,auth-int", "unknown,auth"))Drop sync (#544)Tom Christiebefore adoption206c537
line 322why, one step back322@pytest.mark.asyncioType-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
line 323why, one step back323async def test_digest_auth_qop_including_spaces_and_auth_returns_auth(qop: str) -> None:Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 324–326why, one step back324 url = "https://example.org/"325 auth = DigestAuth(username="tomchristie", password="password123")326Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 327why, one step back327 client = AsyncClient(dispatch=MockDigestAuthDispatch(qop=qop))Drop sync (#544)Tom Christiebefore adoption206c537
line 328why, one step back328 await client.get(url, auth=auth)Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 329–330why, one step back329330Drop sync (#544)Tom Christiebefore adoption206c537
line 331why, one step back331@pytest.mark.asyncioType-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
line 332why, one step back332async def test_digest_auth_qop_auth_int_not_implemented() -> None:Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 333–334why, one step back333 url = "https://example.org/"334 auth = DigestAuth(username="tomchristie", password="password123")Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 335why, one step back335 client = AsyncClient(dispatch=MockDigestAuthDispatch(qop="auth-int"))Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 336–337why, one step back336337 with pytest.raises(NotImplementedError):Drop sync (#544)Tom Christiebefore adoption206c537
line 338why, one step back338 await client.get(url, auth=auth)Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 339–340why, one step back339340Drop sync (#544)Tom Christiebefore adoption206c537
line 341why, one step back341@pytest.mark.asyncioType-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
line 342why, one step back342async def test_digest_auth_qop_must_be_auth_or_auth_int() -> None:Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 343–344why, one step back343 url = "https://example.org/"344 auth = DigestAuth(username="tomchristie", password="password123")Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 345why, one step back345 client = AsyncClient(dispatch=MockDigestAuthDispatch(qop="not-auth"))Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 346–347why, one step back346347 with pytest.raises(ProtocolError):Drop sync (#544)Tom Christiebefore adoption206c537
line 348why, one step back348 await client.get(url, auth=auth)Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 349–350why, one step back349350Drop sync (#544)Tom Christiebefore adoption206c537
line 351why, one step back351@pytest.mark.asyncioType-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
line 352why, one step back352async def test_digest_auth_incorrect_credentials() -> None:Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 353–355why, one step back353 url = "https://example.org/"354 auth = DigestAuth(username="tomchristie", password="password123")355Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 356why, one step back356 client = AsyncClient(dispatch=MockDigestAuthDispatch(send_response_after_attempt=2))Drop sync (#544)Tom Christiebefore adoption206c537
line 357why, one step back357 response = await client.get(url, auth=auth)Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 358–371why, one step back358359 assert response.status_code == 401360361362@pytest.mark.parametrize(363 "auth_header",364 [365 'Digest realm="httpx@example.org", qop="auth"', # missing fields366 'realm="httpx@example.org", qop="auth"', # not starting with Digest367 'DigestZ realm="httpx@example.org", qop="auth"'368 'qop="auth,auth-int",nonce="abc",opaque="xyz"',369 'Digest realm="httpx@example.org", qop="auth,au', # malformed fields list370 ],371)Drop sync (#544)Tom Christiebefore adoption206c537
line 372why, one step back372@pytest.mark.asyncioType-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
lines 373–375why, one step back373async def test_digest_auth_raises_protocol_error_on_malformed_header(374 auth_header: str,375) -> None:Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 376–377why, one step back376 url = "https://example.org/"377 auth = DigestAuth(username="tomchristie", password="password123")Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
lines 378–380why, one step back378 client = AsyncClient(379 dispatch=MockDispatch(auth_header=auth_header, status_code=401)380 )Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 381–382why, one step back381382 with pytest.raises(ProtocolError):Drop sync (#544)Tom Christiebefore adoption206c537
line 383why, one step back383 await client.get(url, auth=auth)