Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return 404 when the iiif endpoint is called for a file on a collection #1153

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions app/models/stacks_rights.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ def cocina_file
end

def find_file
public_json.dig('structural', 'contains')
.lazy.flat_map { |file_set| file_set.dig('structural', 'contains') }
.find { |file| file['filename'] == file_name } || raise(ActionController::MissingFile, "File not found '#{file_name}'")
file_sets = public_json.dig('structural', 'contains')
raise(ActionController::MissingFile, "File not found '#{file_name}'") unless file_sets # Trap for Collections

file_sets.lazy.flat_map { |file_set| file_set.dig('structural', 'contains') }
.find { |file| file['filename'] == file_name } || raise(ActionController::MissingFile, "File not found '#{file_name}'")
end

def public_json
Expand Down
24 changes: 13 additions & 11 deletions spec/requests/iiif_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,17 +265,6 @@
end

describe 'image requests for world readable items' do
let(:ability) { instance_double(CocinaAbility, can?: false) }

before do
# for the cache headers
allow_any_instance_of(IiifController).to receive(:anonymous_ability).and_return ability
# for authorize! in #show
allow_any_instance_of(IiifController).to receive(:authorize!).with(:read, Projection).and_return(true)
# for current_image
allow_any_instance_of(IiifController).to receive(:can?).with(:download, StacksImage).and_return(true)
end

context 'when the request is valid' do
before do
stub_request(:get, "http://imageserver-prod.stanford.edu/iiif/2/#{image_server_path('nr349ct7889', 'image.jp2')}/0,640,2552,2552/100,100/0/default.jpg")
Expand Down Expand Up @@ -319,6 +308,19 @@
end
end

context 'when the object has no filesets (e.g. a collection)' do
let(:public_json) do
{ 'structural' => {} }
end

it 'returns 404 Not Found' do
stub_request(:get, "http://imageserver-prod.stanford.edu/iiif/2/nr%2F349%2Fct%2F7889%2Fimage.jp2/0,640,2552,2552/100,100/0/default.jpg")
.to_return(status: 200, body: "", headers: {})
get "/image/iiif/nr349ct7889%2Fimage.jp2/0,640,2552,2552/100,100/0/default.jpg"
expect(response).to have_http_status :not_found
end
end

context 'with the download flag set' do
before do
stub_request(:get, "http://imageserver-prod.stanford.edu/iiif/2/#{image_server_path('nr349ct7889', 'image.jp2')}/0,640,2552,2552/100,100/0/default.jpg")
Expand Down
Loading