From 93681b00305f88cad72d68231c05928083708f64 Mon Sep 17 00:00:00 2001 From: Marie PUPO JEAMMET Date: Tue, 27 Aug 2024 18:05:46 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=85(mailboxes)=20remove=20'+'=20from=20va?= =?UTF-8?q?lid=20special=20caracters?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We previously accepted '+' as a special caracter during mailbox creation. We now remove it, as this caracter has a very special meaning and it wouldn't make sense to create a mail using it. --- src/backend/mailbox_manager/models.py | 2 +- .../mailbox_manager/tests/test_models_mailboxes.py | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/backend/mailbox_manager/models.py b/src/backend/mailbox_manager/models.py index 9db60c1..1933b50 100644 --- a/src/backend/mailbox_manager/models.py +++ b/src/backend/mailbox_manager/models.py @@ -116,7 +116,7 @@ class Mailbox(BaseModel): max_length=150, null=False, blank=False, - validators=[validators.RegexValidator(regex="^[a-zA-Z0-9_.+-]+$")], + validators=[validators.RegexValidator(regex="^[a-zA-Z0-9_.-]+$")], ) domain = models.ForeignKey( MailDomain, diff --git a/src/backend/mailbox_manager/tests/test_models_mailboxes.py b/src/backend/mailbox_manager/tests/test_models_mailboxes.py index 0278776..19710bc 100644 --- a/src/backend/mailbox_manager/tests/test_models_mailboxes.py +++ b/src/backend/mailbox_manager/tests/test_models_mailboxes.py @@ -38,13 +38,12 @@ def test_models_mailboxes__local_part_matches_expected_format(): The local part should contain alpha-numeric caracters and a limited set of special caracters ("+", "-", ".", "_"). """ - factories.MailboxFactory(local_part="Marie-Jose.Perec+JO_2024") + # "-", ".", "_" are allowed + factories.MailboxFactory(local_part="Marie-Jose.Perec_2024") - # other special characters (such as "@" or "!") should raise a validation error - with pytest.raises(exceptions.ValidationError, match="Enter a valid value"): - factories.MailboxFactory(local_part="mariejo@unnecessarydomain.com") - - for character in ["!", "$", "%"]: + # other special characters should raise a validation error + # "+" included, as this test is about mail creation + for character in ["+", "@", "!", "$", "%", " "]: with pytest.raises(exceptions.ValidationError, match="Enter a valid value"): factories.MailboxFactory(local_part=f"marie{character}jo") @@ -186,7 +185,6 @@ def test_models_mailboxes__wrong_secret(): payload = json.loads(rsps.calls[1].request.body) assert payload == { "displayName": f"{mailbox.first_name} {mailbox.last_name}", - "email": f"{mailbox.local_part}@{domain.name}", "givenName": mailbox.first_name, "surName": mailbox.last_name, } @@ -239,7 +237,6 @@ def test_models_mailboxes__create_mailbox_success(mock_info, mock_error): payload = json.loads(rsps.calls[1].request.body) assert payload == { "displayName": f"{mailbox.first_name} {mailbox.last_name}", - "email": f"{mailbox.local_part}@{domain.name}", "givenName": mailbox.first_name, "surName": mailbox.last_name, }