Commit d1281c73 authored by Etienne Baqué's avatar Etienne Baqué

Removed key param in validate_actor

parent e8906a60
---
title: Remove key parameter check when validating actor in personal access token API
merge_request: 57675
author:
type: fixed
...@@ -31,7 +31,7 @@ module EE ...@@ -31,7 +31,7 @@ module EE
actor.update_last_used_at! actor.update_last_used_at!
user = actor.user user = actor.user
error_message = validate_actor_key(actor, params[:key_id]) error_message = validate_actor(actor)
return { success: false, message: error_message } if error_message return { success: false, message: error_message } if error_message
......
...@@ -109,9 +109,7 @@ module API ...@@ -109,9 +109,7 @@ module API
end end
end end
def validate_actor_key(actor, key_id) def validate_actor(actor)
return 'Could not find a user without a key' unless key_id
return 'Could not find the given key' unless actor.key return 'Could not find the given key' unless actor.key
'Could not find a user for the given key' unless actor.user 'Could not find a user for the given key' unless actor.user
...@@ -201,7 +199,7 @@ module API ...@@ -201,7 +199,7 @@ module API
actor.update_last_used_at! actor.update_last_used_at!
user = actor.user user = actor.user
error_message = validate_actor_key(actor, params[:key_id]) error_message = validate_actor(actor)
if params[:user_id] && user.nil? if params[:user_id] && user.nil?
break { success: false, message: 'Could not find the given user' } break { success: false, message: 'Could not find the given user' }
...@@ -230,7 +228,7 @@ module API ...@@ -230,7 +228,7 @@ module API
actor.update_last_used_at! actor.update_last_used_at!
user = actor.user user = actor.user
error_message = validate_actor_key(actor, params[:key_id]) error_message = validate_actor(actor)
break { success: false, message: 'Deploy keys cannot be used to create personal access tokens' } if actor.key.is_a?(DeployKey) break { success: false, message: 'Deploy keys cannot be used to create personal access tokens' } if actor.key.is_a?(DeployKey)
...@@ -303,7 +301,7 @@ module API ...@@ -303,7 +301,7 @@ module API
actor.update_last_used_at! actor.update_last_used_at!
user = actor.user user = actor.user
error_message = validate_actor_key(actor, params[:key_id]) error_message = validate_actor(actor)
if error_message if error_message
{ success: false, message: error_message } { success: false, message: error_message }
......
# frozen_string_literal: true # frozen_string_literal: true
RSpec.shared_examples 'actor key validations' do RSpec.shared_examples 'actor key validations' do
context 'key id is not provided' do
let(:key_id) { nil }
it 'returns an error message' do
subject
expect(json_response['success']).to be_falsey
expect(json_response['message']).to eq('Could not find a user without a key')
end
end
context 'key does not exist' do context 'key does not exist' do
let(:key_id) { non_existing_record_id } let(:key_id) { non_existing_record_id }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment