FIX: Check if auth token exists before revocation (#9095)
This commit is contained in:
parent
f14dd1f82d
commit
20cfa7b810
|
@ -1347,7 +1347,7 @@ class UsersController < ApplicationController
|
|||
if params[:token_id]
|
||||
token = UserAuthToken.find_by(id: params[:token_id], user_id: user.id)
|
||||
# The user should not be able to revoke the auth token of current session.
|
||||
raise Discourse::InvalidParameters.new(:token_id) if guardian.auth_token == token.auth_token
|
||||
raise Discourse::InvalidParameters.new(:token_id) if !token || guardian.auth_token == token.auth_token
|
||||
UserAuthToken.where(id: params[:token_id], user_id: user.id).each(&:destroy!)
|
||||
|
||||
MessageBus.publish "/file-change", ["refresh"], user_ids: [user.id]
|
||||
|
|
|
@ -3935,6 +3935,20 @@ describe UsersController do
|
|||
expect(user.user_auth_tokens.first.id).to eq(ids[1])
|
||||
end
|
||||
|
||||
it 'checks if token exists' do
|
||||
ids = user.user_auth_tokens.order(:created_at).pluck(:id)
|
||||
|
||||
post "/u/#{user.username}/preferences/revoke-auth-token.json",
|
||||
params: { token_id: ids[0] }
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
post "/u/#{user.username}/preferences/revoke-auth-token.json",
|
||||
params: { token_id: ids[0] }
|
||||
|
||||
expect(response.status).to eq(400)
|
||||
end
|
||||
|
||||
it 'does not let user log out of current session' do
|
||||
token = UserAuthToken.generate!(user_id: user.id)
|
||||
env = Rack::MockRequest.env_for("/", "HTTP_COOKIE" => "_t=#{token.unhashed_auth_token};")
|
||||
|
|
Loading…
Reference in New Issue