62 Commits

Author SHA1 Message Date
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
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
Carlos Antonio da Silva
89a08357d6 Uses the responder redirect_status when recall returns a redirect
It appears some people use the recall functionality with a redirect
response, and Devise starting on version 4.9 was overriding that status
code to the configured `error_status` for better Turbo support, which
broke the redirect functionality / expectation.

While I don't think it's really great usage of the recall functionality,
or at least it was unexpected usage, it's been working like that
basically forever where recalling would use the status code of the
recalled action, so this at least keeps it more consistent with that
behavior by respecting redirects and keeping that response as a redirect
based on the configured status, which should also work with Turbo I
believe, and makes this less of a breaking change.

Closes #5570
Closes #5561 (it was closed previously, but related / closes with an
actual change now.)
2023-03-20 18:18:54 -03:00
Carlos Antonio da Silva
eed51179c7 Add explicit test for respecting the error_status responder config
While introducing this on turbo, looks like no specific test was added,
so this at least covers that a bit.

It needs some conditional checks since not all supported Rails +
Responders version work with the customization, so there's one test for
the hardcoded status version too, which can be removed in the future.
2023-03-20 17:58:48 -03:00
Carlos Antonio da Silva
e1c53d6580 Check for empty response body on redirect with Rails main (future 7.1)
Rails is no longer returning a message with the response body on
redirects, just an empty body.

https://github.com/rails/rails/pull/44554
2022-04-22 09:30:58 -03:00
Carlos Antonio da Silva
f3e8fd3baa Move the Gemfile to test with Rails 7.0 alpha2, fix session test issue
It appears setting the `rack.session` to a simple hash doesn't work
anymore as it now has a few additional methods Rails is relying on to
determine whether it's enabled or not:
https://github.com/rails/rails/pull/42231

Failure:
    NoMethodError: undefined method `enabled?' for {}:Hash
    rails (f55cdafe4b82) actionpack/lib/action_dispatch/middleware/flash.rb:62:in `commit_flash'

Turns we we don't seem to need to set `rack.session` for the tests here.
2021-10-07 18:08:16 -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
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
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
Leonardo Tegon
fcb04f5302 Check if root_path is defined with #respond_to? instead of #present (#5022)
When an application does not define a `root`, the method will be
undefined instead of returning a falsey value.
This commit also includes a new test with fake objects that mimic this
behavior.

Related resources:

* 1aab449933 (diff-c1be825bdb5f3160081e41432f83d0d7R278)
* https://github.com/plataformatec/devise/issues/5021
2019-02-11 11:00:56 -02:00
Colin Ross
40f02ae69b Only flash if the request object that is loaded supports it (#4950) 2018-11-13 15:26:00 -02:00
Wolfram Nikolas Müller
f220b992c3 add test for lazy loading hook 2018-03-29 15:32:46 -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
Kostas Diamantis
4015488b90 Add missing support of Rails.application.config.action_controller.relative_url_root (#4146)
* Add Devise::FailureApp#{relative_url_root, relative_url_root?}

Also support missing action_controller.relative_url_root configuration.

* Dry assignment of relative_url_root

Also this commit adds support for
Rails.application.config.action_controller.relative_url_root
2016-06-13 15:46:43 -03:00
byzg
357ce9c3b5 Humanize authentication keys in failure flash message (#4014)
Humanize and translates the authentication keys in failure flash message.
2016-04-26 11:17:03 -03:00
Paul Menzel
f2d7b8f740 Spell verb *set up* with a space
The verb *set up* is spelled with a space [1].

```
$ git grep -l 'to setup' | xargs sed -i 's/to setup/to set up/g'
$ git grep -l '# Setup' | xargs sed -i 's/# Setup/# Set up/g'
$ git grep -l "test 'setup" | xargs sed -i "s/test 'setup/test 'set up/g"
```

Revert the change for *setup block yields self*.

Change the rest manually.

[1] http://www.merriam-webster.com/dictionary/set%20up
2016-02-02 19:09:19 +01:00
Thomas Walpole
2024fca4df Rails 5 compatability. Remove rails < 4.1 and Ruby < 2.1 2015-12-11 09:47:30 -08:00
Stan Hu
7025f968c6 Account for relative_url_root in FailureApp's recall method
Closes #3738
2015-09-06 00:05:19 -07:00
cipater
15d3fc497c Use router_name from scope if available
Devise.available_router_name currently returns either
Devise.router_name or :main_app. As such, any redirecting is done
within either of those contexts. Which leads to undesirable redirects
for scopes that reside in an isolate_namespace mounted engine.

This commit makes it possible for FailureApp’s redirect behavior to be
performed in the context of the router_name given to devise_for.

Test case added to cover undesirable behavior. Without change to
lib/devise/failure_app.rb, test case throws exception.
2015-03-30 16:18:05 -07:00
Lucas Mazza
a93edc72fd Check for a Hash when using the authentication_keys to generate the FailureApp flash message.
Fixes #3270.
2014-10-27 22:32:19 -02:00
alexsoble
fe015f5a54 Revert "Update routes to match 'sign up'/'log in', incorporate feedback from @carlosantoniodasilva"
This reverts commit de2a24b3d3.
2014-08-10 12:13:35 -04:00
alexsoble
de2a24b3d3 Update routes to match 'sign up'/'log in', incorporate feedback from @carlosantoniodasilva 2014-08-07 11:33:03 -04:00
alexsoble
67d8dd1e94 Replace 'Sign in' with 'Log in' in views, update tests 2014-08-06 13:32:02 -04:00
Kamil Giszczak
9cada8d2d4 Use scope instead of constraints to define routes.
It works the same with rails 3 and rails 4.
2014-04-04 16:07:37 +02:00
Kamil Giszczak
a38f2f96b5 Use _url routes instead of _path 2014-04-02 15:42:41 +02:00
Oleg Pudeyev
47845e44a2 Chase language changes in tests 2014-03-03 10:15:33 -05:00
Anshul Sharma
dc1b399a8b Updated ruby 1.9 hash syntax 2014-02-25 22:12:55 +05:30
Benoit Bénézech
d5514bf916 Add options for FailureApp's i18n_message. Similar #1633 2013-10-24 16:49:13 +02:00
hakanensari
9a60415e2e Fix assertion 2013-07-26 19:31:49 +01:00
Vipul A M
b871bd5036 fix some warning 2013-04-19 19:08:20 +05:30
José Valim
454a5ad1ec Try to fix the build for rails 3.1 2012-05-09 23:41:05 +02:00
José Valim
65ef2592f6 Add a test case to previous commit 2012-05-09 18:27:44 +02:00
José Valim
477d9fbcba Do not fallback to string on failure app, easier for debugging, closes #1587 2012-01-24 13:46:25 +01:00
José Valim
a949f9eca2 FailureApp shuold always consider Devise.router_name, closes #1544 2012-01-03 20:32:51 +01:00
José Valim
0b55ebb150 Remove 3.0 related code. 2012-01-02 21:04:54 +01:00
José Valim
7b0a8f9bdc Also try the root route for convenience, closes #1312. 2011-09-08 08:32:05 +02:00
Emanuel Carnevale
8e12ddf7ed fix for issues #999: HTTP_ACCEPT=*/* should redirect to the default location 2011-04-29 13:22:52 +02:00
José Valim
7a2d76d002 Update changelog, improve coverage. 2011-04-17 18:06:29 +02:00
José Valim
add8f8a203 Works on 3.0.4. 2011-02-15 10:27:34 +01:00
siong1987
6e91edd5e3 failure_app redirects to the correct format if it is a non-html request. This is to ensure that firefox redirects the correct format since firefox doesn't inherit accept info. also fix issue 675 that is resurrected by issue 754. 2011-01-11 18:27:14 +08:00
siong1987
379d8c69a5 Issue 675: recall option is now passed for not confirmed email and inactive account. 2010-12-23 02:24:26 +08:00
José Valim
505bd39700 failure_app now properly handles nil request.format 2010-11-09 23:30:53 +01:00
José Valim
835d1044ae Fix a problem with IE7 headers. 2010-11-08 22:45:42 +01:00
José Valim
c12d75eecf Do not rely on controller being available in params. 2010-09-25 11:22:18 +02:00
José Valim
31d7020637 Reorganize tests for failure app and add entries to CHANGELOG. 2010-08-31 23:55:25 +02:00
Santiago Pastorino
e582112369 set WWW-Authenticate header on http_auth if request is not xhr 2010-09-01 05:35:40 +08:00
Santiago Pastorino
5fb5efbd42 Returning WWW-authenticate on ajaxs calls depends only on Devise.http_authenticatable_on_xhr config 2010-08-31 23:51:58 +08:00
José Valim
9c5ff02ff1 Update CHANGELOG and tidy up tests. 2010-07-07 21:32:13 +02:00
James Pellow
b9df42c350 Add tests for http_authenticatable_on_xhr option 2010-07-08 03:21:13 +08:00