From 634d96f5c694bd13314988aafbd585be1a5a038c Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Thu, 20 Oct 2016 12:21:46 -0700 Subject: [PATCH] add a test for post object with empty conditions Signed-off-by: Yehuda Sadeh --- s3tests/functional/test_s3.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/s3tests/functional/test_s3.py b/s3tests/functional/test_s3.py index d03c9f6..5cdb1e7 100644 --- a/s3tests/functional/test_s3.py +++ b/s3tests/functional/test_s3.py @@ -2287,6 +2287,37 @@ def test_post_object_upload_size_below_minimum(): r = requests.post(url, files = payload) eq(r.status_code, 400) +@attr(resource='object') +@attr(method='post') +@attr(operation='authenticated browser based upload via POST request') +@attr(assertion='empty conditions return appropriate error response') +def test_post_object_empty_conditions(): + bucket = get_new_bucket() + + url = _get_post_url(s3.main, bucket) + + utc = pytz.utc + expires = datetime.datetime.now(utc) + datetime.timedelta(seconds=+6000) + + policy_document = {"expiration": expires.strftime("%Y-%m-%dT%H:%M:%SZ"),\ + "conditions": [\ + { }\ + ]\ + } + + json_policy_document = json.JSONEncoder().encode(policy_document) + policy = base64.b64encode(json_policy_document) + conn = s3.main + signature = base64.b64encode(hmac.new(conn.aws_secret_access_key, policy, sha).digest()) + + payload = OrderedDict([ ("key" , "foo.txt"),("AWSAccessKeyId" , conn.aws_access_key_id),\ + ("acl" , "private"),("signature" , signature),("policy" , policy),\ + ("Content-Type" , "text/plain"),('file', ('bar'))]) + + r = requests.post(url, files = payload) + eq(r.status_code, 400) + + @attr(resource='object') @attr(method='get')