Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor reCAPTCHA validator as form model #10540

Merged
merged 3 commits into from
May 2, 2024
Merged

Conversation

aduth
Copy link
Member

@aduth aduth commented May 1, 2024

馃帿 Ticket

Supports LG-12873

馃洜 Summary of changes

Refactors reCAPTCHA validator classes to behave and validate as a form class.

See previous discussion: #10522 (comment)

馃摐 Testing Plan

Validate that there are no regressions in the expected behavior of reCAPTCHA phone validation.

Configure reCAPTCHA score threshold in config/application.yml

phone_recaptcha_score_threshold: 0.5
  1. Go to http://localhost:3000
  2. Create an account
  3. When prompted to select MFA, choose phone
  4. Enter an international phone number, e.g. +610491570006
  5. In the reCAPTCHA score debugger tool, enter a value between 0.0 and 1.0
  6. Click "Send code"
  7. Observe that you are blocked if the score you entered was less than 0.5

changelog: Internal, reCAPTCHA, Refactor reCAPTCHA validator as form model
@@ -1,14 +1,21 @@
# frozen_string_literal: true

class RecaptchaValidator
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we rename to Form and move to app/forms as well?

Copy link
Member Author

@aduth aduth May 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I thought about that. We probably should, wasn't sure if the amount of noise it might add to this pull request might be worth doing it incrementally (i.e. separate pull request), especially since there's subclasses that might also need to be moved.

I did find that we have a couple other examples of form validators in services (e.g. SamlRequestValidator), though I think those probably ought to be moved as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of the app/validator objects don't have the same interface as forms, but yes SamlRequestValidator seems to implement the Form interface

@aduth aduth marked this pull request as ready for review May 2, 2024 14:36
@aduth aduth requested a review from a team May 2, 2024 14:36
@aduth
Copy link
Member Author

aduth commented May 2, 2024

I will plan to move/rename this to app/forms, but will do that as a separate pull request, to keep diff noise to a minimum.

Comment on lines +134 to +135
recaptcha_validator.submit(recaptcha_token)
errors.merge!(recaptcha_validator)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does errors.merge! work with an entire validator? I'd expect more like

Suggested change
recaptcha_validator.submit(recaptcha_token)
errors.merge!(recaptcha_validator)
recaptcha_validator.submit(recaptcha_token)
errors.merge!(recaptcha_validator.errors)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I initially expected as well, but it error'd because ActiveModel::Errors doesn't have an errors method; it's expecting the model, not the errors.

@aduth aduth merged commit b0fb701 into main May 2, 2024
2 checks passed
@aduth aduth deleted the aduth-recaptcha-validator-form branch May 2, 2024 18:40
@jmdembe jmdembe mentioned this pull request May 7, 2024
samathad2023 pushed a commit that referenced this pull request May 11, 2024
* Refactor reCAPTCHA validator as form model

changelog: Internal, reCAPTCHA, Refactor reCAPTCHA validator as form model

* Update spec stubs

* Update mock validator specs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants