Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
password_expirable helper bugfix (#201)
Fixes #186 Co-authored-by: Troy Rosenberg <tmr08c@gmail.com>
- Loading branch information
Showing
7 changed files
with
85 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
class TestPasswordExpirableWorkflow < ActionDispatch::IntegrationTest | ||
include IntegrationHelpers | ||
|
||
setup do | ||
@user = User.create!(password: 'passWord1', | ||
password_confirmation: 'passWord1', | ||
email: 'bob@microsoft.com', | ||
password_changed_at: 4.months.ago) # the default expiration time is 3.months.ago | ||
@user.confirm | ||
|
||
assert @user.valid? | ||
assert @user.need_change_password? | ||
end | ||
|
||
test 'sign in and change expired password' do | ||
skip("Does not work in Rails < 5.0") if Rails.gem_version < Gem::Version.new('5.0') | ||
|
||
sign_in(@user) | ||
assert_redirected_to(root_path) | ||
follow_redirect! | ||
assert_redirected_to(user_password_expired_path) | ||
# @note This is not the same controller used by Devise for password changes | ||
put '/users/password_expired', params: { | ||
user: { | ||
current_password: 'passWord1', | ||
password: 'Password12345!', | ||
password_confirmation: 'Password12345!', | ||
}, | ||
} | ||
assert_redirected_to(root_path) | ||
@user.reload | ||
assert_not @user.need_change_password? | ||
end | ||
|
||
test 'sign in and password is updated before redirect completes' do | ||
skip("Does not work in Rails < 5.0") if Rails.gem_version < Gem::Version.new('5.0') | ||
|
||
sign_in(@user) | ||
assert_redirected_to(root_path) | ||
|
||
# simulates an external process updating the password | ||
@user.update(password_changed_at: Time.zone.now) | ||
assert_not @user.need_change_password? | ||
|
||
follow_redirect! | ||
assert_response :success | ||
|
||
# if the password is expired at this point they will be redirected to the | ||
# password change controller. | ||
get root_path | ||
assert_response :success | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters