Skip to content

Commit

Permalink
Merge pull request #290 from cul/ACHYDRA-963-auth-header
Browse files Browse the repository at this point in the history
ACHYDRA-963 - AssetsController#content_datastream? should send auth header with head request check
  • Loading branch information
elohanlon authored Nov 21, 2024
2 parents 4a2ddf0 + b33f12d commit 514ec11
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion app/controllers/assets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion spec/controllers/assets_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@
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 } }

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
Expand Down

0 comments on commit 514ec11

Please sign in to comment.