@@ -10140,13 +10140,6 @@ def post_generated_presigned_post_with_default_file(
10140
10140
allow_redirects = False ,
10141
10141
)
10142
10142
10143
- @staticmethod
10144
- def parse_response_xml (content : bytes ) -> dict :
10145
- if not is_aws_cloud ():
10146
- # AWS use double quotes in error messages and LocalStack uses single. Try to unify before snapshotting
10147
- content = content .replace (b"'" , b'"' )
10148
- return xmltodict .parse (content )
10149
-
10150
10143
@markers .aws .validated
10151
10144
@pytest .mark .xfail (
10152
10145
reason = "failing sporadically with new HTTP gateway (only in CI)" ,
@@ -10763,8 +10756,7 @@ def test_post_object_policy_conditions_validation_eq(self, s3_bucket, aws_client
10763
10756
10764
10757
# assert that it's rejected
10765
10758
assert response .status_code == 403
10766
- resp_content = self .parse_response_xml (response .content )
10767
- snapshot .match ("invalid-condition-eq" , resp_content )
10759
+ snapshot .match ("invalid-condition-eq" , xmltodict .parse (response .content ))
10768
10760
10769
10761
# PostObject with a wrong condition (missing $ prefix)
10770
10762
presigned_request = aws_client .s3 .generate_presigned_post (
@@ -10781,8 +10773,7 @@ def test_post_object_policy_conditions_validation_eq(self, s3_bucket, aws_client
10781
10773
10782
10774
# assert that it's rejected
10783
10775
assert response .status_code == 403
10784
- resp_content = self .parse_response_xml (response .content )
10785
- snapshot .match ("invalid-condition-missing-prefix" , resp_content )
10776
+ snapshot .match ("invalid-condition-missing-prefix" , xmltodict .parse (response .content ))
10786
10777
10787
10778
# PostObject with a wrong condition (multiple condition in one dict)
10788
10779
presigned_request = aws_client .s3 .generate_presigned_post (
@@ -10799,8 +10790,7 @@ def test_post_object_policy_conditions_validation_eq(self, s3_bucket, aws_client
10799
10790
10800
10791
# assert that it's rejected
10801
10792
assert response .status_code == 400
10802
- resp_content = self .parse_response_xml (response .content )
10803
- snapshot .match ("invalid-condition-wrong-condition" , resp_content )
10793
+ snapshot .match ("invalid-condition-wrong-condition" , xmltodict .parse (response .content ))
10804
10794
10805
10795
# PostObject with a wrong condition value casing
10806
10796
presigned_request = aws_client .s3 .generate_presigned_post (
@@ -10815,8 +10805,7 @@ def test_post_object_policy_conditions_validation_eq(self, s3_bucket, aws_client
10815
10805
response = self .post_generated_presigned_post_with_default_file (presigned_request )
10816
10806
# assert that it's rejected
10817
10807
assert response .status_code == 403
10818
- resp_content = self .parse_response_xml (response .content )
10819
- snapshot .match ("invalid-condition-wrong-value-casing" , resp_content )
10808
+ snapshot .match ("invalid-condition-wrong-value-casing" , xmltodict .parse (response .content ))
10820
10809
10821
10810
object_expires = rfc_1123_datetime (
10822
10811
datetime .datetime .now (ZoneInfo ("GMT" )) + datetime .timedelta (minutes = 10 )
@@ -10948,17 +10937,15 @@ def test_post_object_policy_conditions_validation_starts_with(
10948
10937
10949
10938
# assert that it's rejected
10950
10939
assert response .status_code == 403
10951
- resp_content = self .parse_response_xml (response .content )
10952
- snapshot .match ("invalid-condition-starts-with" , resp_content )
10940
+ snapshot .match ("invalid-condition-starts-with" , xmltodict .parse (response .content ))
10953
10941
10954
10942
# PostObject with a right redirect location start but wrong casing
10955
10943
presigned_request ["fields" ]["success_action_redirect" ] = "HTTP://localhost.test/random"
10956
10944
response = self .post_generated_presigned_post_with_default_file (presigned_request )
10957
10945
10958
10946
# assert that it's rejected
10959
10947
assert response .status_code == 403
10960
- resp_content = self .parse_response_xml (response .content )
10961
- snapshot .match ("invalid-condition-starts-with-casing" , resp_content )
10948
+ snapshot .match ("invalid-condition-starts-with-casing" , xmltodict .parse (response .content ))
10962
10949
10963
10950
# PostObject with a right redirect location start
10964
10951
presigned_request ["fields" ]["success_action_redirect" ] = redirect_location
@@ -11079,6 +11066,45 @@ def test_post_object_policy_validation_size(self, s3_bucket, aws_client, snapsho
11079
11066
final_object = aws_client .s3 .get_object (Bucket = s3_bucket , Key = object_key )
11080
11067
snapshot .match ("final-object" , final_object )
11081
11068
11069
+ # try with string values for the content length range
11070
+ presigned_request = aws_client .s3 .generate_presigned_post (
11071
+ Bucket = s3_bucket ,
11072
+ Key = object_key ,
11073
+ ExpiresIn = 60 ,
11074
+ Conditions = [
11075
+ {"bucket" : s3_bucket },
11076
+ ["content-length-range" , "5" , "10" ],
11077
+ ],
11078
+ )
11079
+ # PostObject with a body length of 10
11080
+ response = requests .post (
11081
+ presigned_request ["url" ],
11082
+ data = presigned_request ["fields" ],
11083
+ files = {"file" : "a" * 10 },
11084
+ verify = False ,
11085
+ )
11086
+ assert response .status_code == 204
11087
+
11088
+ # try with string values that are not cast-able for the content length range
11089
+ presigned_request = aws_client .
F438
s3 .generate_presigned_post (
11090
+ Bucket = s3_bucket ,
11091
+ Key = object_key ,
11092
+ ExpiresIn = 60 ,
11093
+ Conditions = [
11094
+ {"bucket" : s3_bucket },
11095
+ ["content-length-range" , "test" , "10" ],
11096
+ ],
11097
+ )
11098
+ # PostObject with a body length of 10
11099
+ response = requests .post (
11100
+ presigned_request ["url" ],
11101
+ data = presigned_request ["fields" ],
11102
+ files = {"file" : "a" * 10 },
11103
+ verify = False ,
11104
+ )
11105
+ assert response .status_code == 403
11106
+ snapshot .match ("invalid-content-length-wrong-type" , xmltodict .parse (response .content ))
11107
+
11082
11108
@pytest .mark .skipif (
11083
11109
condition = TEST_S3_IMAGE or LEGACY_V2_S3_PROVIDER ,
11084
11110
reason = "STS not enabled in S3 image / moto does not implement this" ,
0 commit comments