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 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 pytest7Tighten up top-level API to only expose public API (#608)Tom Christiebefore adoptiond15dc0b
lines 8–10why, one step back8from httpx import URL, Client, DigestAuth, ProtocolError, Request, Response9from 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")91Drop sync (#544)Tom Christiebefore adoption206c537
lines 92–93why, one step back92 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 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/"102Drop sync (#544)Tom Christiebefore adoption206c537
lines 103–104why, one step back103 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 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")114Drop sync (#544)Tom Christiebefore adoption206c537
lines 115–116why, one step back115 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 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 request129Drop sync (#544)Tom Christiebefore adoption206c537
lines 130–131why, one step back130 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 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"141Drop sync (#544)Tom Christiebefore adoption206c537
lines 142–143why, one step back142 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 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–163why, one step back153 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.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"167No I/O auth (#644)Tom Christiebefore adoption6c69e09
lines 168–169why, one step back168 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 back170171 assert response.status_code == 200172 assert response.json() == {"auth": None}173No I/O auth (#644)Tom Christiebefore adoption6c69e09
lines 174–175why, one step back174 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 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")194Drop sync (#544)Tom Christiebefore adoption206c537
lines 195–196why, one step back195 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 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/"Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
lines 204–206why, one step back204 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 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")215Drop sync (#544)Tom Christiebefore adoption206c537
lines 216–217why, one step back216 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 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"'228Drop sync (#544)Tom Christiebefore adoption206c537
lines 229–230why, one step back229 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 back231232 assert response.status_code == 200233 assert response.json() == {"auth": None}234235Drop sync (#544)Tom Christiebefore adoption206c537
line 236why, one step back236@pytest.mark.asyncioType-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
line 237why, one step back237async def test_digest_auth_401_response_without_digest_auth_header() -> None:Additional DigestAuth tests (#334)Yeray Diaz Diazbefore adoption1cd9156
lines 238–240why, one step back238 url = "https://example.org/"239 auth = DigestAuth(username="tomchristie", password="password123")240Drop sync (#544)Tom Christiebefore adoption206c537
lines 241–242why, one step back241 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 back243244 assert response.status_code == 401245 assert response.json() == {"auth": None}246247Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 248–260why, one step back248@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 back261@pytest.mark.asyncioType-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
lines 262–264why, one step back262async 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 back265 url = "https://example.org/"266 auth = DigestAuth(username="tomchristie", password="password123")267Drop sync (#544)Tom Christiebefore adoption206c537
lines 268–269why, one step back268 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 back270271 assert response.status_code == 200Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
lines 272–274why, one step back272 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 back275Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
line 276why, one step back276 response_fields = [field.strip() for field in fields.split(",")]Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 277–290why, one step back277 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 + 2289290Drop sync (#544)Tom Christiebefore adoption206c537
line 291why, one step back291@pytest.mark.asyncioType-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
line 292why, one step back292async def test_digest_auth_no_specified_qop() -> None:Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 293–295why, one step back293 url = "https://example.org/"294 auth = DigestAuth(username="tomchristie", password="password123")295Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
line 296why, one step back296 client = Client(dispatch=MockDigestAuthDispatch(qop=""))Drop sync (#544)Tom Christiebefore adoption206c537
line 297why, one step back297 response = await client.get(url, auth=auth)Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 298–299why, one step back298299 assert response.status_code == 200Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
lines 300–302why, one step back300 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 back303Type-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
line 304why, one step back304 response_fields = [field.strip() for field in fields.split(",")]Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 305–318why, one step back305 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"317318Additional DigestAuth tests (#334)Yeray Diaz Diazbefore adoption1cd9156
line 319why, one step back319@pytest.mark.parametrize("qop", ("auth, auth-int", "auth,auth-int", "unknown,auth"))Drop sync (#544)Tom Christiebefore adoption206c537
line 320why, one step back320@pytest.mark.asyncioType-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
line 321why, one step back321async 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 back322 url = "https://example.org/"323 auth = DigestAuth(username="tomchristie", password="password123")324Drop sync (#544)Tom Christiebefore adoption206c537
lines 325–326why, one step back325 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 back327328Drop sync (#544)Tom Christiebefore adoption206c537
line 329why, one step back329@pytest.mark.asyncioType-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
line 330why, one step back330async def test_digest_auth_qop_auth_int_not_implemented() -> None:Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 331–332why, one step back331 url = "https://example.org/"332 auth = DigestAuth(username="tomchristie", password="password123")Drop sync (#544)Tom Christiebefore adoption206c537
line 333why, one step back333 client = Client(dispatch=MockDigestAuthDispatch(qop="auth-int"))Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 334–335why, one step back334335 with pytest.raises(NotImplementedError):Drop sync (#544)Tom Christiebefore adoption206c537
line 336why, one step back336 await client.get(url, auth=auth)Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 337–338why, one step back337338Drop sync (#544)Tom Christiebefore adoption206c537
line 339why, one step back339@pytest.mark.asyncioType-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
line 340why, one step back340async 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 back341 url = "https://example.org/"342 auth = DigestAuth(username="tomchristie", password="password123")Drop sync (#544)Tom Christiebefore adoption206c537
line 343why, one step back343 client = Client(dispatch=MockDigestAuthDispatch(qop="not-auth"))Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 344–345why, one step back344345 with pytest.raises(ProtocolError):Drop sync (#544)Tom Christiebefore adoption206c537
line 346why, one step back346 await client.get(url, auth=auth)Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 347–348why, one step back347348Drop sync (#544)Tom Christiebefore adoption206c537
line 349why, one step back349@pytest.mark.asyncioType-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
line 350why, one step back350async def test_digest_auth_incorrect_credentials() -> None:Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 351–353why, one step back351 url = "https://example.org/"352 auth = DigestAuth(username="tomchristie", password="password123")353Drop sync (#544)Tom Christiebefore adoption206c537
lines 354–355why, one step back354 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 back356357 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 back370@pytest.mark.asyncioType-check test_auth.py (#665)Florimond Mancabefore adoption49e4d15
lines 371–373why, one step back371async 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 back374 url = "https://example.org/"375 auth = DigestAuth(username="tomchristie", password="password123")Drop sync (#544)Tom Christiebefore adoption206c537
line 376why, one step back376 client = Client(dispatch=MockDispatch(auth_header=auth_header, status_code=401))Add DigestAuth middleware (#332)Yeray Diaz Diazbefore adoptionfd3b69d
lines 377–378why, one step back377378 with pytest.raises(ProtocolError):Drop sync (#544)Tom Christiebefore adoption206c537
line 379why, one step back379 await client.get(url, auth=auth)