11"""
2- Tests for AnonymousClient — anonymous session API operations.
2+ Tests for AnonymousClient, covering anonymous session API operations.
33"""
44
55import inspect
3838class OneSlotStore :
3939 """
4040 Models StatelessStateStore: a store identifier is a salt, not a location.
41- One physical slot per instance — a mismatched identifier reads as absent,
42- not as a different record. AsyncMock cannot catch a collision because it
43- treats every identifier as a distinct key; this fake is required instead.
41+ One physical slot per instance, so a mismatched identifier reads as
42+ absent, not as a different record. AsyncMock cannot catch a collision
43+ because it treats every identifier as a distinct key, so this fake is
44+ required instead.
4445 """
4546
4647 def __init__ (self ):
@@ -77,7 +78,7 @@ def _fake_response(status_code=200, body=None):
7778
7879
7980class _FakeAsyncClient :
80- """Patches httpx.AsyncClient; call sequence maps 1:1 to responses."""
81+ """Patches httpx.AsyncClient. Call sequence maps 1:1 to responses."""
8182
8283 def __init__ (self , responses ):
8384 self ._responses = list (responses )
@@ -155,13 +156,13 @@ def test_constructor_accepts_callable_domain(self):
155156 assert client ._domain_resolver is resolver
156157
157158 def test_no_dpop_key_parameter_exists (self ):
158- """Structural guard (D1/§6) : AnonymousClient has no dpop_key parameter anywhere."""
159+ """Structural guard: AnonymousClient has no dpop_key parameter anywhere."""
159160 for name , method in inspect .getmembers (AnonymousClient , predicate = inspect .isfunction ):
160161 sig = inspect .signature (method )
161162 assert "dpop_key" not in sig .parameters , f"{ name } must never accept dpop_key"
162163
163164
164- # ── Fail-closed store isolation (D3a / B7) ───────────────────────────────────
165+ # ── Fail-closed store isolation ──────────── ───────────────────────────────────
165166
166167class TestStoreIsolation :
167168 @pytest .mark .asyncio
@@ -190,7 +191,7 @@ async def test_logout_without_store_raises_configuration_error(self):
190191
191192 @pytest .mark .asyncio
192193 async def test_no_write_attempted_when_store_missing (self ):
193- """Fails closed BEFORE any store write — never falls back to another store."""
194+ """Fails closed before any store write, never falls back to another store."""
194195 client = _make_client (anonymous_store = None )
195196 with patch ("httpx.AsyncClient" ) as mock_http :
196197 with pytest .raises (ConfigurationError ):
@@ -243,7 +244,7 @@ async def test_create_session_never_attaches_dpop_header(self):
243244
244245 @pytest .mark .asyncio
245246 async def test_create_session_persists_at_distinct_location_from_state_store (self ):
246- """D3a: the anonymous store instance is separate from any authenticated session store."""
247+ """The anonymous store instance is separate from any authenticated session store."""
247248 anon_store = OneSlotStore ()
248249 state_store = OneSlotStore ()
249250 state_store .slot = ("_a0_session" , {"user" : "authenticated" })
@@ -252,7 +253,7 @@ async def test_create_session_persists_at_distinct_location_from_state_store(sel
252253 with patch ("httpx.AsyncClient" , fake_http ):
253254 await client .create_session (audience = "aud" , scope = "s" )
254255 assert anon_store .slot [0 ] == ANON_IDENTIFIER
255- # The authenticated session store is a different instance entirely —
256+ # The authenticated session store is a different instance entirely,
256257 # never touched by anonymous writes.
257258 assert state_store .slot == ("_a0_session" , {"user" : "authenticated" })
258259
@@ -337,26 +338,6 @@ async def test_invalid_scope_maps_to_scope_error(self):
337338 with pytest .raises (AnonymousScopeError ):
338339 await client .create_session (audience = "aud" , scope = "s" )
339340
340- @pytest .mark .asyncio
341- async def test_secrets_never_leak_into_cause_even_nested (self ):
342- store = OneSlotStore ()
343- client = _make_client (anonymous_store = store )
344- fake_http = _FakeAsyncClient ([
345- _fake_response (400 , {
346- "error" : "invalid_request" ,
347- "error_description" : "bad" ,
348- "session_token" : "LEAKED_TOKEN" ,
349- "details" : {"client_secret" : "LEAKED_SECRET" },
350- })
351- ])
352- with patch ("httpx.AsyncClient" , fake_http ):
353- with pytest .raises (AnonymousResourceServerError ) as exc :
354- await client .create_session (audience = "aud" , scope = "s" )
355- cause_str = str (exc .value .cause )
356- assert "LEAKED_TOKEN" not in cause_str
357- assert "LEAKED_SECRET" not in cause_str
358- assert "[REDACTED]" in cause_str
359-
360341 @pytest .mark .asyncio
361342 async def test_network_failure_raises_create_error (self ):
362343 store = OneSlotStore ()
@@ -520,7 +501,7 @@ async def test_get_token_never_writes_to_authenticated_state_store(self):
520501 auth_state_store .delete .assert_not_called ()
521502
522503
523- # ── MCD / cross-tenant isolation (B6) ────────────────────────────────────────
504+ # ── MCD / cross-tenant isolation ─────── ────────────────────────────────────────
524505
525506class TestMcdIsolation :
526507 @pytest .mark .asyncio
@@ -693,7 +674,7 @@ async def test_returns_none_when_no_session(self):
693674
694675 @pytest .mark .asyncio
695676 async def test_returns_none_never_raises_on_corrupted_token (self ):
696- """Malformed stored token must deny the link, never abort the caller (D1 §5 step 5) ."""
677+ """Malformed stored token must deny the link, never abort the caller."""
697678 store = OneSlotStore ()
698679 store .slot = (ANON_IDENTIFIER , {"context" : "garbage" })
699680 client = _make_client (anonymous_store = store )
0 commit comments