Created
March 19, 2021 21:58
-
-
Save amarjandu/631d741ffa5c554d8a4398843ba54fc3 to your computer and use it in GitHub Desktop.
moto presigned url failure, simple reproduction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import moto | |
import boto3 | |
import requests | |
import tempfile | |
from botocore.config import Config | |
region = 'us-gov-west-1' | |
bucket_name = 'banana-slugs' | |
test_config = Config(region_name=region) | |
class Foo: | |
@moto.mock_sts | |
@moto.mock_s3 | |
def bar(self): | |
client = boto3.client('s3', config=test_config) | |
client = boto3.client('s3', config=test_config) | |
client.create_bucket(Bucket=bucket_name, | |
CreateBucketConfiguration={ | |
'LocationConstraint': region | |
}) | |
file = tempfile.NamedTemporaryFile() | |
file.write(bytes('foobar', 'UTF-8')) | |
client.upload_file(file.name, bucket_name, 'trash-file') | |
presigned_url = client.generate_presigned_url( | |
ClientMethod=client.get_object.__name__, | |
Params={ | |
'Bucket': bucket_name, | |
'Key': 'trash-file', | |
**({'ResponseContentDisposition': f'attachment;filename=bar'}) | |
}) | |
resp = requests.get(presigned_url) | |
print(resp.text) | |
assert resp.status_code == 200 | |
a = Foo() | |
a.bar() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(.venv) CBSEspecter:azul amar$ de | |
CBSEspecter:azul amar$ make virtualenv | |
if test -e .venv; then rm -rf .venv/; fi | |
python3.8 -m venv .venv | |
Run 'source .venv/bin/activate' now! | |
CBSEspecter:azul amar$ ae | |
(.venv) CBSEspecter:azul amar$ pip install moto[all]==2.0.2 | |
Collecting moto[all]==2.0.2 | |
Using cached https://files.pythonhosted.org/packages/ea/34/5d837227ac7e035a8f804d220757d28ef05c11c1b1368b219e6ca8f3292a/moto-2.0.2-py2.py3-none-any.whl | |
Collecting boto3>=1.9.201 (from moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/30/6d/1c43d87bfff9e7afb5130629dfb7d57617245eeb4a474bf77f45d637c3a6/boto3-1.17.33-py2.py3-none-any.whl | |
Collecting six>1.9 (from moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/ee/ff/48bde5c0f013094d729fe4b0316ba2a24774b3ff1c52d924a8a4cb04078a/six-1.15.0-py2.py3-none-any.whl | |
Collecting mock (from moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/5c/03/b7e605db4a57c0f6fba744b11ef3ddf4ddebcada35022927a2b5fc623fdf/mock-4.0.3-py3-none-any.whl | |
Collecting zipp (from moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/0f/8c/715c54e9e34c0c4820f616a913a7de3337d0cd79074dd1bed4dd840f16ae/zipp-3.4.1-py3-none-any.whl | |
Collecting werkzeug (from moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/cc/94/5f7079a0e00bd6863ef8f1da638721e9da21e5bacee597595b318f71d62e/Werkzeug-1.0.1-py2.py3-none-any.whl | |
Collecting responses>=0.9.0 (from moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/b1/a1/162c90162e0f4539534b6ce6d723c4c07be8ad38c1cb975d7c63128502e0/responses-0.13.1-py2.py3-none-any.whl | |
Collecting MarkupSafe<2.0 (from moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/0c/12/37f68957526d1ec0883b521934b4e1b8ff3dd8e4fab858a5bf3e487bcee9/MarkupSafe-1.1.1-cp38-cp38-macosx_10_9_x86_64.whl | |
Requirement already satisfied: setuptools in ./.venv/lib/python3.8/site-packages (from moto[all]==2.0.2) (41.2.0) | |
Collecting cryptography>=3.3.1 (from moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/32/52/4ba2bdec39b51a072a968c2b425c3649777d4816d27832703e082e2c5534/cryptography-3.4.6-cp36-abi3-macosx_10_10_x86_64.whl | |
Collecting xmltodict (from moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/28/fd/30d5c1d3ac29ce229f6bdc40bbc20b28f716e8b363140c26eff19122d8a5/xmltodict-0.12.0-py2.py3-none-any.whl | |
Collecting botocore>=1.12.201 (from moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/dd/1c/f922d7fa47cdd6a18c7470252e86f7c4d24e85cb3cdff09486675df3769c/botocore-1.20.33-py2.py3-none-any.whl | |
Collecting python-dateutil<3.0.0,>=2.1 (from moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/d4/70/d60450c3dd48ef87586924207ae8907090de0b306af2bce5d134d78615cb/python_dateutil-2.8.1-py2.py3-none-any.whl | |
Collecting more-itertools (from moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/05/47/514062a0798c2e9bdfd4514bacf9971fc8961b715f01487e4cfda3cc45a7/more_itertools-8.7.0-py3-none-any.whl | |
Collecting Jinja2>=2.10.1 (from moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/7e/c2/1eece8c95ddbc9b1aeb64f5783a9e07a286de42191b7204d67b7496ddf35/Jinja2-2.11.3-py2.py3-none-any.whl | |
Collecting requests>=2.5 (from moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/29/c1/24814557f1d22c56d50280771a17307e6bf87b70727d975fd6b2ce6b014a/requests-2.25.1-py2.py3-none-any.whl | |
Collecting pytz (from moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/70/94/784178ca5dd892a98f113cdd923372024dc04b8d40abe77ca76b5fb90ca6/pytz-2021.1-py2.py3-none-any.whl | |
Collecting docker>=2.5.1; extra == "all" (from moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/c4/22/410313ad554477e87ec406d38d85f810e61ddb0d2fc44e64994857476de9/docker-4.4.4-py2.py3-none-any.whl | |
Collecting python-jose[cryptography]<4.0.0,>=3.1.0; extra == "all" (from moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/2b/55/bc3e9a4013a50287ec30e653c85cd10f077f8bca73bcda869847bf18cf37/python_jose-3.2.0-py2.py3-none-any.whl | |
Collecting jsondiff>=1.1.2; extra == "all" (from moto[all]==2.0.2) | |
Collecting aws-xray-sdk!=0.96,>=0.93; extra == "all" (from moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/e1/cd/12f2bc3a7683e88abe60ee6e0c09248103052b7532a7cf7ce1fccefa1a71/aws_xray_sdk-2.6.0-py2.py3-none-any.whl | |
Collecting ecdsa<0.15; extra == "all" (from moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/a2/25/3bb32da623b39a27a07d194cd58e4540224421d924661de2e694304ae4fa/ecdsa-0.14.1-py2.py3-none-any.whl | |
Collecting cfn-lint>=0.4.0; extra == "all" (from moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/31/54/f6712193a29803952e59320a45ca1da22a6e71de2a827e4df66642738c3c/cfn_lint-0.47.2-py3-none-any.whl | |
Collecting idna<3,>=2.5; extra == "all" (from moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/a2/38/928ddce2273eaa564f6f50de919327bf3a00f091b5baba8dfa9460f3a8a8/idna-2.10-py2.py3-none-any.whl | |
Collecting PyYAML>=5.1; extra == "all" (from moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/cb/3f/2f35751408c0b2a425aa48dd79301a48418858d3366f84c75d1aa42b6e2d/PyYAML-5.4.1-cp38-cp38-macosx_10_9_x86_64.whl | |
Collecting sshpubkeys>=3.1.0; python_version > "3" and extra == "all" (from moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/e3/76/bc71db2f6830196554e5a197331ad668c049a12fb331075f4f579ff73cb4/sshpubkeys-3.3.1-py2.py3-none-any.whl | |
Collecting jmespath<1.0.0,>=0.7.1 (from boto3>=1.9.201->moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/07/cb/5f001272b6faeb23c1c9e0acc04d48eaaf5c862c17709d20e3469c6e0139/jmespath-0.10.0-py2.py3-none-any.whl | |
Collecting s3transfer<0.4.0,>=0.3.0 (from boto3>=1.9.201->moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/98/14/0b4be62b65c52d6d1c442f24e02d2a9889a73d3c352002e14c70f84a679f/s3transfer-0.3.6-py2.py3-none-any.whl | |
Collecting urllib3>=1.25.10 (from responses>=0.9.0->moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/09/c6/d3e3abe5b4f4f16cf0dfc9240ab7ce10c2baa0e268989a4e3ec19e90c84e/urllib3-1.26.4-py2.py3-none-any.whl | |
Collecting cffi>=1.12 (from cryptography>=3.3.1->moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/57/cc/4c80c4796ca182433502cd20119a2f4b2bab6caa097745ecaf23fc692ae1/cffi-1.14.5-cp38-cp38-macosx_10_9_x86_64.whl | |
Collecting certifi>=2017.4.17 (from requests>=2.5->moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/5e/a0/5f06e1e1d463903cf0c0eebeb751791119ed7a4b3737fdc9a77f1cdfb51f/certifi-2020.12.5-py2.py3-none-any.whl | |
Collecting chardet<5,>=3.0.2 (from requests>=2.5->moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/19/c7/fa589626997dd07bd87d9269342ccb74b1720384a4d739a1872bd84fbe68/chardet-4.0.0-py2.py3-none-any.whl | |
Collecting websocket-client>=0.32.0 (from docker>=2.5.1; extra == "all"->moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/08/33/80e0d4f60e84a1ddd9a03f340be1065a2a363c47ce65c4bd3bae65ce9631/websocket_client-0.58.0-py2.py3-none-any.whl | |
Collecting pyasn1 (from python-jose[cryptography]<4.0.0,>=3.1.0; extra == "all"->moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/62/1e/a94a8d635fa3ce4cfc7f506003548d0a2447ae76fd5ca53932970fe3053f/pyasn1-0.4.8-py2.py3-none-any.whl | |
Collecting rsa (from python-jose[cryptography]<4.0.0,>=3.1.0; extra == "all"->moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/e9/93/0c0f002031f18b53af7a6166103c02b9c0667be528944137cc954ec921b3/rsa-4.7.2-py3-none-any.whl | |
Collecting jsonpickle (from aws-xray-sdk!=0.96,>=0.93; extra == "all"->moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/bb/1a/f2db026d4d682303793559f1c2bb425ba3ec0d6fd7ac63397790443f2461/jsonpickle-2.0.0-py2.py3-none-any.whl | |
Collecting future (from aws-xray-sdk!=0.96,>=0.93; extra == "all"->moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/45/0b/38b06fd9b92dc2b68d58b75f900e97884c45bedd2ff83203d933cf5851c9/future-0.18.2.tar.gz | |
Collecting wrapt (from aws-xray-sdk!=0.96,>=0.93; extra == "all"->moto[all]==2.0.2) | |
Collecting junit-xml~=1.9 (from cfn-lint>=0.4.0; extra == "all"->moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/2a/93/2d896b5fd3d79b4cadd8882c06650e66d003f465c9d12c488d92853dff78/junit_xml-1.9-py2.py3-none-any.whl | |
Collecting jsonschema~=3.0 (from cfn-lint>=0.4.0; extra == "all"->moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/c5/8f/51e89ce52a085483359217bc72cdbf6e75ee595d5b1d4b5ade40c7e018b8/jsonschema-3.2.0-py2.py3-none-any.whl | |
Collecting networkx~=2.4; python_version >= "3.5" (from cfn-lint>=0.4.0; extra == "all"->moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/9b/cd/dc52755d30ba41c60243235460961fc28022e5b6731f16c268667625baea/networkx-2.5-py3-none-any.whl | |
Collecting aws-sam-translator>=1.34.0 (from cfn-lint>=0.4.0; extra == "all"->moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/99/76/0c14af2d6ee91022d69851a12454545e49791175c74025a2b9e3ccc2a7af/aws_sam_translator-1.35.0-py3-none-any.whl | |
Collecting jsonpatch; python_version != "3.4" (from cfn-lint>=0.4.0; extra == "all"->moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/a3/55/f7c93bae36d869292aedfbcbae8b091386194874f16390d680136edd2b28/jsonpatch-1.32-py2.py3-none-any.whl | |
Collecting pycparser (from cffi>=1.12->cryptography>=3.3.1->moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/ae/e7/d9c3a176ca4b02024debf82342dab36efadfc5776f9c8db077e8f6e71821/pycparser-2.20-py2.py3-none-any.whl | |
Collecting pyrsistent>=0.14.0 (from jsonschema~=3.0->cfn-lint>=0.4.0; extra == "all"->moto[all]==2.0.2) | |
Collecting attrs>=17.4.0 (from jsonschema~=3.0->cfn-lint>=0.4.0; extra == "all"->moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/c3/aa/cb45262569fcc047bf070b5de61813724d6726db83259222cd7b4c79821a/attrs-20.3.0-py2.py3-none-any.whl | |
Collecting decorator>=4.3.0 (from networkx~=2.4; python_version >= "3.5"->cfn-lint>=0.4.0; extra == "all"->moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/ed/1b/72a1821152d07cf1d8b6fce298aeb06a7eb90f4d6d41acec9861e7cc6df0/decorator-4.4.2-py2.py3-none-any.whl | |
Collecting jsonpointer>=1.9 (from jsonpatch; python_version != "3.4"->cfn-lint>=0.4.0; extra == "all"->moto[all]==2.0.2) | |
Using cached https://files.pythonhosted.org/packages/23/52/05f67532aa922e494c351344e0d9624a01f74f5dd8402fe0d1b563a6e6fc/jsonpointer-2.1-py2.py3-none-any.whl | |
Installing collected packages: jmespath, six, python-dateutil, urllib3, botocore, s3transfer, boto3, mock, zipp, werkzeug, certifi, idna, chardet, requests, responses, MarkupSafe, pycparser, cffi, cryptography, xmltodict, more-itertools, Jinja2, pytz, websocket-client, docker, pyasn1, rsa, ecdsa, python-jose, jsondiff, jsonpickle, future, wrapt, aws-xray-sdk, junit-xml, PyYAML, pyrsistent, attrs, jsonschema, decorator, networkx, aws-sam-translator, jsonpointer, jsonpatch, cfn-lint, sshpubkeys, moto | |
Running setup.py install for future ... done | |
Successfully installed Jinja2-2.11.3 MarkupSafe-1.1.1 PyYAML-5.4.1 attrs-20.3.0 aws-sam-translator-1.35.0 aws-xray-sdk-2.6.0 boto3-1.17.33 botocore-1.20.33 certifi-2020.12.5 cffi-1.14.5 cfn-lint-0.47.2 chardet-4.0.0 cryptography-3.4.6 decorator-4.4.2 docker-4.4.4 ecdsa-0.14.1 future-0.18.2 idna-2.10 jmespath-0.10.0 jsondiff-1.2.0 jsonpatch-1.32 jsonpickle-2.0.0 jsonpointer-2.1 jsonschema-3.2.0 junit-xml-1.9 mock-4.0.3 more-itertools-8.7.0 moto-2.0.2 networkx-2.5 pyasn1-0.4.8 pycparser-2.20 pyrsistent-0.17.3 python-dateutil-2.8.1 python-jose-3.2.0 pytz-2021.1 requests-2.25.1 responses-0.13.1 rsa-4.7.2 s3transfer-0.3.6 six-1.15.0 sshpubkeys-3.3.1 urllib3-1.26.4 websocket-client-0.58.0 werkzeug-1.0.1 wrapt-1.12.1 xmltodict-0.12.0 zipp-3.4.1 | |
WARNING: You are using pip version 19.2.3, however version 21.0.1 is available. | |
You should consider upgrading via the 'pip install --upgrade pip' command. | |
(.venv) CBSEspecter:azul amar$ cat simple-reproduction.py | |
import moto | |
import boto3 | |
import requests | |
import tempfile | |
from botocore.config import Config | |
region = 'us-gov-west-1' | |
bucket_name = 'banana-slugs' | |
test_config = Config(region_name=region) | |
class Foo: | |
@moto.mock_sts | |
@moto.mock_s3 | |
def bar(self): | |
client = boto3.client('s3', config=test_config) | |
client = boto3.client('s3', config=test_config) | |
client.create_bucket(Bucket=bucket_name, | |
CreateBucketConfiguration={ | |
'LocationConstraint': region | |
}) | |
file = tempfile.NamedTemporaryFile() | |
file.write(bytes('foobar', 'UTF-8')) | |
client.upload_file(file.name, bucket_name, 'trash-file') | |
presigned_url = client.generate_presigned_url( | |
ClientMethod=client.get_object.__name__, | |
Params={ | |
'Bucket': bucket_name, | |
'Key': 'trash-file', | |
**({'ResponseContentDisposition': f'attachment;filename=bar'}) | |
}) | |
resp = requests.get(presigned_url) | |
print(resp.text) | |
assert resp.status_code == 200 | |
a = Foo() | |
a.bar() | |
(.venv) CBSEspecter:azul amar$ python simple-reproduction.py | |
The method is not implemented | |
Traceback (most recent call last): | |
File "simple-reproduction.py", line 37, in <module> | |
a.bar() | |
File "/Users/amar/dev/hca/azul/.venv/lib/python3.8/site-packages/moto/core/models.py", line 106, in wrapper | |
result = func(*args, **kwargs) | |
File "/Users/amar/dev/hca/azul/.venv/lib/python3.8/site-packages/moto/core/models.py", line 106, in wrapper | |
result = func(*args, **kwargs) | |
File "simple-reproduction.py", line 35, in bar | |
assert resp.status_code == 200 | |
AssertionError | |
(.venv) CBSEspecter:azul amar$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment