Skip to content

Commit 07c1174

Browse files
authored
🐛Fixes: Registration of the same phone number (ITISFoundation#3315)
1 parent 3b16347 commit 07c1174

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

services/web/server/src/simcore_service_webserver/login/handlers.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff 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

services/web/server/tests/unit/with_dbs/03/test_login_2fa.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from aiohttp import web
1111
from aiohttp.test_utils import TestClient
1212
from pytest import MonkeyPatch
13+
from pytest_simcore.helpers import utils_login
1314
from pytest_simcore.helpers.utils_assert import assert_status
1415
from pytest_simcore.helpers.utils_dict import ConfigDict
1516
from 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"]

0 commit comments

Comments
 (0)