Skip to content

Commit c0f3e5c

Browse files
test: cover organization forwarding and blank-org ordering for session transfer token
Add tests that organization is forwarded onto the mint request and omitted when absent, and rewrite the blank-organization test to set up an expired session and assert the refresh, state-store write, and token request are all skipped - proving the check runs before actor resolution.
1 parent b9d6ccd commit c0f3e5c

1 file changed

Lines changed: 34 additions & 3 deletions

File tree

src/auth0_server_python/tests/test_server_client.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4228,16 +4228,47 @@ def test_build_session_transfer_redirect_rejects_blank_organization():
42284228

42294229

42304230
@pytest.mark.asyncio
4231-
async def test_request_session_transfer_token_rejects_blank_organization(mocker):
4232-
"""A blank organization is rejected before the actor is resolved or any request is sent."""
4231+
async def test_request_session_transfer_token_forwards_organization_on_mint(mocker):
4232+
"""A provided organization is forwarded onto the mint request."""
42334233
client, post_mock = _stt_client(mocker)
42344234

4235+
await client.request_session_transfer_token(
4236+
subject_token="subj", subject_token_type="urn:acme:sub", actor_token="a",
4237+
organization="org_abc123",
4238+
)
4239+
4240+
assert post_mock.post.call_args[1]["data"]["organization"] == "org_abc123"
4241+
4242+
4243+
@pytest.mark.asyncio
4244+
async def test_request_session_transfer_token_omits_organization_when_absent(mocker):
4245+
"""No organization passed → the parameter is absent from the mint request, not empty."""
4246+
client, post_mock = _stt_client(mocker)
4247+
4248+
await client.request_session_transfer_token(
4249+
subject_token="subj", subject_token_type="urn:acme:sub", actor_token="a",
4250+
)
4251+
4252+
assert "organization" not in post_mock.post.call_args[1]["data"]
4253+
4254+
4255+
@pytest.mark.asyncio
4256+
async def test_request_session_transfer_token_rejects_blank_organization_before_refresh(mocker):
4257+
"""A blank organization is rejected before the expired session is refreshed or persisted."""
4258+
client, post_mock = _stt_client(mocker)
4259+
client._state_store.get.return_value = {"id_token": "stale", "refresh_token": "rt"}
4260+
usable = mocker.patch.object(client, "_is_id_token_usable", side_effect=[False, True])
4261+
refresh = mocker.patch.object(client, "get_token_by_refresh_token")
4262+
42354263
with pytest.raises(InvalidArgumentError):
42364264
await client.request_session_transfer_token(
4237-
subject_token="subj", subject_token_type="urn:acme:sub", actor_token="a",
4265+
subject_token="subj", subject_token_type="urn:acme:sub",
42384266
organization=" ",
42394267
)
42404268

4269+
refresh.assert_not_called()
4270+
usable.assert_not_called()
4271+
client._state_store.set.assert_not_called()
42414272
post_mock.post.assert_not_called()
42424273

42434274

0 commit comments

Comments
 (0)