Skip to content

Commit a7c7ef0

Browse files
committed
test(client): pin that auth and mgmt share one last-response store
The ordering tests assert behavior, which leaves the shape unpinned: they pass whether get_last_response() reads one store or picks between two that happen to hold the same object. Assert the identity directly, including the by-token client, so a re-split fails on the invariant rather than on a symptom.
1 parent 5392fb3 commit a7c7ef0

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

tests/test_descope_client.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,32 @@ async def test_verbose_mode_captures_mgmt_response(self, client_factory):
840840
assert last_resp.headers.get("cf-ray") == "mgmt-ray-123"
841841
assert last_resp.status_code == 200
842842

843+
async def test_auth_and_mgmt_share_one_last_response_store(self, client_factory):
844+
"""The auth and mgmt clients must hold the same store object, not two equal ones.
845+
846+
This is the invariant that makes `get_last_response()` a single read. The
847+
ordering tests cannot catch a re-split on their own: once both clients write
848+
to one store, reading either of them returns the same response, so a stale
849+
`mgmt_resp or auth_resp` still looks correct. Pin the identity instead.
850+
"""
851+
client = client_factory.make(
852+
PROJECT_ID,
853+
public_key=PUBLIC_KEY_DICT,
854+
management_key="test-mgmt-key",
855+
verbose=True,
856+
)
857+
raw = client._raw
858+
if client_factory.mode == "sync":
859+
auth_store = raw._auth_http_client.last_response_store
860+
mgmt_store = raw._mgmt_http_client.last_response_store
861+
else:
862+
auth_store = raw._auth_http.last_response_store
863+
mgmt_store = raw._mgmt_http.last_response_store
864+
865+
assert auth_store is mgmt_store
866+
assert raw._last_response_store is auth_store
867+
assert raw._mgmt._outbound_application_by_token._http.last_response_store is auth_store
868+
843869
async def test_verbose_mode_returns_most_recent_across_mgmt_then_auth(self, client_factory):
844870
"""A mgmt call followed by an auth call must return the auth response, not the mgmt one."""
845871
mgmt_response = mock.Mock()

0 commit comments

Comments
 (0)