@@ -1095,6 +1095,24 @@ async def test_create_reset_password_link(
10951095async def test_send_reset_password_email (
10961096 driver_config_client : TestClient ,
10971097):
1098+
1099+ tenant_info , token_info , rid_info , reset_url = "" , "" , "" , ""
1100+
1101+ class CustomEmailDeliveryService (
1102+ thirdpartyemailpassword .EmailDeliveryInterface [PasswordResetEmailTemplateVars ]
1103+ ):
1104+ async def send_email (
1105+ self ,
1106+ template_vars : PasswordResetEmailTemplateVars ,
1107+ user_context : Dict [str , Any ],
1108+ ):
1109+ nonlocal reset_url , token_info , rid_info , tenant_info
1110+ password_reset_url = template_vars .password_reset_link
1111+ reset_url = password_reset_url .split ("?" )[0 ]
1112+ token_info = password_reset_url .split ("?" )[1 ].split ("&" )[0 ]
1113+ rid_info = password_reset_url .split ("?" )[1 ].split ("&" )[1 ]
1114+ tenant_info = password_reset_url .split ("?" )[1 ].split ("&" )[2 ]
1115+
10981116 init (
10991117 supertokens_config = SupertokensConfig ("http://localhost:3567" ),
11001118 app_info = InputAppInfo (
@@ -1105,7 +1123,11 @@ async def test_send_reset_password_email(
11051123 ),
11061124 framework = "fastapi" ,
11071125 recipe_list = [
1108- thirdpartyemailpassword .init (),
1126+ thirdpartyemailpassword .init (
1127+ email_delivery = thirdpartyemailpassword .EmailDeliveryConfig (
1128+ CustomEmailDeliveryService ()
1129+ )
1130+ ),
11091131 session .init (get_token_transfer_method = lambda _ , __ , ___ : "cookie" ),
11101132 ],
11111133 )
@@ -1121,6 +1143,47 @@ async def test_send_reset_password_email(
11211143 resp = await send_reset_password_email ("public" , user_info ["id" ])
11221144 assert isinstance (resp , SendResetPasswordEmailEmailOkResult )
11231145
1146+ assert reset_url == "http://supertokens.io/auth/reset-password"
1147+ assert token_info is not None and "token=" in token_info
1148+ assert rid_info is not None and "rid=thirdpartyemailpassword" in rid_info
1149+ assert tenant_info is not None and "tenantId=public" in tenant_info
1150+
1151+ link = await send_reset_password_email ("public" , "invalidUserId" )
1152+ assert isinstance (link , SendResetPasswordEmailUnknownUserIdError )
1153+
1154+ with raises (GeneralError ) as err :
1155+ await send_reset_password_email ("invalidTenantId" , user_info ["id" ])
1156+ assert "status code: 400" in str (err .value )
1157+
1158+
1159+ @mark .asyncio
1160+ async def test_send_reset_password_email_invalid_input (
1161+ driver_config_client : TestClient ,
1162+ ):
1163+
1164+ init (
1165+ supertokens_config = SupertokensConfig ("http://localhost:3567" ),
1166+ app_info = InputAppInfo (
1167+ app_name = "SuperTokens Demo" ,
1168+ api_domain = "http://api.supertokens.io" ,
1169+ website_domain = "http://supertokens.io" ,
1170+ api_base_path = "/auth" ,
1171+ ),
1172+ framework = "fastapi" ,
1173+ recipe_list = [
1174+ thirdpartyemailpassword .init (),
1175+ session .init (get_token_transfer_method = lambda _ , __ , ___ : "cookie" ),
1176+ ],
1177+ )
1178+ start_st ()
1179+
1180+ response_1 = sign_up_request (
1181+ driver_config_client ,
"[email protected] " ,
"validpass123" 1182+ )
1183+ assert response_1 .status_code == 200
1184+ dict_response = json .loads (response_1 .text )
1185+ user_info = dict_response ["user" ]
1186+
11241187 link = await send_reset_password_email ("public" , "invalidUserId" )
11251188 assert isinstance (link , SendResetPasswordEmailUnknownUserIdError )
11261189
0 commit comments