424 Commits

Author SHA1 Message Date
Carlos Antonio da Silva
e9c534d363 Fix "Test is missing assertions" warnings
`test_set_null_fields_on_migrations`
      ./devise/test/models_test.rb:87
    `test_does_not_crash_when_the_last_request_at_is_a_String`
      ./devise/test/integration/timeoutable_test.rb:191
    `test_defined_Warden_after_authentication_callback_should_not_be_called_when_sign_in_is_called`
      ./devise/test/test/controller_helpers_test.rb:114
    `test_defined_Warden_before_logout_callback_should_not_be_called_when_sign_out_is_called`
      ./devise/test/test/controller_helpers_test.rb:128
2026-01-05 18:16:22 -03:00
Julius Graakjær Grantzau
356b094312 Downcase authentication keys and humanize error message (#4834)
"Invalid Email or password." is grammatically incorrect, a change
introduced a while ago by #4014.

Signed-off-by: Carlos Antonio da Silva <carlosantoniodasilva@gmail.com>
2025-12-31 14:40:36 -03:00
Carlos Antonio da Silva
051f94a498 Pass locale with activatable / timeoutable hooks (#5815)
We need to explicitly pass the `locale` around from the options (passed
to `warden.authenticate!` for instance) or the `I18n.locale` when
logging out and redirecting the user via `throw :warden`, otherwise in a
multi-locale app we'd lose the locale previously set / passed around and
fallback to the default for that flash message.

This is a follow-up of the fixes in #5567 where we implemented the
locale passing logic down to the failure app, but it missed these places
where we were using `throw :warden`.

Closes #5812
2025-12-31 09:12:25 -03:00
Carlos Antonio da Silva
fa052e5064 Remove some mongoid version checks from test suite
We no longer run against or support old Mongoid versions.
2025-10-31 11:26:19 -03:00
Carlos Antonio da Silva
5667ceaa1e Merge pull request #5600 from heartcombo/rm-drop-support-to-old-rubies-and-rails
Drop support to EOL rubies and Rails
2023-10-13 11:23:18 -03:00
Carlos Antonio da Silva
4d18d81311 Respect locale set by controller in the failure app (#5567)
A common usage of I18n with different locales is to create some around
callback in the application controller that sets the locale for the
entire action, via params/url/user/etc., which ensure the locale is
respected for the duration of that action, and resets at the end.

Devise was not respecting the locale when the authenticate failed and
triggered the failure app, because that happens in a warden middleware
right up in the change, by that time the controller around callback had
already reset the locale back to its default, and the failure app would
just translate flash messages using the default locale.

Now we are passing the current locale down to the failure app via warden
options, and wrapping it with an around callback, which makes the
failure app respect the set I18n locale by the controller at the time
the authentication failure is triggered, working as expected. (much more
like a normal controller would.)

I chose to introduce a callback in the failure app so we could wrap the
whole `respond` action processing rather than adding individual `locale`
options to the `I18n.t` calls, because that should ensure other possible
`I18n.t` calls from overridden failure apps would respect the set locale
as well, and makes it more like one would implement in a controller. I
don't recommend people using callbacks in their own failure apps though,
as this is not going to be documented as a "feature" of failures apps,
it's considered "internal" and could be refactored at any point.

It is possible to override the locale with the new `i18n_locale` method,
which simply defaults to the passed locale from the controller.

Closes #5247
Closes #5246

Related to: #3052, #4823, and possible others already closed.
Related to warden: (may be closed there afterwards)
https://github.com/wardencommunity/warden/issues/180
https://github.com/wardencommunity/warden/issues/170
2023-10-13 11:20:29 -03:00
Rafael Mendonça França
c8207373ea Drop support to all EOL rails versions 2023-10-12 16:52:01 -03:00
Carlos Antonio da Silva
e688b2f256 Merge branch '4-stable' 2023-10-11 19:12:53 -03:00
Carlos Antonio da Silva
34cb23ed9c Fix mocha warnings with hash vs kwargs 2023-10-10 11:29:27 -03:00
Edouard CHIN
4f82235630 Use Omniauth.allowed_methods' as routing verbs for the auth path:
- ### Context

  Since version 2.0.0, Omniauth no longer recognizes `GET` request
  on the auth path (`/users/auth/<provider>`). `POST` is the only
  verb that is by default recognized in order to mitigate CSRF
  attack. 66110da85e/lib/omniauth/strategy.rb (L205)

  Ultimatelly, when a user try to access `GET /users/auth/facebook`,
  Devise [passthru action](6d32d2447c/app/controllers/devise/omniauth_callbacks_controller.rb (L6))
  will be called which just return a raw 404 page.

  ### Problem

  There is no problem per se and everything work. However the
  advantage of not matching GET request at the router layer allows
  to get that same 404 page stylized for "free" (Rails ending up
  rendering the 404 page of the app).

  I believe it's also more consistent and less surprising for users
  if this passthru action don't get called.

  ### Drawback

  An application can no longer override the `passthru` to perform
  the logic it wants (i.e. redirect the user).

  If this is a dealbreaker, feel free to close this PR :).
2023-06-09 23:46:12 +00:00
Rafael Mendonça França
6d058bfde8 Fix tests after #5515 2023-06-09 22:34:19 +00:00
Carlos Antonio da Silva
232c855c54 Fix tests with Rails main
Rails main / 7.1.0.alpha introduced a change to improve typography by
default, by converting all apostrophes to be single quotation marks.
https://github.com/rails/rails/pull/45463

The change caused all our text based matching to fail, this updates the
tests to ensure compatibility.

Model tests were changed to test against the error type & information
rather than the translated string, which I think is an improvement
overall that should make them a little less brittle. I thought of using
[of_kind?] but that isn't available on all Rails versions we currently
support, while `added?` is. The drawback is that `added?` require full
details like the `:confirmation` example which requires the related
attribute that is being confirmed, but that's a small price to pay.

Integration tests were changed to match on a regexp that accepts both
quotes. I could've used a simple `.` to match anything there, but
thought I'd just keep it specific for clarity on what it is really
expected to match there. Plus, since it's integration testing against a
rendered response body, it's better to match the actual text rather than
resort on other ways. (like using I18n directly, etc.)

[of_kind?] https://api.rubyonrails.org/classes/ActiveModel/Errors.html#method-i-of_kind-3F
2023-03-17 10:59:55 -03:00
Carlos Antonio da Silva
890bd9e3b5 Replace usage of assert ! with actual assert_not helper 2023-03-02 18:41:44 -03:00
tabakazu
8acbdd6d93 Replace matcher refute to assert_not 2023-03-02 18:38:04 -03:00
Carlos Antonio da Silva
df8b79a53f Fix added tests for sign_in_after_reset_password per resource class
We can't just "swap" those model properties, as that sets instance vars
on the classes that get reverted to their "previous" value, which ends
up leaving the instance vars set as `nil`. However, our logic for those
model/class properties actually checks for `defined?` as a way to
override them, and delegates up to `Devise` global config if they are
not defined, so leaving instance vars back with `nil` values isn't
enough, we need to actually remove them.

This introduces a new test helper specifically for overriding those
model configs so that we can do proper cleanup.
2023-03-01 22:50:03 -03:00
Matt Redmond
60c5774ff4 Delegate sign_in_after_reset_password to resource class
Allows resource class scopes to overrides the global configuration for sign in after reset password behaviour.
2023-03-01 22:18:16 -03:00
Carlos Antonio da Silva
88625d488f Use button_to to generate a POST form, disable turbo with OmniAuth
This changes the OmniAuth "sign in" links to use buttons, which can be
wrapped in an actual HTML form with a method POST, making them work
better with and without Turbo in the app. It doesn't require rails/ujs
anymore in case of a non-Turbo app, as it previously did with links +
method=POST.

Turbo is disabled for those OmniAuth buttons, as they simply don't work
trying to follow the redirect to the OmniAuth provider via fetch,
causing CORS issues/errors.
2023-02-01 11:29:17 -03:00
Carlos Antonio da Silva
b5172a0cdb Fix csrf cleanup for Rails 7.1 (main)
Rails implemented a CSRF token storage strategy to allow storing the
CSRF tokens outside of the sessios (for example, in an encrypted
cookie), and changed how the value is kept around during the request
cycle, by using a request.env value.

We still want to ensure the final session value is cleaned correctly in
the test, but the implementation needed to change since we can't simply
delete from the session anymore, we need to make sure we call the Rails
methods for resetting the current storage strategy so it works with all
of them.

https://github.com/rails/rails/pull/44283
2022-04-22 11:08:44 -03:00
Carlos Antonio da Silva
51bf327017 Refactor using helper to swap config 2021-10-07 19:06:33 -03:00
Carlos Antonio da Silva
a793472a3e Replace XML with JSON serialization across the test suite
This allows us to remove the dependency on the XML serializer provided
by the external `activemodel-serializers-xml` gem, and eliminates the
following deprecation warning:

    DEPRECATION WARNING: ActiveModel::Errors#to_xml is deprecated and
    will be removed in Rails 6.2.

Please note: this does not mean Devise doesn't support XML, it simply
means our test suite will use JSON to test non-navigatable formats
instead of XML, for simplicity. Devise's job is not to test object
serialization, so as long as your objects properly serialize to
XML/JSON/any other format, it should work out of the box.
2021-02-15 14:40:05 -03:00
Jordan Owens
837baaf2e1 Update omniauthable tests for OmniAuth 2.0 (#5331) 2021-01-19 15:19:55 -03:00
Bibek Sharma Chapagain
fd03f9e353 Added missing full stop "." on registrations.updated_but_not_signed_in. 2020-11-23 12:21:22 +11:00
mune
eed641d2be Add spaces around method arguments when setting default values
Closes #5288
2020-08-31 18:15:45 -03:00
Carlos Antonio da Silva
97aa37bb50 Use assert_empty minitest helper 2020-08-27 18:40:03 -03:00
Carlos Antonio da Silva
15135f7dc6 User assert_includes/refute_includes minitest helpers 2020-08-27 18:38:26 -03:00
Carlos Antonio da Silva
e39b9b9134 Fix order of arguments for assert_equal on tests
Use `assert_equal expected, actual` for proper error messages in case of
failures.
2020-08-27 18:24:17 -03:00
Luke Rollans
0d95c5ae8b Generalise email address 2019-12-17 13:47:40 +08:00
Luke Rollans
9fb079c097 Add a test which checks for Case Mapping Collisions when resetting pw
See here for more information
https://eng.getwisdom.io/hacking-github-with-unicode-dotless-i/
2019-12-17 13:43:53 +08:00
Samuel Pordeus
fb18c6ca8d Fix typos 2019-11-28 18:13:47 -03:00
tabakazu
940b939791 Add assert for check last_sign_in_ip value 2019-10-24 21:12:27 +09:00
Renan Gurgel
421ffc479f Add test to admin error message 2019-10-03 14:15:47 -03:00
Leonardo Tegon
fee43f3c11 Always return an error when confirmation_token is blank (#5132)
As reported in https://github.com/plataformatec/devise/issues/5071, if
for some reason, a user in the database had the `confirmation_token`
column as a blank string, Devise would confirm that user after receiving
a request with a blank `confirmation_token` parameter.
After this commit, a request sending a blank `confirmation_token`
parameter will receive a validation error.
For applications that have users with a blank `confirmation_token` in
the database, it's recommended to manually regenerate or to nullify
them.
2019-09-04 15:42:48 -03:00
Alessandro
ee65cd60c9 FIX plataformatec/devise#4127 (#4700) 2019-01-23 15:32:29 -02:00
Leonardo Tegon
c000b58c56 Add Rails 6 to CI (#5009) 2019-01-22 12:43:31 -02:00
kenji kobayashi
e3a00b27d1 Add an option to not automatically sign in a user after changing a password (#4569) 2018-12-28 11:29:58 -02:00
Tony Correia
1c8e97c75a Issue 4763: Change login errors for when in paranoid mode 2018-05-09 10:49:27 -03:00
Koichi ITO
dac90eeb80 Use update instead of update_attributes
`update_attributes` and `update_attributes!` will be deprecated in Rails 6.

Refer 5645149d3a
2018-03-29 15:39:24 -03:00
Leonardo Tegon
3722aa6296 Revert "Replace log_process_action to append_info_to_payload" 2018-03-15 09:43:12 -03:00
Leonardo Tegon
5664b19703 Ensure Devise isn't performing model validations 2018-03-14 15:21:07 -03:00
Justin Coyne
a45bbe1783 Test on Rails 5.2.0.rc1 (#4711) 2018-02-22 10:05:19 -03:00
Pat Allan
f39c6fd927 Add the frozen_string_literal pragma comment to all Ruby files. (#4725) 2017-12-21 15:36:29 -02:00
Rafael França
701d4929d8 Merge pull request #4375 from fbbergamo/change-status-append
Replace log_process_action to append_info_to_payload
2017-11-22 15:53:28 -05:00
Masato Oba
975bb8490d Fix typo 'an user' to 'a user' 2017-10-29 12:31:06 +00:00
Masato Oba
6ceb649b10 Fix small typo in authenticatable_test.rb 2017-10-29 12:10:39 +00:00
Dan Schultzer
be2e17841e Separate Devise test methods from Devise 2017-04-29 10:24:22 -07:00
Matthew Rudy Jacobs
7c4e8c8d17 Rails 5.1 requires ActionController::TestRequest to have a controller class
Pass it in as an anonymous class
2017-04-28 10:51:27 -05:00
Felipe Bergamo
6eb412efae Typo test doc 2017-04-24 18:38:49 -03:00
Felipe Bergamo
9caae50339 Replace log_process_action to append_info_to_payload 2016-12-10 18:40:57 -02:00
Marc G Gauthier
8ee01fc10b Fix a minor typo in specs
There is nothing much to this one, it's in the test description so it shouldn't impact a thing and will make this line more greppable.
2016-08-11 09:56:45 +02:00
Stefan Botzenhart
cbbe932ee2 Fix authenticated engine routes (#4081)
Fix infinite loop in authenticated engine routes in Rails 5

https://github.com/plataformatec/devise/issues/3705
2016-05-21 11:55:56 -03:00