Skip to content

Commit

Permalink
Sanitize the mailbox email before creating it
Browse files Browse the repository at this point in the history
  • Loading branch information
acasajus committed Nov 28, 2024
1 parent 2498764 commit 2387d30
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/mailbox_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from app.log import LOG
from app.models import User, Mailbox, Job, MailboxActivation, Alias
from app.user_audit_log_utils import emit_user_audit_log, UserAuditLogAction
from app.utils import canonicalize_email
from app.utils import canonicalize_email, sanitize_email


@dataclasses.dataclass
Expand Down Expand Up @@ -54,6 +54,7 @@ def create_mailbox(
use_digit_codes: bool = False,
send_link: bool = True,
) -> CreateMailboxOutput:
email = sanitize_email(email)
if not user.is_premium():
LOG.i(
f"User {user} has tried to create mailbox with {email} but is not premium"
Expand Down
8 changes: 8 additions & 0 deletions tests/test_mailbox_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ def test_already_used():
mailbox_utils.create_mailbox(user, user.email)


def test_already_used_with_different_case():
user.lifetime = True
email = random_email()
mailbox_utils.create_mailbox(user, email)
with pytest.raises(mailbox_utils.MailboxError):
mailbox_utils.create_mailbox(user, email.upper())


@mail_sender.store_emails_test_decorator
def test_create_mailbox():
email = random_email()
Expand Down

0 comments on commit 2387d30

Please sign in to comment.