From ea5851582d8df8c78c2fac7b73d9131ea0634727 Mon Sep 17 00:00:00 2001 From: Glandos Date: Fri, 9 Sep 2022 22:18:11 +0200 Subject: [PATCH] Captcha value should be case insensitive on both side (form and l10n values) Fixes #1060 --- ihatemoney/forms.py | 2 +- ihatemoney/tests/main_test.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/ihatemoney/forms.py b/ihatemoney/forms.py index af44ead7..c4fc32a8 100644 --- a/ihatemoney/forms.py +++ b/ihatemoney/forms.py @@ -254,7 +254,7 @@ class ProjectFormWithCaptcha(ProjectForm): ) def validate_captcha(self, field): - if not field.data.lower() == _("euro"): + if not field.data.lower() == _("euro").lower(): message = _("Please, validate the captcha to proceed.") raise ValidationError(Markup(message)) diff --git a/ihatemoney/tests/main_test.py b/ihatemoney/tests/main_test.py index 97ab82ac..f0a11d66 100644 --- a/ihatemoney/tests/main_test.py +++ b/ihatemoney/tests/main_test.py @@ -301,6 +301,23 @@ class EmailFailureTestCase(IhatemoneyTestCase): class CaptchaTestCase(IhatemoneyTestCase): ENABLE_CAPTCHA = True + def test_project_creation_with_captcha_case_insensitive(self): + # Test that case doesn't matter + # Patch the lazy_gettext as it is imported as '_' in forms for captcha value check + with patch("ihatemoney.forms._", new=lambda x: "ÉÙÜẞ"), self.client as c: + c.post( + "/create", + data={ + "name": "raclette party", + "id": "raclette", + "password": "party", + "contact_email": "raclette@notmyidea.org", + "default_currency": "USD", + "captcha": "éùüß", + }, + ) + assert len(models.Project.query.all()) == 1 + def test_project_creation_with_captcha(self): with self.client as c: c.post(