mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-10-28 08:26:48 +09:00
A password change ends every session, but a sign-in or sign-in link checked against the old password just before the change could still save its session just after, and that session outlived the change. The session now checks, as it's saved, that the user's password is still the one the request loaded. The save's transaction holds SQLite's write lock from the start, so a change commits either before the check, which fails it, or after the insert, and ends this session with the others. Sessions start through the user's association so the check sees the user that was authenticated, and a refused sign-in is answered like a wrong password.
21 lines
654 B
Ruby
21 lines
654 B
Ruby
require "test_helper"
|
|
|
|
class SessionTest < ActiveSupport::TestCase
|
|
test "start a session" do
|
|
assert_difference -> { users(:david).sessions.count }, +1 do
|
|
users(:david).sessions.create!(user_agent: "This device", ip_address: "127.0.0.1")
|
|
end
|
|
end
|
|
|
|
test "a session doesn't start on a password checked before it changed" do
|
|
user = User.find(users(:david).id)
|
|
User.find(user.id).update!(password: "a new secret123456")
|
|
|
|
assert_no_difference -> { Session.count } do
|
|
assert_raises(ActiveRecord::RecordInvalid) do
|
|
user.sessions.create!(user_agent: "This device", ip_address: "127.0.0.1")
|
|
end
|
|
end
|
|
end
|
|
end
|