Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions tests/unit/accounts/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def test_validate(self, metrics):
"new_password": "mysupersecurepassword1!",
"password_confirm": "mysupersecurepassword1!",
"email": "foo@bar.com",
"captcha_reponse": "",
"g_recaptcha_reponse": "",
}
),
user_service=user_service,
Expand Down Expand Up @@ -634,12 +634,12 @@ def test_recaptcha_disabled(self):
assert not form.validate()
# there shouldn't be any errors for the recaptcha field if it's
# disabled
assert not form.captcha_response.errors
assert not form.g_recaptcha_response.errors

def test_recaptcha_required_error(self):
form = forms.RegistrationForm(
request=pretend.stub(),
formdata=MultiDict({"captcha_response": ""}),
formdata=MultiDict({"g_recaptcha_response": ""}),
user_service=pretend.stub(),
captcha_service=pretend.stub(
enabled=True,
Expand All @@ -648,12 +648,12 @@ def test_recaptcha_required_error(self):
breach_service=pretend.stub(check_password=lambda pw, tags=None: False),
)
assert not form.validate()
assert form.captcha_response.errors.pop() == "Captcha error."
assert form.g_recaptcha_response.errors.pop() == "Captcha error."

def test_recaptcha_error(self):
form = forms.RegistrationForm(
request=pretend.stub(),
formdata=MultiDict({"captcha_response": "asd"}),
formdata=MultiDict({"g_recaptcha_response": "asd"}),
user_service=pretend.stub(),
captcha_service=pretend.stub(
verify_response=pretend.raiser(recaptcha.RecaptchaError),
Expand All @@ -662,7 +662,7 @@ def test_recaptcha_error(self):
breach_service=pretend.stub(check_password=lambda pw, tags=None: False),
)
assert not form.validate()
assert form.captcha_response.errors.pop() == "Captcha error."
assert form.g_recaptcha_response.errors.pop() == "Captcha error."

def test_username_exists(self, pyramid_config):
form = forms.RegistrationForm(
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/accounts/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1752,7 +1752,7 @@ def _find_service(service=None, name=None, context=None):
"password_confirm": "MyStr0ng!shP455w0rd",
"email": "foo@bar.com",
"full_name": "full_name",
"captcha_response": "captchavalue",
"g_recaptcha_response": "captchavalue",
}
)

Expand Down
4 changes: 2 additions & 2 deletions warehouse/accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,15 +407,15 @@ class RegistrationForm( # type: ignore[misc]
PreventNullBytesValidator(),
]
)
captcha_response = wtforms.StringField()
g_recaptcha_response = wtforms.StringField()

def __init__(self, *args, captcha_service, user_service, **kwargs):
super().__init__(*args, **kwargs)
self.user_service = user_service
self.user_id = None
self.captcha_service = captcha_service

def validate_captcha_response(self, field):
def validate_g_recaptcha_response(self, field):
# do required data validation here due to enabled flag being required
if self.captcha_service.enabled and not field.data:
raise wtforms.validators.ValidationError("Captcha error.")
Expand Down
4 changes: 2 additions & 2 deletions warehouse/templates/includes/input-captcha.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
{% if captcha_svc.enabled %}
<div class="{{ captcha_svc.class_name }}"
data-sitekey="{{ captcha_svc.site_key }}"></div>
{% if form.captcha_response.errors %}
{% if form.g_recaptcha_response.errors %}
<ul class="form-errors">
{% for error in form.captcha_response.errors %}<li>{{ error }}</li>{% endfor %}
{% for error in form.g_recaptcha_response.errors %}<li>{{ error }}</li>{% endfor %}
</ul>
{% endif %}
{% endif %}
Expand Down