44from urllib .parse import parse_qs , urlparse
55
66import pytest
7+ from pydantic_core import ValidationError
78from auth0_server_python .auth_server .my_account_client import MyAccountClient
89from auth0_server_python .auth_server .server_client import ServerClient
910from auth0_server_python .auth_types import (
@@ -2135,14 +2136,13 @@ async def test_custom_token_exchange_empty_token():
21352136 )
21362137
21372138 # Act & Assert - empty token
2138- with pytest .raises (CustomTokenExchangeError ) as exc :
2139+ with pytest .raises (ValidationError ) as exc :
21392140 await client .custom_token_exchange (
21402141 CustomTokenExchangeOptions (
21412142 subject_token = " " ,
21422143 subject_token_type = "urn:acme:mcp-token"
21432144 )
21442145 )
2145- assert exc .value .code == CustomTokenExchangeErrorCode .INVALID_TOKEN_FORMAT
21462146 assert "empty or whitespace" in str (exc .value ).lower ()
21472147
21482148
@@ -2160,14 +2160,13 @@ async def test_custom_token_exchange_bearer_prefix():
21602160 )
21612161
21622162 # Act & Assert
2163- with pytest .raises (CustomTokenExchangeError ) as exc :
2163+ with pytest .raises (ValidationError ) as exc :
21642164 await client .custom_token_exchange (
21652165 CustomTokenExchangeOptions (
21662166 subject_token = "Bearer abc123" ,
21672167 subject_token_type = "urn:ietf:params:oauth:token-type:access_token"
21682168 )
21692169 )
2170- assert exc .value .code == CustomTokenExchangeErrorCode .INVALID_TOKEN_FORMAT
21712170 assert "Bearer" in str (exc .value )
21722171
21732172
@@ -2185,7 +2184,7 @@ async def test_custom_token_exchange_missing_actor_token_type():
21852184 )
21862185
21872186 # Act & Assert
2188- with pytest .raises (CustomTokenExchangeError ) as exc :
2187+ with pytest .raises (ValidationError ) as exc :
21892188 await client .custom_token_exchange (
21902189 CustomTokenExchangeOptions (
21912190 subject_token = "token" ,
@@ -2194,7 +2193,6 @@ async def test_custom_token_exchange_missing_actor_token_type():
21942193 actor_token_type = None
21952194 )
21962195 )
2197- assert exc .value .code == CustomTokenExchangeErrorCode .INVALID_TOKEN_FORMAT
21982196 assert "actor_token_type" in str (exc .value ).lower ()
21992197
22002198
@@ -2500,7 +2498,7 @@ async def test_login_with_custom_token_exchange_success(mocker):
25002498 )
25012499
25022500 # Assert
2503- assert "state_data" in result .state_data
2501+ assert result .state_data is not None
25042502 assert result .state_data ["user" ]["sub" ] == "user123"
25052503 assert result .state_data ["user" ]["name" ] == "John Doe"
25062504 assert result .state_data ["id_token" ] == id_token
0 commit comments