diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 018db2c2..80e8a186 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -29,4 +29,6 @@ jobs: - name: Install dependencies run: bin/setup - name: Run tests - run: bundle exec rake + run: bin/rake + - name: Run tests (with cocina) + run: SETTINGS__FEATURES__COCINA=true bin/rake spec diff --git a/app/models/cocina_rights.rb b/app/models/cocina_rights.rb index 76647742..eee46947 100644 --- a/app/models/cocina_rights.rb +++ b/app/models/cocina_rights.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -# The rights derived from cocina +# The file rights derived from cocina class CocinaRights def initialize(file_rights) @file_rights = file_rights diff --git a/app/models/stacks_rights.rb b/app/models/stacks_rights.rb index 47579263..b26e69de 100644 --- a/app/models/stacks_rights.rb +++ b/app/models/stacks_rights.rb @@ -13,29 +13,59 @@ def initialize(id:, file_name:) end def maybe_downloadable? - rights.world_unrestricted_file?(file_name) || - rights.stanford_only_unrestricted_file?(file_name) + if use_json? + %w[world stanford].include?(cocina_rights.download) + else + rights.world_unrestricted_file?(file_name) || + rights.stanford_only_unrestricted_file?(file_name) + end end def stanford_restricted? - value, _rule = rights.stanford_only_rights_for_file file_name + if use_json? + cocina_rights.view == 'stanford' + else + value, _rule = rights.stanford_only_rights_for_file file_name - value + value + end end def cdl_restricted? - value, _rule = rights.cdl_rights_for_file file_name + if use_json? + cocina_rights.controlled_digital_lending? + else + value, _rule = rights.cdl_rights_for_file file_name - value + value + end end # Returns true if a given file has any location restrictions. # Falls back to the object-level behavior if none at file level. def restricted_by_location? - rights.restricted_by_location?(file_name) + if use_json? + cocina_rights.view == 'location-based' || cocina_rights.download == 'location-based' + else + rights.restricted_by_location?(file_name) + end end - delegate :embargoed?, :embargo_release_date, to: :rights + def embargoed? + use_json? ? cocina_embargo? : rights.embargoed? + end + + def embargo_release_date + use_json? ? cocina_embargo_release_date : rights.embargo_release_date + end + + def cocina_embargo? + cocina_embargo_release_date && Time.parse(cocina_embargo_release_date).getlocal > Time.now.getlocal + end + + def cocina_embargo_release_date + @cocina_embargo_release_date ||= public_json.dig('access', 'embargo', 'releaseDate') + end def object_thumbnail? use_json? ? cocina_thumbnail? : xml_thumbnail? diff --git a/spec/abilities/ability_spec.rb b/spec/abilities/ability_spec.rb index 9654bcb6..2dc5646c 100644 --- a/spec/abilities/ability_spec.rb +++ b/spec/abilities/ability_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' require 'cancan/matchers' -RSpec.describe 'Ability', type: :model do +RSpec.describe 'Ability', type: :model, unless: Settings.features.cocina do subject(:ability) { Ability.new(user) } let(:user) { nil } diff --git a/spec/controllers/file_controller_spec.rb b/spec/controllers/file_controller_spec.rb index eb530b56..465c3685 100644 --- a/spec/controllers/file_controller_spec.rb +++ b/spec/controllers/file_controller_spec.rb @@ -6,6 +6,29 @@ before do allow(StacksFile).to receive(:new).and_return(file) stub_rights_xml(world_readable_rights_xml) + allow(Purl).to receive(:public_json).and_return(public_json) + end + + let(:public_json) do + { + 'structural' => { + 'contains' => [ + { + 'structural' => { + 'contains' => [ + { + 'filename' => 'xf680rd3068_1.jp2', + 'access' => { + 'view' => 'world', + 'download' => 'world' + } + } + ] + } + } + ] + } + } end let(:file) { StacksFile.new(id: druid, file_name: 'xf680rd3068_1.jp2') } diff --git a/spec/controllers/object_controller_spec.rb b/spec/controllers/object_controller_spec.rb index 0be0deca..f1d13757 100644 --- a/spec/controllers/object_controller_spec.rb +++ b/spec/controllers/object_controller_spec.rb @@ -18,15 +18,17 @@ allow(Faraday).to receive(:get).with('https://purl.stanford.edu/foo.xml').and_return( instance_double(Faraday::Response, status: 404, success?: false) ) + allow(Faraday).to receive(:get).with('https://purl.stanford.edu/foo.json').and_return( + instance_double(Faraday::Response, status: 404, success?: false) + ) get :show, params: { id: 'foo' } expect(response.status).to eq 404 end end context "with downloadable files" do - before do - allow(Faraday).to receive(:get).with('https://purl.stanford.edu/fd063dh3727.xml').and_return( - instance_double(Faraday::Response, success?: true, body: <<-EOXML) + let(:xml) do + <<-EOXML @@ -59,8 +61,76 @@ - EOXML - ) + EOXML + end + let(:json) do + { + 'structural' => { + 'contains' => [ + { + 'structural' => { + 'contains' => [ + { + 'filename' => '36105116040556_0002.pdf', + 'access' => { + 'view' => 'world', + 'download' => 'world' + } + }, + { + 'filename' => '36105116040556_0002.xml', + 'access' => { + 'view' => 'world', + 'download' => 'world' + } + }, + { + 'filename' => '36105116040556_0002.jp2', + 'access' => { + 'view' => 'world', + 'download' => 'world' + } + } + ] + } + }, + { + 'structural' => { + 'contains' => [ + { + 'filename' => '36105116040556_0003.pdf', + 'access' => { + 'view' => 'world', + 'download' => 'world' + } + }, + { + 'filename' => '36105116040556_0003.xml', + 'access' => { + 'view' => 'world', + 'download' => 'world' + } + }, + { + 'filename' => '36105116040556_0003.jp2', + 'access' => { + 'view' => 'world', + 'download' => 'world' + } + } + ] + } + } + ] + } + }.to_json + end + + before do + allow(Faraday).to receive(:get).with('https://purl.stanford.edu/fd063dh3727.xml') + .and_return(instance_double(Faraday::Response, success?: true, body: xml)) + allow(Faraday).to receive(:get).with('https://purl.stanford.edu/fd063dh3727.json') + .and_return(instance_double(Faraday::Response, success?: true, body: json)) end it 'creates a zip' do @@ -71,9 +141,8 @@ end context "with a stanford access file" do - before do - allow(Faraday).to receive(:get).with('https://purl.stanford.edu/bb142ws0723.xml').and_return( - instance_double(Faraday::Response, success?: true, body: <<-EOXML) + let(:xml) do + <<-EOXML @@ -107,8 +176,56 @@ - EOXML - ) + EOXML + end + + let(:json) do + { + 'structural' => { + 'contains' => [ + { + 'structural' => { + 'contains' => [ + { + 'filename' => 'bb142ws0723_01_sl.mp4', + 'access' => { + 'view' => 'stanford', + 'download' => 'stanford' + } + }, + { + 'filename' => 'bb142ws0723_01_thumb.jp2', + 'access' => { + 'view' => 'stanford', + 'download' => 'stanford' + } + } + ] + } + }, + { + 'structural' => { + 'contains' => [ + { + 'filename' => 'bb142ws0723_program.pdf', + 'access' => { + 'view' => 'world', + 'download' => 'world' + } + } + ] + } + } + ] + } + }.to_json + end + + before do + allow(Faraday).to receive(:get).with('https://purl.stanford.edu/bb142ws0723.xml') + .and_return(instance_double(Faraday::Response, success?: true, body: xml)) + allow(Faraday).to receive(:get).with('https://purl.stanford.edu/bb142ws0723.json') + .and_return(instance_double(Faraday::Response, success?: true, body: json)) end it 'redirects to login' do @@ -127,9 +244,8 @@ end context "with a stanford access file" do - before do - allow(Faraday).to receive(:get).with('https://purl.stanford.edu/bb142ws0723.xml').and_return( - instance_double(Faraday::Response, success?: true, body: <<-EOXML) + let(:xml) do + <<-EOXML @@ -163,8 +279,55 @@ - EOXML - ) + EOXML + end + let(:json) do + { + 'structural' => { + 'contains' => [ + { + 'structural' => { + 'contains' => [ + { + 'filename' => 'bb142ws0723_01_sl.mp4', + 'access' => { + 'view' => 'stanford', + 'download' => 'stanford' + } + }, + { + 'filename' => 'bb142ws0723_01_thumb.jp2', + 'access' => { + 'view' => 'stanford', + 'download' => 'stanford' + } + } + ] + } + }, + { + 'structural' => { + 'contains' => [ + { + 'filename' => 'bb142ws0723_program.pdf', + 'access' => { + 'view' => 'world', + 'download' => 'world' + } + } + ] + } + } + ] + } + }.to_json + end + + before do + allow(Faraday).to receive(:get).with('https://purl.stanford.edu/bb142ws0723.xml') + .and_return(instance_double(Faraday::Response, success?: true, body: xml)) + allow(Faraday).to receive(:get).with('https://purl.stanford.edu/bb142ws0723.json') + .and_return(instance_double(Faraday::Response, success?: true, body: json)) end it 'creates a zip' do diff --git a/spec/models/purl_spec.rb b/spec/models/purl_spec.rb index 46ee19c2..310c21d8 100644 --- a/spec/models/purl_spec.rb +++ b/spec/models/purl_spec.rb @@ -20,30 +20,70 @@ end describe '.files' do - it 'gets all the files for a resource' do - allow(Faraday).to receive(:get).with('https://purl.stanford.edu/abc.xml').and_return( - double(success?: true, body: - <<-EOXML - - - - - - - - - - - - - - - - - EOXML - ) - ) + let(:xml) do + <<-EOXML + + + + + + + + + + + + + + + + + EOXML + end + let(:json) do + { + 'structural' => { + 'contains' => [ + { + 'structural' => { + 'contains' => [ + { + 'filename' => '26855.jp2', + 'access' => { + 'view' => 'world', + 'download' => 'world' + } + } + ] + } + }, + { + 'structural' => { + 'contains' => [ + { + 'filename' => '123.jp2', + 'access' => { + 'view' => 'world', + 'download' => 'world' + } + } + ] + } + } + ] + } + }.to_json + end + + before do + allow(Faraday).to receive(:get).with('https://purl.stanford.edu/abc.xml') + .and_return(double(success?: true, body: xml)) + allow(Faraday).to receive(:get).with('https://purl.stanford.edu/abc.json') + .and_return(double(success?: true, body: json)) + end + + it 'gets all the files for a resource' do actual = described_class.files('abc').map { |file| "#{file.id}/#{file.file_name}" } expect(actual).to match_array ['abc/26855.jp2', 'abc/123.jp2'] diff --git a/spec/requests/file_auth_request_spec.rb b/spec/requests/file_auth_request_spec.rb index 9160792a..2812234e 100644 --- a/spec/requests/file_auth_request_spec.rb +++ b/spec/requests/file_auth_request_spec.rb @@ -18,6 +18,7 @@ end before(:each) do + allow(Purl).to receive(:public_json).and_return(public_json) allow(File).to receive(:world_readable?).with(path).and_return(perms) end @@ -64,6 +65,28 @@ # NOTE: stanford only + location rights tested under location context context 'stanford only (no location qualifications)' do + let(:public_json) do + { + 'structural' => { + 'contains' => [ + { + 'structural' => { + 'contains' => [ + { + 'filename' => 'xf680rd3068_1.jp2', + 'access' => { + 'view' => 'stanford', + 'download' => 'stanford' + } + } + ] + } + } + ] + } + } + end + context 'webauthed user' do it 'allows when user webauthed and authorized' do allow_any_instance_of(FileController).to receive(:current_user).and_return(user_webauth_stanford_no_loc) @@ -88,6 +111,29 @@ end context 'location' do context 'not stanford qualified in any way' do + let(:public_json) do + { + 'structural' => { + 'contains' => [ + { + 'structural' => { + 'contains' => [ + { + 'filename' => 'xf680rd3068_1.jp2', + 'access' => { + 'view' => 'location-based', + 'download' => 'location-based', + 'location' => 'location1' + } + } + ] + } + } + ] + } + } + end + it 'allows when user in location' do allow_any_instance_of(FileController).to receive(:current_user).and_return(user_loc_no_webauth) allow(Purl).to receive(:public_xml).and_return(location_rights) diff --git a/spec/requests/file_spec.rb b/spec/requests/file_spec.rb index f5f5793b..77dac360 100644 --- a/spec/requests/file_spec.rb +++ b/spec/requests/file_spec.rb @@ -5,6 +5,29 @@ RSpec.describe "File requests", type: :request do before do allow(Purl).to receive(:public_xml).and_return('') + allow(Purl).to receive(:public_json).and_return(public_json) + end + + let(:public_json) do + { + 'structural' => { + 'contains' => [ + { + 'structural' => { + 'contains' => [ + { + 'filename' => 'nr349ct7889_00_0001.jp2', + 'access' => { + 'view' => 'world', + 'download' => 'world' + } + } + ] + } + } + ] + } + } end describe 'OPTIONS options' do @@ -31,6 +54,27 @@ EOF end + let(:public_json) do + { + 'structural' => { + 'contains' => [ + { + 'structural' => { + 'contains' => [ + { + 'filename' => 'path/to/xf680rd3068_1.jp2', + 'access' => { + 'view' => 'world', + 'download' => 'world' + } + } + ] + } + } + ] + } + } + end before do allow_any_instance_of(FileController).to receive(:send_file).with(stacks_file.path, disposition: :inline) diff --git a/spec/requests/iiif_auth_request_spec.rb b/spec/requests/iiif_auth_request_spec.rb index 041f2266..004fd205 100644 --- a/spec/requests/iiif_auth_request_spec.rb +++ b/spec/requests/iiif_auth_request_spec.rb @@ -29,7 +29,7 @@ end describe "#show" do - before(:each) do + before do allow_any_instance_of(Projection).to receive(:valid?).and_return(true) allow(HTTP).to receive(:use) .and_return(http_client) @@ -37,9 +37,32 @@ allow_any_instance_of(IiifController).to receive(:current_user).and_return(current_user) allow_any_instance_of(IiifController).to receive(:current_image).and_return(current_image) + allow(Purl).to receive(:public_json).and_return(public_json) end context 'with a public item' do + let(:public_json) do + { + 'structural' => { + 'contains' => [ + { + 'structural' => { + 'contains' => [ + { + 'filename' => 'nr349ct7889_00_0001', + 'access' => { + 'view' => 'world', + 'download' => 'world' + } + } + ] + } + } + ] + } + } + end + before do stub_rights_xml(world_readable_rights_xml) end @@ -56,6 +79,28 @@ end context 'with a stanford only item' do + let(:public_json) do + { + 'structural' => { + 'contains' => [ + { + 'structural' => { + 'contains' => [ + { + 'filename' => 'nr349ct7889_00_0001', + 'access' => { + 'view' => 'stanford', + 'download' => 'stanford' + } + } + ] + } + } + ] + } + } + end + before do stub_rights_xml(stanford_restricted_rights_xml) end @@ -90,6 +135,29 @@ end context 'with a location-restricted item' do + let(:public_json) do + { + 'structural' => { + 'contains' => [ + { + 'structural' => { + 'contains' => [ + { + 'filename' => 'nr349ct7889_00_0001', + 'access' => { + 'view' => 'location-based', + 'download' => 'location-based', + 'location' => 'location1' + } + } + ] + } + } + ] + } + } + end + before do stub_rights_xml(location_rights_xml) end diff --git a/spec/requests/iiif_spec.rb b/spec/requests/iiif_spec.rb index decf364c..0e1f7485 100644 --- a/spec/requests/iiif_spec.rb +++ b/spec/requests/iiif_spec.rb @@ -22,8 +22,31 @@ mtime: Time.zone.now) end + let(:public_json) do + { + 'structural' => { + 'contains' => [ + { + 'structural' => { + 'contains' => [ + { + 'filename' => 'nr349ct7889_00_0001.jp2', + 'access' => { + 'view' => 'world', + 'download' => 'world' + } + } + ] + } + } + ] + } + } + end + before do stub_rights_xml(world_readable_rights_xml) + allow(Purl).to receive(:public_json).and_return(public_json) # stubbing Rails.cache.fetch is required because you can't dump a singleton (double) # which is what happens when writing to the cache. @@ -49,6 +72,29 @@ end context 'for location-restricted documents' do + let(:public_json) do + { + 'structural' => { + 'contains' => [ + { + 'structural' => { + 'contains' => [ + { + 'filename' => 'nr349ct7889_00_0001.jp2', + 'access' => { + 'view' => 'location-based', + 'download' => 'location_based', + 'location' => 'location1' + } + } + ] + } + } + ] + } + } + end + before do stub_rights_xml(location_rights_xml) end @@ -63,6 +109,29 @@ before do stub_rights_xml(location_thumbnail_rights_xml) end + let(:public_json) do + { + 'structural' => { + 'contains' => [ + { + 'structural' => { + 'contains' => [ + { + 'filename' => 'nr349ct7889_00_0001.jp2', + 'access' => { + 'view' => 'location-based', + 'download' => 'location_based', + 'location' => 'location1' + }, + 'hasMimeType' => 'image/jp2' + } + ] + } + } + ] + } + } + end it 'redirects requests to the degraded info.json' do get '/image/iiif/nr349ct7889%2Fnr349ct7889_00_0001/info.json' @@ -86,6 +155,27 @@ end context 'for stanford-restricted documents' do + let(:public_json) do + { + 'structural' => { + 'contains' => [ + { + 'structural' => { + 'contains' => [ + { + 'filename' => 'nr349ct7889_00_0001.jp2', + 'access' => { + 'view' => 'stanford', + 'download' => 'stanford' + } + } + ] + } + } + ] + } + } + end before do stub_rights_xml(stanford_restricted_rights_xml) end @@ -108,6 +198,28 @@ end context 'rights xml where no one can download' do + let(:public_json) do + { + 'structural' => { + 'contains' => [ + { + 'structural' => { + 'contains' => [ + { + 'filename' => 'nr349ct7889_00_0001.jp2', + 'access' => { + 'view' => 'world', + 'download' => 'none' + } + } + ] + } + } + ] + } + } + end + before do stub_rights_xml(world_no_download_xml) end @@ -125,6 +237,27 @@ end context 'rights xml where stanford only no download' do + let(:public_json) do + { + 'structural' => { + 'contains' => [ + { + 'structural' => { + 'contains' => [ + { + 'filename' => 'nr349ct7889_00_0001.jp2', + 'access' => { + 'view' => 'stanford', + 'download' => 'none' + } + } + ] + } + } + ] + } + } + end before do stub_rights_xml(stanford_only_no_download_xml) end diff --git a/spec/requests/media_auth_request_spec.rb b/spec/requests/media_auth_request_spec.rb index bce0fcb5..aab43d67 100644 --- a/spec/requests/media_auth_request_spec.rb +++ b/spec/requests/media_auth_request_spec.rb @@ -26,6 +26,28 @@ EOF end + let(:public_json) do + { + 'structural' => { + 'contains' => [ + { + 'structural' => { + 'contains' => [ + { + 'filename' => 'file', + 'access' => { + 'view' => 'stanford', + 'download' => 'stanford' + } + } + ] + } + } + ] + } + } + end + let(:mock_media) do sms = StacksMediaStream.new(id: 'bb582xs1304', file_name: 'file', format:) allow(Purl).to receive(:public_xml).with('bb582xs1304').and_return(public_xml) @@ -33,6 +55,7 @@ end before do + allow(Purl).to receive(:public_json).and_return(public_json) allow_any_instance_of(MediaController).to receive(:current_user).and_return(user) allow_any_instance_of(MediaController).to receive(:current_media).and_return(mock_media) end @@ -69,6 +92,28 @@ EOF end + let(:public_json) do + { + 'structural' => { + 'contains' => [ + { + 'structural' => { + 'contains' => [ + { + 'filename' => 'file', + 'access' => { + 'view' => 'location-based', + 'download' => 'location-based', + 'location' => 'spec' + } + } + ] + } + } + ] + } + } + end it 'indicates that the object is location restricted in the json' do get "/media/#{druid}/file.#{format}/auth_check" @@ -94,6 +139,33 @@ EOF end + let(:public_json) do + { + 'access' => { + 'embargo' => { + "releaseDate" => Time.parse('2099-05-15').getlocal.as_json + } + }, + 'structural' => { + 'contains' => [ + { + 'structural' => { + 'contains' => [ + { + 'filename' => 'file', + 'access' => { + 'view' => 'stanford', + 'download' => 'stanford' + } + } + ] + } + } + ] + } + } + end + it 'indicates that the object is stanford restricted and embargoed in the json' do get "/media/#{druid}/file.#{format}/auth_check" expect(response.parsed_body).to eq( @@ -116,6 +188,32 @@ EOF end + let(:public_json) do + { + 'access' => { + 'embargo' => { + "releaseDate" => Time.parse('2099-05-15').getlocal.as_json + } + }, + 'structural' => { + 'contains' => [ + { + 'structural' => { + 'contains' => [ + { + 'filename' => 'file', + 'access' => { + 'view' => 'none', + 'download' => 'none' + } + } + ] + } + } + ] + } + } + end it 'indicates that the object is embargoed in the json' do get "/media/#{druid}/file.#{format}/auth_check.js" diff --git a/spec/requests/media_headers_request_spec.rb b/spec/requests/media_headers_request_spec.rb index 43a812d5..b347fd68 100644 --- a/spec/requests/media_headers_request_spec.rb +++ b/spec/requests/media_headers_request_spec.rb @@ -11,7 +11,32 @@ def verify_origin_header(allow_origin) end RSpec.describe "CORS headers for Media requests", type: :request do - before { stub_rights_xml(world_readable_rights_xml) } + before do + stub_rights_xml(world_readable_rights_xml) + allow(Purl).to receive(:public_json).and_return(public_json) + end + + let(:public_json) do + { + 'structural' => { + 'contains' => [ + { + 'structural' => { + 'contains' => [ + { + 'filename' => filename, + 'access' => { + 'view' => 'world', + 'download' => 'world' + } + } + ] + } + } + ] + } + } + end let(:druid) { 'bb582xs1304' } let(:filename) { 'bb582xs1304_sl.mp4' } diff --git a/spec/requests/remote_iiif_image_delivery_spec.rb b/spec/requests/remote_iiif_image_delivery_spec.rb index 210c487e..58298dad 100644 --- a/spec/requests/remote_iiif_image_delivery_spec.rb +++ b/spec/requests/remote_iiif_image_delivery_spec.rb @@ -17,8 +17,31 @@ "http://imageserver-prod.stanford.edu/iiif/2/nr%2F349%2Fct%2F7889%2Fimage.jp2/full/max/0/default.jpg" end + let(:public_json) do + { + 'structural' => { + 'contains' => [ + { + 'structural' => { + 'contains' => [ + { + 'filename' => 'image.jp2', + 'access' => { + 'view' => 'world', + 'download' => 'world' + } + } + ] + } + } + ] + } + } + end + before do stub_rights_xml(world_readable_rights_xml) + allow(Purl).to receive(:public_json).and_return(public_json) allow(Settings.stacks).to receive(:storage_root).and_return('spec/fixtures') stub_request(:get, info_request) .to_return(status: 200, body: info_response) diff --git a/spec/services/iiif_info_service_spec.rb b/spec/services/iiif_info_service_spec.rb index 6af65bb0..92f6fdcf 100644 --- a/spec/services/iiif_info_service_spec.rb +++ b/spec/services/iiif_info_service_spec.rb @@ -151,8 +151,32 @@ let(:downloadable_anonymously) { false } let(:location_service) { image_info['service'] } + let(:public_json) do + { + 'structural' => { + 'contains' => [ + { + 'structural' => { + 'contains' => [ + { + 'filename' => 'nr349ct7889_00_0001', + 'access' => { + 'view' => 'location-based', + 'download' => 'location-based', + 'location' => 'spec' + } + } + ] + } + } + ] + } + } + end before do + allow(Purl).to receive(:public_json).and_return(public_json) + stub_rights_xml(world_readable_rights_xml) allow(image).to receive(:restricted_by_location?).and_return(true) end @@ -176,7 +200,31 @@ end let(:downloadable_anonymously) { false } + let(:public_json) do + { + 'structural' => { + 'contains' => [ + { + 'structural' => { + 'contains' => [ + { + 'filename' => 'nr349ct7889_00_0001', + 'access' => { + 'view' => 'stanford', + 'download' => 'stanford' + }, + 'hasMimeType' => 'text/csv' + } + ] + } + } + ] + } + } + end + before do + allow(Purl).to receive(:public_json).and_return(public_json) stub_rights_xml(world_readable_rights_xml) allow(image).to receive(:stanford_restricted?).and_return(true) allow(image).to receive(:restricted_by_location?).and_return(true) @@ -197,8 +245,32 @@ RestrictedImage.new(id: 'whatever', file_name: 'something') end let(:downloadable_anonymously) { false } + let(:public_json) do + { + 'structural' => { + 'contains' => [ + { + 'structural' => { + 'contains' => [ + { + 'filename' => 'something', + 'access' => { + 'view' => 'none', + 'download' => 'none', + 'controlledDigitalLending' => true + }, + 'hasMimeType' => 'text/csv' + } + ] + } + } + ] + } + } + end before do + allow(Purl).to receive(:public_json).and_return(public_json) stub_rights_xml(world_readable_rights_xml) allow(image).to receive(:cdl_restricted?).and_return(true) end