moto/tests/test_core/test_instance_metadata.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

45 lines
1.3 KiB
Python
Raw Normal View History

2021-10-18 19:44:29 +00:00
import sure # noqa # pylint: disable=unused-import
2013-07-08 23:40:24 +00:00
import requests
from moto import mock_ec2, settings
if settings.TEST_SERVER_MODE:
BASE_URL = "http://localhost:5000"
else:
BASE_URL = "http://169.254.169.254"
2013-07-08 23:40:24 +00:00
@mock_ec2
def test_latest_meta_data():
res = requests.get(f"{BASE_URL}/latest/meta-data/")
2014-08-26 17:25:50 +00:00
res.content.should.equal(b"iam")
2013-07-08 23:40:24 +00:00
@mock_ec2
def test_meta_data_iam():
res = requests.get(f"{BASE_URL}/latest/meta-data/iam")
2013-07-08 23:40:24 +00:00
json_response = res.json()
default_role = json_response["security-credentials"]["default-role"]
default_role.should.contain("AccessKeyId")
default_role.should.contain("SecretAccessKey")
default_role.should.contain("Token")
default_role.should.contain("Expiration")
@mock_ec2
def test_meta_data_security_credentials():
res = requests.get(f"{BASE_URL}/latest/meta-data/iam/security-credentials/")
2014-08-26 17:25:50 +00:00
res.content.should.equal(b"default-role")
2013-07-08 23:40:24 +00:00
@mock_ec2
def test_meta_data_default_role():
2017-02-24 02:37:43 +00:00
res = requests.get(
f"{BASE_URL}/latest/meta-data/iam/security-credentials/default-role"
2019-10-31 15:44:26 +00:00
)
2013-07-08 23:40:24 +00:00
json_response = res.json()
json_response.should.contain("AccessKeyId")
json_response.should.contain("SecretAccessKey")
json_response.should.contain("Token")
json_response.should.contain("Expiration")