From 0474a47b4b234dcdd2a4ecb57f6a1ebca839980a Mon Sep 17 00:00:00 2001 From: Philip Montgomery Date: Sat, 21 Nov 2015 00:19:45 -0500 Subject: [PATCH] Added support and test for If-Match on object get --- lib/fakes3/server.rb | 6 ++++++ test/right_aws_commands_test.rb | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/fakes3/server.rb b/lib/fakes3/server.rb index 00affde9..30bf4108 100644 --- a/lib/fakes3/server.rb +++ b/lib/fakes3/server.rb @@ -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 diff --git a/test/right_aws_commands_test.rb b/test/right_aws_commands_test.rb index 18a433c6..163db458 100644 --- a/test/right_aws_commands_test.rb +++ b/test/right_aws_commands_test.rb @@ -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")