-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add cors headers for file show method #1068
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,30 @@ | |
Factories.cocina_with_file | ||
end | ||
|
||
let(:stanford_json) do | ||
{ | ||
'structural' => { | ||
'contains' => [ | ||
{ | ||
'structural' => { | ||
'contains' => [ | ||
{ | ||
'filename' => 'xf680rd3068_1.jp2', | ||
'access' => { | ||
'view' => 'stanford', | ||
'download' => 'stanford' | ||
} | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
end | ||
|
||
let(:file) { StacksFile.new(id: druid, file_name: 'xf680rd3068_1.jp2') } | ||
|
||
describe '#show' do | ||
let(:druid) { 'nr349ct7889' } | ||
|
||
|
@@ -20,6 +44,7 @@ | |
it 'sends the file to the user' do | ||
expect(controller).to receive(:send_file).with(path, filename: 'image.jp2', disposition: :inline).and_call_original | ||
subject | ||
expect(response.headers.to_h).to include 'Access-Control-Allow-Origin' => '*' | ||
end | ||
|
||
context 'when file is not in a content addressable path' do | ||
|
@@ -32,6 +57,24 @@ | |
"content-disposition" => "attachment; filename=\"image.jp2\"; filename*=UTF-8''image.jp2" | ||
) | ||
end | ||
|
||
it 'sets disposition attachment with download param' do | ||
expect(controller).to receive(:send_file).with(file.path, disposition: :attachment).and_call_original | ||
get :show, params: { id: 'xf680rd3068', file_name: 'xf680rd3068_1.jp2', download: 'any' } | ||
end | ||
|
||
context 'when Stanford restricted' do | ||
before do | ||
# stub_rights_xml(stanford_restricted_rights_xml) | ||
allow(Purl).to receive(:public_json).and_return(stanford_json) | ||
end | ||
|
||
it 'sends host-specific and credentials CORS headers' do | ||
subject | ||
expect(response.headers.to_h).to include 'Access-Control-Allow-Origin' => 'https://embed.stanford.edu', | ||
'Access-Control-Allow-Credentials' => 'true' | ||
end | ||
end | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it worth adding a test for when the file is not Stanford Only to make sure the header is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup, can just add that check to an existing spec (basically ensure the header is not there). are you interested in taking that on and seeing if you can sort why CI is failing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I can take a look. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that CI is running the tests like this, which fails for me locally (unlike a regular rspec run):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh, yes. good catch. likely an issue with the mocking in the test not accounting for cocina rights computation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. Had a problem in my mocked cocina json (it wasn't internally consistent for stanford only). |
||
context 'when file is in a content addressable path' do | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well that looks easy -- nicely done!