Simplify DFC authorisation control

I want to add other ways to authenticate for easier testing and possibly
more integrations. It will be easier to just test if we got a user or
not instead of testing pre-conditions to that as well.
This commit is contained in:
Maikel Linke
2022-11-03 16:17:29 +11:00
committed by David Cook
parent 2630fde763
commit 96193a27a4
3 changed files with 6 additions and 13 deletions

View File

@@ -5,23 +5,14 @@ module DfcProvider
class BaseController < ActionController::Base
rescue_from ActiveRecord::RecordNotFound, with: :not_found
before_action :check_authorization,
:check_user
before_action :check_authorization
respond_to :json
private
def check_authorization
return if access_token.present?
head :unprocessable_entity
end
def check_user
return if current_user.present?
head :unauthorized
head :unauthorized if current_user.nil?
end
def check_enterprise

View File

@@ -9,6 +9,8 @@ module DfcProvider
end
def process
return unless @access_token
decode_token
find_ofn_user
end

View File

@@ -93,9 +93,9 @@ describe DfcProvider::CatalogItemsController, type: :controller do
end
context 'without an authorization token' do
it 'returns unprocessable_entity head' do
it 'returns unauthorized head' do
api_get :index, enterprise_id: enterprise.id
expect(response).to be_unprocessable
expect(response).to be_unauthorized
end
end
end