Captcha value should be case insensitive on both side (form and l10n values)

Fixes #1060
This commit is contained in:
Glandos 2022-09-09 22:18:11 +02:00
parent 8695b899db
commit ea5851582d
2 changed files with 18 additions and 1 deletions

View file

@ -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))

View file

@ -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(