Merge pull request 'fix(auth): enforce RFC-compliant email validation rejecting invalid domains' (#30) from fix/email-format-validation into main
Reviewed-on: https://git.zedobject.local/AcuPedia/acupedia-api/pulls/30 Reviewed-by: Amit Salunke <amit@noreply.localhost>
This commit is contained in:
commit
6abe3a66ec
|
|
@ -19,7 +19,9 @@ from .errors import InvalidEmailError, InvalidTokenError, WeakPasswordError
|
|||
DEFAULT_JWT_SECRET = "panacea-secret-key-for-jwt-token-generation"
|
||||
JWT_SECRET = os.getenv("JWT_SECRET", DEFAULT_JWT_SECRET)
|
||||
JWT_TTL_SECONDS = int(os.getenv("JWT_TTL_SECONDS", str(86400 * 7)))
|
||||
EMAIL_REGEX = re.compile(r"^[^\s@]+@[^\s@]+\.[^\s@]+$")
|
||||
EMAIL_REGEX = re.compile(
|
||||
r"^[a-zA-Z0-9_%+-]+(?:\.[a-zA-Z0-9_%+-]+)*@[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?)*\.[a-zA-Z]{2,}$"
|
||||
)
|
||||
|
||||
|
||||
def base64url_encode(data: bytes) -> str:
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ class TestEmailAndPhoneNormalization:
|
|||
def test_normalize_valid_email(self) -> None:
|
||||
assert normalize_email(" USER@Example.COM ") == "user@example.com"
|
||||
assert normalize_email("john.doe+test@domain.co.in") == "john.doe+test@domain.co.in"
|
||||
assert normalize_email("sanskar+sarak@gmail.com") == "sanskar+sarak@gmail.com"
|
||||
|
||||
def test_normalize_invalid_email_raises(self) -> None:
|
||||
invalid_emails = [
|
||||
|
|
@ -30,6 +31,13 @@ class TestEmailAndPhoneNormalization:
|
|||
"username@.com",
|
||||
"user name@domain.com",
|
||||
"user@domain",
|
||||
"sanskar@+gmail+.com",
|
||||
"sanskar@+gmail.com",
|
||||
"sanskar@gmail+.com",
|
||||
"user@domain..com",
|
||||
"user@-domain.com",
|
||||
"user@domain-.com",
|
||||
"user@domain.c",
|
||||
]
|
||||
for email in invalid_emails:
|
||||
with pytest.raises(InvalidEmailError):
|
||||
|
|
|
|||
Loading…
Reference in New Issue