From e6d87968f653df5e43e0c3bfd21bee8f60b51264 Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Thu, 27 Jun 2024 17:04:45 -0500 Subject: [PATCH] Get rid of old xml test data --- app/models/purl.rb | 18 +-- spec/controllers/object_controller_spec.rb | 120 ------------------ spec/models/purl_spec.rb | 35 ----- spec/requests/file_auth_request_spec.rb | 45 ------- spec/requests/file_spec.rb | 16 +-- .../iiif/auth/v2/probe_service_spec.rb | 36 ------ spec/requests/iiif_spec.rb | 4 +- spec/requests/media_auth_request_spec.rb | 59 +-------- 8 files changed, 5 insertions(+), 328 deletions(-) diff --git a/app/models/purl.rb b/app/models/purl.rb index 0c78f210..c9a64fe8 100644 --- a/app/models/purl.rb +++ b/app/models/purl.rb @@ -11,19 +11,7 @@ def self.instance end class << self - delegate :public_xml, :public_json, :files, to: :instance - end - - # TODO: was etag a valid key? - def public_xml(druid) - Rails.cache.fetch("purl/#{druid}/public_xml", expires_in: 10.minutes) do - benchmark "Fetching public xml for #{druid}" do - response = Faraday.get(public_xml_url(druid)) - raise Purl::Exception, response.status unless response.success? - - response.body - end - end + delegate :public_json, :files, to: :instance end def public_json(druid) @@ -56,10 +44,6 @@ def files_from_json(druid) private - def public_xml_url(druid) - Settings.purl.url + "#{druid}.xml" - end - def public_json_url(druid) "#{Settings.purl.url}#{druid}.json" end diff --git a/spec/controllers/object_controller_spec.rb b/spec/controllers/object_controller_spec.rb index 2948d766..fff45b96 100644 --- a/spec/controllers/object_controller_spec.rb +++ b/spec/controllers/object_controller_spec.rb @@ -15,9 +15,6 @@ let(:druid) { 'foo' } it 'returns a 404 Not Found' do - 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) ) @@ -27,42 +24,6 @@ end context "with downloadable files" do - let(:xml) do - <<-EOXML - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - EOXML - end let(:json) do { 'structural' => { @@ -127,8 +88,6 @@ 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 @@ -141,44 +100,6 @@ end context "with a stanford access file" do - let(:xml) do - <<-EOXML - - - - - - - - - - - - - - - - - - - - - - - stanford - - - - bb142ws0723_program.pdf - - - - - - - EOXML - end - let(:json) do { 'structural' => { @@ -222,8 +143,6 @@ 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 @@ -244,43 +163,6 @@ end context "with a stanford access file" do - let(:xml) do - <<-EOXML - - - - - - - - - - - - - - - - - - - - - - - stanford - - - - bb142ws0723_program.pdf - - - - - - - EOXML - end let(:json) do { 'structural' => { @@ -324,8 +206,6 @@ 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 diff --git a/spec/models/purl_spec.rb b/spec/models/purl_spec.rb index 938f7d36..de913616 100644 --- a/spec/models/purl_spec.rb +++ b/spec/models/purl_spec.rb @@ -7,40 +7,7 @@ Rails.cache.clear end - describe '.public_xml' do - it 'fetches the public xml' do - allow(Faraday).to receive(:get).with('https://purl.stanford.edu/abc.xml').and_return( - double(body: '', success?: true) - ) - - described_class.public_xml('abc') - - expect(Faraday).to have_received(:get).with('https://purl.stanford.edu/abc.xml') - end - end - describe '.files' do - let(:xml) do - <<-EOXML - - - - - - - - - - - - - - - - - EOXML - end - let(:json) do { 'structural' => { @@ -77,8 +44,6 @@ 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 diff --git a/spec/requests/file_auth_request_spec.rb b/spec/requests/file_auth_request_spec.rb index 88cb55ec..53992b68 100644 --- a/spec/requests/file_auth_request_spec.rb +++ b/spec/requests/file_auth_request_spec.rb @@ -21,46 +21,6 @@ end describe "#show" do - let(:group_rights) do - <<-EOF - - - - - Stanford - - - - - EOF - end - let(:location_rights) do - <<-EOF - - - - - location1 - - - - - EOF - end - let(:location_other_rights) do - <<-EOF - - - - - location-other - - - - - EOF - end - # NOTE: stanford only + location rights tested under location context context 'stanford only (no location qualifications)' do let(:public_json) do @@ -88,21 +48,18 @@ 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) - allow(Purl).to receive(:public_xml).and_return(group_rights) expect_any_instance_of(FileController).to receive(:send_file).with(sf.path, disposition: :inline).and_call_original get "/file/#{druid}/#{file_name}" end it 'blocks when user webauthed but NOT authorized' do allow_any_instance_of(FileController).to receive(:current_user).and_return(user_webauth_no_stanford_no_loc) - allow(Purl).to receive(:public_xml).and_return(group_rights) get "/file/#{druid}/#{file_name}" expect(response).to have_http_status(:forbidden) end end it "prompts for webauth when user not webauthed" do allow_any_instance_of(FileController).to receive(:current_user).and_return(user_no_loc_no_webauth) - allow(Purl).to receive(:public_xml).and_return(group_rights) get "/file/#{druid}/#{file_name}" expect(response).to redirect_to(auth_file_url(id: druid, file_name:)) end @@ -134,14 +91,12 @@ 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) expect_any_instance_of(FileController).to receive(:send_file).with(sf.path, disposition: :inline).and_call_original get "/file/#{druid}/#{file_name}" end it 'blocks when user not in location' do allow_any_instance_of(FileController).to receive(:current_user).and_return(user_no_loc_no_webauth) - allow(Purl).to receive(:public_xml).and_return(location_other_rights) get "/file/#{druid}/#{file_name}" expect(response).to have_http_status(:forbidden) end diff --git a/spec/requests/file_spec.rb b/spec/requests/file_spec.rb index d4c665a2..ff17b8ee 100644 --- a/spec/requests/file_spec.rb +++ b/spec/requests/file_spec.rb @@ -4,7 +4,7 @@ RSpec.describe "File requests" do before do - allow(Purl).to receive_messages(public_xml: '', public_json:) + allow(Purl).to receive_messages(public_json:) end let(:druid) { 'nr349ct7889' } @@ -43,19 +43,6 @@ describe 'GET file with slashes in filename' do let(:file_name) { 'path/to/image.jp2' } let(:stacks_file) { StacksFile.new(id: druid, file_name:) } - let(:world_rights) do - <<-EOF - - - - - - - - - - EOF - end let(:public_json) do { 'structural' => { @@ -82,7 +69,6 @@ allow(StacksFile).to receive(:new).and_return(stacks_file) allow(stacks_file).to receive(:path) allow_any_instance_of(FileController).to receive(:send_file).with(stacks_file.path, disposition: :inline) - allow(Purl).to receive(:public_xml).and_return(world_rights) end it 'returns a successful HTTP response' do diff --git a/spec/requests/iiif/auth/v2/probe_service_spec.rb b/spec/requests/iiif/auth/v2/probe_service_spec.rb index 718753b7..e2cb0307 100644 --- a/spec/requests/iiif/auth/v2/probe_service_spec.rb +++ b/spec/requests/iiif/auth/v2/probe_service_spec.rb @@ -303,17 +303,6 @@ } } end - let(:rights_xml) do - <<~EOF - - - - #{xml_location} - - - - EOF - end before do get "/iiif/auth/v2/probe?id=#{stacks_uri_param}" @@ -321,7 +310,6 @@ context 'when special collections' do let(:location) { 'spec' } - let(:xml_location) { 'spec' } it 'returns a not authorized response' do expect(response).to have_http_status :ok @@ -339,7 +327,6 @@ context 'when media & microtext' do let(:location) { 'm&m' } - let(:xml_location) { 'm&m' } it 'returns a not authorized response' do expect(response).to have_http_status :ok @@ -383,18 +370,6 @@ } } end - let(:rights_xml) do - <<~EOF - - - - 2099-05-15 - stanford - - - - EOF - end before do get "/iiif/auth/v2/probe?id=#{stacks_uri_param}" @@ -442,17 +417,6 @@ } } end - let(:rights_xml) do - <<~EOF - - - - 2099-05-15 - - - - EOF - end before do get "/iiif/auth/v2/probe?id=#{stacks_uri_param}" diff --git a/spec/requests/iiif_spec.rb b/spec/requests/iiif_spec.rb index 7f435381..15b05133 100644 --- a/spec/requests/iiif_spec.rb +++ b/spec/requests/iiif_spec.rb @@ -197,7 +197,7 @@ end end - context 'rights xml where no one can download' do + context 'where no one can download' do let(:public_json) do { 'structural' => { @@ -233,7 +233,7 @@ end end - context 'rights xml where stanford only no download' do + context 'where stanford only no download rights' do let(:public_json) do { 'structural' => { diff --git a/spec/requests/media_auth_request_spec.rb b/spec/requests/media_auth_request_spec.rb index cbb74c43..f3399f01 100644 --- a/spec/requests/media_auth_request_spec.rb +++ b/spec/requests/media_auth_request_spec.rb @@ -4,27 +4,7 @@ RSpec.describe "Authentication for Media requests" do let(:druid) { 'bb582xs1304' } - let(:format) { 'mp4' } - let(:public_xml) do - <<-XML - - #{rights_xml} - - XML - end - - let(:rights_xml) do - <<~EOF - - - - Stanford - - - - EOF - end let(:public_json) do { @@ -49,9 +29,7 @@ end let(:mock_media) do - sms = StacksMediaStream.new(id: 'bb582xs1304', file_name: 'file') - allow(Purl).to receive(:public_xml).with('bb582xs1304').and_return(public_xml) - sms + StacksMediaStream.new(id: 'bb582xs1304', file_name: 'file') end before do @@ -86,17 +64,6 @@ end context 'location restricted' do - let(:rights_xml) do - <<~EOF - - - - spec - - - - EOF - end let(:public_json) do { 'structural' => { @@ -131,19 +98,6 @@ end context 'when the file is embargoed or stanford restricted' do - let(:rights_xml) do - <<~EOF - - - - 2099-05-15 - stanford - - - - EOF - end - let(:public_json) do { 'access' => { @@ -182,17 +136,6 @@ end context 'when the file is embargoed' do - let(:rights_xml) do - <<~EOF - - - - 2099-05-15 - - - - EOF - end let(:public_json) do { 'access' => {