From ad8dfcc28f07e9b13228577cf8abdcfb3af77d41 Mon Sep 17 00:00:00 2001 From: Maciej Szlosarczyk Date: Tue, 7 Aug 2018 14:52:33 +0300 Subject: [PATCH] Make authentication errors more consistent with other errors --- app/controllers/api/v1/registrant/auth_controller.rb | 4 ++-- app/controllers/api/v1/registrant/base_controller.rb | 2 +- .../api/registrant/registrant_api_authentication_test.rb | 2 +- .../integration/api/registrant/registrant_api_domains_test.rb | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/v1/registrant/auth_controller.rb b/app/controllers/api/v1/registrant/auth_controller.rb index 5be48f558..929d5b5c9 100644 --- a/app/controllers/api/v1/registrant/auth_controller.rb +++ b/app/controllers/api/v1/registrant/auth_controller.rb @@ -21,7 +21,7 @@ module Api if token render json: token else - render json: { error: 'Cannot create generate session token' } + render json: { errors: [{ base: ['Cannot create generate session token'] }] } end end @@ -46,7 +46,7 @@ module Api allowed_ips = ENV['registrant_api_auth_allowed_ips'].to_s.split(',').map(&:strip) return if allowed_ips.include?(request.ip) || Rails.env.development? - render json: { errors: ['Not authorized'] }, status: :unauthorized + render json: { errors: [{ base: ['Not authorized'] }] }, status: :unauthorized end end end diff --git a/app/controllers/api/v1/registrant/base_controller.rb b/app/controllers/api/v1/registrant/base_controller.rb index bc5fa21d7..4df0d226c 100644 --- a/app/controllers/api/v1/registrant/base_controller.rb +++ b/app/controllers/api/v1/registrant/base_controller.rb @@ -29,7 +29,7 @@ module Api if decryptor.valid? sign_in decryptor.user else - render json: { errors: ['Not authorized'] }, status: :unauthorized + render json: { errors: [{base: ['Not authorized']}] }, status: :unauthorized end end end diff --git a/test/integration/api/registrant/registrant_api_authentication_test.rb b/test/integration/api/registrant/registrant_api_authentication_test.rb index 14ef1c879..97651b029 100644 --- a/test/integration/api/registrant/registrant_api_authentication_test.rb +++ b/test/integration/api/registrant/registrant_api_authentication_test.rb @@ -42,7 +42,7 @@ class RegistrantApiAuthenticationTest < ActionDispatch::IntegrationTest assert_equal(401, response.status) json_body = JSON.parse(response.body, symbolize_names: true) - assert_equal({ errors: ['Not authorized'] }, json_body) + assert_equal({ errors: [base: ['Not authorized']] }, json_body) ENV['registrant_api_auth_allowed_ips'] = @original_whitelist_ip end diff --git a/test/integration/api/registrant/registrant_api_domains_test.rb b/test/integration/api/registrant/registrant_api_domains_test.rb index 2d0b83903..0f2be7db5 100644 --- a/test/integration/api/registrant/registrant_api_domains_test.rb +++ b/test/integration/api/registrant/registrant_api_domains_test.rb @@ -19,7 +19,7 @@ class RegistrantApiDomainsTest < ActionDispatch::IntegrationTest assert_equal(401, response.status) json_body = JSON.parse(response.body, symbolize_names: true) - assert_equal({ errors: ['Not authorized'] }, json_body) + assert_equal({ errors: [base: ['Not authorized']] }, json_body) end private