2023-08-07 16:48:48 +00:00
|
|
|
from unittest import SkipTest
|
|
|
|
|
2022-08-13 09:49:43 +00:00
|
|
|
import requests
|
|
|
|
|
|
|
|
from moto import settings
|
|
|
|
from moto.server import ThreadedMotoServer
|
|
|
|
|
|
|
|
|
|
|
|
SERVER_PORT = 5001
|
|
|
|
BASE_URL = f"http://localhost:{SERVER_PORT}/"
|
|
|
|
|
|
|
|
|
|
|
|
class TestAccountIdResolution:
|
2022-10-28 00:37:11 +00:00
|
|
|
def setup_method(self):
|
2022-08-13 09:49:43 +00:00
|
|
|
if settings.TEST_SERVER_MODE:
|
|
|
|
raise SkipTest(
|
|
|
|
"No point in testing this in ServerMode, as we already start our own server"
|
|
|
|
)
|
|
|
|
self.server = ThreadedMotoServer(port=SERVER_PORT, verbose=False)
|
|
|
|
self.server.start()
|
|
|
|
|
2022-10-28 00:37:11 +00:00
|
|
|
def teardown_method(self):
|
2022-08-13 09:49:43 +00:00
|
|
|
self.server.stop()
|
|
|
|
|
|
|
|
def test_with_custom_request_header(self):
|
|
|
|
buckets_for_account_1 = ["foo", "bar"]
|
|
|
|
for name in buckets_for_account_1:
|
|
|
|
requests.put(f"http://{name}.localhost:{SERVER_PORT}/")
|
|
|
|
|
|
|
|
res = requests.get(BASE_URL)
|
2023-08-07 16:48:48 +00:00
|
|
|
assert b"<Name>foo</Name>" in res.content
|
|
|
|
assert b"<Name>bar</Name>" in res.content
|
2022-08-13 09:49:43 +00:00
|
|
|
|
|
|
|
# Create two more buckets in another account
|
|
|
|
headers = {"x-moto-account-id": "333344445555"}
|
|
|
|
buckets_for_account_2 = ["baz", "bla"]
|
|
|
|
for name in buckets_for_account_2:
|
|
|
|
requests.put(f"http://{name}.localhost:{SERVER_PORT}/", headers=headers)
|
|
|
|
|
|
|
|
# Verify only these buckets exist in this account
|
|
|
|
res = requests.get(BASE_URL, headers=headers)
|
2023-08-07 16:48:48 +00:00
|
|
|
assert b"<Name>baz</Name>" in res.content
|
|
|
|
assert b"<Name>bla</Name>" in res.content
|
|
|
|
assert b"<Name>foo</Name>" not in res.content
|
|
|
|
assert b"<Name>bar</Name>" not in res.content
|
2022-08-13 09:49:43 +00:00
|
|
|
|
|
|
|
# Verify these buckets do not exist in the original account
|
|
|
|
res = requests.get(BASE_URL)
|
2023-08-07 16:48:48 +00:00
|
|
|
assert b"<Name>baz</Name>" not in res.content
|
|
|
|
assert b"<Name>bla</Name>" not in res.content
|