Skip to content
Myr

test_auth.py

This file

Path

tests/client/test_auth.py

681 lines · 21.5 KiB · Python

Last changed by

Support Response(text=...), Response(html=...), Response(json=...) (#1297)Tom Christiebefore adoptionf3c2941

History of this file

Take it

The walk stopped after 200 commits: lines older than 19bf211 point at it.

Add support for sync-specific or async-specific auth flows (#1217)Florimond Mancabefore adoption016e4ee

lines 1–6why, one step back
1"""
2Integration tests for authentication.34Unit tests for auth classes also exist in tests/test_auth.py5"""6import asyncio

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 7–8why, one step back
7import hashlib
8import os

Add support for sync-specific or async-specific auth flows (#1217)Florimond Mancabefore adoption016e4ee

line 9why, one step back
9import threading

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 10–13why, one step back
10import typing
1112import pytest13

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

line 14why, one step back
14import httpx

Drop ContentStream (#1295)Tom Christiebefore adoptionfbb21fb

line 15why, one step back
15from httpx import URL, Auth, BasicAuth, DigestAuth, ProtocolError, Request, Response

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 16why, one step back
16from tests.utils import AsyncMockTransport, MockTransport

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 17why, one step back
17

Use relative tests directory references (#1052)Florimond Mancabefore adoption09672a9

line 18why, one step back
18from ..common import FIXTURES_DIR

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 19why, one step back
19

Use relative tests directory references (#1052)Florimond Mancabefore adoption09672a9

line 20why, one step back
20

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

lines 21–22why, one step back
21class App:
22 def __init__(self, auth_header: str = "", status_code: int = 200) -> None:

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 23–25why, one step back
23 self.auth_header = auth_header
24 self.status_code = status_code25

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

lines 26–28why, one step back
26 def __call__(self, request: httpx.Request) -> httpx.Response:
27 headers = {"www-authenticate": self.auth_header} if self.auth_header else {}28 data = {"auth": request.headers.get("Authorization")}

Support Response(text=...), Response(html=...), Response(json=...) (#1297)Tom Christiebefore adoptionf3c2941

line 29why, one step back
29 return httpx.Response(self.status_code, headers=headers, json=data)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 30–31why, one step back
30
31

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 32why, one step back
32class DigestApp:

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 33–45why, 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 = 045

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 46why, one step back
46 def __call__(self, request: httpx.Request) -> httpx.Response:

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 47why, one step back
47 if self._response_count < self.send_response_after_attempt:

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 48why, one step back
48 return self.challenge_send(request)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 49why, one step back
49

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 50why, one step back
50 data = {"auth": request.headers.get("Authorization")}

Support Response(text=...), Response(html=...), Response(json=...) (#1297)Tom Christiebefore adoptionf3c2941

line 51why, one step back
51 return httpx.Response(200, json=data)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 52why, one step back
52

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

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

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 54–74why, one step back
54 self._response_count += 1
55 nonce = (56 hashlib.sha256(os.urandom(8)).hexdigest()57 if self._regenerate_nonce58 else "ee96edced2a0b43e4869e96ebe27563f369c1205a049d06419bb51d8aeddf3d3"59 )60 challenge_data = {61 "nonce": nonce,62 "qop": self.qop,63 "opaque": (64 "ee6378f3ee14ebfd2fff54b70a91a7c9390518047f242ab2271380db0e14bda1"65 ),66 "algorithm": self.algorithm,67 "stale": "FALSE",68 }69 challenge_str = ", ".join(70 '{}="{}"'.format(key, value)71 for key, value in challenge_data.items()72 if value73 )74

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

lines 75–78why, one step back
75 headers = {
76 "www-authenticate": f'Digest realm="httpx@example.org", {challenge_str}',77 }78 return Response(401, headers=headers)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 79–80why, one step back
79
80

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

lines 81–126why, one step back
81class RepeatAuth(Auth):
82 """83 A mock authentication scheme that requires clients to send84 the request a fixed number of times, and then send a last request containing85 an aggregation of nonces that the server sent in 'WWW-Authenticate' headers86 of intermediate responses.87 """8889 requires_request_body = True9091 def __init__(self, repeat: int):92 self.repeat = repeat9394 def auth_flow(self, request: Request) -> typing.Generator[Request, Response, None]:95 nonces = []9697 for index in range(self.repeat):98 request.headers["Authorization"] = f"Repeat {index}"99 response = yield request100 nonces.append(response.headers["www-authenticate"])101102 key = ".".join(nonces)103 request.headers["Authorization"] = f"Repeat {key}"104 yield request105106107class ResponseBodyAuth(Auth):108 """109 A mock authentication scheme that requires clients to send an 'Authorization'110 header, then send back the contents of the response in the 'Authorization'111 header.112 """113114 requires_response_body = True115116 def __init__(self, token):117 self.token = token118119 def auth_flow(self, request: Request) -> typing.Generator[Request, Response, None]:120 request.headers["Authorization"] = self.token121 response = yield request122 data = response.text123 request.headers["Authorization"] = data124 yield request125126

Add support for sync-specific or async-specific auth flows (#1217)Florimond Mancabefore adoption016e4ee

lines 127–151why, one step back
127class SyncOrAsyncAuth(Auth):
128 """129 A mock authentication scheme that uses a different implementation for the130 sync and async cases.131 """132133 def __init__(self) -> None:134 self._lock = threading.Lock()135 self._async_lock = asyncio.Lock()136137 def sync_auth_flow(138 self, request: Request139 ) -> typing.Generator[Request, Response, None]:140 with self._lock:141 request.headers["Authorization"] = "sync-auth"142 yield request143144 async def async_auth_flow(145 self, request: Request146 ) -> typing.AsyncGenerator[Request, Response]:147 async with self._async_lock:148 request.headers["Authorization"] = "async-auth"149 yield request150151

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 152–155why, one step back
152@pytest.mark.asyncio
153async def test_basic_auth() -> None:154 url = "https://example.org/"155 auth = ("tomchristie", "password123")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 156why, one step back
156 app = App()

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 157why, one step back
157

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 158why, one step back
158 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

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

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 160–167why, one step back
160
161 assert response.status_code == 200162 assert response.json() == {"auth": "Basic dG9tY2hyaXN0aWU6cGFzc3dvcmQxMjM="}163164165@pytest.mark.asyncio166async def test_basic_auth_in_url() -> None:167 url = "https://tomchristie:password123@example.org/"

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 168why, one step back
168 app = App()

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 169why, one step back
169

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 170why, one step back
170 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

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

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 172–180why, one step back
172
173 assert response.status_code == 200174 assert response.json() == {"auth": "Basic dG9tY2hyaXN0aWU6cGFzc3dvcmQxMjM="}175176177@pytest.mark.asyncio178async def test_basic_auth_on_session() -> None:179 url = "https://example.org/"180 auth = ("tomchristie", "password123")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 181why, one step back
181 app = App()

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 182why, one step back
182

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

lines 183–185why, one step back
183 async with httpx.AsyncClient(
184 transport=AsyncMockTransport(app), auth=auth185 ) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

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

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 187–194why, one step back
187
188 assert response.status_code == 200189 assert response.json() == {"auth": "Basic dG9tY2hyaXN0aWU6cGFzc3dvcmQxMjM="}190191192@pytest.mark.asyncio193async def test_custom_auth() -> None:194 url = "https://example.org/"

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 195why, one step back
195 app = App()

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 196–200why, one step back
196
197 def auth(request: Request) -> Request:198 request.headers["Authorization"] = "Token 123"199 return request200

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 201why, one step back
201 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

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

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 203–209why, one step back
203
204 assert response.status_code == 200205 assert response.json() == {"auth": "Token 123"}206207208@pytest.mark.asyncio209async def test_netrc_auth() -> None:

Use relative tests directory references (#1052)Florimond Mancabefore adoption09672a9

line 210why, one step back
210 os.environ["NETRC"] = str(FIXTURES_DIR / ".netrc")

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 211why, one step back
211 url = "http://netrcexample.org"

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 212why, one step back
212 app = App()

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 213why, one step back
213

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 214why, one step back
214 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

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

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 216–224why, one step back
216
217 assert response.status_code == 200218 assert response.json() == {219 "auth": "Basic ZXhhbXBsZS11c2VybmFtZTpleGFtcGxlLXBhc3N3b3Jk"220 }221222223@pytest.mark.asyncio224async def test_auth_header_has_priority_over_netrc() -> None:

Use relative tests directory references (#1052)Florimond Mancabefore adoption09672a9

line 225why, one step back
225 os.environ["NETRC"] = str(FIXTURES_DIR / ".netrc")

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 226why, one step back
226 url = "http://netrcexample.org"

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 227why, one step back
227 app = App()

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 228why, one step back
228

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 229why, one step back
229 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

line 230why, one step back
230 response = await client.get(url, headers={"Authorization": "Override"})

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 231–237why, one step back
231
232 assert response.status_code == 200233 assert response.json() == {"auth": "Override"}234235236@pytest.mark.asyncio237async def test_trust_env_auth() -> None:

Use relative tests directory references (#1052)Florimond Mancabefore adoption09672a9

line 238why, one step back
238 os.environ["NETRC"] = str(FIXTURES_DIR / ".netrc")

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 239why, one step back
239 url = "http://netrcexample.org"

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 240why, one step back
240 app = App()

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 241why, one step back
241

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

line 242why, one step back
242 async with httpx.AsyncClient(

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 243why, one step back
243 transport=AsyncMockTransport(app), trust_env=False

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

lines 244–245why, one step back
244 ) as client:
245 response = await client.get(url)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 246–249why, one step back
246
247 assert response.status_code == 200248 assert response.json() == {"auth": None}249

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

line 250why, one step back
250 async with httpx.AsyncClient(

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 251why, one step back
251 transport=AsyncMockTransport(app), trust_env=True

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

lines 252–253why, one step back
252 ) as client:
253 response = await client.get(url)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 254–260why, one step back
254
255 assert response.status_code == 200256 assert response.json() == {257 "auth": "Basic ZXhhbXBsZS11c2VybmFtZTpleGFtcGxlLXBhc3N3b3Jk"258 }259260

Allow disabling auth per-request using `auth=None` (#1115)Florimond Mancabefore adoptiona4463d0

lines 261–264why, one step back
261@pytest.mark.asyncio
262async def test_auth_disable_per_request() -> None:263 url = "https://example.org/"264 auth = ("tomchristie", "password123")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 265why, one step back
265 app = App()

Allow disabling auth per-request using `auth=None` (#1115)Florimond Mancabefore adoptiona4463d0

line 266why, one step back
266

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

lines 267–269why, one step back
267 async with httpx.AsyncClient(
268 transport=AsyncMockTransport(app), auth=auth269 ) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

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

Allow disabling auth per-request using `auth=None` (#1115)Florimond Mancabefore adoptiona4463d0

lines 271–275why, one step back
271
272 assert response.status_code == 200273 assert response.json() == {"auth": None}274275

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 276–286why, one step back
276def test_auth_hidden_url() -> None:
277 url = "http://example-username:example-password@example.org/"278 expected = "URL('http://example-username:[secure]@example.org/')"279 assert url == URL(url)280 assert expected == repr(URL(url))281282283@pytest.mark.asyncio284async def test_auth_hidden_header() -> None:285 url = "https://example.org/"286 auth = ("example-username", "example-password")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 287why, one step back
287 app = App()

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 288why, one step back
288

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 289why, one step back
289 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

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

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 291–295why, one step back
291
292 assert "'authorization': '[secure]'" in str(response.request.headers)293294295@pytest.mark.asyncio

Add `Client.auth` setter (#1185)Florimond Mancabefore adoptioncb620e6

line 296why, one step back
296async def test_auth_property() -> None:

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

lines 297–299why, one step back
297 app = App()
298299 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

line 300why, one step back
300 assert client.auth is None

Add `Client.auth` setter (#1185)Florimond Mancabefore adoptioncb620e6

line 301why, one step back
301

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

lines 302–303why, one step back
302 client.auth = ("tomchristie", "password123") # type: ignore
303 assert isinstance(client.auth, BasicAuth)

Add `Client.auth` setter (#1185)Florimond Mancabefore adoptioncb620e6

line 304why, one step back
304

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

lines 305–308why, one step back
305 url = "https://example.org/"
306 response = await client.get(url)307 assert response.status_code == 200308 assert response.json() == {"auth": "Basic dG9tY2hyaXN0aWU6cGFzc3dvcmQxMjM="}

Add `Client.auth` setter (#1185)Florimond Mancabefore adoptioncb620e6

lines 309–312why, one step back
309
310311@pytest.mark.asyncio312async def test_auth_invalid_type() -> None:

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

lines 313–314why, one step back
313 app = App()
314

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 315why, one step back
315 with pytest.raises(TypeError):

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

line 316why, one step back
316 client = httpx.AsyncClient(

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 317why, one step back
317 transport=AsyncMockTransport(app),

Add `Client.auth` setter (#1185)Florimond Mancabefore adoptioncb620e6

lines 318–320why, one step back
318 auth="not a tuple, not a callable", # type: ignore
319 )320

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 321why, one step back
321 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

lines 322–323why, one step back
322 with pytest.raises(TypeError):
323 await client.get(auth="not a tuple, not a callable") # type: ignore

Add `Client.auth` setter (#1185)Florimond Mancabefore adoptioncb620e6

line 324why, one step back
324

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

lines 325–326why, one step back
325 with pytest.raises(TypeError):
326 client.auth = "not a tuple, not a callable" # type: ignore

Add `Client.auth` setter (#1185)Florimond Mancabefore adoptioncb620e6

line 327why, one step back
327

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 328–332why, one step back
328
329@pytest.mark.asyncio330async def test_digest_auth_returns_no_auth_if_no_digest_header_in_response() -> None:331 url = "https://example.org/"332 auth = DigestAuth(username="tomchristie", password="password123")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 333why, one step back
333 app = App()

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 334why, one step back
334

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 335why, one step back
335 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

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

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 337–342why, one step back
337
338 assert response.status_code == 200339 assert response.json() == {"auth": None}340 assert len(response.history) == 0341342

Handle multiple auth headers correctly (#1240)Tom Christiebefore adoption33d339a

lines 343–345why, one step back
343def test_digest_auth_returns_no_auth_if_alternate_auth_scheme() -> None:
344 url = "https://example.org/"345 auth = DigestAuth(username="tomchristie", password="password123")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

lines 346–347why, one step back
346 auth_header = "Token ..."
347 app = App(auth_header=auth_header, status_code=401)

Handle multiple auth headers correctly (#1240)Tom Christiebefore adoption33d339a

line 348why, one step back
348

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 349why, one step back
349 client = httpx.Client(transport=MockTransport(app))

Handle multiple auth headers correctly (#1240)Tom Christiebefore adoption33d339a

lines 350–356why, one step back
350 response = client.get(url, auth=auth)
351352 assert response.status_code == 401353 assert response.json() == {"auth": None}354 assert len(response.history) == 0355356

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 357–360why, one step back
357@pytest.mark.asyncio
358async def test_digest_auth_200_response_including_digest_auth_header() -> None:359 url = "https://example.org/"360 auth = DigestAuth(username="tomchristie", password="password123")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

lines 361–362why, one step back
361 auth_header = 'Digest realm="realm@host.com",qop="auth",nonce="abc",opaque="xyz"'
362 app = App(auth_header=auth_header, status_code=200)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 363why, one step back
363

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 364why, one step back
364 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

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

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 366–375why, one step back
366
367 assert response.status_code == 200368 assert response.json() == {"auth": None}369 assert len(response.history) == 0370371372@pytest.mark.asyncio373async def test_digest_auth_401_response_without_digest_auth_header() -> None:374 url = "https://example.org/"375 auth = DigestAuth(username="tomchristie", password="password123")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 376why, one step back
376 app = App(auth_header="", status_code=401)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 377why, one step back
377

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 378why, one step back
378 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

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

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 380–404why, one step back
380
381 assert response.status_code == 401382 assert response.json() == {"auth": None}383 assert len(response.history) == 0384385386@pytest.mark.parametrize(387 "algorithm,expected_hash_length,expected_response_length",388 [389 ("MD5", 64, 32),390 ("MD5-SESS", 64, 32),391 ("SHA", 64, 40),392 ("SHA-SESS", 64, 40),393 ("SHA-256", 64, 64),394 ("SHA-256-SESS", 64, 64),395 ("SHA-512", 64, 128),396 ("SHA-512-SESS", 64, 128),397 ],398)399@pytest.mark.asyncio400async def test_digest_auth(401 algorithm: str, expected_hash_length: int, expected_response_length: int402) -> None:403 url = "https://example.org/"404 auth = DigestAuth(username="tomchristie", password="password123")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 405why, one step back
405 app = DigestApp(algorithm=algorithm)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 406why, one step back
406

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 407why, one step back
407 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

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

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 409–435why, one step back
409
410 assert response.status_code == 200411 assert len(response.history) == 1412413 authorization = typing.cast(dict, response.json())["auth"]414 scheme, _, fields = authorization.partition(" ")415 assert scheme == "Digest"416417 response_fields = [field.strip() for field in fields.split(",")]418 digest_data = dict(field.split("=") for field in response_fields)419420 assert digest_data["username"] == '"tomchristie"'421 assert digest_data["realm"] == '"httpx@example.org"'422 assert "nonce" in digest_data423 assert digest_data["uri"] == '"/"'424 assert len(digest_data["response"]) == expected_response_length + 2 # extra quotes425 assert len(digest_data["opaque"]) == expected_hash_length + 2426 assert digest_data["algorithm"] == algorithm427 assert digest_data["qop"] == "auth"428 assert digest_data["nc"] == "00000001"429 assert len(digest_data["cnonce"]) == 16 + 2430431432@pytest.mark.asyncio433async def test_digest_auth_no_specified_qop() -> None:434 url = "https://example.org/"435 auth = DigestAuth(username="tomchristie", password="password123")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 436why, one step back
436 app = DigestApp(qop="")

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 437why, one step back
437

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 438why, one step back
438 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

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

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 440–467why, one step back
440
441 assert response.status_code == 200442 assert len(response.history) == 1443444 authorization = typing.cast(dict, response.json())["auth"]445 scheme, _, fields = authorization.partition(" ")446 assert scheme == "Digest"447448 response_fields = [field.strip() for field in fields.split(",")]449 digest_data = dict(field.split("=") for field in response_fields)450451 assert "qop" not in digest_data452 assert "nc" not in digest_data453 assert "cnonce" not in digest_data454 assert digest_data["username"] == '"tomchristie"'455 assert digest_data["realm"] == '"httpx@example.org"'456 assert len(digest_data["nonce"]) == 64 + 2 # extra quotes457 assert digest_data["uri"] == '"/"'458 assert len(digest_data["response"]) == 64 + 2459 assert len(digest_data["opaque"]) == 64 + 2460 assert digest_data["algorithm"] == "SHA-256"461462463@pytest.mark.parametrize("qop", ("auth, auth-int", "auth,auth-int", "unknown,auth"))464@pytest.mark.asyncio465async def test_digest_auth_qop_including_spaces_and_auth_returns_auth(qop: str) -> None:466 url = "https://example.org/"467 auth = DigestAuth(username="tomchristie", password="password123")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 468why, one step back
468 app = DigestApp(qop=qop)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 469why, one step back
469

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 470why, one step back
470 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

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

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 472–480why, one step back
472
473 assert response.status_code == 200474 assert len(response.history) == 1475476477@pytest.mark.asyncio478async def test_digest_auth_qop_auth_int_not_implemented() -> None:479 url = "https://example.org/"480 auth = DigestAuth(username="tomchristie", password="password123")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 481why, one step back
481 app = DigestApp(qop="auth-int")

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 482why, one step back
482

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 483why, one step back
483 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

lines 484–485why, one step back
484 with pytest.raises(NotImplementedError):
485 await client.get(url, auth=auth)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 486–491why, one step back
486
487488@pytest.mark.asyncio489async def test_digest_auth_qop_must_be_auth_or_auth_int() -> None:490 url = "https://example.org/"491 auth = DigestAuth(username="tomchristie", password="password123")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 492why, one step back
492 app = DigestApp(qop="not-auth")

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 493why, one step back
493

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 494why, one step back
494 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

lines 495–496why, one step back
495 with pytest.raises(ProtocolError):
496 await client.get(url, auth=auth)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 497–502why, one step back
497
498499@pytest.mark.asyncio500async def test_digest_auth_incorrect_credentials() -> None:501 url = "https://example.org/"502 auth = DigestAuth(username="tomchristie", password="password123")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 503why, one step back
503 app = DigestApp(send_response_after_attempt=2)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 504why, one step back
504

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 505why, one step back
505 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

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

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 507–514why, one step back
507
508 assert response.status_code == 401509 assert len(response.history) == 1510511512@pytest.mark.parametrize(513 "auth_header",514 [

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

lines 515–516why, one step back
515 'Digest realm="httpx@example.org", qop="auth"', # missing fields
516 'Digest realm="httpx@example.org", qop="auth,au', # malformed fields list

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 517–519why, one step back
517 ],
518)519@pytest.mark.asyncio

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

line 520why, one step back
520async def test_async_digest_auth_raises_protocol_error_on_malformed_header(

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 521why, one step back
521 auth_header: str,

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 522–524why, one step back
522) -> None:
523 url = "https://example.org/"524 auth = DigestAuth(username="tomchristie", password="password123")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

lines 525–527why, one step back
525 app = App(auth_header=auth_header, status_code=401)
526527 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

lines 528–529why, one step back
528 with pytest.raises(ProtocolError):
529 await client.get(url, auth=auth)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 530–531why, one step back
530
531

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

lines 532–534why, one step back
532@pytest.mark.parametrize(
533 "auth_header",534 [

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

lines 535–536why, one step back
535 'Digest realm="httpx@example.org", qop="auth"', # missing fields
536 'Digest realm="httpx@example.org", qop="auth,au', # malformed fields list

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

lines 537–539why, one step back
537 ],
538)539def test_sync_digest_auth_raises_protocol_error_on_malformed_header(

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 540why, one step back
540 auth_header: str,

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

lines 541–543why, one step back
541) -> None:
542 url = "https://example.org/"543 auth = DigestAuth(username="tomchristie", password="password123")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 544why, one step back
544 app = App(auth_header=auth_header, status_code=401)

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

line 545why, one step back
545

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 546why, one step back
546 with httpx.Client(transport=MockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

lines 547–548why, one step back
547 with pytest.raises(ProtocolError):
548 client.get(url, auth=auth)

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

lines 549–550why, one step back
549
550

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

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

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

line 552why, one step back
552async def test_async_auth_history() -> None:

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 553–556why, one step back
553 """
554 Test that intermediate requests sent as part of an authentication flow555 are recorded in the response history.556 """

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

lines 557–558why, one step back
557 url = "https://example.org/"
558 auth = RepeatAuth(repeat=2)

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 559why, one step back
559 app = App(auth_header="abc")

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 560why, one step back
560

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 561why, one step back
561 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

lines 562–563why, one step back
562 response = await client.get(url, auth=auth)
563

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

lines 564–565why, one step back
564 assert response.status_code == 200
565 assert response.json() == {"auth": "Repeat abc.abc"}

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 566why, one step back
566

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

lines 567–570why, one step back
567 assert len(response.history) == 2
568 resp1, resp2 = response.history569 assert resp1.json() == {"auth": "Repeat 0"}570 assert resp2.json() == {"auth": "Repeat 1"}

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 571why, one step back
571

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

lines 572–573why, one step back
572 assert len(resp2.history) == 1
573 assert resp2.history == [resp1]

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 574why, one step back
574

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

line 575why, one step back
575 assert len(resp1.history) == 0

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 576–577why, one step back
576
577

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

lines 578–582why, one step back
578def test_sync_auth_history() -> None:
579 """580 Test that intermediate requests sent as part of an authentication flow581 are recorded in the response history.582 """

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 583–584why, one step back
583 url = "https://example.org/"
584 auth = RepeatAuth(repeat=2)

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 585why, one step back
585 app = App(auth_header="abc")

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 586why, one step back
586

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 587why, one step back
587 with httpx.Client(transport=MockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

lines 588–589why, one step back
588 response = client.get(url, auth=auth)
589

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 590–607why, one step back
590 assert response.status_code == 200
591 assert response.json() == {"auth": "Repeat abc.abc"}592593 assert len(response.history) == 2594 resp1, resp2 = response.history595 assert resp1.json() == {"auth": "Repeat 0"}596 assert resp2.json() == {"auth": "Repeat 1"}597598 assert len(resp2.history) == 1599 assert resp2.history == [resp1]600601 assert len(resp1.history) == 0602603604@pytest.mark.asyncio605async def test_digest_auth_unavailable_streaming_body():606 url = "https://example.org/"607 auth = DigestAuth(username="tomchristie", password="password123")

Drop ContentStream (#1295)Tom Christiebefore adoptionfbb21fb

line 608why, one step back
608 app = DigestApp()

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 609–610why, one step back
609
610 async def streaming_body():

Transport API (#963)Yeray Diaz Diazbefore adoptiond2816c9

line 611why, one step back
611 yield b"Example request body" # pragma: nocover

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 612why, one step back
612

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 613why, one step back
613 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Drop ContentStream (#1295)Tom Christiebefore adoptionfbb21fb

line 614why, one step back
614 with pytest.raises(httpx.StreamConsumed):

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

line 615why, one step back
615 await client.post(url, data=streaming_body(), auth=auth)

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 616–618why, one step back
616
617618@pytest.mark.asyncio

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

line 619why, one step back
619async def test_async_auth_reads_response_body() -> None:

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 620–623why, one step back
620 """
621 Test that we can read the response body in an auth flow if `requires_response_body`622 is set.623 """

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

lines 624–625why, one step back
624 url = "https://example.org/"
625 auth = ResponseBodyAuth("xyz")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

lines 626–628why, one step back
626 app = App()
627628 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

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

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 630why, one step back
630

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

lines 631–632why, one step back
631 assert response.status_code == 200
632 assert response.json() == {"auth": '{"auth": "xyz"}'}

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 633–634why, one step back
633
634

Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067

lines 635–639why, one step back
635def test_sync_auth_reads_response_body() -> None:
636 """637 Test that we can read the response body in an auth flow if `requires_response_body`638 is set.639 """

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 640–641why, one step back
640 url = "https://example.org/"
641 auth = ResponseBodyAuth("xyz")

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 642why, one step back
642 app = App()

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

line 643why, one step back
643

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 644why, one step back
644 with httpx.Client(transport=MockTransport(app)) as client:

Closing AsyncClient in all tests (#871) (#1219)cdelerbefore adoptionfa7661b

lines 645–646why, one step back
645 response = client.get(url, auth=auth)
646

Test Suite on GitHub Actions (#907)Tom Christiebefore adoption19bf211

lines 647–648why, one step back
647 assert response.status_code == 200
648 assert response.json() == {"auth": '{"auth": "xyz"}'}

Add support for sync-specific or async-specific auth flows (#1217)Florimond Mancabefore adoption016e4ee

lines 649–659why, one step back
649
650651@pytest.mark.asyncio652async def test_async_auth() -> None:653 """654 Test that we can use an auth implementation specific to the async case, to655 support cases that require performing I/O or using concurrency primitives (such656 as checking a disk-based cache or fetching a token from a remote auth server).657 """658 url = "https://example.org/"659 auth = SyncOrAsyncAuth()

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 660why, one step back
660 app = App()

Add support for sync-specific or async-specific auth flows (#1217)Florimond Mancabefore adoption016e4ee

line 661why, one step back
661

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 662why, one step back
662 async with httpx.AsyncClient(transport=AsyncMockTransport(app)) as client:

Add support for sync-specific or async-specific auth flows (#1217)Florimond Mancabefore adoption016e4ee

lines 663–674why, one step back
663 response = await client.get(url, auth=auth)
664665 assert response.status_code == 200666 assert response.json() == {"auth": "async-auth"}667668669def test_sync_auth() -> None:670 """671 Test that we can use an auth implementation specific to the sync case.672 """673 url = "https://example.org/"674 auth = SyncOrAsyncAuth()

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 675why, one step back
675 app = App()

Add support for sync-specific or async-specific auth flows (#1217)Florimond Mancabefore adoption016e4ee

line 676why, one step back
676

Refactor test_auth.py to use `MockTransport` class. (#1288)Tom Christiebefore adoption2d6c30d

line 677why, one step back
677 with httpx.Client(transport=MockTransport(app)) as client:

Add support for sync-specific or async-specific auth flows (#1217)Florimond Mancabefore adoption016e4ee

lines 678–681why, one step back
678 response = client.get(url, auth=auth)
679680 assert response.status_code == 200681 assert response.json() == {"auth": "sync-auth"}