Skip to content

Commit c2589c1

Browse files
fix: classify Radar email and SMS challenges correctly (#750)
Co-authored-by: workos-tars[bot] <269013284+workos-tars[bot]@users.noreply.github.com>
1 parent 5c1faa3 commit c2589c1

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

‎src/workos/_errors.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,5 +423,7 @@ def __init__(self, message: str = "Request timed out") -> None:
423423
"email_password_auth_disabled": EmailPasswordAuthDisabledError,
424424
"passkey_progressive_enrollment": PasskeyProgressiveEnrollmentError,
425425
"radar_challenge": RadarChallengeError,
426+
"radar_email_challenge": RadarChallengeError,
427+
"radar_sms_challenge": RadarChallengeError,
426428
"radar_sign_up_challenge": RadarSignUpChallengeError,
427429
}

‎tests/test_generated_client.py‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,33 @@ def test_raises_simple_auth_flow_errors(self, httpx_mock):
263263
assert exc_info.value.pending_authentication_token == "pat_tok"
264264
client.close()
265265

266+
@pytest.mark.parametrize(
267+
"error_code", ["radar_email_challenge", "radar_sms_challenge"]
268+
)
269+
@pytest.mark.parametrize("error_field", ["code", "error"])
270+
def test_raises_radar_challenge(self, workos, httpx_mock, error_code, error_field):
271+
payload = {
272+
error_field: error_code,
273+
"message": "Radar challenge required",
274+
"pending_authentication_token": "pat_radar",
275+
"radar_challenge_id": "radar_challenge_123",
276+
}
277+
httpx_mock.add_response(
278+
status_code=403, json=payload, headers={"X-Request-ID": "req_radar"}
279+
)
280+
with pytest.raises(RadarChallengeError) as exc_info:
281+
workos.user_management.authenticate_with_password(
282+
email="user@example.com", password="password"
283+
)
284+
error = exc_info.value
285+
assert isinstance(error, AuthenticationFlowError)
286+
assert isinstance(error, AuthorizationError)
287+
assert error.pending_authentication_token == "pat_radar"
288+
assert error.response_json == payload
289+
assert getattr(error, error_field) == error_code
290+
assert error.status_code == 403
291+
assert error.request_id == "req_radar"
292+
266293
def test_auth_flow_errors_are_catchable_as_authorization_error(self, httpx_mock):
267294
httpx_mock.add_response(
268295
status_code=403,
@@ -731,6 +758,35 @@ async def test_raises_sso_required(self, httpx_mock):
731758
assert exc_info.value.connection_ids == ["conn_1"]
732759
await client.close()
733760

761+
@pytest.mark.parametrize(
762+
"error_code", ["radar_email_challenge", "radar_sms_challenge"]
763+
)
764+
@pytest.mark.parametrize("error_field", ["code", "error"])
765+
async def test_raises_radar_challenge(
766+
self, async_workos, httpx_mock, error_code, error_field
767+
):
768+
payload = {
769+
error_field: error_code,
770+
"message": "Radar challenge required",
771+
"pending_authentication_token": "pat_radar",
772+
"radar_challenge_id": "radar_challenge_123",
773+
}
774+
httpx_mock.add_response(
775+
status_code=403, json=payload, headers={"X-Request-ID": "req_radar"}
776+
)
777+
with pytest.raises(RadarChallengeError) as exc_info:
778+
await async_workos.user_management.authenticate_with_password(
779+
email="user@example.com", password="password"
780+
)
781+
error = exc_info.value
782+
assert isinstance(error, AuthenticationFlowError)
783+
assert isinstance(error, AuthorizationError)
784+
assert error.pending_authentication_token == "pat_radar"
785+
assert error.response_json == payload
786+
assert getattr(error, error_field) == error_code
787+
assert error.status_code == 403
788+
assert error.request_id == "req_radar"
789+
734790
async def test_auth_flow_errors_backward_compat(self, httpx_mock):
735791
httpx_mock.add_response(
736792
status_code=403,

0 commit comments

Comments
 (0)