2013-07-08 23:40:24 +00:00
|
|
|
import requests
|
|
|
|
|
2024-01-07 12:03:33 +00:00
|
|
|
from moto import mock_aws, settings
|
2017-02-24 00:43:48 +00:00
|
|
|
|
|
|
|
if settings.TEST_SERVER_MODE:
|
2017-03-13 01:04:19 +00:00
|
|
|
BASE_URL = "http://localhost:5000"
|
2017-02-24 00:43:48 +00:00
|
|
|
else:
|
|
|
|
BASE_URL = "http://169.254.169.254"
|
2013-07-08 23:40:24 +00:00
|
|
|
|
|
|
|
|
2024-01-07 12:03:33 +00:00
|
|
|
@mock_aws
|
2023-12-14 21:35:36 +00:00
|
|
|
def test_latest_meta_data() -> None:
|
2022-11-17 22:41:08 +00:00
|
|
|
res = requests.get(f"{BASE_URL}/latest/meta-data/")
|
2023-07-10 21:04:31 +00:00
|
|
|
assert res.content == b"iam"
|
2013-07-08 23:40:24 +00:00
|
|
|
|
|
|
|
|
2024-01-07 12:03:33 +00:00
|
|
|
@mock_aws
|
2023-12-14 21:35:36 +00:00
|
|
|
def test_meta_data_iam() -> None:
|
2022-11-17 22:41:08 +00:00
|
|
|
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"]
|
2023-07-10 21:04:31 +00:00
|
|
|
assert "AccessKeyId" in default_role
|
|
|
|
assert "SecretAccessKey" in default_role
|
|
|
|
assert "Token" in default_role
|
|
|
|
assert "Expiration" in default_role
|
2013-07-08 23:40:24 +00:00
|
|
|
|
|
|
|
|
2024-01-07 12:03:33 +00:00
|
|
|
@mock_aws
|
2023-12-14 21:35:36 +00:00
|
|
|
def test_meta_data_security_credentials() -> None:
|
2022-11-17 22:41:08 +00:00
|
|
|
res = requests.get(f"{BASE_URL}/latest/meta-data/iam/security-credentials/")
|
2023-07-10 21:04:31 +00:00
|
|
|
assert res.content == b"default-role"
|
2013-07-08 23:40:24 +00:00
|
|
|
|
|
|
|
|
2024-01-07 12:03:33 +00:00
|
|
|
@mock_aws
|
2023-12-14 21:35:36 +00:00
|
|
|
def test_meta_data_default_role() -> None:
|
2017-02-24 02:37:43 +00:00
|
|
|
res = requests.get(
|
2022-11-17 22:41:08 +00:00
|
|
|
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()
|
2023-07-10 21:04:31 +00:00
|
|
|
assert "AccessKeyId" in json_response
|
|
|
|
assert "SecretAccessKey" in json_response
|
|
|
|
assert "Token" in json_response
|
|
|
|
assert "Expiration" in json_response
|