Specs for ETag headers
This commit is contained in:
parent
5dd1d26b20
commit
189d202d66
@ -124,8 +124,8 @@ module RemoteStorage
|
||||
existing_object_size = object_size(object)
|
||||
etag = object.etag
|
||||
|
||||
if match_requirement = server.env["HTTP_IF_MATCH"]
|
||||
server.halt 412 unless match_requirement == etag
|
||||
if required_match = server.env["HTTP_IF_MATCH"]
|
||||
server.halt 412 unless required_match == etag
|
||||
end
|
||||
|
||||
if binary_key = object.meta["binary_key"]
|
||||
|
||||
@ -44,6 +44,18 @@ describe "Directories" do
|
||||
last_modified.day.must_equal now.day
|
||||
end
|
||||
|
||||
it "has an ETag header set" do
|
||||
get "/jimmy/tasks/"
|
||||
|
||||
last_response.status.must_equal 200
|
||||
last_response.headers["ETag"].wont_be_nil
|
||||
|
||||
# check that ETag stays the same
|
||||
etag = last_response.headers["ETag"]
|
||||
get "/jimmy/tasks/"
|
||||
last_response.headers["ETag"].must_equal etag
|
||||
end
|
||||
|
||||
it "has CORS headers set" do
|
||||
get "/jimmy/tasks/"
|
||||
|
||||
@ -55,6 +67,9 @@ describe "Directories" do
|
||||
|
||||
context "with sub-directories" do
|
||||
before do
|
||||
get "/jimmy/tasks/"
|
||||
@old_etag = last_response.headers["ETag"]
|
||||
|
||||
put "/jimmy/tasks/home/laundry", "do the laundry"
|
||||
end
|
||||
|
||||
@ -71,6 +86,13 @@ describe "Directories" do
|
||||
content["home/"].to_s.length.must_equal 13
|
||||
end
|
||||
|
||||
it "updates the ETag of the parent directory" do
|
||||
get "/jimmy/tasks/"
|
||||
|
||||
last_response.headers["ETag"].wont_be_nil
|
||||
last_response.headers["ETag"].wont_equal @old_etag
|
||||
end
|
||||
|
||||
context "for a different user" do
|
||||
before do
|
||||
auth = auth_bucket.new("alice:321")
|
||||
@ -260,6 +282,13 @@ describe "Directories" do
|
||||
content["tasks/"].must_be_kind_of Integer
|
||||
content["tasks/"].to_s.length.must_equal 13
|
||||
end
|
||||
|
||||
it "has an ETag header set" do
|
||||
get "/jimmy/"
|
||||
|
||||
last_response.status.must_equal 200
|
||||
last_response.headers["ETag"].wont_be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context "for the public directory" do
|
||||
@ -280,6 +309,13 @@ describe "Directories" do
|
||||
content = JSON.parse(last_response.body)
|
||||
content.must_include "5apps"
|
||||
end
|
||||
|
||||
it "has an ETag header set" do
|
||||
get "/jimmy/public/bookmarks/"
|
||||
|
||||
last_response.status.must_equal 200
|
||||
last_response.headers["ETag"].wont_be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context "when directly authorized for the public directory" do
|
||||
@ -449,6 +485,17 @@ describe "Directories" do
|
||||
directory_bucket.get("jimmy:").wont_be_nil
|
||||
end
|
||||
|
||||
it "updates the ETag header of the parent directory" do
|
||||
get "/jimmy/tasks/"
|
||||
@old_etag = last_response.headers["ETag"]
|
||||
|
||||
delete "/jimmy/tasks/home/trash"
|
||||
|
||||
get "/jimmy/tasks/"
|
||||
last_response.headers["ETag"].wont_be_nil
|
||||
last_response.headers["ETag"].wont_equal @old_etag
|
||||
end
|
||||
|
||||
describe "timestamps" do
|
||||
before do
|
||||
@old_timestamp = (2.seconds.ago.to_f * 1000).to_i
|
||||
|
||||
@ -32,6 +32,11 @@ describe "App with Riak backend" do
|
||||
last_modified.year.must_equal now.year
|
||||
last_modified.day.must_equal now.day
|
||||
end
|
||||
|
||||
it "has an ETag header set" do
|
||||
last_response.status.must_equal 200
|
||||
last_response.headers["ETag"].wont_be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET data with custom content type" do
|
||||
@ -102,6 +107,10 @@ describe "App with Riak backend" do
|
||||
data_bucket.get("jimmy:documents:bar").content_type.must_equal "text/plain; charset=utf-8"
|
||||
end
|
||||
|
||||
it "sets the ETag header" do
|
||||
last_response.headers["ETag"].wont_be_nil
|
||||
end
|
||||
|
||||
it "indexes the data set" do
|
||||
indexes = data_bucket.get("jimmy:documents:bar").indexes
|
||||
indexes["user_id_bin"].must_be_kind_of Set
|
||||
@ -197,15 +206,18 @@ describe "App with Riak backend" do
|
||||
describe "with existing content" do
|
||||
before do
|
||||
put "/jimmy/documents/archive/foo", "lorem ipsum"
|
||||
put "/jimmy/documents/archive/foo", "some awesome content"
|
||||
end
|
||||
|
||||
it "saves the value" do
|
||||
put "/jimmy/documents/archive/foo", "some awesome content"
|
||||
|
||||
last_response.status.must_equal 200
|
||||
data_bucket.get("jimmy:documents/archive:foo").data.must_equal "some awesome content"
|
||||
end
|
||||
|
||||
it "logs the operations" do
|
||||
put "/jimmy/documents/archive/foo", "some awesome content"
|
||||
|
||||
objects = []
|
||||
opslog_bucket.keys.each { |k| objects << opslog_bucket.get(k) rescue nil }
|
||||
|
||||
@ -220,21 +232,29 @@ describe "App with Riak backend" do
|
||||
update_entry.indexes["user_id_bin"].must_include "jimmy"
|
||||
end
|
||||
|
||||
describe "when no serializer is registered for the given content-type" do
|
||||
before do
|
||||
header "Content-Type", "text/html; charset=UTF-8"
|
||||
put "/jimmy/documents/html", '<html></html>'
|
||||
put "/jimmy/documents/html", '<html><body></body></html>'
|
||||
end
|
||||
it "changes the ETag header" do
|
||||
old_etag = last_response.headers["ETag"]
|
||||
put "/jimmy/documents/archive/foo", "some awesome content"
|
||||
|
||||
it "saves the value" do
|
||||
last_response.status.must_equal 200
|
||||
data_bucket.get("jimmy:documents:html").raw_data.must_equal "<html><body></body></html>"
|
||||
end
|
||||
last_response.headers["ETag"].wont_be_nil
|
||||
last_response.headers["ETag"].wont_equal old_etag
|
||||
end
|
||||
end
|
||||
|
||||
it "uses the requested content type" do
|
||||
data_bucket.get("jimmy:documents:html").content_type.must_equal "text/html; charset=UTF-8"
|
||||
end
|
||||
describe "exsting content without serializer registered for the given content-type" do
|
||||
before do
|
||||
header "Content-Type", "text/html; charset=UTF-8"
|
||||
put "/jimmy/documents/html", '<html></html>'
|
||||
put "/jimmy/documents/html", '<html><body></body></html>'
|
||||
end
|
||||
|
||||
it "saves the value" do
|
||||
last_response.status.must_equal 200
|
||||
data_bucket.get("jimmy:documents:html").raw_data.must_equal "<html><body></body></html>"
|
||||
end
|
||||
|
||||
it "uses the requested content type" do
|
||||
data_bucket.get("jimmy:documents:html").content_type.must_equal "text/html; charset=UTF-8"
|
||||
end
|
||||
end
|
||||
|
||||
@ -396,6 +416,10 @@ describe "App with Riak backend" do
|
||||
log_entry.indexes["user_id_bin"].must_include "jimmy"
|
||||
end
|
||||
|
||||
it "sets the ETag header" do
|
||||
last_response.headers["ETag"].wont_be_nil
|
||||
end
|
||||
|
||||
context "non-existing object" do
|
||||
before do
|
||||
delete "/jimmy/documents/foozius"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user