Skip to content

Commit

Permalink
Get rid of old xml test data
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Jun 27, 2024
1 parent e301845 commit e6d8796
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 328 deletions.
18 changes: 1 addition & 17 deletions app/models/purl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
120 changes: 0 additions & 120 deletions spec/controllers/object_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand All @@ -27,42 +24,6 @@
end

context "with downloadable files" do
let(:xml) do
<<-EOXML
<publicObject id="druid:fd063dh3727" published="2019-12-19T17:58:11Z" publishVersion="dor-services/8.1.1">
<contentMetadata objectId="druid:fd063dh3727" type="book">
<resource id="fd063dh3727_1" sequence="1" type="page">
<label>Page 1</label>
<file id="36105116040556_0002.pdf" mimetype="application/pdf" size="191643"></file>
<file id="36105116040556_0002.xml" role="transcription" mimetype="application/xml" size="4220"></file>
<file id="36105116040556_0002.jp2" mimetype="image/jp2" size="744853">
<imageData width="1738" height="2266"/>
</file>
</resource>
<resource id="fd063dh3727_2" sequence="2" type="page">
<label>Page 2</label>
<file id="36105116040556_0003.pdf" mimetype="application/pdf" size="21418"></file>
<file id="36105116040556_0003.xml" role="transcription" mimetype="application/xml" size="1129"></file>
<file id="36105116040556_0003.jp2" mimetype="image/jp2" size="418977">
<imageData width="1241" height="1954"/>
</file>
</resource>
</contentMetadata>
<rightsMetadata>
<access type="discover">
<machine>
<world/>
</machine>
</access>
<access type="read">
<machine>
<world/>
</machine>
</access>
</rightsMetadata>
</publicObject>
EOXML
end
let(:json) do
{
'structural' => {
Expand Down Expand Up @@ -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
Expand All @@ -141,44 +100,6 @@
end

context "with a stanford access file" do
let(:xml) do
<<-EOXML
<publicObject id="druid:bb142ws0723" published="2020-05-09T00:44:17Z" publishVersion="dor-services/9.3.0">
<contentMetadata objectId="bb142ws0723" type="media">
<resource sequence="1" id="bb142ws0723_1" type="video">
<label>Video file 1</label>
<file id="bb142ws0723_01_sl.mp4" size="256265102" mimetype="video/mp4"> </file>
<file id="bb142ws0723_01_thumb.jp2" size="740541" mimetype="image/jp2">
<imageData width="1280" height="720"/>
</file>
</resource>
<resource sequence="9" id="bb142ws0723_9" type="file">
<label>Program</label>
<file id="bb142ws0723_program.pdf" size="991048" mimetype="application/pdf"> </file>
</resource>
</contentMetadata>
<rightsMetadata>
<access type="discover">
<machine>
<world/>
</machine>
</access>
<access type="read">
<machine>
<group>stanford</group>
</machine>
</access>
<access type="read">
<file>bb142ws0723_program.pdf</file>
<machine>
<world/>
</machine>
</access>
</rightsMetadata>
</publicObject>
EOXML
end

let(:json) do
{
'structural' => {
Expand Down Expand Up @@ -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
Expand All @@ -244,43 +163,6 @@
end

context "with a stanford access file" do
let(:xml) do
<<-EOXML
<publicObject id="druid:bb142ws0723" published="2020-05-09T00:44:17Z" publishVersion="dor-services/9.3.0">
<contentMetadata objectId="bb142ws0723" type="media">
<resource sequence="1" id="bb142ws0723_1" type="video">
<label>Video file 1</label>
<file id="bb142ws0723_01_sl.mp4" size="256265102" mimetype="video/mp4"> </file>
<file id="bb142ws0723_01_thumb.jp2" size="740541" mimetype="image/jp2">
<imageData width="1280" height="720"/>
</file>
</resource>
<resource sequence="9" id="bb142ws0723_9" type="file">
<label>Program</label>
<file id="bb142ws0723_program.pdf" size="991048" mimetype="application/pdf"> </file>
</resource>
</contentMetadata>
<rightsMetadata>
<access type="discover">
<machine>
<world/>
</machine>
</access>
<access type="read">
<machine>
<group>stanford</group>
</machine>
</access>
<access type="read">
<file>bb142ws0723_program.pdf</file>
<machine>
<world/>
</machine>
</access>
</rightsMetadata>
</publicObject>
EOXML
end
let(:json) do
{
'structural' => {
Expand Down Expand Up @@ -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
Expand Down
35 changes: 0 additions & 35 deletions spec/models/purl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
<publicObject id="druid:kn112rm5773" published="2018-02-05T18:34:41Z" publishVersion="dor-services/5.23.1">
<contentMetadata objectId="kn112rm5773" type="image">
<resource id="kn112rm5773_1" sequence="1" type="image">
<label>Image 1</label>
<file id="26855.jp2" mimetype="image/jp2" size="3832255">
<imageData width="4850" height="4180"/>
</file>
</resource>
<resource id="kn112rm5773_2" sequence="2" type="image">
<label>Virtual image</label>
<file id="123.jp2" mimetype="image/jp2" size="3832255">
<imageData width="4850" height="4180"/>
</file>
</resource>
</contentMetadata>
</publicObject>
EOXML
end

let(:json) do
{
'structural' => {
Expand Down Expand Up @@ -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
Expand Down
45 changes: 0 additions & 45 deletions spec/requests/file_auth_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,46 +21,6 @@
end

describe "#show" do
let(:group_rights) do
<<-EOF
<publicObject>
<rightsMetadata>
<access type="read">
<machine>
<group>Stanford</group>
</machine>
</access>
</rightsMetadata>
</publicObject>
EOF
end
let(:location_rights) do
<<-EOF
<publicObject>
<rightsMetadata>
<access type="read">
<machine>
<location>location1</location>
</machine>
</access>
</rightsMetadata>
</publicObject>
EOF
end
let(:location_other_rights) do
<<-EOF
<publicObject>
<rightsMetadata>
<access type="read">
<machine>
<location>location-other</location>
</machine>
</access>
</rightsMetadata>
</publicObject>
EOF
end

# NOTE: stanford only + location rights tested under location context
context 'stanford only (no location qualifications)' do
let(:public_json) do
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 1 addition & 15 deletions spec/requests/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

RSpec.describe "File requests" do
before do
allow(Purl).to receive_messages(public_xml: '<publicObject />', public_json:)
allow(Purl).to receive_messages(public_json:)
end

let(:druid) { 'nr349ct7889' }
Expand Down Expand Up @@ -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
<publicObject>
<rightsMetadata>
<access type="read">
<machine>
<world/>
</machine>
</access>
</rightsMetadata>
</publicObject>
EOF
end
let(:public_json) do
{
'structural' => {
Expand All @@ -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
Expand Down
Loading

0 comments on commit e6d8796

Please sign in to comment.