From 2352b0f80d14e0733e3f3056570e5d3e0c16ccf9 Mon Sep 17 00:00:00 2001 From: Nicholas Staples Date: Wed, 6 Apr 2016 16:45:35 +0100 Subject: [PATCH] Fix issue with uppercase in the domain name. --- app/main/validators.py | 2 +- tests/app/main/test_validators.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/main/validators.py b/app/main/validators.py index 10c56a149..9fead6336 100644 --- a/app/main/validators.py +++ b/app/main/validators.py @@ -36,5 +36,5 @@ class ValidEmailDomainRegex(object): "https://docs.google.com/forms/d/1AL8U-xJX_HAFEiQiJszGQw0PcEaEUnYATSntEghNDGo/viewform") valid_domains = current_app.config.get('EMAIL_DOMAIN_REGEXES', []) email_regex = "[^\@^\s]+@([^@^\\.^\\s]+\.)*({})$".format("|".join(valid_domains)) - if not re.match(email_regex, field.data): + if not re.match(email_regex, field.data.lower()): raise ValidationError(message) diff --git a/tests/app/main/test_validators.py b/tests/app/main/test_validators.py index 4e89d089f..80c4db467 100644 --- a/tests/app/main/test_validators.py +++ b/tests/app/main/test_validators.py @@ -57,6 +57,8 @@ def _gen_mock_field(x): @pytest.mark.parametrize("email", [ 'test@gov.uk', + 'test@GOV.UK', + 'test@gov.uK', 'test@test.test.gov.uk', 'test@test.gov.uk', 'test@mod.uk', @@ -71,7 +73,8 @@ def _gen_mock_field(x): 'test@nhs.net', 'test@gov.nhs.net', 'test@police.uk', - 'test@gov.police.uk' + 'test@gov.police.uk', + 'test@GOV.PoliCe.uk', ]) def test_valid_list_of_white_list_email_domains(app_, email): with app_.test_request_context():