Prefer authentication token for session if present
This commit is contained in:
@ -22,10 +22,10 @@ class ApplicationController < ActionController::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def find_or_login_current_user
|
def find_or_login_current_user
|
||||||
ExternalUser.find_by(id: session[:external_user_id]) ||
|
login_from_authentication_token ||
|
||||||
|
ExternalUser.find_by(id: session[:external_user_id]) ||
|
||||||
login_from_session ||
|
login_from_session ||
|
||||||
login_from_other_sources ||
|
login_from_other_sources ||
|
||||||
login_from_authentication_token ||
|
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
private :find_or_login_current_user
|
private :find_or_login_current_user
|
||||||
|
@ -107,6 +107,23 @@ describe 'Authentication' do
|
|||||||
visit(root_path)
|
visit(root_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with an authentication token" do
|
||||||
|
let(:request_for_comment) { create(:rfc_with_comment, user: user) }
|
||||||
|
let(:study_group) { request_for_comment.submission.study_group }
|
||||||
|
let(:commenting_user) { InternalUser.create(attributes_for(:teacher)) }
|
||||||
|
let(:mail) { UserMailer.got_new_comment(request_for_comment.comments.first, request_for_comment, commenting_user) }
|
||||||
|
let(:rfc_link) { request_for_comment_url(request_for_comment, token: token.shared_secret) }
|
||||||
|
|
||||||
|
it 'still invalidates the token on login' do
|
||||||
|
token = create(:authentication_token, user: user, study_group: study_group)
|
||||||
|
mail = UserMailer.got_new_comment(request_for_comment.comments.first, request_for_comment, commenting_user)
|
||||||
|
mail.deliver_now
|
||||||
|
visit(request_for_comment_url(request_for_comment, token: token.shared_secret))
|
||||||
|
expect(token.reload.expire_at).to be_within(10.seconds).of(Time.zone.now)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
it "displays the user's displayname" do
|
it "displays the user's displayname" do
|
||||||
expect(page).to have_content(user.displayname)
|
expect(page).to have_content(user.displayname)
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user