mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-10-27 16:06:48 +09:00
Sign the browser out when its new session is refused after a password change
If the password changes again between this browser's change and its new session, that session is refused, and the browser is sent to sign in instead of an error.
(cherry picked from commit a476cbfa24)
This commit is contained in:
1 parent
09402c7752
commit
9ca680de02
2 files changed
+13
No files matched your search
@@ -18,6 +18,9 @@ class Users::ProfilesController < ApplicationController
|
||||
else
|
||||
redirect_to user_profile_url, alert: update_alert
|
||||
end
|
||||
rescue ActiveRecord::RecordInvalid
|
||||
# The password changed again before this browser's new session could start, and that change signed it out.
|
||||
redirect_to new_session_url
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -43,6 +43,16 @@ class Users::ProfilesControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_equal 1, users(:david).sessions.count
|
||||
end
|
||||
|
||||
test "changing the password signs this browser out when it changes again before its new session starts" do
|
||||
User.stubs(:uncached).returns(BCrypt::Password.create("someone else's secret", cost: BCrypt::Engine::MIN_COST))
|
||||
|
||||
assert_changes -> { users(:david).sessions.count }, to: 0 do
|
||||
put user_profile_url, params: { user: { password: "a new secret123456", password_challenge: "secret123456" } }
|
||||
end
|
||||
|
||||
assert_redirected_to new_session_url
|
||||
end
|
||||
|
||||
test "changing the password gives this browser a new session, so a copy of its cookie stops working" do
|
||||
copied_cookie = cookies[:session_token]
|
||||
|
||||
|
||||
Reference in new issue
Block a user