Skip to content

Commit

Permalink
adds tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Jan 8, 2025
1 parent 5133418 commit 501a0dc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ def handle_invalid_invitation_code_error(request: Request, exception: Exception)
user_msg,
error=exception,
error_context={
"request": f"{request}",
"request.method": f"{request.method}",
"request.url": f"{request.url}",
"request.body": getattr(request, "_json", None),
},
tip="An invitation link could not be extracted",
)
Expand Down
34 changes: 31 additions & 3 deletions services/invitations/tests/unit/test__symmetric_encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import pytest
from cryptography.fernet import Fernet, InvalidToken
from faker import Faker
from starlette.datastructures import URL


Expand Down Expand Up @@ -44,18 +45,45 @@ def consume(url):
raise

except InvalidToken as err:
# TODO: cannot decode
print("Invalid Key", err)
raise


def test_encrypt_and_decrypt(monkeypatch: pytest.MonkeyPatch):
@pytest.fixture(
params=[
"en_US", # English (United States)
"fr_FR", # French (France)
"de_DE", # German (Germany)
"ru_RU", # Russian
"ja_JP", # Japanese
"zh_CN", # Chinese (Simplified)
"ko_KR", # Korean
"ar_EG", # Arabic (Egypt)
"he_IL", # Hebrew (Israel)
"hi_IN", # Hindi (India)
"th_TH", # Thai (Thailand)
"vi_VN", # Vietnamese (Vietnam)
"ta_IN", # Tamil (India)
]
)
def fake_email(request):
locale = request.param
faker = Faker(locale)
# Use a localized name for the username part of the email
name = faker.name().replace(" ", "").replace(".", "").lower()
# Construct the email address
return f"{name}@example.{locale.split('_')[-1].lower()}"


def test_encrypt_and_decrypt(monkeypatch: pytest.MonkeyPatch, fake_email: str):
secret_key = Fernet.generate_key()
monkeypatch.setenv("SECRET_KEY", secret_key.decode())

# invitation generator app
invitation_url = produce(guest_email="[email protected]")
invitation_url = produce(guest_email=fake_email)
assert invitation_url.fragment

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

0 comments on commit 501a0dc

Please sign in to comment.