From ad1d5a1217142a77cc6a87559c58435878df0f3b Mon Sep 17 00:00:00 2001 From: Kevin Morris Date: Thu, 3 Feb 2022 17:13:48 -0800 Subject: [PATCH] fix: don't check email deliverability when verifying input For tests, we only care about emails having a valid syntax. I don't think we should verify this at all, as aurweb.scripts.notify will timeout if it cant deliver via sendmail/smtp. Signed-off-by: Kevin Morris --- aurweb/util.py | 8 +++----- test/test_accounts_routes.py | 12 ------------ 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/aurweb/util.py b/aurweb/util.py index 776cf516..1f75ac22 100644 --- a/aurweb/util.py +++ b/aurweb/util.py @@ -13,7 +13,7 @@ from urllib.parse import urlparse import fastapi import pygit2 -from email_validator import EmailNotValidError, EmailUndeliverableError, validate_email +from email_validator import EmailSyntaxError, validate_email from fastapi.responses import JSONResponse import aurweb.config @@ -51,10 +51,8 @@ def valid_username(username): def valid_email(email): try: - validate_email(email) - except EmailUndeliverableError: - return False - except EmailNotValidError: + validate_email(email, check_deliverability=False) + except EmailSyntaxError: return False return True diff --git a/test/test_accounts_routes.py b/test/test_accounts_routes.py index 01e61101..30531ac7 100644 --- a/test/test_accounts_routes.py +++ b/test/test_accounts_routes.py @@ -446,18 +446,6 @@ def test_post_register_error_invalid_email(client: TestClient): assert "The email address is invalid." in content -def test_post_register_error_undeliverable_email(client: TestClient): - with client as request: - # At the time of writing, webchat.freenode.net does not contain - # mx records; if it ever does, it'll break this test. - response = post_register(request, E="email@bad.c") - - assert response.status_code == int(HTTPStatus.BAD_REQUEST) - - content = response.content.decode() - assert "The email address is invalid." in content - - def test_post_register_invalid_backup_email(client: TestClient): with client as request: response = post_register(request, BE="bad@email")