-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
32 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
import pytest | ||
from cryptography.fernet import Fernet, InvalidToken | ||
from faker import Faker | ||
from starlette.datastructures import URL | ||
|
||
|
||
|
@@ -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 |