From b33f12da4c2ecb81a7bc2d0667a46ba683f4d75b Mon Sep 17 00:00:00 2001 From: Eric O Date: Thu, 21 Nov 2024 16:09:39 -0500 Subject: [PATCH] ACHYDRA-963 - AssetsController#content_datastream? should send auth header with head request check --- app/controllers/assets_controller.rb | 5 ++++- spec/controllers/assets_controller_spec.rb | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/controllers/assets_controller.rb b/app/controllers/assets_controller.rb index c3881dddf..b62e11376 100644 --- a/app/controllers/assets_controller.rb +++ b/app/controllers/assets_controller.rb @@ -67,7 +67,10 @@ def restricted? def content_datastream? # TODO: can be refactored after a general reindex of assets to use datastreams_ssim - HTTP.head(ds_content_url('content')).code == 200 + + HTTP.basic_auth( + user: ActiveFedora.config.credentials[:user], pass: ActiveFedora.config.credentials[:password] + ).head(ds_content_url('content')).code == 200 end def ds_content_url(dsid) diff --git a/spec/controllers/assets_controller_spec.rb b/spec/controllers/assets_controller_spec.rb index dd52cf544..e7fa72d51 100644 --- a/spec/controllers/assets_controller_spec.rb +++ b/spec/controllers/assets_controller_spec.rb @@ -27,6 +27,7 @@ let(:parent_doc) { SolrDocument.new(object_state_ssi: 'A') } let(:mock_resource) { double(docs: [resource_doc]) } let(:mock_parent) { double(docs: [parent_doc]) } + let(:mock_http_client_with_basic_auth) { double(HTTP::Client) } let(:mock_head_response) { double('headers', code: 200) } let(:resource_params) { { qt: 'search', fq: ['id:"10.7616/TESTTEST"', 'has_model_ssim:("info:fedora/ldpd:GenericResource" OR "info:fedora/ldpd:Resource")'], rows: 1 } } let(:parent_params) { { qt: 'search', fq: ['fedora3_pid_ssi:(parent\:id)'], rows: 100_000 } } @@ -34,7 +35,8 @@ before do allow(Blacklight.default_index).to receive(:search).with(resource_params).and_return(mock_resource) allow(Blacklight.default_index).to receive(:search).with(parent_params).and_return(mock_parent) - allow(HTTP).to receive(:head).and_return(mock_head_response) + allow(HTTP).to receive(:basic_auth).and_return(mock_http_client_with_basic_auth) + allow(mock_http_client_with_basic_auth).to receive(:head).and_return(mock_head_response) get :download, params: { id: '10.7616/TESTTEST' } end