From c03e151311db9c876ca5199915e13c6b2dccb9b0 Mon Sep 17 00:00:00 2001 From: Artur Shiriev Date: Thu, 1 Oct 2026 14:54:06 +0300 Subject: [PATCH] test: mock the identity provider with httpware's transport= option --- jwks_client/testing.py | 4 +--- pyproject.toml | 4 ++-- tests/conftest.py | 2 +- tests/test_fastapi.py | 4 +--- tests/test_litestar.py | 4 +--- 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/jwks_client/testing.py b/jwks_client/testing.py index 2da07d2..1ea8f5d 100644 --- a/jwks_client/testing.py +++ b/jwks_client/testing.py @@ -39,9 +39,7 @@ def issue_token( def create_jwks_client(self) -> JWKSClient: transport: typing.Final = httpx2.MockTransport(lambda _: httpx2.Response(200, json=self.jwks)) - return JWKSClient( - self.jwks_uri, http_client=httpware.AsyncClient(httpx2_client=httpx2.AsyncClient(transport=transport)) - ) + return JWKSClient(self.jwks_uri, http_client=httpware.AsyncClient(transport=transport)) class StaticTokenVerifier: diff --git a/pyproject.toml b/pyproject.toml index 68da56d..b91cb01 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,8 +27,8 @@ version = "0" dependencies = [ # 2.15.1 carries the fixes for the 2026 advisories and binds a PyJWK's algorithm at verify time. "pyjwt[crypto]>=2.15.1", - # 0.15.0 introduced max_response_body_bytes. - "httpware>=0.15.0,<1", + # 0.18.0 forwards transport= to the owned httpx2 client, which jwks_client.testing relies on. + "httpware>=0.18.0,<1", "httpx2>=2.0.0,<3", ] diff --git a/tests/conftest.py b/tests/conftest.py index fd8d35e..f91617a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -85,7 +85,7 @@ def signing_key() -> SigningKey: @pytest.fixture def http_client(server: JWKSServer) -> httpware.AsyncClient: - return httpware.AsyncClient(httpx2_client=httpx2.AsyncClient(transport=httpx2.MockTransport(server.handle))) + return httpware.AsyncClient(transport=httpx2.MockTransport(server.handle)) @pytest.fixture diff --git a/tests/test_fastapi.py b/tests/test_fastapi.py index f2eea64..4d64af8 100644 --- a/tests/test_fastapi.py +++ b/tests/test_fastapi.py @@ -74,9 +74,7 @@ async def test_missing_or_invalid_token_is_unauthorized(verifier: JWTVerifier, t async def test_unreachable_identity_provider_is_service_unavailable(idp: FakeIdentityProvider) -> None: transport = httpx2.MockTransport(lambda _: httpx2.Response(HTTPStatus.BAD_GATEWAY)) - jwks = JWKSClient( - idp.jwks_uri, http_client=httpware.AsyncClient(httpx2_client=httpx2.AsyncClient(transport=transport)) - ) + jwks = JWKSClient(idp.jwks_uri, http_client=httpware.AsyncClient(transport=transport)) response = await call(build_app(JWKSBearer(JWTVerifier(jwks, algorithms=["RS256"]))), idp.issue_token()) diff --git a/tests/test_litestar.py b/tests/test_litestar.py index 2ae6ce0..961dfa1 100644 --- a/tests/test_litestar.py +++ b/tests/test_litestar.py @@ -103,9 +103,7 @@ async def test_token_outside_policy_is_unauthorized(idp: FakeIdentityProvider, v async def test_unreachable_identity_provider_is_service_unavailable(idp: FakeIdentityProvider) -> None: transport = httpx2.MockTransport(lambda _: httpx2.Response(HTTPStatus.BAD_GATEWAY)) - jwks = JWKSClient( - idp.jwks_uri, http_client=httpware.AsyncClient(httpx2_client=httpx2.AsyncClient(transport=transport)) - ) + jwks = JWKSClient(idp.jwks_uri, http_client=httpware.AsyncClient(transport=transport)) async with AsyncTestClient(build_app(JWTVerifier(jwks, algorithms=["RS256"]))) as client: response = await client.get("/claims", headers={"Authorization": f"Bearer {idp.issue_token()}"})