|
| 1 | +# pylint: disable=redefined-outer-name |
| 2 | +# pylint: disable=unused-argument |
| 3 | +# pylint: disable=unused-variable |
| 4 | +# pylint: disable=too-many-arguments |
| 5 | + |
1 | 6 | import base64 |
2 | 7 | import json |
3 | 8 | import os |
4 | 9 | from urllib.parse import parse_qsl, urlparse |
5 | 10 |
|
6 | 11 | import pytest |
7 | 12 | from cryptography.fernet import Fernet, InvalidToken |
| 13 | +from faker import Faker |
8 | 14 | from starlette.datastructures import URL |
9 | 15 |
|
10 | 16 |
|
@@ -44,18 +50,45 @@ def consume(url): |
44 | 50 | raise |
45 | 51 |
|
46 | 52 | except InvalidToken as err: |
47 | | - # TODO: cannot decode |
48 | 53 | print("Invalid Key", err) |
49 | 54 | raise |
50 | 55 |
|
51 | 56 |
|
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): |
53 | 84 | secret_key = Fernet.generate_key() |
54 | 85 | monkeypatch.setenv("SECRET_KEY", secret_key.decode()) |
55 | 86 |
|
56 | 87 | # invitation generator app |
57 | | - invitation_url = produce( guest_email="[email protected]") |
| 88 | + invitation_url = produce(guest_email=fake_email) |
| 89 | + assert invitation_url.fragment |
58 | 90 |
|
59 | 91 | # osparc side |
60 | 92 | invitation_data = consume(invitation_url) |
61 | 93 | print(json.dumps(invitation_data, indent=1)) |
| 94 | + assert invitation_data["guest"] == fake_email |
0 commit comments