* Update the s3 post functionality to better support success_action_redirect
- Add the bucket/key values to the redirect url like s3 does, which
supports code that relies on the key value being there on the
redirect.
- Add support for replacing ${filename} in the key value with the actual
filename from the form upload.
See Issue #3667
* Update s3 tests for changed success_action_redirect behavior
- Adds a new test called test_s3_server_post_to_bucket_redirect that
tests both the ${filename} replacement and the key/value addition to the
redirect query args
- Updated the test_creating_presigned_post checks to handle the
key/value additions to the redirect url.
* Fix test updates to work with python2.7
- remove f-string usage
- fix urllib.parse imports to use six
Co-authored-by: Wynn Wilkes <wynn@leading2lean.com>
This commit is contained in:
parent
46679b3b02
commit
891118a7c7
3 changed files with 76 additions and 11 deletions
|
|
@ -1,5 +1,6 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
|
|
@ -11,7 +12,14 @@ from moto.core.utils import (
|
|||
py2_strip_unicode_keys,
|
||||
unix_time_millis,
|
||||
)
|
||||
from six.moves.urllib.parse import parse_qs, urlparse, unquote, parse_qsl
|
||||
from six.moves.urllib.parse import (
|
||||
parse_qs,
|
||||
parse_qsl,
|
||||
urlparse,
|
||||
unquote,
|
||||
urlencode,
|
||||
urlunparse,
|
||||
)
|
||||
|
||||
import xmltodict
|
||||
|
||||
|
|
@ -859,10 +867,28 @@ class ResponseObject(_TemplateEnvironmentMixin, ActionAuthenticatorMixin):
|
|||
if "file" in form:
|
||||
f = form["file"]
|
||||
else:
|
||||
f = request.files["file"].stream.read()
|
||||
fobj = request.files["file"]
|
||||
f = fobj.stream.read()
|
||||
key = key.replace("${filename}", os.path.basename(fobj.filename))
|
||||
|
||||
if "success_action_redirect" in form:
|
||||
response_headers["Location"] = form["success_action_redirect"]
|
||||
redirect = form["success_action_redirect"]
|
||||
parts = urlparse(redirect)
|
||||
queryargs = parse_qs(parts.query)
|
||||
queryargs["key"] = key
|
||||
queryargs["bucket"] = bucket_name
|
||||
redirect_queryargs = urlencode(queryargs, doseq=True)
|
||||
newparts = (
|
||||
parts.scheme,
|
||||
parts.netloc,
|
||||
parts.path,
|
||||
parts.params,
|
||||
redirect_queryargs,
|
||||
parts.fragment,
|
||||
)
|
||||
fixed_redirect = urlunparse(newparts)
|
||||
|
||||
response_headers["Location"] = fixed_redirect
|
||||
|
||||
if "success_action_status" in form:
|
||||
status_code = form["success_action_status"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue