Refactor validity of token authentication
This commit is contained in:

committed by
Sebastian Serth

parent
e77223e628
commit
b6837e9539
@ -40,7 +40,10 @@ class ApplicationController < ActionController::Base
|
|||||||
token = AuthenticationToken.find_by(shared_secret: params[:token])
|
token = AuthenticationToken.find_by(shared_secret: params[:token])
|
||||||
return unless token
|
return unless token
|
||||||
|
|
||||||
auto_login(token.user) if token.expire_at.future?
|
if token.expire_at.future?
|
||||||
|
token.update(expire_at: Time.zone.now)
|
||||||
|
auto_login(token.user)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_sentry_context
|
def set_sentry_context
|
||||||
|
@ -78,6 +78,25 @@ describe 'Authentication' do
|
|||||||
expect(page).to have_content(I18n.t('application.not_authorized'))
|
expect(page).to have_content(I18n.t('application.not_authorized'))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when the authentication token is used to login' do
|
||||||
|
let(:token) { create(:authentication_token, user: user) }
|
||||||
|
|
||||||
|
it 'invalidates the token on login' do
|
||||||
|
mail.deliver_now
|
||||||
|
visit(rfc_link)
|
||||||
|
expect(token.reload.expire_at).to be_within(10.seconds).of(Time.zone.now)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not allow a second login' do
|
||||||
|
mail.deliver_now
|
||||||
|
visit(rfc_link)
|
||||||
|
expect(page).to have_current_path(rfc_link)
|
||||||
|
visit(sign_out_path)
|
||||||
|
visit(rfc_link)
|
||||||
|
expect(page).to have_current_path(root_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user