File tree Expand file tree Collapse file tree 15 files changed +27
-553
lines changed
lib/devise/secure_password Expand file tree Collapse file tree 15 files changed +27
-553
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,9 @@ Gemfile.lock
52
52
.ruby-version
53
53
.ruby-gemset
54
54
55
+ # Ignore gemfiles/*.gemfile.lock files
56
+ /gemfiles /* .gemfile.lock
57
+
55
58
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
56
59
.rvmrc
57
60
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -18,13 +18,18 @@ def redirected_in_session?
18
18
warden . authenticated? && warden . session [ 'secure_password_last_controller' ] == 'Devise::SessionsController'
19
19
end
20
20
21
+ # Prevent infinite loops and allow specified controllers to bypass.
22
+ # @NOTE: The ability to extend this list may be made public, in the
23
+ # future if that functionality is needed.
21
24
def skip_current_controller?
22
25
exclusion_list = [
23
26
'Devise::SessionsController' ,
24
27
'Devise::PasswordsWithPolicyController#edit' ,
25
- 'Devise::PasswordsWithPolicyController#update'
28
+ 'Devise::PasswordsWithPolicyController#update' ,
29
+ 'DeviseInvitable::RegistrationsController#edit' ,
30
+ 'DeviseInvitable::RegistrationsController#update'
26
31
]
27
- exclusion_list . select { | e | e == "#{ self . class . name } #" + action_name || e == self . class . name . to_s } . empty?
32
+ ! ( exclusion_list . include? ( "#{ self . class . name } #" + action_name ) || ( exclusion_list & self . class . ancestors . map ( & : to_s) ) . any? )
28
33
end
29
34
30
35
def error_string_for_password_expired
Original file line number Diff line number Diff line change @@ -10,9 +10,9 @@ class ::DeviseController
10
10
11
11
protected
12
12
13
- # Override the devise require_no_authentication before callback so users
14
- # have to prevent authenticated users with expired passwords from
15
- # escaping to other pages without first updating their passwords.
13
+ # Override the devise require_no_authentication before callback to
14
+ # prevent authenticated users with expired passwords from escaping to
15
+ # other pages without first updating their passwords.
16
16
def require_no_authentication
17
17
return if check_password_expired_and_redirect!
18
18
@@ -42,11 +42,14 @@ def save_controller_state
42
42
warden . session ( scope_name ) [ :secure_last_action ] = action_name
43
43
end
44
44
45
+ # Prevent infinite loops and allow specified controllers to bypass.
46
+ # @NOTE: The ability to extend this list may be made public, in the
47
+ # future if that functionality is needed.
45
48
def skip_current_devise_controller?
46
49
exclusion_list = [
47
50
'Devise::SessionsController'
48
51
]
49
- exclusion_list . select { | e | e == "#{ self . class . name } #" + action_name || e == self . class . name . to_s } . empty?
52
+ ! ( exclusion_list . include? ( "#{ self . class . name } #" + action_name ) || ( exclusion_list & self . class . ancestors . map ( & : to_s) ) . any? )
50
53
end
51
54
52
55
def error_string_for_password_expired
Original file line number Diff line number Diff line change @@ -9,11 +9,11 @@ class PreviousPassword < ::ActiveRecord::Base
9
9
validates :encrypted_password , presence : true
10
10
11
11
def fresh? ( minimum_age_duration , now = ::Time . zone . now )
12
- now <= ( created_at + minimum_age_duration )
12
+ now <= ( updated_at + minimum_age_duration )
13
13
end
14
14
15
15
def stale? ( maximum_age_duration , now = ::Time . zone . now )
16
- now > ( created_at + maximum_age_duration )
16
+ now > ( updated_at + maximum_age_duration )
17
17
end
18
18
end
19
19
end
Original file line number Diff line number Diff line change 1
1
module Devise
2
2
module SecurePassword
3
- VERSION = '1.0.3 ' . freeze
3
+ VERSION = '1.0.4 ' . freeze
4
4
end
5
5
end
Original file line number Diff line number Diff line change 45
45
before do
46
46
user . save
47
47
last_password = user . previous_passwords . unscoped . last
48
- last_password . created_at = Time . zone . now - 2 . days
48
+ last_password . created_at = last_password . updated_at = Time . zone . now - 2 . days
49
49
last_password . save
50
50
login_as ( user , scope : :user )
51
51
visit '/users/change_password/edit'
Original file line number Diff line number Diff line change 14
14
before do
15
15
user . save
16
16
last_password = user . previous_passwords . unscoped . last
17
- last_password . created_at = Time . zone . now - User . password_maximum_age
17
+ last_password . created_at = last_password . updated_at = Time . zone . now - User . password_maximum_age
18
18
last_password . save
19
19
visit '/users/sign_in'
20
20
end
Original file line number Diff line number Diff line change 62
62
user . save
63
63
# reset its previous_password record to one day before
64
64
last_password = user . previous_passwords . unscoped . last
65
- last_password . created_at = Time . zone . now - Isolated ::UserFrequentChanges . password_minimum_age
65
+ last_password . created_at = last_password . updated_at = Time . zone . now - Isolated ::UserFrequentChanges . password_minimum_age
66
66
last_password . save
67
67
# bypass frequent_reuse validator by changing password
68
68
user . password = user . password_confirmation = user . password + 'Z'
89
89
user . save
90
90
# reset its previous_password record one day past minimum
91
91
last_password = user . previous_passwords . unscoped . last
92
- last_password . created_at = Time . zone . now - Isolated ::UserFrequentChanges . password_minimum_age
92
+ last_password . created_at = last_password . updated_at = Time . zone . now - Isolated ::UserFrequentChanges . password_minimum_age
93
93
last_password . save
94
94
end
95
95
Original file line number Diff line number Diff line change 41
41
user . save
42
42
# reset its previous_password record to one day past maximum
43
43
last_password = user . previous_passwords . unscoped . last
44
- last_password . created_at = Time . zone . now - Isolated ::UserRegularUpdates . password_maximum_age
44
+ last_password . created_at = last_password . updated_at = Time . zone . now - Isolated ::UserRegularUpdates . password_maximum_age
45
45
last_password . save
46
46
end
47
47
Original file line number Diff line number Diff line change 71
71
72
72
context 'when a password is not recent' do
73
73
it 'returns false' do
74
- previous_password . created_at = Time . zone . now - 1 . day
74
+ previous_password . created_at = previous_password . updated_at = Time . zone . now - 1 . day
75
75
expect ( previous_password . fresh? ( 1 . day ) ) . to be false
76
76
end
77
77
end
92
92
93
93
context 'when a password is old' do
94
94
it 'returns true' do
95
- previous_password . created_at = Time . zone . now - 1 . day
95
+ previous_password . created_at = previous_password . updated_at = Time . zone . now - 1 . day
96
96
expect ( previous_password . stale? ( 1 . day ) ) . to be true
97
97
end
98
98
end
You can’t perform that action at this time.
0 commit comments