Procházet zdrojové kódy

feat(e2e2): verify that email casing is stored properly, see #417

Peter Thomassen před 4 roky
rodič
revize
14f60b6232
2 změnil soubory, kde provedl 12 přidání a 5 odebrání
  1. 8 4
      test/e2e2/conftest.py
  2. 4 1
      test/e2e2/spec/test_api_user_mgmt.py

+ 8 - 4
test/e2e2/conftest.py

@@ -14,12 +14,16 @@ import requests
 from requests.exceptions import SSLError
 
 
+def random_mixed_case_string(n):
+    k = random.randint(1, n-1)
+    s = random.choices(string.ascii_lowercase, k=k) + random.choices(string.ascii_uppercase, k=n-k)
+    random.shuffle(s)
+    return ''.join(s)
+
+
 @pytest.fixture()
 def random_email() -> Callable[[], str]:
-    return lambda: (
-        "".join(random.choice(string.ascii_letters) for _ in range(10))
-        + "@desec.test"
-    )
+    return lambda: f'{random_mixed_case_string(10)}@{random_mixed_case_string(10)}.desec.test'
 
 
 @pytest.fixture()

+ 4 - 1
test/e2e2/spec/test_api_user_mgmt.py

@@ -24,6 +24,9 @@ def test_register(api_anon: DeSECAPIV1Client):
 
 def test_register2(api_user: DeSECAPIV1Client):
     user = api_user.get("/auth/account/").json()
-    assert user["email"] == api_user.email
+
+    # Verify that email address local part is stored as provided, and hostname is lowercased
+    email_name, domain_part = api_user.email.strip().rsplit('@', 1)
+    assert user["email"] == email_name + '@' + domain_part.lower()
     assert api_user.headers['Authorization'].startswith('Token ')
     assert len(api_user.headers['Authorization']) > len('Token ') + 10