Send "Not Found" message body with 404 responses (refs #42)
This commit is contained in:
parent
83d8f29a04
commit
cc91b5c4cd
@ -57,7 +57,7 @@ module RemoteStorage
|
|||||||
|
|
||||||
return res.body
|
return res.body
|
||||||
rescue RestClient::ResourceNotFound
|
rescue RestClient::ResourceNotFound
|
||||||
server.halt 404
|
server.halt 404, "Not Found"
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_head_directory_listing(user, directory)
|
def get_head_directory_listing(user, directory)
|
||||||
@ -187,7 +187,7 @@ module RemoteStorage
|
|||||||
|
|
||||||
server.halt 200
|
server.halt 200
|
||||||
rescue RestClient::ResourceNotFound
|
rescue RestClient::ResourceNotFound
|
||||||
server.halt 404
|
server.halt 404, "Not Found"
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@ -263,6 +263,16 @@ describe "App" do
|
|||||||
|
|
||||||
redis.smembers("rs:m:phil:/:items").must_be_empty
|
redis.smembers("rs:m:phil:/:items").must_be_empty
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -313,6 +323,20 @@ describe "App" do
|
|||||||
end
|
end
|
||||||
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
|
describe "directory listings" do
|
||||||
|
|
||||||
it "has an ETag in the header" do
|
it "has an ETag in the header" do
|
||||||
@ -364,5 +388,58 @@ describe "App" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
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
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user