Merge branch 'master' into feature/update_to_recent_rs_spec
# Conflicts: # spec/swift/app_spec.rb
This commit is contained in:
@@ -134,6 +134,7 @@ describe "App" do
|
||||
end
|
||||
|
||||
last_response.status.must_equal 409
|
||||
last_response.body.must_equal "Conflict"
|
||||
|
||||
metadata = redis.hgetall "rs:m:phil:food"
|
||||
metadata.must_be_empty
|
||||
@@ -164,7 +165,82 @@ describe "App" do
|
||||
last_response.status.must_equal 400
|
||||
end
|
||||
end
|
||||
|
||||
describe "If-Match header" do
|
||||
before do
|
||||
put_stub = OpenStruct.new(headers: {
|
||||
etag: "oldetag",
|
||||
last_modified: "Fri, 04 Mar 2016 12:20:18 GMT"
|
||||
})
|
||||
|
||||
RestClient.stub :put, put_stub do
|
||||
put "/phil/food/aguacate", "si"
|
||||
end
|
||||
end
|
||||
|
||||
it "allows the request if the header matches the current ETag" do
|
||||
header "If-Match", "\"oldetag\""
|
||||
|
||||
put_stub = OpenStruct.new(headers: {
|
||||
etag: "newetag",
|
||||
last_modified: "Fri, 04 Mar 2016 12:20:18 GMT"
|
||||
})
|
||||
|
||||
RestClient.stub :put, put_stub do
|
||||
put "/phil/food/aguacate", "aye"
|
||||
end
|
||||
|
||||
last_response.status.must_equal 200
|
||||
last_response.headers["Etag"].must_equal "\"newetag\""
|
||||
end
|
||||
|
||||
it "fails the request if the header does not match the current ETag" do
|
||||
header "If-Match", "someotheretag"
|
||||
|
||||
put "/phil/food/aguacate", "aye"
|
||||
|
||||
last_response.status.must_equal 412
|
||||
last_response.body.must_equal "Precondition Failed"
|
||||
end
|
||||
end
|
||||
|
||||
describe "If-None-Match header set to '*'" do
|
||||
it "succeeds when the document doesn't exist yet" do
|
||||
put_stub = OpenStruct.new(headers: {
|
||||
etag: "someetag",
|
||||
last_modified: "Fri, 04 Mar 2016 12:20:18 GMT"
|
||||
})
|
||||
|
||||
header "If-None-Match", "*"
|
||||
|
||||
RestClient.stub :put, put_stub do
|
||||
put "/phil/food/aguacate", "si"
|
||||
end
|
||||
|
||||
last_response.status.must_equal 200
|
||||
end
|
||||
|
||||
it "fails the request if the document already exsits" do
|
||||
put_stub = OpenStruct.new(headers: {
|
||||
etag: "someetag",
|
||||
last_modified: "Fri, 04 Mar 2016 12:20:18 GMT"
|
||||
})
|
||||
|
||||
RestClient.stub :put, put_stub do
|
||||
put "/phil/food/aguacate", "si"
|
||||
end
|
||||
|
||||
header "If-None-Match", "*"
|
||||
RestClient.stub :put, put_stub do
|
||||
put "/phil/food/aguacate", "si"
|
||||
end
|
||||
|
||||
last_response.status.must_equal 412
|
||||
last_response.body.must_equal "Precondition Failed"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "DELETE requests" do
|
||||
@@ -173,6 +249,29 @@ describe "App" do
|
||||
purge_redis
|
||||
end
|
||||
|
||||
context "not authorized" do
|
||||
|
||||
describe "with no token" do
|
||||
it "says it's not authorized" do
|
||||
delete "/phil/food/aguacate"
|
||||
|
||||
last_response.status.must_equal 401
|
||||
last_response.body.must_equal "Unauthorized"
|
||||
end
|
||||
end
|
||||
|
||||
describe "with wrong token" do
|
||||
it "says it's not authorized" do
|
||||
header "Authorization", "Bearer wrongtoken"
|
||||
delete "/phil/food/aguacate"
|
||||
|
||||
last_response.status.must_equal 401
|
||||
last_response.body.must_equal "Unauthorized"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "authorized" do
|
||||
before do
|
||||
redis.sadd "authorizations:phil:amarillo", [":rw"]
|
||||
@@ -240,13 +339,44 @@ describe "App" do
|
||||
redis.smembers("rs:m:phil:/:items").must_be_empty
|
||||
end
|
||||
|
||||
it "responds with the ETag of the deleted item in the haeder" do
|
||||
it "responds with the ETag of the deleted item in the header" do
|
||||
RestClient.stub :delete, "" do
|
||||
delete "/phil/food/aguacate"
|
||||
end
|
||||
|
||||
last_response.headers["ETag"].must_equal "\"bla\""
|
||||
end
|
||||
|
||||
it "returns a 404 when item doesn't exist" do
|
||||
raises_exception = ->(url, headers) { raise RestClient::ResourceNotFound.new }
|
||||
RestClient.stub :delete, raises_exception do
|
||||
delete "/phil/food/steak"
|
||||
end
|
||||
|
||||
last_response.status.must_equal 404
|
||||
last_response.body.must_equal "Not Found"
|
||||
end
|
||||
|
||||
describe "If-Match header" do
|
||||
it "succeeds when the header matches the current ETag" do
|
||||
header "If-Match", "\"bla\""
|
||||
|
||||
RestClient.stub :delete, "" do
|
||||
delete "/phil/food/aguacate"
|
||||
end
|
||||
|
||||
last_response.status.must_equal 200
|
||||
end
|
||||
|
||||
it "fails the request if it does not match the current ETag" do
|
||||
header "If-Match", "someotheretag"
|
||||
|
||||
delete "/phil/food/aguacate"
|
||||
|
||||
last_response.status.must_equal 412
|
||||
last_response.body.must_equal "Precondition Failed"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -256,6 +386,29 @@ describe "App" do
|
||||
purge_redis
|
||||
end
|
||||
|
||||
context "not authorized" do
|
||||
|
||||
describe "without token" do
|
||||
it "says it's not authorized" do
|
||||
get "/phil/food/"
|
||||
|
||||
last_response.status.must_equal 401
|
||||
last_response.body.must_equal "Unauthorized"
|
||||
end
|
||||
end
|
||||
|
||||
describe "with wrong token" do
|
||||
it "says it's not authorized" do
|
||||
header "Authorization", "Bearer wrongtoken"
|
||||
get "/phil/food/"
|
||||
|
||||
last_response.status.must_equal 401
|
||||
last_response.body.must_equal "Unauthorized"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "authorized" do
|
||||
|
||||
before do
|
||||
@@ -294,6 +447,16 @@ describe "App" do
|
||||
last_response.headers["Content-Type"].must_equal "text/plain; charset=utf-8"
|
||||
end
|
||||
|
||||
it "returns a 404 when data doesn't exist" do
|
||||
raises_exception = ->(url, headers) { raise RestClient::ResourceNotFound.new }
|
||||
RestClient.stub :get, raises_exception do
|
||||
get "/phil/food/steak"
|
||||
end
|
||||
|
||||
last_response.status.must_equal 404
|
||||
last_response.body.must_equal "Not Found"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "directory listings" do
|
||||
@@ -371,6 +534,29 @@ describe "App" do
|
||||
purge_redis
|
||||
end
|
||||
|
||||
context "not authorized" do
|
||||
|
||||
describe "without token" do
|
||||
it "says it's not authorized" do
|
||||
head "/phil/food/camarones"
|
||||
|
||||
last_response.status.must_equal 401
|
||||
last_response.body.must_be_empty
|
||||
end
|
||||
end
|
||||
|
||||
describe "with wrong token" do
|
||||
it "says it's not authorized" do
|
||||
header "Authorization", "Bearer wrongtoken"
|
||||
head "/phil/food/camarones"
|
||||
|
||||
last_response.status.must_equal 401
|
||||
last_response.body.must_be_empty
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "authorized" do
|
||||
|
||||
before do
|
||||
@@ -399,6 +585,18 @@ describe "App" do
|
||||
end
|
||||
end
|
||||
|
||||
describe "data" do
|
||||
it "returns a 404 when data doesn't exist" do
|
||||
raises_exception = ->(url, headers) { raise RestClient::ResourceNotFound.new }
|
||||
RestClient.stub :head, raises_exception do
|
||||
head "/phil/food/steak"
|
||||
end
|
||||
|
||||
last_response.status.must_equal 404
|
||||
last_response.body.must_be_empty
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user