Skip to content

Commit 3cd1b6a

Browse files
committed
adds tests
1 parent e28b4f9 commit 3cd1b6a

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-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: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1+
# pylint: disable=redefined-outer-name
2+
# pylint: disable=unused-argument
3+
# pylint: disable=unused-variable
4+
# pylint: disable=too-many-arguments
5+
16
import base64
27
import json
38
import os
49
from urllib.parse import parse_qsl, urlparse
510

611
import pytest
712
from cryptography.fernet import Fernet, InvalidToken
13+
from faker import Faker
814
from starlette.datastructures import URL
915

1016

@@ -44,18 +50,45 @@ def consume(url):
4450
raise
4551

4652
except InvalidToken as err:
47-
# TODO: cannot decode
4853
print("Invalid Key", err)
4954
raise
5055

5156

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

5687
# invitation generator app
57-
invitation_url = produce(guest_email="[email protected]")
88+
invitation_url = produce(guest_email=fake_email)
89+
assert invitation_url.fragment
5890

5991
# osparc side
6092
invitation_data = consume(invitation_url)
6193
print(json.dumps(invitation_data, indent=1))
94+
assert invitation_data["guest"] == fake_email

0 commit comments

Comments
 (0)