This commit is contained in:
Daniel Wallace 2020-04-21 21:43:32 -05:00
parent 4b0ba73204
commit 80b27a6b93
No known key found for this signature in database
GPG Key ID: 9FD9048A8BD617F2
2 changed files with 24 additions and 17 deletions

View File

@ -797,12 +797,12 @@ class ResponseObject(_TemplateEnvironmentMixin, ActionAuthenticatorMixin):
if hasattr(request, "form"):
# Not HTTPretty
form = request.form
elif request.headers.get('Content-Type').startswith('multipart/form-data'):
elif request.headers.get("Content-Type").startswith("multipart/form-data"):
request = Request.from_values(
input_stream=six.BytesIO(request.body),
content_length=request.headers['Content-Length'],
content_type=request.headers['Content-Type'],
method='POST',
content_length=request.headers["Content-Length"],
content_type=request.headers["Content-Type"],
method="POST",
)
form = request.form
else:

View File

@ -4433,30 +4433,37 @@ def test_s3_config_dict():
@mock_s3
def test_creating_presigned_post():
bucket = 'presigned-test'
s3 = boto3.client('s3', region_name='us-east-1')
bucket = "presigned-test"
s3 = boto3.client("s3", region_name="us-east-1")
s3.create_bucket(Bucket=bucket)
success_url = 'http://localhost/completed'
fdata = b'test data\n'
success_url = "http://localhost/completed"
fdata = b"test data\n"
file_uid = uuid.uuid4()
conditions = [
{"Content-Type": 'text/plain'},
{"Content-Type": "text/plain"},
{"x-amz-server-side-encryption": "AES256"},
{'success_action_redirect': success_url},
{"success_action_redirect": success_url},
]
conditions.append(["content-length-range", 1, 30])
data = s3.generate_presigned_post(
Bucket=bucket,
Key='{file_uid}.txt'.format(file_uid=file_uid),
Key="{file_uid}.txt".format(file_uid=file_uid),
Fields={
'content-type': 'text/plain',
'success_action_redirect': success_url,
'x-amz-server-side-encryption': 'AES256'
"content-type": "text/plain",
"success_action_redirect": success_url,
"x-amz-server-side-encryption": "AES256",
},
Conditions=conditions,
ExpiresIn=1000,
)
resp = requests.post(data['url'], data=data['fields'], files={'file': fdata}, allow_redirects=False)
assert resp.headers['Location'] == success_url
resp = requests.post(
data["url"], data=data["fields"], files={"file": fdata}, allow_redirects=False
)
assert resp.headers["Location"] == success_url
assert resp.status_code == 303
assert s3.get_object(Bucket=bucket, Key='{file_uid}.txt'.format(file_uid=file_uid))['Body'].read() == fdata
assert (
s3.get_object(Bucket=bucket, Key="{file_uid}.txt".format(file_uid=file_uid))[
"Body"
].read()
== fdata
)