BigW Consortium Gitlab

Commit 8b6154c1 by Drew Blessing

Minor edits to two_factor_recovery_codes API error catching

parent 0e3c7b2f
...@@ -105,15 +105,19 @@ module API ...@@ -105,15 +105,19 @@ module API
post '/two_factor_recovery_codes' do post '/two_factor_recovery_codes' do
status 200 status 200
key = Key.find(params[:key_id]) key = Key.find_by(id: params[:key_id])
user = key.user
unless key
return { 'success' => false, 'message' => 'Could not find the given key' }
end
# Make sure this isn't a deploy key if key.is_a?(DeployKey)
unless key.type.nil?
return { success: false, message: 'Deploy keys cannot be used to retrieve recovery codes' } return { success: false, message: 'Deploy keys cannot be used to retrieve recovery codes' }
end end
unless user.present? user = key.user
unless user
return { success: false, message: 'Could not find a user for the given key' } return { success: false, message: 'Could not find a user for the given key' }
end end
......
...@@ -44,8 +44,8 @@ describe API::API, api: true do ...@@ -44,8 +44,8 @@ describe API::API, api: true do
secret_token: secret_token, secret_token: secret_token,
key_id: 12345 key_id: 12345
expect(response).to have_http_status(404) expect(json_response['success']).to be_falsey
expect(json_response['message']).to eq('404 Not found') expect(json_response['message']).to eq('Could not find the given key')
end end
it 'returns an error message when the key is a deploy key' do it 'returns an error message when the key is a deploy key' do
......
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