Skip to content

Commit 501a0dc

Browse files
committed
adds tests
1 parent 5133418 commit 501a0dc

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

services/invitations/src/simcore_service_invitations/core/exceptions_handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ def handle_invalid_invitation_code_error(request: Request, exception: Exception)
2020
user_msg,
2121
error=exception,
2222
error_context={
23-
"request": f"{request}",
2423
"request.method": f"{request.method}",
2524
"request.url": f"{request.url}",
25+
"request.body": getattr(request, "_json", None),
2626
},
2727
tip="An invitation link could not be extracted",
2828
)

services/invitations/tests/unit/test__symmetric_encryption.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import pytest
77
from cryptography.fernet import Fernet, InvalidToken
8+
from faker import Faker
89
from starlette.datastructures import URL
910

1011

@@ -44,18 +45,45 @@ def consume(url):
4445
raise
4546

4647
except InvalidToken as err:
47-
# TODO: cannot decode
4848
print("Invalid Key", err)
4949
raise
5050

5151

52-
def test_encrypt_and_decrypt(monkeypatch: pytest.MonkeyPatch):
52+
@pytest.fixture(
53+
params=[
54+
"en_US", # English (United States)
55+
"fr_FR", # French (France)
56+
"de_DE", # German (Germany)
57+
"ru_RU", # Russian
58+
"ja_JP", # Japanese
59+
"zh_CN", # Chinese (Simplified)
60+
"ko_KR", # Korean
61+
"ar_EG", # Arabic (Egypt)
62+
"he_IL", # Hebrew (Israel)
63+
"hi_IN", # Hindi (India)
64+
"th_TH", # Thai (Thailand)
65+
"vi_VN", # Vietnamese (Vietnam)
66+
"ta_IN", # Tamil (India)
67+
]
68+
)
69+
def fake_email(request):
70+
locale = request.param
71+
faker = Faker(locale)
72+
# Use a localized name for the username part of the email
73+
name = faker.name().replace(" ", "").replace(".", "").lower()
74+
# Construct the email address
75+
return f"{name}@example.{locale.split('_')[-1].lower()}"
76+
77+
78+
def test_encrypt_and_decrypt(monkeypatch: pytest.MonkeyPatch, fake_email: str):
5379
secret_key = Fernet.generate_key()
5480
monkeypatch.setenv("SECRET_KEY", secret_key.decode())
5581

5682
# invitation generator app
57-
invitation_url = produce(guest_email="[email protected]")
83+
invitation_url = produce(guest_email=fake_email)
84+
assert invitation_url.fragment
5885

5986
# osparc side
6087
invitation_data = consume(invitation_url)
6188
print(json.dumps(invitation_data, indent=1))
89+
assert invitation_data["guest"] == fake_email

0 commit comments

Comments
 (0)