Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def run(self):
"""Start and run the mock S3 server."""
app = moto.server.DomainDispatcherApplication(moto.server.create_backend_app, service='s3')
moto.server.run_simple('0.0.0.0', self.port, app, threaded=True)
def test_iot_list():
backend = server.create_backend_app("iot")
test_client = backend.test_client()
# just making sure that server is up
res = test_client.get("/things")
res.status_code.should.equal(404)
def test_rotate_secret_that_does_not_match():
backend = server.create_backend_app("secretsmanager")
test_client = backend.test_client()
create_secret = test_client.post(
"/",
data={"Name": DEFAULT_SECRET_NAME, "SecretString": "foosecret"},
headers={"X-Amz-Target": "secretsmanager.CreateSecret"},
)
rotate_secret = test_client.post(
"/",
data={"SecretId": "i-dont-match"},
headers={"X-Amz-Target": "secretsmanager.RotateSecret"},
)
json_data = json.loads(rotate_secret.data.decode("utf-8"))
assert json_data["message"] == "Secrets Manager can't find the specified secret"
def test_list_streams():
backend = server.create_backend_app("kinesis")
test_client = backend.test_client()
res = test_client.get("/?Action=ListStreams")
json_data = json.loads(res.data.decode("utf-8"))
json_data.should.equal({"HasMoreStreams": False, "StreamNames": []})
def test_sqs_list_identities():
backend = server.create_backend_app("sqs")
test_client = backend.test_client()
res = test_client.get("/?Action=ListQueues")
res.data.should.contain(b"ListQueuesResponse")
# Make sure that we can receive messages from queues whose name contains dots (".")
# The AWS API mandates that the names of FIFO queues use the suffix ".fifo"
# See: https://github.com/spulec/moto/issues/866
for queue_name in ("testqueue", "otherqueue.fifo"):
res = test_client.put("/?Action=CreateQueue&QueueName=%s" % queue_name)
res = test_client.put(
"/123/%s?MessageBody=test-message&Action=SendMessage" % queue_name
)
def test_messages_polling():
backend = server.create_backend_app("sqs")
test_client = backend.test_client()
messages = []
test_client.put("/?Action=CreateQueue&QueueName=testqueue")
def insert_messages():
messages_count = 5
while messages_count > 0:
test_client.put(
"/123/testqueue?MessageBody=test-message&Action=SendMessage"
"&Attribute.1.Name=WaitTimeSeconds&Attribute.1.Value=10"
)
messages_count -= 1
time.sleep(0.5)
def get_messages():
def test_rotate_secret_client_request_token_too_short():
backend = server.create_backend_app("secretsmanager")
test_client = backend.test_client()
create_secret = test_client.post(
"/",
data={"Name": DEFAULT_SECRET_NAME, "SecretString": "foosecret"},
headers={"X-Amz-Target": "secretsmanager.CreateSecret"},
)
client_request_token = "ED9F8B6C-85B7-B7E4-38F2A3BEB13C"
rotate_secret = test_client.post(
"/",
data={
"SecretId": DEFAULT_SECRET_NAME,
"ClientRequestToken": client_request_token,
},
headers={"X-Amz-Target": "secretsmanager.RotateSecret"},
def test_put_secret_value_versions_differ_if_same_secret_put_twice():
backend = server.create_backend_app("secretsmanager")
test_client = backend.test_client()
put_first_secret_value_json = test_client.post(
"/",
data={
"SecretId": DEFAULT_SECRET_NAME,
"SecretString": "secret",
"VersionStages": ["AWSCURRENT"],
},
headers={"X-Amz-Target": "secretsmanager.PutSecretValue"},
)
first_secret_json_data = json.loads(
put_first_secret_value_json.data.decode("utf-8")
)
first_secret_version_id = first_secret_json_data["VersionId"]
def test_resourcegroupstaggingapi_list():
backend = server.create_backend_app("resourcegroupstaggingapi")
test_client = backend.test_client()
# do test
headers = {
"X-Amz-Target": "ResourceGroupsTaggingAPI_20170126.GetResources",
"X-Amz-Date": "20171114T234623Z",
}
resp = test_client.post("/", headers=headers, data="{}")
assert resp.status_code == 200
assert b"ResourceTagMappingList" in resp.data
all_objects = muppy.get_objects()
result = summary.summarize(all_objects)
result = result[0:20]
summary = '\n'.join([l for l in summary.format_(result)])
result = '%s\n\n%s' % (summary, json.dumps(result))
return result, 200, {'content-type': 'text/plain'}
def create_backend_app(service):
backend_app = moto_server.create_backend_app_orig(service)
backend_app.add_url_rule(
'/_stats', endpoint='_get_stats', methods=['GET'], view_func=_get_stats, strict_slashes=False)
return backend_app
if not hasattr(moto_server, 'create_backend_app_orig'):
moto_server.create_backend_app_orig = moto_server.create_backend_app
moto_server.create_backend_app = create_backend_app