Compare commits

...

59 Commits

Author SHA1 Message Date
Leonardo Tegon
3b0bc08ec6 Prepare for 4.5.0 release 2018-08-15 20:03:08 -03:00
Leonardo Tegon
2eca92f950 Update CHANGELOG.md 2018-08-15 17:05:50 -03:00
Isaac Orme
acc45c5a44 issue 4356 adds is_navigational_format? check to after_sign_up_path_for (#4833) 2018-08-02 11:02:50 -03:00
Guillaume CABANEL
e4dd1509c4 Update README.md (#4911)
update links to rubydoc.info to the url `www.rubydoc.info` since the ssl certificate is only valid for www.rubydoc.info (not rubydoc.info)
2018-07-31 11:36:42 -03:00
Phil Nash
b8f644198d Corrects brakes -> breaks when talking about tests (#4897) 2018-07-03 09:52:07 -03:00
lucfranken
715192a770 Improve getting started text on Gemfile (#4875)
The original text: 

> You can add it to your Gemfile with:

Could easily be read as: "Run this command to add it to your Gemfile"

That's what I did at least. I think the change makes it much clearer that you need to really manually add a line of text into the Gemfile.

One of the reasons why this is not fully clear is that it's badly visible on Github whether a command is a console / terminal command or a ruby line of code. Visually they look the same except for the $ sign which is easy to overlook.
2018-05-16 14:48:24 -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
Samy Kacimi
af8f7e9797 remove :trackable from the default modules (#4857)
This removes :trackable from the default modules in the generators,
to be more GDPR-friendly.
2018-05-14 18:11:15 -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
Maud de Vries
246a50876a Mention the -c flag for the controller generator
Similar to the views section, that mentions the -v flag
2018-05-11 10:20:23 -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
Gustavo Bazan
cd9ad848fb Update simple form templates
Update `simple_form` templates with changes from 16b3d6d67c and 6260c29a86
2018-05-08 15:42:26 -03:00
Vasiliy Ermolovich
be15116426 Merge pull request #4858 from lookageek/patch-1
Fix in rdoc of DeviseController#_prefixes
2018-05-03 13:12:38 +03:00
Jayanth Manklu
9d90a559ce Fix in rdoc of DeviseController#_prefixes
Removing an additional "is"
2018-05-03 15:36:43 +05:30
Rafael França
d98f38cf5f Merge pull request #4848 from abhishekkanojia/refactor_code
Remove redundant self from database_authenticatable module.
2018-04-23 12:08:42 -04:00
Abhishek kanojia
f99636da76 Remove redundant self from database_authenticatable module. 2018-04-22 11:57:18 +05:30
Gustavo Bazan
6260c29a86 Improve passwords autocomplete
Use `autocomplete="new-password"` or `autocomplete="current-password"` to better signal to browsers and password managers how to handle the password fields.

This feature is especially useful for “change your password” and “new user” forms
2018-04-19 12:58:58 -04:00
Rafael França
45481df14a Merge pull request #4843 from lancecarlson/master
upgrade dependencies for rails and responders
2018-04-18 13:55:41 -04:00
Lance Carlson
7eccd4e9c6 upgrade dependencies for rails and responders 2018-04-17 00:03:12 -04:00
yhirano55
2cf18f99e0 CI against Ruby 2.3.7, 2.4.4, 2.5.1 2018-04-07 00:21:12 -03:00
Leonardo Tegon
bcbea08187 Add note in the documentation about sign_in and timeoutable
In order to use the `sign_in` helper along with the timeoutable module,
we have to set `env["devise.skip_timeout"] = true` in the request.
Currently, we do this in the sessions controller: https://github.com/plataformatec/devise/blob/master/app/controllers/devise/sessions_controller.rb#L7
This commit adds a note to the `sign_in` documentation to help other
developers that want to use custom warden strategies.

Closes #4773
2018-04-04 21:00:49 -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
yusukemorita
20bde34981 added link to integration tests section 2018-03-30 10:57:12 -03:00
yusukemorita
e9abba797a added comment in README about controller tests for rails 5 2018-03-30 10:57:12 -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
Wolfram Nikolas Müller
2bb8e1c236 Fix missing do block in config 2018-03-29 15:32:46 -03:00
Wolfram Nikolas Müller
e44a8b2d43 Include configuration for Turbolinks in devise initializer template 2018-03-29 15:32:46 -03:00
Wolfram Nikolas Müller
268bd69164 Allow people to extend devise failure app, through invoking ActiveSupport.run_load_hooks once Devise::FailureApp is loaded 2018-03-29 15:32:46 -03:00
Eden Rohatensky
d750709250 Use before_action instead of before_filter 2018-03-28 09:12:11 -03:00
Fred Ngo
c9a2d0654e Update sample code in Devise::Models::Authenticatable.
- DRY up some of the sample code by refactoring into smaller methods.
- ‘Namespace’ method names to reduce chances of conflict.
- Mark send_pending_devise_notifications, pending_devise_notifications, and render_and_send_devise_message as `private` since they are only used internally.
- Update comments.
2018-03-23 22:42:48 -03:00
Johan Kim
26723d9bbc cleanup in ToC 2018-03-23 10:05:31 -03:00
Leonardo Tegon
75f9e76f65 Prepare for 4.4.3 release 2018-03-17 20:44:00 -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
64aad8b138 Fix Devise::Test::ControllerHelpers
This was broken on 3e23371b01 (diff-bafaaa60fc003e648eb4981c9add523eR142)
because of a call to the method `Devise::Test.rails5?` which is only
defined inside our test suite's rails app a45bbe1783/test/rails_app/config/boot.rb (L19)
This commits checks for the rails version directly.
2018-03-16 11:17:48 -03:00
Leonardo Tegon
0d279415f3 Prepare for 4.4.2 release 2018-03-15 09:56:15 -03:00
Leonardo Tegon
fc45f916d6 Update CHANGELOG.md 2018-03-15 09:48:59 -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
Leonardo Tegon
d870c0dced Check if the record is persisted in update_tracked_fields!
In some cases, invalid records could be created during the signup
process because we were calling `save(validate: false)` inside the
`update_tracked_fields!` method. See
https://github.com/plataformatec/devise/issues/4673 for more
information.
This was fixed on https://github.com/plataformatec/devise/pull/4674 by
calling `save` directly, but it caused some trouble and confusion since
it changed Devise's behavior significantly.
We talked about on https://github.com/plataformatec/devise/issues/4790
and it doesn't even make sense to call `save` on an object that isn't
persisted yet, so I've added a guard clause to the
`update_tracked_fields!` method.

Fixes https://github.com/plataformatec/devise/issues/4790
2018-03-14 15:21:07 -03:00
Danilo Araújo Silva
8ab7963e50 Creating a new section for controller configuration on devise.rb template
Creating a new section called `Controller configuration`.

An optional devise configuration is set `config.parent_controller` but this configuration is missing in the `devise.rb` template file.
2018-03-14 15:09:04 -03:00
Rafael França
d545fe3e3f Merge pull request #4784 from gmcnaughton/fix-controller-tests-content_type
Fixes #4783 - preserve content_type for unauthenticated test responses
2018-02-26 13:04:03 -05: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
Leonardo Tegon
6bda962547 Update CHANGELOG.md [ci skip] 2018-02-22 18:00:13 -03:00
Leonardo Tegon
f141bb57ec Update CHANGELOG.md [ci skip] 2018-02-22 17:59:33 -03:00
Rafael França
9001123b7e Merge pull request #4779 from Fudoshiki/master
Allow test rails 6
2018-02-22 14:30:01 -05:00
Yuri S
5919620b24 change right border 2018-02-22 21:55:17 +05:00
Justin Coyne
a45bbe1783 Test on Rails 5.2.0.rc1 (#4711) 2018-02-22 10:05:19 -03:00
Yuri S
2514c69d81 Allow rails 6 2018-02-21 07:18:36 +05:00
Leonardo Tegon
8b53975652 Improve documentation about the test suite (#4774) 2018-02-06 10:49:45 -02:00
Gencer W. Genç
bdd6081815 Support for :credentials on Rails v5.2.x. (#4712)
This fixes #4710.

Rails introduced :secrets in v5.1. They somehow changed it to :credentials. This fix represents this change.

Devise will now look :credentials first, then fallback to :secrets for 5.1.x compatibility then it will check for standard secret key. If three not found then exception will arise.
2018-01-23 19:19:29 -02:00
Leonardo Tegon
e55c9caa05 Prepare for 4.4.1 release 2018-01-23 15:03:41 -02:00
Leonardo Tegon
0f8695dd4b Update CHANGELOG.md [ci skip] 2018-01-23 13:31:26 -02:00
Alex Matchneer
d9deeba582 Fix signed_in? docs w.r.t. running auth hooks (#4733)
Addresses #4599

The docs previously mentioned that authentication hooks are not run when `signed_in?` is called, when in fact they are. This commit fixes the comment and suggests calling `authenticated?` on warden directly as an alternative for when you _don't_ want to run auth hooks.
2018-01-23 13:18:37 -02: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
Rafael França
371d657e35 Merge pull request #4753 from segiddins/patch-1
[Gemspec] Ensure it is loaded as utf-8
2018-01-15 15:03:03 -05:00
Samuel Giddins
82087ce211 [Gemspec] Ensure it is loaded as utf-8 2018-01-12 21:26:42 -08:00
Leonardo Tegon
463351922f Update copyright [ci skip] 2018-01-03 21:20:13 -02:00
67 changed files with 957 additions and 247 deletions

View File

@@ -2,14 +2,15 @@ language: ruby
rvm:
- 2.1.10
- 2.2.8
- 2.3.5
- 2.4.2
- 2.5.0
- 2.2.10
- 2.3.7
- 2.4.4
- 2.5.1
- ruby-head
gemfile:
- Gemfile
- gemfiles/Gemfile.rails-5.2-rc1
- gemfiles/Gemfile.rails-5.0-stable
- gemfiles/Gemfile.rails-4.2-stable
- gemfiles/Gemfile.rails-4.1-stable
@@ -18,20 +19,24 @@ matrix:
exclude:
- rvm: 2.1.10
gemfile: Gemfile
- rvm: 2.5.0
- rvm: 2.1.10
gemfile: gemfiles/Gemfile.rails-5.2-rc1
- rvm: 2.1.10
gemfile: gemfiles/Gemfile.rails-5.0-stable
- rvm: 2.2.10
gemfile: gemfiles/Gemfile.rails-5.2-rc1
- rvm: 2.4.4
gemfile: gemfiles/Gemfile.rails-4.1-stable
- rvm: 2.4.2
- rvm: 2.5.1
gemfile: gemfiles/Gemfile.rails-4.1-stable
- rvm: ruby-head
gemfile: gemfiles/Gemfile.rails-4.1-stable
- rvm: 2.1.10
gemfile: gemfiles/Gemfile.rails-5.0-stable
- rvm: 2.1.10
gemfile: Gemfile
- env: DEVISE_ORM=mongoid
gemfile: Gemfile
- env: DEVISE_ORM=mongoid
gemfile: gemfiles/Gemfile.rails-5.0-stable
- env: DEVISE_ORM=mongoid
gemfile: gemfiles/Gemfile.rails-5.2-rc1
allow_failures:
- rvm: ruby-head
services:
@@ -47,8 +52,9 @@ env:
- DEVISE_ORM=mongoid
before_install:
- "rm ${BUNDLE_GEMFILE}.lock"
- gem update --system
- gem install bundler
- "rm ${BUNDLE_GEMFILE}.lock"
before_script: "bundle update"

View File

@@ -1,5 +1,54 @@
### Unreleased
### 4.5.0 - 2018-08-15
* enhancements
* Use `before_action` instead of `before_filter` (by @edenthecat)
* Allow people to extend devise failure app, through invoking `ActiveSupport.run_load_hooks` once `Devise::FailureApp` is loaded (by @wnm)
* Use `update` instead of `update_attributes` (by @koic)
* Split IP resolution from `update_tracked_fields` (by @mckramer)
* upgrade dependencies for rails and responders (by @lancecarlson)
* Add `autocomplete="new-password"` to new password fields (by @gssbzn)
* Add `autocomplete="current-password"` to current password fields (by @gssbzn)
* Remove redundant `self` from `database_authenticatable` module (by @abhishekkanojia)
* Update `simple_form` templates with changes from https://github.com/plataformatec/devise/commit/16b3d6d67c7e017d461ea17ed29ea9738dc77e83 and https://github.com/plataformatec/devise/commit/6260c29a867b9a656f1e1557abe347a523178fab (by @gssbzn)
* Remove `:trackable` from the default modules in the generators, to be more GDPR-friendly (by @fakenine)
* bug fixes
* Use same string on failed login regardless of whether account exists when in paranoid mode (by @TonyMK9068)
* Fix error when params is not a hash inside `Devise::ParameterSanitizer` (by @b0nn1e)
* Look for `secret_key_base` inside `Rails.application` (by @gencer)
* Ensure `Devise::ParameterFilter` does not add missing keys when called with a hash that has a `default` / `default_proc`
configured (by @joshpencheon)
* Adds `is_navigational_format?` check to `after_sign_up_path_for` to keep consistency (by @iorme1)
### 4.4.3 - 2018-03-17
* bug fixes
* Fix undefined method `rails5?` for Devise::Test:Module (by @tegon)
* Fix: secret key was being required to be set inside credentials on Rails 5.2 (by @tegon)
### 4.4.2 - 2018-03-15
* enhancements
* Support for :credentials on Rails v5.2.x. (by @gencer)
* Improve documentation about the test suite. (by @tegon)
* Test with Rails 5.2.rc1 on Travis. (by @jcoyne)
* Allow test with Rails 6. (by @Fudoshiki)
* Creating a new section for controller configuration on `devise.rb` template (by @Danilo-Araujo-Silva)
* bug fixes
* Preserve content_type for unauthenticated tests (by @gmcnaughton)
* Check if the resource is persisted in `update_tracked_fields!` instead of performing validations (by @tegon)
* Revert "Replace log_process_action to append_info_to_payload" (by @tegon)
### 4.4.1 - 2018-01-23
* bug fixes
* Ensure Gemspec is loaded as utf-8. (by @segiddins)
* Fix `ActiveRecord` check on `Confirmable`. (by @tegon)
* Fix `signed_in?` docs without running auth hooks. by (@machty)
### 4.4.0 - 2017-12-29
* enhancements
@@ -17,7 +66,7 @@
* Validations were being ignored on singup in the `Trackable#update_tracked_fields!` method. (by @AshleyFoster)
* Do not modify options for `#serializable_hash`. (by @guigs)
* Email confirmations were being sent on sign in/sign out for application using `mongoid` and `mongoid-paperclip` gems. This is because previously we were checking if a model is from Active Record by checking if the method `after_commit` was defined - since `mongoid` doesn' have one - but `mongoid-paperclip` gem does define one, which cause this issue. (by @fjg)
### 4.3.0 - 2017-05-14
* Enhancements

View File

@@ -4,7 +4,7 @@ source "https://rubygems.org"
gemspec
gem "rails", "~> 5.1"
gem "rails", "~> 5.2"
gem "omniauth", "~> 1.3"
gem "oauth2"
gem "omniauth-oauth2"
@@ -14,7 +14,7 @@ gem "activemodel-serializers-xml", github: "rails/activemodel-serializers-xml"
gem "rails-controller-testing"
gem "responders", "~> 2.1"
gem "responders", "~> 2.4"
group :test do
gem "omniauth-facebook"

View File

@@ -10,91 +10,99 @@ GIT
PATH
remote: .
specs:
devise (4.4.0)
devise (4.5.0)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0, < 5.2)
railties (>= 4.1.0, < 6.0)
responders
warden (~> 1.2.3)
GEM
remote: https://rubygems.org/
specs:
actioncable (5.1.0)
actionpack (= 5.1.0)
actioncable (5.2.0)
actionpack (= 5.2.0)
nio4r (~> 2.0)
websocket-driver (~> 0.6.1)
actionmailer (5.1.0)
actionpack (= 5.1.0)
actionview (= 5.1.0)
activejob (= 5.1.0)
websocket-driver (>= 0.6.1)
actionmailer (5.2.0)
actionpack (= 5.2.0)
actionview (= 5.2.0)
activejob (= 5.2.0)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (5.1.0)
actionview (= 5.1.0)
activesupport (= 5.1.0)
actionpack (5.2.0)
actionview (= 5.2.0)
activesupport (= 5.2.0)
rack (~> 2.0)
rack-test (~> 0.6.3)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.1.0)
activesupport (= 5.1.0)
actionview (5.2.0)
activesupport (= 5.2.0)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (5.1.0)
activesupport (= 5.1.0)
activejob (5.2.0)
activesupport (= 5.2.0)
globalid (>= 0.3.6)
activemodel (5.1.0)
activesupport (= 5.1.0)
activerecord (5.1.0)
activemodel (= 5.1.0)
activesupport (= 5.1.0)
arel (~> 8.0)
activesupport (5.1.0)
activemodel (5.2.0)
activesupport (= 5.2.0)
activerecord (5.2.0)
activemodel (= 5.2.0)
activesupport (= 5.2.0)
arel (>= 9.0)
activestorage (5.2.0)
actionpack (= 5.2.0)
activerecord (= 5.2.0)
marcel (~> 0.3.1)
activesupport (5.2.0)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
arel (8.0.0)
bcrypt (3.1.11)
arel (9.0.0)
bcrypt (3.1.12)
builder (3.2.3)
concurrent-ruby (1.0.5)
erubi (1.6.0)
crass (1.0.4)
erubi (1.7.1)
faraday (0.11.0)
multipart-post (>= 1.2, < 3)
globalid (0.4.0)
globalid (0.4.1)
activesupport (>= 4.2.0)
hashie (3.5.5)
i18n (0.8.1)
hashie (3.5.7)
i18n (1.0.0)
concurrent-ruby (~> 1.0)
jwt (1.5.6)
loofah (2.0.3)
loofah (2.2.2)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.6.5)
mime-types (>= 1.16, < 4)
mail (2.7.0)
mini_mime (>= 0.1.1)
marcel (0.3.2)
mimemagic (~> 0.3.2)
metaclass (0.0.4)
method_source (0.8.2)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mini_portile2 (2.1.0)
minitest (5.10.1)
method_source (0.9.0)
mimemagic (0.3.2)
mini_mime (1.0.0)
mini_portile2 (2.3.0)
minitest (5.11.3)
mocha (1.2.1)
metaclass (~> 0.0.1)
multi_json (1.12.1)
multi_xml (0.6.0)
multipart-post (2.0.0)
nio4r (2.0.0)
nokogiri (1.7.1)
mini_portile2 (~> 2.1.0)
nio4r (2.3.0)
nokogiri (1.8.2)
mini_portile2 (~> 2.3.0)
oauth2 (1.3.1)
faraday (>= 0.8, < 0.12)
jwt (~> 1.0)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (>= 1.2, < 3)
omniauth (1.6.1)
omniauth (1.8.1)
hashie (>= 3.4.6, < 3.6.0)
rack (>= 1.6.2, < 3)
omniauth-facebook (4.0.0)
@@ -106,40 +114,41 @@ GEM
omniauth (~> 1.0)
rack-openid (~> 1.3.1)
orm_adapter (0.5.0)
rack (2.0.1)
rack (2.0.4)
rack-openid (1.3.1)
rack (>= 1.1.0)
ruby-openid (>= 2.1.8)
rack-test (0.6.3)
rack (>= 1.0)
rails (5.1.0)
actioncable (= 5.1.0)
actionmailer (= 5.1.0)
actionpack (= 5.1.0)
actionview (= 5.1.0)
activejob (= 5.1.0)
activemodel (= 5.1.0)
activerecord (= 5.1.0)
activesupport (= 5.1.0)
bundler (>= 1.3.0, < 2.0)
railties (= 5.1.0)
rack-test (1.0.0)
rack (>= 1.0, < 3)
rails (5.2.0)
actioncable (= 5.2.0)
actionmailer (= 5.2.0)
actionpack (= 5.2.0)
actionview (= 5.2.0)
activejob (= 5.2.0)
activemodel (= 5.2.0)
activerecord (= 5.2.0)
activestorage (= 5.2.0)
activesupport (= 5.2.0)
bundler (>= 1.3.0)
railties (= 5.2.0)
sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.1)
actionpack (~> 5.x)
actionview (~> 5.x)
activesupport (~> 5.x)
rails-dom-testing (2.0.2)
activesupport (>= 4.2.0, < 6.0)
nokogiri (~> 1.6)
rails-html-sanitizer (1.0.3)
loofah (~> 2.0)
railties (5.1.0)
actionpack (= 5.1.0)
activesupport (= 5.1.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2)
railties (5.2.0)
actionpack (= 5.2.0)
activesupport (= 5.2.0)
method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (12.0.0)
rake (12.3.1)
rdoc (5.1.0)
responders (2.4.0)
actionpack (>= 4.2.0, < 5.3)
@@ -148,14 +157,14 @@ GEM
sprockets (3.7.1)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.0)
sprockets-rails (3.2.1)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.3.13)
thor (0.19.4)
thor (0.20.0)
thread_safe (0.3.6)
tzinfo (1.2.3)
tzinfo (1.2.5)
thread_safe (~> 0.1)
warden (1.2.7)
rack (>= 1.0)
@@ -163,9 +172,9 @@ GEM
nokogiri (>= 1.2.0)
rack (>= 1.0)
rack-test (>= 0.5.3)
websocket-driver (0.6.5)
websocket-driver (0.7.0)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)
websocket-extensions (0.1.3)
PLATFORMS
ruby
@@ -182,12 +191,12 @@ DEPENDENCIES
omniauth-facebook
omniauth-oauth2
omniauth-openid
rails (~> 5.1)
rails (~> 5.2)
rails-controller-testing
rdoc
responders (~> 2.1)
responders (~> 2.4)
sqlite3
webrat (= 0.7.3)
BUNDLED WITH
1.15.3
1.16.1

View File

@@ -16,16 +16,16 @@ Devise is a flexible authentication solution for Rails based on Warden. It:
It's composed of 10 modules:
* [Database Authenticatable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/DatabaseAuthenticatable): hashes and stores a password in the database to validate the authenticity of a user while signing in. The authentication can be done both through POST requests or HTTP Basic Authentication.
* [Omniauthable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Omniauthable): adds OmniAuth (https://github.com/omniauth/omniauth) support.
* [Confirmable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Confirmable): sends emails with confirmation instructions and verifies whether an account is already confirmed during sign in.
* [Recoverable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Recoverable): resets the user password and sends reset instructions.
* [Registerable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Registerable): handles signing up users through a registration process, also allowing them to edit and destroy their account.
* [Rememberable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Rememberable): manages generating and clearing a token for remembering the user from a saved cookie.
* [Trackable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Trackable): tracks sign in count, timestamps and IP address.
* [Timeoutable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Timeoutable): expires sessions that have not been active in a specified period of time.
* [Validatable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Validatable): provides validations of email and password. It's optional and can be customized, so you're able to define your own validations.
* [Lockable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Lockable): locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.
* [Database Authenticatable](http://www.rubydoc.info/github/plataformatec/devise/master/Devise/Models/DatabaseAuthenticatable): hashes and stores a password in the database to validate the authenticity of a user while signing in. The authentication can be done both through POST requests or HTTP Basic Authentication.
* [Omniauthable](http://www.rubydoc.info/github/plataformatec/devise/master/Devise/Models/Omniauthable): adds OmniAuth (https://github.com/omniauth/omniauth) support.
* [Confirmable](http://www.rubydoc.info/github/plataformatec/devise/master/Devise/Models/Confirmable): sends emails with confirmation instructions and verifies whether an account is already confirmed during sign in.
* [Recoverable](http://www.rubydoc.info/github/plataformatec/devise/master/Devise/Models/Recoverable): resets the user password and sends reset instructions.
* [Registerable](http://www.rubydoc.info/github/plataformatec/devise/master/Devise/Models/Registerable): handles signing up users through a registration process, also allowing them to edit and destroy their account.
* [Rememberable](http://www.rubydoc.info/github/plataformatec/devise/master/Devise/Models/Rememberable): manages generating and clearing a token for remembering the user from a saved cookie.
* [Trackable](http://www.rubydoc.info/github/plataformatec/devise/master/Devise/Models/Trackable): tracks sign in count, timestamps and IP address.
* [Timeoutable](http://www.rubydoc.info/github/plataformatec/devise/master/Devise/Models/Timeoutable): expires sessions that have not been active in a specified period of time.
* [Validatable](http://www.rubydoc.info/github/plataformatec/devise/master/Devise/Models/Validatable): provides validations of email and password. It's optional and can be customized, so you're able to define your own validations.
* [Lockable](http://www.rubydoc.info/github/plataformatec/devise/master/Devise/Models/Lockable): locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.
## Table of Contents
@@ -53,11 +53,6 @@ It's composed of 10 modules:
- [Integration tests](#integration-tests)
- [OmniAuth](#omniauth)
- [Configuring multiple models](#configuring-multiple-models)
- [Create a migration with the required fields](#create-a-migration-with-the-required-fields)
- [Inside your Admin model](#inside-your-admin-model)
- [Inside your routes](#inside-your-routes)
- [Inside your protected controller](#inside-your-protected-controller)
- [Inside your controllers and views](#inside-your-controllers-and-views)
- [ActiveJob Integration](#activejob-integration)
- [Password reset tokens and Rails logs](#password-reset-tokens-and-rails-logs)
- [Other ORMs](#other-orms)
@@ -123,7 +118,36 @@ We hope that you will consider contributing to Devise. Please read this short ov
https://github.com/plataformatec/devise/wiki/Contributing
You will usually want to write tests for your changes. To run the test suite, go into Devise's top-level directory and run "bundle install" and "rake". For the tests to pass, you will need to have a MongoDB server (version 2.0 or newer) running on your system.
You will usually want to write tests for your changes. To run the test suite, go into Devise's top-level directory and run `bundle install` and `bin/test`.
Devise works with multiple Ruby and Rails versions, and ActiveRecord and Mongoid ORMs, which means you can run the test suite with some modifiers: `DEVISE_ORM` and `BUNDLE_GEMFILE`.
### DEVISE_ORM
Since Devise support both Mongoid and ActiveRecord, we rely on this variable to run specific code for each ORM.
The default value of `DEVISE_ORM` is `active_record`. To run the tests for mongoid, you can pass `mongoid`:
```
DEVISE_ORM=mongoid bin/test
==> Devise.orm = :mongoid
```
When running the tests for Mongoid, you will need to have a MongoDB server (version 2.0 or newer) running on your system.
Please note that the command output will show the variable value being used.
### BUNDLE_GEMFILE
We can use this variable to tell bundler what Gemfile it should use (instead of the one in the current directory).
Inside the [gemfiles](https://github.com/plataformatec/devise/tree/master/gemfiles) directory, we have one for each version of Rails we support. When you send us a pull request, it may happen that the test suite breaks on Travis using some of them. If that's the case, you can simulate the same environment using the `BUNDLE_GEMFILE` variable.
For example, if the tests broke using Ruby 2.4.2 and Rails 4.1, you can do the following:
```bash
rbenv shell 2.4.2 # or rvm use 2.4.2
BUNDLE_GEMFILE=gemfiles/Gemfile.rails-4.1-stable bundle install
BUNDLE_GEMFILE=gemfiles/Gemfile.rails-4.1-stable bin/test
```
You can also combine both of them if the tests broke for Mongoid:
```bash
BUNDLE_GEMFILE=gemfiles/Gemfile.rails-4.1-stable bundle install
BUNDLE_GEMFILE=gemfiles/Gemfile.rails-4.1-stable DEVISE_ORM=mongoid bin/test
```
## Starting with Rails?
@@ -137,7 +161,7 @@ Once you have solidified your understanding of Rails and authentication mechanis
## Getting started
Devise 4.0 works with Rails 4.1 onwards. You can add it to your Gemfile with:
Devise 4.0 works with Rails 4.1 onwards. Add the following line to your Gemfile:
```ruby
gem 'devise'
@@ -166,7 +190,7 @@ In the following command you will replace `MODEL` with the class name used for t
$ rails generate devise MODEL
```
Next, check the MODEL for any additional configuration options you might want to add, such as confirmable or lockable. If you add an option, be sure to inspect the migration file (created by the generator if your ORM supports them) and uncomment the appropriate section. For example, if you add the confirmable option in the model, you'll need to uncomment the Confirmable section in the migration.
Next, check the MODEL for any additional configuration options you might want to add, such as confirmable or lockable. If you add an option, be sure to inspect the migration file (created by the generator if your ORM supports them) and uncomment the appropriate section. For example, if you add the confirmable option in the model, you'll need to uncomment the Confirmable section in the migration.
Then run `rails db:migrate`
@@ -375,6 +399,7 @@ If the customization at the views level is not enough, you can customize each co
...
end
```
(Use the -c flag to specify a controller, for example: `rails generate devise:controllers users -c=sessions`)
2. Tell the router to use this controller:
@@ -490,6 +515,9 @@ cases/specs.
Controller tests require that you include `Devise::Test::ControllerHelpers` on
your test case or its parent `ActionController::TestCase` superclass.
For Rails 5, include `Devise::Test::IntegrationHelpers` instead, since the superclass
for controller tests has been changed to ActionDispatch::IntegrationTest
(for more details, see the [Integration tests](#integration-tests) section).
```ruby
class PostsControllerTest < ActionController::TestCase
@@ -674,6 +702,6 @@ https://github.com/plataformatec/devise/graphs/contributors
## License
MIT License. Copyright 2009-2017 Plataformatec. http://plataformatec.com.br
MIT License. Copyright 2009-2018 Plataformatec. http://plataformatec.com.br
You are not granted rights or licenses to the trademarks of Plataformatec, including without limitation the Devise name or logo.

View File

@@ -112,7 +112,7 @@ class Devise::RegistrationsController < DeviseController
# The path used after sign up. You need to overwrite this method
# in your own RegistrationsController.
def after_sign_up_path_for(resource)
after_sign_in_path_for(resource)
after_sign_in_path_for(resource) if is_navigational_format?
end
# The path used after sign up for inactive accounts. You need to overwrite

View File

@@ -22,7 +22,7 @@ class DeviseController < Devise.parent_controller.constantize
# Action Controller tests that forces _prefixes to be
# loaded before even having a request object.
#
# This method should be public as it is is in ActionPack
# This method should be public as it is in ActionPack
# itself. Changing its visibility may break other gems.
def _prefixes #:nodoc:
@_prefixes ||= if self.class.scoped_views? && request && devise_mapping

View File

@@ -9,7 +9,7 @@
<% if @minimum_password_length %>
<em>(<%= @minimum_password_length %> characters minimum)</em><br />
<% end %>
<%= f.password_field :password, autofocus: true, autocomplete: "off" %>
<%= f.password_field :password, autofocus: true, autocomplete: "new-password" %>
</div>
<div class="field">

View File

@@ -14,7 +14,7 @@
<div class="field">
<%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
<%= f.password_field :password, autocomplete: "off" %>
<%= f.password_field :password, autocomplete: "new-password" %>
<% if @minimum_password_length %>
<br />
<em><%= @minimum_password_length %> characters minimum</em>
@@ -23,12 +23,12 @@
<div class="field">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
<%= f.password_field :password_confirmation, autocomplete: "new-password" %>
</div>
<div class="field">
<%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
<%= f.password_field :current_password, autocomplete: "off" %>
<%= f.password_field :current_password, autocomplete: "current-password" %>
</div>
<div class="actions">

View File

@@ -13,12 +13,12 @@
<% if @minimum_password_length %>
<em>(<%= @minimum_password_length %> characters minimum)</em>
<% end %><br />
<%= f.password_field :password, autocomplete: "off" %>
<%= f.password_field :password, autocomplete: "new-password" %>
</div>
<div class="field">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
<%= f.password_field :password_confirmation, autocomplete: "new-password" %>
</div>
<div class="actions">

View File

@@ -8,7 +8,7 @@
<div class="field">
<%= f.label :password %><br />
<%= f.password_field :password, autocomplete: "off" %>
<%= f.password_field :password, autocomplete: "current-password" %>
</div>
<% if devise_mapping.rememberable? -%>

View File

@@ -1,6 +1,6 @@
# -*- encoding: utf-8 -*-
# frozen_string_literal: true
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "devise/version"
@@ -23,6 +23,6 @@ Gem::Specification.new do |s|
s.add_dependency("warden", "~> 1.2.3")
s.add_dependency("orm_adapter", "~> 0.1")
s.add_dependency("bcrypt", "~> 3.0")
s.add_dependency("railties", ">= 4.1.0", "< 5.2")
s.add_dependency("railties", ">= 4.1.0", "< 6.0")
s.add_dependency("responders")
end

View File

@@ -21,10 +21,10 @@ GIT
PATH
remote: ..
specs:
devise (4.4.0)
devise (4.5.0)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0, < 5.2)
railties (>= 4.1.0, < 6.0)
responders
warden (~> 1.2.3)
@@ -54,7 +54,7 @@ GEM
thread_safe (~> 0.1)
tzinfo (~> 1.1)
arel (5.0.1.20140414130214)
bcrypt (3.1.11)
bcrypt (3.1.12)
bson (3.2.6)
builder (3.2.3)
concurrent-ruby (1.0.5)
@@ -168,4 +168,4 @@ DEPENDENCIES
webrat (= 0.7.3)
BUNDLED WITH
1.15.3
1.16.1

View File

@@ -57,10 +57,10 @@ GIT
PATH
remote: ..
specs:
devise (4.4.0)
devise (4.5.0)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0, < 5.2)
railties (>= 4.1.0, < 6.0)
responders
warden (~> 1.2.3)
@@ -68,7 +68,7 @@ GEM
remote: https://rubygems.org/
specs:
arel (6.0.4)
bcrypt (3.1.11)
bcrypt (3.1.12)
bson (3.2.6)
builder (3.2.3)
concurrent-ruby (1.0.5)
@@ -189,4 +189,4 @@ DEPENDENCIES
webrat (= 0.7.3)
BUNDLED WITH
1.15.3
1.16.1

View File

@@ -10,10 +10,10 @@ GIT
PATH
remote: ..
specs:
devise (4.4.0)
devise (4.5.0)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0, < 5.2)
railties (>= 4.1.0, < 6.0)
responders
warden (~> 1.2.3)
@@ -58,7 +58,7 @@ GEM
minitest (~> 5.1)
tzinfo (~> 1.1)
arel (7.1.4)
bcrypt (3.1.11)
bcrypt (3.1.12)
builder (3.2.3)
concurrent-ruby (1.0.5)
erubis (2.7.0)
@@ -189,4 +189,4 @@ DEPENDENCIES
webrat (= 0.7.3)
BUNDLED WITH
1.15.3
1.16.1

View File

@@ -0,0 +1,26 @@
source "https://rubygems.org"
gemspec path: ".."
gem "rails", '~> 5.2.0.rc1'
gem "omniauth"
gem "omniauth-oauth2"
gem "rdoc"
gem "activemodel-serializers-xml", github: "rails/activemodel-serializers-xml"
gem "rails-controller-testing"
gem "responders", "~> 2.1"
group :test do
gem "omniauth-facebook"
gem "omniauth-openid"
gem "webrat", "0.7.3", require: false
gem "mocha", "~> 1.1", require: false
gem 'test_after_commit', require: false
end
platforms :ruby do
gem "sqlite3"
end

View File

@@ -0,0 +1,201 @@
GIT
remote: git://github.com/rails/activemodel-serializers-xml.git
revision: 356edf4dfc38fb1fbfee90c87856e4fe5b73c5e1
specs:
activemodel-serializers-xml (1.0.2)
activemodel (> 5.x)
activesupport (> 5.x)
builder (~> 3.1)
PATH
remote: ..
specs:
devise (4.5.0)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0, < 6.0)
responders
warden (~> 1.2.3)
GEM
remote: https://rubygems.org/
specs:
actioncable (5.2.0.rc1)
actionpack (= 5.2.0.rc1)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailer (5.2.0.rc1)
actionpack (= 5.2.0.rc1)
actionview (= 5.2.0.rc1)
activejob (= 5.2.0.rc1)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (5.2.0.rc1)
actionview (= 5.2.0.rc1)
activesupport (= 5.2.0.rc1)
rack (~> 2.0)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.2.0.rc1)
activesupport (= 5.2.0.rc1)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (5.2.0.rc1)
activesupport (= 5.2.0.rc1)
globalid (>= 0.3.6)
activemodel (5.2.0.rc1)
activesupport (= 5.2.0.rc1)
activerecord (5.2.0.rc1)
activemodel (= 5.2.0.rc1)
activesupport (= 5.2.0.rc1)
arel (>= 9.0)
activestorage (5.2.0.rc1)
actionpack (= 5.2.0.rc1)
activerecord (= 5.2.0.rc1)
marcel (~> 0.3.1)
activesupport (5.2.0.rc1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7)
minitest (~> 5.1)
tzinfo (~> 1.1)
arel (9.0.0)
bcrypt (3.1.12)
builder (3.2.3)
concurrent-ruby (1.0.5)
crass (1.0.3)
erubi (1.7.0)
faraday (0.12.2)
multipart-post (>= 1.2, < 3)
globalid (0.4.1)
activesupport (>= 4.2.0)
hashie (3.5.7)
i18n (0.9.3)
concurrent-ruby (~> 1.0)
jwt (1.5.6)
loofah (2.1.1)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.0)
mini_mime (>= 0.1.1)
marcel (0.3.1)
mimemagic (~> 0.3.2)
metaclass (0.0.4)
method_source (0.9.0)
mimemagic (0.3.2)
mini_mime (1.0.0)
mini_portile2 (2.3.0)
minitest (5.11.3)
mocha (1.3.0)
metaclass (~> 0.0.1)
multi_json (1.13.1)
multi_xml (0.6.0)
multipart-post (2.0.0)
nio4r (2.2.0)
nokogiri (1.8.2)
mini_portile2 (~> 2.3.0)
oauth2 (1.4.0)
faraday (>= 0.8, < 0.13)
jwt (~> 1.0)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (>= 1.2, < 3)
omniauth (1.8.1)
hashie (>= 3.4.6, < 3.6.0)
rack (>= 1.6.2, < 3)
omniauth-facebook (4.0.0)
omniauth-oauth2 (~> 1.2)
omniauth-oauth2 (1.5.0)
oauth2 (~> 1.1)
omniauth (~> 1.2)
omniauth-openid (1.0.1)
omniauth (~> 1.0)
rack-openid (~> 1.3.1)
orm_adapter (0.5.0)
rack (2.0.4)
rack-openid (1.3.1)
rack (>= 1.1.0)
ruby-openid (>= 2.1.8)
rack-test (0.8.2)
rack (>= 1.0, < 3)
rails (5.2.0.rc1)
actioncable (= 5.2.0.rc1)
actionmailer (= 5.2.0.rc1)
actionpack (= 5.2.0.rc1)
actionview (= 5.2.0.rc1)
activejob (= 5.2.0.rc1)
activemodel (= 5.2.0.rc1)
activerecord (= 5.2.0.rc1)
activestorage (= 5.2.0.rc1)
activesupport (= 5.2.0.rc1)
bundler (>= 1.3.0)
railties (= 5.2.0.rc1)
sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.2)
actionpack (~> 5.x, >= 5.0.1)
actionview (~> 5.x, >= 5.0.1)
activesupport (~> 5.x)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.3)
loofah (~> 2.0)
railties (5.2.0.rc1)
actionpack (= 5.2.0.rc1)
activesupport (= 5.2.0.rc1)
method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (12.3.0)
rdoc (6.0.1)
responders (2.4.0)
actionpack (>= 4.2.0, < 5.3)
railties (>= 4.2.0, < 5.3)
ruby-openid (2.7.0)
sprockets (3.7.1)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.1)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.3.13)
test_after_commit (1.1.0)
activerecord (>= 3.2)
thor (0.20.0)
thread_safe (0.3.6)
tzinfo (1.2.5)
thread_safe (~> 0.1)
warden (1.2.7)
rack (>= 1.0)
webrat (0.7.3)
nokogiri (>= 1.2.0)
rack (>= 1.0)
rack-test (>= 0.5.3)
websocket-driver (0.7.0)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.3)
PLATFORMS
ruby
DEPENDENCIES
activemodel-serializers-xml!
devise!
mocha (~> 1.1)
omniauth
omniauth-facebook
omniauth-oauth2
omniauth-openid
rails (~> 5.2.0.rc1)
rails-controller-testing
rdoc
responders (~> 2.1)
sqlite3
test_after_commit
webrat (= 0.7.3)
BUNDLED WITH
1.16.1

View File

@@ -76,7 +76,7 @@ end
class TestController < ApplicationController
include Rails.application.routes.url_helpers
before_filter :authenticate_user!
before_action :authenticate_user!
def index
render plain: 'Home'

View File

@@ -18,6 +18,7 @@ module Devise
autoload :TestHelpers, 'devise/test_helpers'
autoload :TimeInflector, 'devise/time_inflector'
autoload :TokenGenerator, 'devise/token_generator'
autoload :SecretKeyFinder, 'devise/secret_key_finder'
module Controllers
autoload :Helpers, 'devise/controllers/helpers'

View File

@@ -12,11 +12,6 @@ module Devise
if respond_to?(:helper_method)
helper_method :warden, :signed_in?, :devise_controller?
end
def append_info_to_payload(payload)
super
payload[:status] ||= 401 unless payload[:exception]
end
end
module ClassMethods
@@ -83,6 +78,11 @@ module Devise
end
METHODS
end
def log_process_action(payload)
payload[:status] ||= 401 unless payload[:exception]
super
end
end
# Define authentication filters and accessor helpers based on mappings.

View File

@@ -6,7 +6,10 @@ module Devise
# Included by default in all controllers.
module SignInOut
# Return true if the given scope is signed in session. If no scope given, return
# true if any scope is signed in. Does not run authentication hooks.
# true if any scope is signed in. This will run authentication hooks, which may
# cause exceptions to be thrown from this method; if you simply want to check
# if a scope has already previously been authenticated without running
# authentication hooks, you can directly call `warden.authenticated?(scope: scope)`
def signed_in?(scope=nil)
[scope || Devise.mappings.keys].flatten.any? do |_scope|
warden.authenticate?(scope: _scope)
@@ -16,6 +19,9 @@ module Devise
# Sign in a user that already was authenticated. This helper is useful for logging
# users in after sign up. All options given to sign_in is passed forward
# to the set_user method in warden.
# If you are using a custom warden strategy and the timeoutable module, you have to
# set `env["devise.skip_timeout"] = true` in the request to use this method, like we do
# in the sessions controller: https://github.com/plataformatec/devise/blob/master/app/controllers/devise/sessions_controller.rb#L7
#
# Examples:
#

View File

@@ -260,5 +260,7 @@ module Devise
def relative_url_root?
relative_url_root.present?
end
ActiveSupport.run_load_hooks(:devise_failure_app, self)
end
end

View File

@@ -134,16 +134,18 @@ module Devise
# This is an internal method called every time Devise needs
# to send a notification/mail. This can be overridden if you
# need to customize the e-mail delivery logic. For instance,
# if you are using a queue to deliver e-mails (delayed job,
# sidekiq, resque, etc), you must add the delivery to the queue
# if you are using a queue to deliver e-mails (active job, delayed
# job, sidekiq, resque, etc), you must add the delivery to the queue
# just after the transaction was committed. To achieve this,
# you can override send_devise_notification to store the
# deliveries until the after_commit callback is triggered:
# deliveries until the after_commit callback is triggered.
#
# The following example uses Active Job's `deliver_later` :
#
# class User
# devise :database_authenticatable, :confirmable
#
# after_commit :send_pending_notifications
# after_commit :send_pending_devise_notifications
#
# protected
#
@@ -152,38 +154,43 @@ module Devise
# # delivery until the after_commit callback otherwise
# # send now because after_commit will not be called.
# if new_record? || changed?
# pending_notifications << [notification, args]
# pending_devise_notifications << [notification, args]
# else
# message = devise_mailer.send(notification, self, *args)
# Remove once we move to Rails 4.2+ only.
# if message.respond_to?(:deliver_now)
# message.deliver_now
# else
# message.deliver
# end
# render_and_send_devise_message(notification, *args)
# end
# end
#
# def send_pending_notifications
# pending_notifications.each do |notification, args|
# message = devise_mailer.send(notification, self, *args)
# Remove once we move to Rails 4.2+ only.
# if message.respond_to?(:deliver_now)
# message.deliver_now
# else
# message.deliver
# end
# private
#
# def send_pending_devise_notifications
# pending_devise_notifications.each do |notification, args|
# render_and_send_devise_message(notification, *args)
# end
#
# # Empty the pending notifications array because the
# # after_commit hook can be called multiple times which
# # could cause multiple emails to be sent.
# pending_notifications.clear
# pending_devise_notifications.clear
# end
#
# def pending_notifications
# @pending_notifications ||= []
# def pending_devise_notifications
# @pending_devise_notifications ||= []
# end
#
# def render_and_send_devise_message(notification, *args)
# message = devise_mailer.send(notification, self, *args)
#
# # Deliver later with Active Job's `deliver_later`
# if message.respond_to?(:deliver_later)
# message.deliver_later
# # Remove once we move to Rails 4.2+ only, as `deliver` is deprecated.
# elsif message.respond_to?(:deliver_now)
# message.deliver_now
# else
# message.deliver
# end
# end
#
# end
#
def send_devise_notification(notification, *args)

View File

@@ -48,7 +48,7 @@ module Devise
included do
before_create :generate_confirmation_token, if: :confirmation_required?
after_create :skip_reconfirmation_in_callback!, if: :send_confirmation_notification?
if defined?(ActiveRecord) && self.is_a?(ActiveRecord::Base) # ActiveRecord
if defined?(ActiveRecord) && self < ActiveRecord::Base # ActiveRecord
after_commit :send_on_create_confirmation_instructions, on: :create, if: :send_confirmation_notification?
after_commit :send_reconfirmation_instructions, on: :update, if: :reconfirmation_required?
else # Mongoid

View File

@@ -73,11 +73,11 @@ module Devise
end
result = if valid_password?(current_password)
update_attributes(params, *options)
update(params, *options)
else
self.assign_attributes(params, *options)
self.valid?
self.errors.add(:current_password, current_password.blank? ? :blank : :invalid)
assign_attributes(params, *options)
valid?
errors.add(:current_password, current_password.blank? ? :blank : :invalid)
false
end
@@ -101,7 +101,7 @@ module Devise
params.delete(:password)
params.delete(:password_confirmation)
result = update_attributes(params, *options)
result = update(params, *options)
clean_up_passwords
result
end
@@ -113,8 +113,8 @@ module Devise
result = if valid_password?(current_password)
destroy
else
self.valid?
self.errors.add(:current_password, current_password.blank? ? :blank : :invalid)
valid?
errors.add(:current_password, current_password.blank? ? :blank : :invalid)
false
end

View File

@@ -22,7 +22,7 @@ module Devise
self.last_sign_in_at = old_current || new_current
self.current_sign_in_at = new_current
old_current, new_current = self.current_sign_in_ip, request.remote_ip
old_current, new_current = self.current_sign_in_ip, extract_ip_from(request)
self.last_sign_in_ip = old_current || new_current
self.current_sign_in_ip = new_current
@@ -31,9 +31,21 @@ module Devise
end
def update_tracked_fields!(request)
# We have to check if the user is already persisted before running
# `save` here because invalid users can be saved if we don't.
# See https://github.com/plataformatec/devise/issues/4673 for more details.
return if new_record?
update_tracked_fields(request)
save
save(validate: false)
end
protected
def extract_ip_from(request)
request.remote_ip
end
end
end
end

View File

@@ -18,6 +18,8 @@ module Devise
def filtered_hash_by_method_for_given_keys(conditions, method, condition_keys)
condition_keys.each do |k|
next unless conditions.key?(k)
value = conditions[k]
conditions[k] = value.send(method) if value.respond_to?(method)
end

View File

@@ -135,7 +135,19 @@ module Devise
end
def default_params
@params.fetch(@resource_name, {})
if hashable_resource_params?
@params.fetch(@resource_name)
else
empty_params
end
end
def hashable_resource_params?
@params[@resource_name].respond_to?(:permit)
end
def empty_params
ActionController::Parameters.new({})
end
def permit_keys(parameters, keys)

View File

@@ -34,11 +34,7 @@ module Devise
end
initializer "devise.secret_key" do |app|
if app.respond_to?(:secrets)
Devise.secret_key ||= app.secrets.secret_key_base
elsif app.config.respond_to?(:secret_key_base)
Devise.secret_key ||= app.config.secret_key_base
end
Devise.secret_key ||= Devise::SecretKeyFinder.new(app).find
Devise.token_generator ||=
if secret_key = Devise.secret_key

View File

@@ -0,0 +1,27 @@
# frozen_string_literal: true
module Devise
class SecretKeyFinder
def initialize(application)
@application = application
end
def find
if @application.respond_to?(:credentials) && key_exists?(@application.credentials)
@application.credentials.secret_key_base
elsif @application.respond_to?(:secrets) && key_exists?(@application.secrets)
@application.secrets.secret_key_base
elsif @application.config.respond_to?(:secret_key_base) && key_exists?(@application.config)
@application.config.secret_key_base
elsif @application.respond_to?(:secret_key_base) && key_exists?(@application)
@application.secret_key_base
end
end
private
def key_exists?(object)
object.secret_key_base.present?
end
end
end

View File

@@ -17,7 +17,9 @@ module Devise
end
mapping.to.new.password = password if !hashed && Devise.paranoid
fail(:not_found_in_database) unless resource
unless resource
Devise.paranoid ? fail(:invalid) : fail(:not_found_in_database)
end
end
end
end

View File

@@ -139,6 +139,7 @@ module Devise
status, headers, response = Devise.warden_config[:failure_app].call(env).to_a
@controller.response.headers.merge!(headers)
@controller.response.content_type = headers["Content-Type"] unless Rails.version.start_with?('5')
@controller.status = status
@controller.response.body = response.body
nil # causes process return @response

View File

@@ -1,5 +1,5 @@
# frozen_string_literal: true
module Devise
VERSION = "4.4.0".freeze
VERSION = "4.5.0".freeze
end

View File

@@ -54,11 +54,11 @@ module ActiveRecord
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, default: 0, null: false
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.#{ip_column} :current_sign_in_ip
t.#{ip_column} :last_sign_in_ip
# t.integer :sign_in_count, default: 0, null: false
# t.datetime :current_sign_in_at
# t.datetime :last_sign_in_at
# t.#{ip_column} :current_sign_in_ip
# t.#{ip_column} :last_sign_in_ip
## Confirmable
# t.string :confirmation_token

View File

@@ -6,9 +6,9 @@ module Devise
def model_contents
buffer = <<-CONTENT
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
:recoverable, :rememberable, :validatable
CONTENT
buffer

View File

@@ -34,11 +34,11 @@ module Mongoid
field :remember_created_at, type: Time
## Trackable
field :sign_in_count, type: Integer, default: 0
field :current_sign_in_at, type: Time
field :last_sign_in_at, type: Time
field :current_sign_in_ip, type: String
field :last_sign_in_ip, type: String
# field :sign_in_count, type: Integer, default: 0
# field :current_sign_in_at, type: Time
# field :last_sign_in_at, type: Time
# field :current_sign_in_ip, type: String
# field :last_sign_in_ip, type: String
## Confirmable
# field :confirmation_token, type: String

View File

@@ -9,6 +9,10 @@ Devise.setup do |config|
# Devise will use the `secret_key_base` as its `secret_key`
# by default. You can change it below and use your own secret key.
# config.secret_key = '<%= SecureRandom.hex(64) %>'
# ==> Controller configuration
# Configure the parent class to the devise controllers.
# config.parent_controller = 'DeviseController'
# ==> Mailer Configuration
# Configure the e-mail address which will be shown in Devise::Mailer,
@@ -276,4 +280,11 @@ Devise.setup do |config|
# When using OmniAuth, Devise cannot automatically set OmniAuth path,
# so you need to do it manually. For the users scope, it would be:
# config.omniauth_path_prefix = '/my_engine/users/auth'
# ==> Turbolinks configuration
# If your app is using Turbolinks, Turbolinks::Controller needs to be included to make redirection work correctly:
#
# ActiveSupport.on_load(:devise_failure_app) do
# include Turbolinks::Controller
# end
end

View File

@@ -5,7 +5,11 @@
<%= f.full_error :confirmation_token %>
<div class="form-inputs">
<%= f.input :email, required: true, autofocus: true %>
<%= f.input :email,
required: true,
autofocus: true,
value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email),
input_html: { autocomplete: "email" } %>
</div>
<div class="form-actions">

View File

@@ -7,7 +7,12 @@
<%= f.full_error :reset_password_token %>
<div class="form-inputs">
<%= f.input :password, label: "New password", required: true, autofocus: true, hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length) %>
<%= f.input :password,
label: "New password",
required: true,
autofocus: true,
hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length),
input_html: { autocomplete: "new-password" } %>
<%= f.input :password_confirmation, label: "Confirm your new password", required: true %>
</div>

View File

@@ -4,7 +4,10 @@
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :email, required: true, autofocus: true %>
<%= f.input :email,
required: true,
autofocus: true,
input_html: { autocomplete: "email" } %>
</div>
<div class="form-actions">

View File

@@ -10,9 +10,17 @@
<p>Currently waiting confirmation for: <%= resource.unconfirmed_email %></p>
<% end %>
<%= f.input :password, autocomplete: "off", hint: "leave it blank if you don't want to change it", required: false %>
<%= f.input :password_confirmation, required: false %>
<%= f.input :current_password, hint: "we need your current password to confirm your changes", required: true %>
<%= f.input :password,
hint: "leave it blank if you don't want to change it",
required: false
input_html: { autocomplete: "new-password" } %>
<%= f.input :password_confirmation,
required: false,
input_html: { autocomplete: "new-password" } %>
<%= f.input :current_password,
hint: "we need your current password to confirm your changes",
required: true,
input_html: { autocomplete: "current-password" } %>
</div>
<div class="form-actions">

View File

@@ -4,9 +4,17 @@
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :email, required: true, autofocus: true %>
<%= f.input :password, required: true, hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length) %>
<%= f.input :password_confirmation, required: true %>
<%= f.input :email,
required: true,
autofocus: true ,
input_html: { autocomplete: "email" }%>
<%= f.input :password,
required: true,
hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length),
input_html: { autocomplete: "new-password" } %>
<%= f.input :password_confirmation,
required: true,
input_html: { autocomplete: "new-password" } %>
</div>
<div class="form-actions">

View File

@@ -2,8 +2,13 @@
<%= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<div class="form-inputs">
<%= f.input :email, required: false, autofocus: true %>
<%= f.input :password, required: false %>
<%= f.input :email,
required: false,
autofocus: true,
input_html: { autocomplete: "email" } %>
<%= f.input :password,
required: false,
input_html: { autocomplete: "current-password" } %>
<%= f.input :remember_me, as: :boolean if devise_mapping.rememberable? %>
</div>

View File

@@ -5,7 +5,10 @@
<%= f.full_error :unlock_token %>
<div class="form-inputs">
<%= f.input :email, required: true, autofocus: true %>
<%= f.input :email,
required: true,
autofocus: true,
input_html: { autocomplete: "email" } %>
</div>
<div class="form-actions">

View File

@@ -337,4 +337,10 @@ class FailureTest < ActiveSupport::TestCase
end
end
end
context "Lazy loading" do
test "loads" do
assert_equal Devise::FailureApp.new.lazy_loading_works?, "yes it does"
end
end
end

View File

@@ -3,6 +3,12 @@
require 'test_helper'
class AuthenticationSanityTest < Devise::IntegrationTest
test 'sign in should not run model validations' do
sign_in_as_user
refute User.validations_performed
end
test 'home should be accessible without sign in' do
visit '/'
assert_response :success
@@ -545,18 +551,6 @@ class AuthenticationOthersTest < Devise::IntegrationTest
refute warden.authenticated?(:user)
end
end
test 'not signed in should return notification payload with 401 status' do
begin
subscriber = ActiveSupport::Notifications.subscribe /process_action.action_controller/ do |_name, _start, _finish, _id, payload|
assert_equal 401, payload[:status]
end
get admins_path
ensure
ActiveSupport::Notifications.unsubscribe(subscriber)
end
end
end
class AuthenticationKeysTest < Devise::IntegrationTest

View File

@@ -263,7 +263,7 @@ class ConfirmationOnChangeTest < Devise::IntegrationTest
test 'admin should be able to request a new confirmation after email changed' do
admin = create_admin
admin.update_attributes(email: 'new_test@example.com')
admin.update(email: 'new_test@example.com')
visit new_admin_session_path
click_link "Didn't receive confirmation instructions?"
@@ -279,7 +279,7 @@ class ConfirmationOnChangeTest < Devise::IntegrationTest
test 'admin with valid confirmation token should be able to confirm email after email changed' do
admin = create_admin
admin.update_attributes(email: 'new_test@example.com')
admin.update(email: 'new_test@example.com')
assert_equal 'new_test@example.com', admin.unconfirmed_email
visit_admin_confirmation_with_token(admin.raw_confirmation_token)
@@ -291,13 +291,13 @@ class ConfirmationOnChangeTest < Devise::IntegrationTest
test 'admin with previously valid confirmation token should not be able to confirm email after email changed again' do
admin = create_admin
admin.update_attributes(email: 'first_test@example.com')
admin.update(email: 'first_test@example.com')
assert_equal 'first_test@example.com', admin.unconfirmed_email
raw_confirmation_token = admin.raw_confirmation_token
admin = Admin.find(admin.id)
admin.update_attributes(email: 'second_test@example.com')
admin.update(email: 'second_test@example.com')
assert_equal 'second_test@example.com', admin.unconfirmed_email
visit_admin_confirmation_with_token(raw_confirmation_token)
@@ -313,7 +313,7 @@ class ConfirmationOnChangeTest < Devise::IntegrationTest
test 'admin email should be unique also within unconfirmed_email' do
admin = create_admin
admin.update_attributes(email: 'new_admin_test@example.com')
admin.update(email: 'new_admin_test@example.com')
assert_equal 'new_admin_test@example.com', admin.unconfirmed_email
create_second_admin(email: "new_admin_test@example.com")

View File

@@ -74,6 +74,19 @@ class DatabaseAuthenticationTest < Devise::IntegrationTest
refute warden.authenticated?(:admin)
end
test 'when in paranoid mode and without a valid e-mail' do
swap Devise, paranoid: true do
store_translations :en, devise: { failure: { not_found_in_database: 'Not found in database' } } do
sign_in_as_user do
fill_in 'email', with: 'wrongemail@test.com'
end
assert_not_contain 'Not found in database'
assert_contain 'Invalid Email or password.'
end
end
end
test 'error message is configurable by resource name' do
store_translations :en, devise: { failure: { admin: { invalid: "Invalid credentials" } } } do
sign_in_as_admin do

View File

@@ -3,6 +3,12 @@
require 'test_helper'
class HttpAuthenticationTest < Devise::IntegrationTest
test 'sign in with HTTP should not run model validations' do
sign_in_as_new_user_with_http
refute User.validations_performed
end
test 'handles unverified requests gets rid of caches but continues signed in' do
swap ApplicationController, allow_forgery_protection: true do
create_user

View File

@@ -42,6 +42,17 @@ class OmniauthableIntegrationTest < Devise::IntegrationTest
end
end
test "omniauth sign in should not run model validations" do
stub_action!(:sign_in_facebook) do
create_user
visit "/users/sign_in"
click_link "Sign in with FaceBook"
assert warden.authenticated?(:user)
refute User.validations_performed
end
end
test "can access omniauth.auth in the env hash" do
visit "/users/sign_in"
click_link "Sign in with FaceBook"

View File

@@ -12,7 +12,7 @@ class RememberMeTest < Devise::IntegrationTest
end
def generate_signed_cookie(raw_cookie)
request = if Devise::Test.rails51?
request = if Devise::Test.rails51? || Devise::Test.rails52?
ActionController::TestRequest.create(Class.new) # needs a "controller class"
elsif Devise::Test.rails5?
ActionController::TestRequest.create

View File

@@ -3,6 +3,11 @@
require 'test_helper'
class TrackableHooksTest < Devise::IntegrationTest
test "trackable should not run model validations" do
sign_in_as_user
refute User.validations_performed
end
test "current and last sign in timestamps are updated on each sign in" do
user = create_user

View File

@@ -19,7 +19,7 @@ class EmailChangedTest < ActionMailer::TestCase
def user
@user ||= create_user.tap { |u|
@original_user_email = u.email
u.update_attributes!(email: 'new-email@example.com')
u.update!(email: 'new-email@example.com')
}
end
@@ -108,7 +108,7 @@ class EmailChangedReconfirmationTest < ActionMailer::TestCase
def admin
@admin ||= create_admin.tap { |u|
@original_admin_email = u.email
u.update_attributes!(email: 'new-email@example.com')
u.update!(email: 'new-email@example.com')
}
end

View File

@@ -8,6 +8,17 @@ class ConfirmableTest < ActiveSupport::TestCase
setup_mailer
end
test 'should set callbacks to send the mail' do
if DEVISE_ORM == :active_record
defined_callbacks = User._commit_callbacks.map(&:filter)
assert_includes defined_callbacks, :send_on_create_confirmation_instructions
assert_includes defined_callbacks, :send_reconfirmation_instructions
elsif DEVISE_ORM == :mongoid
assert_includes User._create_callbacks.map(&:filter), :send_on_create_confirmation_instructions
assert_includes User._update_callbacks.map(&:filter), :send_reconfirmation_instructions
end
end
test 'should generate confirmation token after creating a record' do
assert_nil new_user.confirmation_token
assert_not_nil create_user.confirmation_token
@@ -361,7 +372,7 @@ class ReconfirmableTest < ActiveSupport::TestCase
admin = create_admin
assert admin.confirm
residual_token = admin.confirmation_token
assert admin.update_attributes(email: 'new_test@example.com')
assert admin.update(email: 'new_test@example.com')
assert_not_equal residual_token, admin.confirmation_token
end
@@ -370,7 +381,7 @@ class ReconfirmableTest < ActiveSupport::TestCase
original_token = admin.confirmation_token
assert admin.confirm
admin.skip_reconfirmation!
assert admin.update_attributes(email: 'new_test@example.com')
assert admin.update(email: 'new_test@example.com')
assert admin.confirmed?
refute admin.pending_reconfirmation?
assert_equal original_token, admin.confirmation_token
@@ -381,16 +392,16 @@ class ReconfirmableTest < ActiveSupport::TestCase
admin.skip_confirmation_notification!
assert_email_not_sent do
admin.update_attributes(email: 'new_test@example.com')
admin.update(email: 'new_test@example.com')
end
end
test 'should regenerate confirmation token after changing email' do
admin = create_admin
assert admin.confirm
assert admin.update_attributes(email: 'old_test@example.com')
assert admin.update(email: 'old_test@example.com')
token = admin.confirmation_token
assert admin.update_attributes(email: 'new_test@example.com')
assert admin.update(email: 'new_test@example.com')
assert_not_equal token, admin.confirmation_token
end
@@ -398,7 +409,7 @@ class ReconfirmableTest < ActiveSupport::TestCase
admin = create_admin
assert admin.confirm
assert_email_sent "new_test@example.com" do
assert admin.update_attributes(email: 'new_test@example.com')
assert admin.update(email: 'new_test@example.com')
end
assert_match "new_test@example.com", ActionMailer::Base.deliveries.last.body.encoded
end
@@ -406,7 +417,7 @@ class ReconfirmableTest < ActiveSupport::TestCase
test 'should send confirmation instructions by email after changing email from nil' do
admin = create_admin(email: nil)
assert_email_sent "new_test@example.com" do
assert admin.update_attributes(email: 'new_test@example.com')
assert admin.update(email: 'new_test@example.com')
end
assert_match "new_test@example.com", ActionMailer::Base.deliveries.last.body.encoded
end
@@ -415,7 +426,7 @@ class ReconfirmableTest < ActiveSupport::TestCase
admin = create_admin
assert admin.confirm
assert_email_not_sent do
assert admin.update_attributes(password: 'newpass', password_confirmation: 'newpass')
assert admin.update(password: 'newpass', password_confirmation: 'newpass')
end
end
@@ -431,14 +442,14 @@ class ReconfirmableTest < ActiveSupport::TestCase
test 'should stay confirmed when email is changed' do
admin = create_admin
assert admin.confirm
assert admin.update_attributes(email: 'new_test@example.com')
assert admin.update(email: 'new_test@example.com')
assert admin.confirmed?
end
test 'should update email only when it is confirmed' do
admin = create_admin
assert admin.confirm
assert admin.update_attributes(email: 'new_test@example.com')
assert admin.update(email: 'new_test@example.com')
assert_not_equal 'new_test@example.com', admin.email
assert admin.confirm
assert_equal 'new_test@example.com', admin.email
@@ -447,16 +458,16 @@ class ReconfirmableTest < ActiveSupport::TestCase
test 'should not allow admin to get past confirmation email by resubmitting their new address' do
admin = create_admin
assert admin.confirm
assert admin.update_attributes(email: 'new_test@example.com')
assert admin.update(email: 'new_test@example.com')
assert_not_equal 'new_test@example.com', admin.email
assert admin.update_attributes(email: 'new_test@example.com')
assert admin.update(email: 'new_test@example.com')
assert_not_equal 'new_test@example.com', admin.email
end
test 'should find a admin by send confirmation instructions with unconfirmed_email' do
admin = create_admin
assert admin.confirm
assert admin.update_attributes(email: 'new_test@example.com')
assert admin.update(email: 'new_test@example.com')
confirmation_admin = Admin.send_confirmation_instructions(email: admin.unconfirmed_email)
assert_equal confirmation_admin, admin
end
@@ -525,7 +536,7 @@ class ReconfirmableTest < ActiveSupport::TestCase
original_email = admin.email
assert_difference 'ActionMailer::Base.deliveries.size', 2 do
assert admin.update_attributes(email: 'new-email@example.com')
assert admin.update(email: 'new-email@example.com')
end
assert_equal original_email, ActionMailer::Base.deliveries[-2]['to'].to_s
assert_equal 'new-email@example.com', ActionMailer::Base.deliveries[-1]['to'].to_s

View File

@@ -88,6 +88,13 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
assert_equal( {'strip_whitespace' => 'strip_whitespace_val', 'do_not_strip_whitespace' => ' do_not_strip_whitespace_val '}, conditions )
end
test 'param filter should not add keys to filtered hash' do
conditions = { 'present' => 'present_val' }
conditions.default = ''
conditions = Devise::ParameterFilter.new(['not_present'], []).filter(conditions)
assert_equal({ 'present' => 'present_val' }, conditions)
end
test 'should respond to password and password confirmation' do
user = new_user
assert user.respond_to?(:password)
@@ -234,7 +241,7 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
test 'should not email on password change' do
user = create_user
assert_email_not_sent do
assert user.update_attributes(password: 'newpass', password_confirmation: 'newpass')
assert user.update(password: 'newpass', password_confirmation: 'newpass')
end
end
@@ -243,7 +250,7 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
user = create_user
original_email = user.email
assert_email_sent original_email do
assert user.update_attributes(email: 'new-email@example.com')
assert user.update(email: 'new-email@example.com')
end
assert_match original_email, ActionMailer::Base.deliveries.last.body.encoded
end
@@ -253,7 +260,7 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
swap Devise, send_password_change_notification: true do
user = create_user
assert_email_sent user.email do
assert user.update_attributes(password: 'newpass', password_confirmation: 'newpass')
assert user.update(password: 'newpass', password_confirmation: 'newpass')
end
assert_match user.email, ActionMailer::Base.deliveries.last.body.encoded
end

View File

@@ -41,7 +41,7 @@ class TrackableTest < ActiveSupport::TestCase
assert_equal 0, user.sign_in_count
end
test 'update_tracked_fields should run model validations' do
test "update_tracked_fields! should not persist invalid records" do
user = UserWithValidations.new
request = mock
request.stubs(:remote_ip).returns("127.0.0.1")
@@ -49,4 +49,32 @@ class TrackableTest < ActiveSupport::TestCase
assert_not user.update_tracked_fields!(request)
assert_not user.persisted?
end
test "update_tracked_fields! should not run model validations" do
user = User.new
request = mock
request.stubs(:remote_ip).returns("127.0.0.1")
user.expects(:after_validation_callback).never
assert_not user.update_tracked_fields!(request)
end
test 'extract_ip_from should be overridable' do
class UserWithOverride < User
protected
def extract_ip_from(request)
"127.0.0.2"
end
end
request = mock
request.stubs(:remote_ip).returns("127.0.0.1")
user = UserWithOverride.new
user.update_tracked_fields(request)
assert_equal "127.0.0.2", user.current_sign_in_ip
assert_equal "127.0.0.2", user.last_sign_in_ip
end
end

View File

@@ -4,7 +4,12 @@ ActiveRecord::Migration.verbose = false
ActiveRecord::Base.logger = Logger.new(nil)
ActiveRecord::Base.include_root_in_json = true
ActiveRecord::Migrator.migrate(File.expand_path("../../rails_app/db/migrate/", __FILE__))
migrate_path = File.expand_path("../../rails_app/db/migrate/", __FILE__)
if Devise::Test.rails52?
ActiveRecord::MigrationContext.new(migrate_path).migrate
else
ActiveRecord::Migrator.migrate(migrate_path)
end
class ActiveSupport::TestCase
if Devise::Test.rails5?

View File

@@ -16,6 +16,34 @@ class ParameterSanitizerTest < ActiveSupport::TestCase
assert_equal({ 'email' => 'jose' }, sanitized)
end
test 'permits empty params when received not a hash' do
sanitizer = sanitizer({ 'user' => 'string' })
sanitized = sanitizer.sanitize(:sign_in)
assert_equal({}, sanitized)
end
test 'does not rise error when received string instead of hash' do
sanitizer = sanitizer('user' => 'string')
assert_nothing_raised do
sanitizer.sanitize(:sign_in)
end
end
test 'does not rise error when received nil instead of hash' do
sanitizer = sanitizer('user' => nil)
assert_nothing_raised do
sanitizer.sanitize(:sign_in)
end
end
test 'permits empty params when received nil instead of hash' do
sanitizer = sanitizer({ 'user' => nil })
sanitized = sanitizer.sanitize(:sign_in)
assert_equal({}, sanitized)
end
test 'permits the default parameters for sign up' do
sanitizer = sanitizer('user' => { 'email' => 'jose', 'role' => 'invalid' })
sanitized = sanitizer.sanitize(:sign_up)

View File

@@ -8,4 +8,13 @@ class User < ActiveRecord::Base
include ActiveModel::Serializers::Xml if Devise::Test.rails5?
validates :sign_in_count, presence: true
cattr_accessor :validations_performed
after_validation :after_validation_callback
def after_validation_callback
# used to check in our test if the validations were called
@@validations_performed = true
end
end

View File

@@ -38,4 +38,13 @@ class User
field :failed_attempts, type: Integer, default: 0 # Only if lock strategy is :failed_attempts
field :unlock_token, type: String # Only if unlock strategy is :email or :both
field :locked_at, type: Time
cattr_accessor :validations_performed
after_validation :after_validation_callback
def after_validation_callback
# used to check in our test if the validations were called
@@validations_performed = true
end
end

View File

@@ -33,8 +33,10 @@ module RailsApp
# config.assets.enabled = false
config.action_mailer.default_url_options = { host: "localhost", port: 3000 }
if DEVISE_ORM == :active_record && (Rails::VERSION::MAJOR >= 4 && Rails::VERSION::MINOR >= 2)
rails_version = Gem::Version.new(Rails.version)
if DEVISE_ORM == :active_record &&
rails_version >= Gem::Version.new('4.2.0') &&
rails_version < Gem::Version.new('5.1.0')
config.active_record.raise_in_transactional_callbacks = true
end

View File

@@ -6,7 +6,12 @@ end
module Devise
module Test
# Detection for minor differences between Rails 4 and 5, and 5.1 in tests.
# Detection for minor differences between Rails 4 and 5, 5.1, and 5.2 in tests.
def self.rails52?
Rails.version.start_with? '5.2'
end
def self.rails51?
Rails.version.start_with? '5.1'
end

View File

@@ -179,4 +179,9 @@ Devise.setup do |config|
# manager.failure_app = AnotherApp
# manager.default_strategies(scope: :user).unshift :some_external_strategy
# end
ActiveSupport.on_load(:devise_failure_app) do
require "lazy_load_test_module"
include LazyLoadTestModule
end
end

View File

@@ -0,0 +1,5 @@
module LazyLoadTestModule
def lazy_loading_works?
"yes it does"
end
end

View File

@@ -0,0 +1,121 @@
# frozen_string_literal: true
require 'test_helper'
class Rails52Credentials
def credentials
OpenStruct.new(secret_key_base: 'credentials')
end
end
class Rails52Secrets
def credentials
OpenStruct.new(secret_key_base: nil)
end
def secrets
OpenStruct.new(secret_key_base: 'secrets')
end
end
class Rails52Config
def credentials
OpenStruct.new(secret_key_base: nil)
end
def secrets
OpenStruct.new(secret_key_base: nil)
end
def config
OpenStruct.new(secret_key_base: 'config')
end
end
class Rails52SecretKeyBase
def credentials
OpenStruct.new(secret_key_base: nil)
end
def secrets
OpenStruct.new(secret_key_base: nil)
end
def config
OpenStruct.new(secret_key_base: nil)
end
def secret_key_base
'secret_key_base'
end
end
class Rails41Secrets
def secrets
OpenStruct.new(secret_key_base: 'secrets')
end
def config
OpenStruct.new(secret_key_base: nil)
end
end
class Rails41Config
def secrets
OpenStruct.new(secret_key_base: nil)
end
def config
OpenStruct.new(secret_key_base: 'config')
end
end
class Rails40Config
def config
OpenStruct.new(secret_key_base: 'config')
end
end
class SecretKeyFinderTest < ActiveSupport::TestCase
test "rails 5.2 uses credentials when they're available" do
secret_key_finder = Devise::SecretKeyFinder.new(Rails52Credentials.new)
assert_equal 'credentials', secret_key_finder.find
end
test "rails 5.2 uses secrets when credentials are empty" do
secret_key_finder = Devise::SecretKeyFinder.new(Rails52Secrets.new)
assert_equal 'secrets', secret_key_finder.find
end
test "rails 5.2 uses config when secrets are empty" do
secret_key_finder = Devise::SecretKeyFinder.new(Rails52Config.new)
assert_equal 'config', secret_key_finder.find
end
test "rails 5.2 uses secret_key_base when config is empty" do
secret_key_finder = Devise::SecretKeyFinder.new(Rails52SecretKeyBase.new)
assert_equal 'secret_key_base', secret_key_finder.find
end
test "rails 4.1 uses secrets" do
secret_key_finder = Devise::SecretKeyFinder.new(Rails41Secrets.new)
assert_equal 'secrets', secret_key_finder.find
end
test "rails 4.1 uses config when secrets are empty" do
secret_key_finder = Devise::SecretKeyFinder.new(Rails41Config.new)
assert_equal 'config', secret_key_finder.find
end
test "rails 4.0 uses config" do
secret_key_finder = Devise::SecretKeyFinder.new(Rails40Config.new)
assert_equal 'config', secret_key_finder.find
end
end

View File

@@ -19,6 +19,7 @@ class ActionDispatch::IntegrationTest
user.update_attribute(:confirmation_sent_at, options[:confirmation_sent_at]) if options[:confirmation_sent_at]
user.confirm unless options[:confirm] == false
user.lock_access! if options[:locked] == true
User.validations_performed = false
user
end
end

View File

@@ -100,6 +100,11 @@ class TestControllerHelpersTest < Devise::ControllerTestCase
assert_equal response.body, "<html><body>You are being <a href=\"http://test.host/users/sign_in\">redirected</a>.</body></html>"
end
test "returns the content type of a failure app" do
get :index, params: { format: :xml }
assert response.content_type.include?('application/xml')
end
test "defined Warden after_authentication callback should not be called when sign_in is called" do
begin
Warden::Manager.after_authentication do |user, auth, opts|
@@ -166,7 +171,7 @@ class TestControllerHelpersTest < Devise::ControllerTestCase
test "creates a new warden proxy if the request object has changed" do
old_warden_proxy = warden
@request = if Devise::Test.rails51?
@request = if Devise::Test.rails51? || Devise::Test.rails52?
ActionController::TestRequest.create(Class.new) # needs a "controller class"
elsif Devise::Test.rails5?
ActionController::TestRequest.create