mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 17:59:47 +02:00
Return error when API user not found in REPP #2774
This commit is contained in:
parent
1b9bc92660
commit
f2992b7f45
3 changed files with 15 additions and 0 deletions
|
@ -5,6 +5,11 @@ module Repp
|
|||
|
||||
http_basic do |username, password|
|
||||
@current_user ||= ApiUser.find_by(username: username, password: password)
|
||||
if @current_user
|
||||
true
|
||||
else
|
||||
error! I18n.t('api_user_not_found'), 401
|
||||
end
|
||||
end
|
||||
|
||||
before do
|
||||
|
|
|
@ -871,3 +871,4 @@ en:
|
|||
parameter_value_range_error: 'Parameter value range error: %{key}'
|
||||
payment_received: 'Payment received'
|
||||
domain_registrant_updated: 'Domeeni %{name} registreerija vahetus teostatud / Registrant change of %{name} has been finished.'
|
||||
api_user_not_found: 'API user not found'
|
||||
|
|
|
@ -77,5 +77,14 @@ describe Repp::DomainV1 do
|
|||
|
||||
# TODO: Log failed API requests too
|
||||
end
|
||||
|
||||
it 'returns an error with invalid credentials' do
|
||||
invalid_user = OpenStruct.new(username: 'bla', password: 'blabala')
|
||||
get_with_auth '/repp/v1/domains', {}, invalid_user
|
||||
response.status.should == 401
|
||||
|
||||
body = JSON.parse(response.body)
|
||||
body['error'].should == 'API user not found'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue