Skip to content

Commit

Permalink
Mark if a verification code has been deleted (#2290)
Browse files Browse the repository at this point in the history
  • Loading branch information
acasajus authored Oct 25, 2024
1 parent 01d5f40 commit 7295a20
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 6 additions & 2 deletions app/mailbox_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ def __init__(self):


class CannotVerifyError(MailboxError):
def __init__(self, msg: str):
def __init__(self, msg: str, deleted_activation_code: bool = False):
self.msg = msg
self.deleted_activation_code = deleted_activation_code


MAX_ACTIVATION_TRIES = 3
Expand Down Expand Up @@ -196,7 +197,10 @@ def verify_mailbox_code(user: User, mailbox_id: int, code: str) -> Mailbox:
if activation.tries >= MAX_ACTIVATION_TRIES:
LOG.i(f"User {user} failed to verify mailbox {mailbox_id} more than 3 times")
clear_activation_codes_for_mailbox(mailbox)
raise CannotVerifyError("Invalid activation code. Please request another code.")
raise CannotVerifyError(
"Invalid activation code. Please request another code.",
deleted_activation_code=True,
)
if activation.created_at < arrow.now().shift(minutes=-15):
LOG.i(
f"User {user} failed to verify mailbox {mailbox_id} because code is too old"
Expand Down
5 changes: 4 additions & 1 deletion tests/test_mailbox_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,13 @@ def test_verify_too_may():
output = mailbox_utils.create_mailbox(user, random_email())
output.activation.tries = mailbox_utils.MAX_ACTIVATION_TRIES
Session.commit()
with pytest.raises(mailbox_utils.CannotVerifyError):
try:
mailbox_utils.verify_mailbox_code(
user, output.mailbox.id, output.activation.code
)
assert False
except mailbox_utils.CannotVerifyError as e:
assert e.deleted_activation_code


@mail_sender.store_emails_test_decorator
Expand Down

0 comments on commit 7295a20

Please sign in to comment.