1223 Commits

Author SHA1 Message Date
Jan Bussieck
2fde07b9be Fix test case descriptions, since we are testing proxying to 'authenticated?' 2019-09-19 17:18:02 +02:00
Jan Bussieck
70c5f4bfaf Use warden’s authenticated? for query methods to avoid side effects
Previously checks whether a certain scope is signed in were performed using warden’s
`authenticate?` or `authenticate` methods which would run the strategies and sign in the
scope if valid params were given. We want to remove this side effect from query methods.
2019-09-19 17:18:02 +02:00
Jeremy Wadsack
0a2e67878a When password reset token expires, redirect to new password path (#4837) 2019-09-19 10:22:30 -03:00
Marc Busqué
34238e9f18 Update trackable fields only in a database sign in
References #4584 and waiting-for-dev/devise-jwt#23

* Bug
Users that use devise-jwt, will not have the correct behavior of trackable
feature. As a request for APIs always requires authentication since there
is no session in APIs world, Devise counts +1 on every request since it
contains authentication info.

It happens because Devise has a trackable hook that updates the trackable
info everytime that the user is signed in by Warden.

* Fix
We are moving update_trackable_fields! from trackable hook (which was removed)
to sign_in_out and database_authenticatable. This way, update_trackable_fields!
is going to run only when the user signed in by Devise (only one time).
2019-09-19 10:22:29 -03:00
Felipe Renan
a1c493b009 Remove unnecessary checks for Rails 4 2019-09-19 10:22:29 -03:00
Julius Graakjær Grantzau
b85911dee3 Downcase authentication keys and humanize error message (#4834) 2019-09-19 10:21:02 -03:00
Felipe Renan
2d1a961c1b Remove Rails 4 support 2019-09-19 10:20:59 -03:00
Adan Amarillas
195cbfb9e5 Modified sessions controller to return 401 for destroy action with no user signed in (#4878) 2019-09-19 10:06:14 -03:00
Shriram
64238fc80e Make secure_compare handle empty strings comparison correctly
Used Rails' secure_compare method inside the definition of secure_compare. This will handle the empty strings comparison and return true when both the parameters are blank strings.

Fixes #4441
2019-09-19 10:06:14 -03:00
Siva Gollapalli
afaad713ff Added translations according to unlock strategy 2019-09-19 10:06:13 -03:00
Marcos Ferreira
f48b6f1651 Merge pull request #5067 from shobhitic/master
Using scoped errors for scoped views. Fixes #5066
2019-09-17 14:49:57 -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
Leonardo Tegon
ad5892391d Fix specs on Rails 6 RC2 (#5109)
* Fix specs on Rails 6 RC2

`ActiveRecord::MigrationContext` now has a `schema_migration` attribute.
Ref: https://github.com/rails/rails/pull/36439/files#diff-8d3c44120f7b67ff79e2fbe6a40d0ad6R1018

* Use `media_type` instead of `content_type`

Before Rails 6 RC2, the `ActionDispatch::Response#content_type` method
would return only the media part of the `Content-Type` header, without any
other parts. Now the `#content_type` method returns the entire header -
as it is - and `#media_type` should be used instead to get the previous
behavior.

Ref:
- https://github.com/rails/rails/pull/36034
- https://github.com/rails/rails/pull/36854

* Use render template instead of render file

Render file will need the full path in order to avoid security breaches.
In this particular case, there's no need to use render file, it's ok to
use render template.

Ref: https://github.com/rails/rails/pull/35688

* Don't set `represent_boolean_as_integer` on Rails 6

* Update comments [ci skip]
2019-08-07 12:32:01 -03:00
Rafael Mendonça França
54fb582269 Officially support Rails 6.0
Also remove upper bound on railties so people can try devise with new
versions without having to wait us to change the gem and report bugs.
2019-06-12 16:10:13 -04:00
Shobhit Bakliwal
a823e510f3 Using scoped errors for scoped views. Fixes #5066 2019-05-02 13:24:01 +05:30
Marcos Ferreira
f9d13f015a Revert "[#4245] Allowing password to nil (#4261)"
This reverts commit 3aedbf0a4d.
2019-03-26 10:29:46 -03:00
Marcos Ferreira
e704221842 Revert "Add more tests (#4970)"
This reverts commit 05bf574799.
2019-03-26 10:29:16 -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
Felipe Renan
101e50f9df Fix webrat warnings
Forwarding methods to private methods is deprecated and produces a
warning after Ruby 2.4.

see: https://bugs.ruby-lang.org/issues/12782

To fix this issue I'm mocking patching webrat making RailsAdatper#response
method public since Webrat::Session is delegating functions to it.
2019-02-04 14:50:14 -02:00
Felipe Renan
45438fcfc4 Fix SQLite3 warning
Before setting this option, our test suite was giving the following warning:

```
DEPRECATION WARNING: Leaving `ActiveRecord::ConnectionAdapters::SQLite3Adapter.represent_boolean_as_integer`
set to false is deprecated. SQLite databases have used 't' and 'f' to serialize
boolean values and must have old data converted to 1 and 0 (its native boolean
serialization) before setting this flag to true. Conversion can be accomplished
by setting up a rake task which runs

  ExampleModel.where("boolean_column = 't'").update_all(boolean_column: 1)
  ExampleModel.where("boolean_column = 'f'").update_all(boolean_column: 0)

for all models and all boolean columns, after which the flag must be set to
true by adding the following to your application.rb file:

  Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true
 (called from <top (required)> at $PATH/devise/test/rails_app/app/active_record/user.rb:5)
```

After configuring `represent_boolean_as_integer = true` as specified
above, we don't have this warning anymore.

More info:
https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SQLite3Adapter.html#method-c-represent_boolean_as_integer
2019-01-28 14:39:06 -02: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
Leonardo Tegon
62703943be Make #increment_failed_attempts concurrency safe (#4996)
As reported in #4981, the method `#increment_failed_attempts` of `Devise::Models::Lockable` was
not concurrency safe. The increment operation was being done in two steps: first the value was read from the database, and then incremented by 1. This may result in wrong values if two requests try to update the value concurrently. For example:

```
Browser1 -------> Read `failed_attempts` from DB (1) -------> Increment `failed_attempts` to 2
    Browser2 -------> Read `failed_attempts` from DB (1) -------> Increment `failed_attempts` to 2
```

In the example above, `failed_attempts` should have been set to 3, but it will be set to 2. 

This commit handles this case by calling `ActiveRecord::CounterCache.increment_counter` method, which will do both steps at once, reading the value straight from the database.

This commit also adds a `ActiveRecord::AttributeMethods::Dirty#reload` call to ensure that the application gets the updated value - i.e. that other request might have updated. 
Although this does not ensure that the value is in fact the most recent one - other request could've updated it after the `reload` call - it seems good enough for this implementation. 
Even if a request does not locks the account because it has a stale value, the next one - that updated that value - will do it. That's why we decided not to use a pessimistic lock here.

Closes #4981.
2018-12-28 17:00:50 -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
Stan Hu
1192c76f62 Fix corner case when confirmation_sent_at is equal to 0.days.ago (#4529)
If `Confirmable#confirmation_sent_at` is equal to `0.days.ago`, then
`confirmation_period_valid?` will be deemed valid even if the setting is
configured to disable this outright. To prevent this error, we explicitly
check the configuration setting to be `0.days.ago`.
2018-12-04 14:34:32 -02:00
Kanmaniselvan Murugesan
bafc23eae5 Issue 4895: Add after_database_authentication callback after sign_in immediately after password update (#4916) 2018-11-22 19:13:55 -02:00
Leonardo Tegon
aa6cb411bc Add missing specs for #find_or_initialize_with_errors
After merging https://github.com/plataformatec/devise/pull/4797, I
noticed that we had no specs for the scenarios where this method was
adding the errors to the resource. This commit adds tests to cover those
cases.
2018-11-22 18:44:09 -02:00
Ryan Lue
354df3bc65 [bugfix] [refactoring] Sanitize parameters in find_or_initialize_with_errors (#4797)
* Use parameter sanitizer for new records in find_or_initialize_with_errors

* Add test for find_or_initialize_with_errors bugfix
2018-11-22 15:10:50 -02:00
Leonardo Tegon
05bf574799 Add more tests (#4970)
After merging #4261, I realized that we could add a couple more
tests, to ensure the new behavior added to `#valid_password?` - which is
that it should return `false` when the password is either `nil` or blank
('').
I've also removed [this
condition](https://github.com/plataformatec/devise/blob/master/lib/devise/models/database_authenticatable.rb#L68)
because it's already present at `Devise::Encryptor` module in the
`.compare`
[method](https://github.com/plataformatec/devise/blob/master/lib/devise/encryptor.rb#L15).
2018-11-13 15:29:14 -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
sivagollapalli
3aedbf0a4d [#4245] Allowing password to nil (#4261)
* [#4245] Allowing password to nil

* Set encrypted password to nil if password is nil

* [#4245] Fixing the build

* Removed unnecessary code
2018-11-13 13:57:23 -02:00
Isaac Orme
25f908ad9c issue 4526 adds skip email and password change notifications methods (#4824) 2018-09-28 18:55:00 -03:00
Josh Pencheon
31aceeb104 Fix bug: ParameterFilter should not add keys (#3431) (#4457)
If called with a hash that has a `default` / `default_proc`
configured, `Devise::ParameterFilter` can add in missing keys
it was due to attempt to sanitise the values for.

This patch prevents this from happening, whilst also clarifying
the filtering intent of `ParamaterFilter`.

(This can also occur if NilClass has been augmented with definitions
for `strip` or `downcase`.)

Fixes #3431.
2018-05-15 10:47:18 -03:00
Gencer W. Genç
6c916488af find auto-generated secret_key_base in development (#4869)
With this fix, we will try latest changes in Rails 5.2 together with standard auto-generated secret_key_base in development as a fallback.

If no specified key found, auto-generated value will be used instead.
2018-05-14 18:09:25 -03:00
Andrey Andreev
8866b8e5eb Fix error when params is not a hash 2018-05-09 14:56:50 -03:00
Tony Correia
1c8e97c75a Issue 4763: Change login errors for when in paranoid mode 2018-05-09 10:49:27 -03:00
Max Kramer
b20de505ab Split IP resolution from update_tracked_fields
This permits users to easily customize where the ip address
should be resolved.  When fronting the application with a webserver or
load balancer, the ip address may be the server and not be the user.

E.g. consider the IP address is passed as the header: "X-Forwarded-For".

```ruby
class User
  devise :trackable

  protected
    def extract_ip_from(request)
      request.headers["X-Forwarded-For"]
    end
end
```
2018-04-03 09:53:28 -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
Wolfram Nikolas Müller
f220b992c3 add test for lazy loading hook 2018-03-29 15:32:46 -03:00
Leonardo Tegon
962cea2039 Create Devise::SecretKeyFinder
When supporting Rails 5.2 credentials on
https://github.com/plataformatec/devise/pull/4712, we ended up breaking
apps that were upgraded to Rails 5.2 and weren't using `credentials`
to store their `secret_key_base`. See
https://github.com/plataformatec/devise/issues/4807 for more context.
To fix it, we're now checking whether the key is present before using it.
Since there weren't any automated test for this - the conditionals were
in a Rails engine initializer - I've extracted it to a new class so that
we are able to test it easily.

Fixes #4807
2018-03-17 20:28:38 -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
Gordon McNaughton
3e23371b01 Preserve content_type for unauthenticated tests
In Rails 4, for unauthenticated controller tests which trigger the
failure app, ensure that the simulated failure response includes a
content_type (broken in bb44d42).

This works in Rails5, which parses the content-type header on-demand,
but not in Rails4 which requires setting the response's content_type
explicitly.

Fixes #4783.
2018-02-26 12:15:36 -05:00
Justin Coyne
a45bbe1783 Test on Rails 5.2.0.rc1 (#4711) 2018-02-22 10:05:19 -03:00
Leonardo Tegon
d1948b79d3 Fix ActiveRecord check on Confirmable (#4752)
* Fix `ActiveRecord` check on `Confirmable`

As pointed out by @dark-panda in #4302, the condition for an
`ActiveRecord` model is wrong inside the `Confirmable` initialization
block.

https://github.com/plataformatec/devise/pull/4302#issuecomment-355103489

* Add specs
2018-01-16 10:25:20 -02:00
Filip Soszyński
b01ae718b3 Primary key type in migration template (#4426)
* Tests

* Add primary key type to migration template

* Change Rails version-detecting method in test
2017-12-23 17:20:45 -02:00
Rafael França
0720bc72c3 Merge pull request #4731 from alexhifer/master
Added the ability to change the default migrations path
2017-12-21 18:33:07 -05:00
Pat Allan
f39c6fd927 Add the frozen_string_literal pragma comment to all Ruby files. (#4725) 2017-12-21 15:36:29 -02:00
Guilherme Goettems Schneider
8b9fba73fd Allow frozen options in as_json (#4655)
The test uses `as_json` instead of `to_json` because `to_json` does `#dup` on `options` before it reaches `#serializable_hash` and the test would pass without the fix.
2017-12-21 15:23:25 -02:00
Alexey Degtyarev
12298ef968 Added the ability to change the default migrations path (introduced in Rails 5.0.3) 2017-12-21 17:12:19 +02:00