* 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,6 +1,8 @@
|
|||
# coding=utf-8
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import io
|
||||
from six.moves.urllib.parse import urlparse, parse_qs
|
||||
import sure # noqa
|
||||
|
||||
from flask.testing import FlaskClient
|
||||
|
|
@ -80,6 +82,39 @@ def test_s3_server_post_to_bucket():
|
|||
res.data.should.equal(b"nothing")
|
||||
|
||||
|
||||
def test_s3_server_post_to_bucket_redirect():
|
||||
test_client = authenticated_client()
|
||||
|
||||
res = test_client.put("/", "http://tester.localhost:5000/")
|
||||
res.status_code.should.equal(200)
|
||||
|
||||
redirect_base = "https://redirect.com/success/"
|
||||
filecontent = "nothing"
|
||||
filename = "test_filename.txt"
|
||||
res = test_client.post(
|
||||
"/",
|
||||
"https://tester.localhost:5000/",
|
||||
data={
|
||||
"key": "asdf/the-key/${filename}",
|
||||
"file": (io.BytesIO(filecontent.encode("utf8")), filename),
|
||||
"success_action_redirect": redirect_base,
|
||||
},
|
||||
)
|
||||
real_key = "asdf/the-key/{}".format(filename)
|
||||
res.status_code.should.equal(303)
|
||||
redirect = res.headers["location"]
|
||||
assert redirect.startswith(redirect_base)
|
||||
|
||||
parts = urlparse(redirect)
|
||||
args = parse_qs(parts.query)
|
||||
assert args["key"][0] == real_key
|
||||
assert args["bucket"][0] == "tester"
|
||||
|
||||
res = test_client.get("/{}".format(real_key), "http://tester.localhost:5000/")
|
||||
res.status_code.should.equal(200)
|
||||
res.data.should.equal(filecontent.encode("utf8"))
|
||||
|
||||
|
||||
def test_s3_server_post_without_content_length():
|
||||
test_client = authenticated_client()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue