Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module Authentication
end

def remember(active_session)
cookies.permanent.encrypted[:remember_token] = active_session.remember_token
cookies.permanent.encrypted[:remember_token] = { value: active_session.remember_token, httponly: true, same_site: :strict, secure: true }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you feel about updating the generated test to account for this? 🤔

test "should remember user when logging in" do
assert_nil cookies[:remember_token]
post login_path, params: {
user: {
email: @confirmed_user.email,
password: @confirmed_user.password,
remember_me: 1
}
}
assert_not_nil current_user
assert_not_nil cookies[:remember_token]
end

Maybe something like the following?

remember_me_cookie = cookies.get_cookie("remember_token")

assert remember_me_cookie.http_only?
assert remember_me_cookie.secure?
assert_equal "Strict", remember_me_cookie.to_h["SameSite"]

end

private
Expand All @@ -44,7 +44,7 @@ module Authentication
Current.user = if session[:current_active_session_id].present?
ActiveSession.find_by(id: session[:current_active_session_id])&.user
elsif cookies.permanent.encrypted[:remember_token].present?
ActiveSession.find_by(remember_token: cookies.permanent.encrypted[:remember_token])&.user
ActiveSession.find_by(remember_token: cookies.permanent.encrypted[:remember_token].value)&.user
end
end

Expand All @@ -55,4 +55,4 @@ module Authentication
def store_location
session[:user_return_to] = request.original_url if request.get? && request.local?
end
end
end