File tree Expand file tree Collapse file tree 2 files changed +33
-3
lines changed
src/simcore_service_webserver/login Expand file tree Collapse file tree 2 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -168,7 +168,7 @@ async def register_phone(request: web.Request):
168168
169169 if await db .get_user ({"phone" : phone }):
170170 raise web .HTTPUnauthorized (
171- reason = "Invalid phone number: one phone number per account allowed " ,
171+ reason = "Cannot register this phone number because it is already assigned to an active user " ,
172172 content_type = MIMETYPE_APPLICATION_JSON ,
173173 )
174174
@@ -189,15 +189,19 @@ async def register_phone(request: web.Request):
189189 )
190190 return response
191191
192- except Exception as e :
192+ except web .HTTPException :
193+ raise
194+
195+ except Exception as e : # Unexpected errors -> 503
193196 error_code = create_error_code (e )
194197 log .exception (
195198 "Phone registration unexpectedly failed [%s]" ,
196199 f"{ error_code } " ,
197200 extra = {"error_code" : error_code },
198201 )
202+
199203 raise web .HTTPServiceUnavailable (
200- reason = f"Currently cannot register phone, please try again later ({ error_code } )" ,
204+ reason = f"Currently our system cannot register phones ({ error_code } )" ,
201205 content_type = MIMETYPE_APPLICATION_JSON ,
202206 ) from e
203207
Original file line number Diff line number Diff line change 1010from aiohttp import web
1111from aiohttp .test_utils import TestClient
1212from pytest import MonkeyPatch
13+ from pytest_simcore .helpers import utils_login
1314from pytest_simcore .helpers .utils_assert import assert_status
1415from pytest_simcore .helpers .utils_dict import ConfigDict
1516from pytest_simcore .helpers .utils_envs import setenvs_from_dict
@@ -238,3 +239,28 @@ def _get_confirmation_link_from_email():
238239 assert user ["email" ] == EMAIL
239240 assert user ["phone" ] == PHONE
240241 assert user ["status" ] == UserStatus .ACTIVE .value
242+
243+
244+ async def test_register_phone_fails_with_used_number (
245+ client : TestClient ,
246+ db : AsyncpgStorage ,
247+ ):
248+ """
249+ Tests https://github.com/ITISFoundation/osparc-simcore/issues/3304
250+ """
251+
252+ # some user ALREADY registered with the same phone
253+ await utils_login .create_user (db , data = {"phone" : PHONE })
254+
255+ # new registration with same phone
256+ # 1. submit
257+ url = client .app .router ["auth_verify_2fa_phone" ].url_for ()
258+ rsp = await client .post (
259+ url ,
260+ json = {
261+ "email" : EMAIL ,
262+ "phone" : PHONE ,
263+ },
264+ )
265+ _ , error = await assert_status (rsp , web .HTTPUnauthorized )
266+ assert "phone" in error ["message" ]
You can’t perform that action at this time.
0 commit comments