Send "Not Found" message body with 404 responses (refs #42)

This commit is contained in:
Garret Alfert 2016-06-02 13:18:16 +02:00
parent 83d8f29a04
commit cc91b5c4cd
2 changed files with 79 additions and 2 deletions

View File

@ -57,7 +57,7 @@ module RemoteStorage
return res.body
rescue RestClient::ResourceNotFound
server.halt 404
server.halt 404, "Not Found"
end
def get_head_directory_listing(user, directory)
@ -187,7 +187,7 @@ module RemoteStorage
server.halt 200
rescue RestClient::ResourceNotFound
server.halt 404
server.halt 404, "Not Found"
end
private

View File

@ -263,6 +263,16 @@ describe "App" do
redis.smembers("rs:m:phil:/:items").must_be_empty
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
end
end
@ -313,6 +323,20 @@ 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 :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
it "has an ETag in the header" do
@ -364,5 +388,58 @@ describe "App" do
end
end
describe "HEAD requests" do
before 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
redis.sadd "authorizations:phil:amarillo", [":rw"]
header "Authorization", "Bearer amarillo"
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
end