From 331fdbe1c7eb5064262c308d089d134948d1190a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Fri, 3 Jan 2020 18:17:19 +0100 Subject: [PATCH] Add specs for public resources, including getting partial content --- spec/s3/app_spec.rb | 8 ++++++++ spec/shared_examples.rb | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/spec/s3/app_spec.rb b/spec/s3/app_spec.rb index 65950d2..64f2e3d 100644 --- a/spec/s3/app_spec.rb +++ b/spec/s3/app_spec.rb @@ -16,12 +16,20 @@ describe "S3 provider" do stub_request(:put, "#{container_url_for("phil")}/food/aguacate"). with(body: "aye"). to_return(status: 200, headers: { etag: '"0915etag"', date: "Fri, 04 Mar 2016 12:20:18 GMT" }) + stub_request(:put, "#{container_url_for("phil")}/public/shares/example.jpg"). + to_return(status: 200, headers: { etag: '"0817etag"', content_type: "image/jpeg", date: "Fri, 04 Mar 2016 12:20:18 GMT" }) + stub_request(:put, "#{container_url_for("phil")}/public/shares/example_partial.jpg"). + to_return(status: 200, headers: { etag: '"0817etag"', content_type: "image/jpeg", date: "Fri, 04 Mar 2016 12:20:18 GMT" }) stub_request(:head, "#{container_url_for("phil")}/food/aguacate"). to_return(status: 200, headers: { last_modified: "Fri, 04 Mar 2016 12:20:18 GMT" }) stub_request(:get, "#{container_url_for("phil")}/food/aguacate"). to_return(status: 200, body: "rootbody", headers: { etag: '"0817etag"', content_type: "text/plain; charset=utf-8" }) stub_request(:delete, "#{container_url_for("phil")}/food/aguacate"). to_return(status: 200, headers: { etag: '"0815etag"' }) + stub_request(:get, "#{container_url_for("phil")}/public/shares/example.jpg"). + to_return(status: 200, body: "", headers: { etag: '"0817etag"', content_type: "image/jpeg" }) + stub_request(:get, "#{container_url_for("phil")}/public/shares/example_partial.jpg"). + to_return(status: 206, body: "", headers: { etag: '"0817etag"', content_type: "image/jpeg", content_range: "bytes 0-16/128" }) # Write new content to check the metadata in Redis stub_request(:put, "#{container_url_for("phil")}/food/banano"). diff --git a/spec/shared_examples.rb b/spec/shared_examples.rb index aa8f997..1613fee 100644 --- a/spec/shared_examples.rb +++ b/spec/shared_examples.rb @@ -397,6 +397,47 @@ shared_examples_for 'a REST adapter' do purge_redis end + context "requests to public resources" do + before do + redis.sadd "authorizations:phil:amarillo", [":rw"] + header "Authorization", "Bearer amarillo" + end + + describe "normal request" do + before do + header "Content-Type", "image/jpeg" + + put "/phil/public/shares/example.jpg", "" + end + + it "returns the required response headers" do + get "/phil/public/shares/example.jpg" + + last_response.status.must_equal 200 + last_response.headers["Content-Type"].must_equal "image/jpeg" + end + end + + describe "partial request" do + before do + header "Content-Type", "image/jpeg" + + put "/phil/public/shares/example_partial.jpg", <<-EOF +JFIFddDuckyA␍⎺␉␊␍ +#%'%#//33//@@@@@@@@@@@@@@@&&0##0+.'''.+550055@@?@@@@@@@@@@@>"!1AQaq"2B + EOF + end + + it "returns the required response headers" do + header 'Range', 'bytes=0-16' + get "/phil/public/shares/example_partial.jpg" + + last_response.status.must_equal 206 + last_response.headers["Content-Type"].must_equal "image/jpeg" + end + end + end + context "not authorized" do describe "without token" do