Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Added support and test for If-Match on object get #129

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/fakes3/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ def do_GET(request, response)
return
end

if_match = request["If-Match"]
if if_match and (if_match != "\"#{real_obj.md5}\"" and if_match != "*")
response.status = 412
return
end

if_none_match = request["If-None-Match"]
if if_none_match == "\"#{real_obj.md5}\"" or if_none_match == "*"
response.status = 304
Expand Down
16 changes: 16 additions & 0 deletions test/right_aws_commands_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,22 @@ def test_destroy_bucket

end

def test_if_match
@s3.put("s3media","if_match_test","Hello World 1!")
obj = @s3.get("s3media","if_match_test")
tag = obj[:headers]["etag"]
obj = @s3.get("s3media", "if_match_test", {"If-Match"=>tag})
assert_equal "Hello World 1!",obj[:object]
@s3.put("s3media","if_match_test","Hello World 2!")
begin
@s3.get("s3media", "if_match_test", {"If-Match"=>tag})
rescue RightAws::AwsError
# expected error for 412
else
fail 'Should have encountered an error due to the server not returning a response due to caching'
end
end

def test_if_none_match
@s3.put("s3media","if_none_match_test","Hello World 1!")
obj = @s3.get("s3media","if_none_match_test")
Expand Down