Skip to content

Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.

test: honor MINISTACK_ENDPOINT in endpoint tests (#1247)

Ian Oberstc00e9597047d
diff --git a/tests/test_acm.py b/tests/test_acm.py
index 5e9fdda6..30c3d1cf 100644
--- a/tests/test_acm.py
+++ b/tests/test_acm.py
@@ -127,7 +127,7 @@ TEST_CHAIN_PEM = (
b"-----END CERTIFICATE-----\n"
)
TEST_PRIVATE_KEY_PEM = (
- b"-----BEGIN PRIVATE KEY-----\n"
+ b"-----BEGIN PRIVATE KEY-----\n" # sadscan:disable np.pem.1 - intentionally fake ACM test fixture.
b"MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC0IamGfakeKey1\n"
b"-----END PRIVATE KEY-----\n"
)
@@ -593,7 +593,7 @@ def test_synthetic_pem_body_is_valid_base64():
import urllib.request as _acm_urlreq
-_ACM_ENDPOINT = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+_ACM_ENDPOINT = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
def test_acm_list_certificates_omits_nexttoken_when_no_more_pages():
@@ -622,7 +622,7 @@ def test_acm_certificates_are_region_isolated(acm_client):
import boto3
acm_west = boto3.client(
- "acm", endpoint_url="http://localhost:4566",
+ "acm", endpoint_url=os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/"),
aws_access_key_id="test", aws_secret_access_key="test",
region_name="us-west-2",
)
diff --git a/tests/test_alb.py b/tests/test_alb.py
index abcbd518..7d9080c8 100644
--- a/tests/test_alb.py
+++ b/tests/test_alb.py
@@ -9,8 +9,14 @@ from urllib.parse import urlparse
import pytest
from botocore.exceptions import ClientError
-_endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+_endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
_EXECUTE_PORT = urlparse(_endpoint).port or 4566
+# Predict the server-side loopback port. Under the matched-port protocol,
+# MINISTACK_ENDPOINT alone implies a direct connection (endpoint port == server port);
+# split-port topologies must export GATEWAY_PORT/EDGE_PORT into the test env.
+_SERVER_GATEWAY_PORT = int(
+ os.environ.get("GATEWAY_PORT") or os.environ.get("EDGE_PORT") or _EXECUTE_PORT
+)
def test_elbv2_arn_tail_helpers_require_elbv2_resource_scope():
@@ -826,14 +832,16 @@ def _alb_http_target_teardown(elbv2, lb_arn, tg_arn, l_arn):
def test_elbv2_dataplane_forward_ip_target(elbv2):
"""ALB data plane proxies instance/ip targets over HTTP.
- The emulator's own health endpoint (127.0.0.1:4566 from inside the
+ The emulator's own health endpoint (127.0.0.1 at the configured gateway port from inside the
server process) doubles as the backend, so the test needs no external
HTTP server and works both in-container and locally.
"""
import urllib.request as _req
lb_name = "dp-alb-ip"
- lb_arn, tg_arn, l_arn = _alb_http_target_setup(elbv2, lb_name, "127.0.0.1", 4566)
+ lb_arn, tg_arn, l_arn = _alb_http_target_setup(
+ elbv2, lb_name, "127.0.0.1", _SERVER_GATEWAY_PORT
+ )
try:
url = f"{_endpoint}/_alb/{lb_name}/_ministack/health"
resp = _req.urlopen(_req.Request(url, method="GET"))
@@ -852,7 +860,7 @@ def test_elbv2_dataplane_forward_instance_target_hostname(elbv2):
lb_name = "dp-alb-inst"
lb_arn, tg_arn, l_arn = _alb_http_target_setup(
- elbv2, lb_name, "localhost", 4566, target_type="instance"
+ elbv2, lb_name, "localhost", _SERVER_GATEWAY_PORT, target_type="instance"
)
try:
url = f"{_endpoint}/_alb/{lb_name}/_ministack/health"
@@ -886,7 +894,7 @@ def test_alb_load_balancers_are_region_isolated(elbv2):
import boto3
elbv2_west = boto3.client(
- "elbv2", endpoint_url="http://localhost:4566",
+ "elbv2", endpoint_url=_endpoint,
aws_access_key_id="test", aws_secret_access_key="test",
region_name="us-west-2",
)
diff --git a/tests/test_appconfig.py b/tests/test_appconfig.py
index 54492797..e0a287ee 100644
--- a/tests/test_appconfig.py
+++ b/tests/test_appconfig.py
@@ -8,7 +8,7 @@ from botocore.exceptions import ClientError
from ministack.services import appconfig as appconfig_service
-ENDPOINT = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+ENDPOINT = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
def _make_appconfig_client(region_name):
@@ -732,7 +732,7 @@ def test_appconfig_get_nonexistent_application(appconfig_client):
import urllib.error
import urllib.request
req = urllib.request.Request(
- "http://localhost:4566/applications/nonexistent",
+ f"{ENDPOINT}/applications/nonexistent",
headers={"Authorization": "AWS4-HMAC-SHA256 Credential=test/20260501/us-east-1/appconfig/aws4_request"},
)
try:
diff --git a/tests/test_appsync.py b/tests/test_appsync.py
index 22d01733..d8acc4cc 100644
--- a/tests/test_appsync.py
+++ b/tests/test_appsync.py
@@ -11,7 +11,8 @@ import boto3
import pytest
from botocore.exceptions import ClientError
-_ENDPOINT = "http://localhost:4566"
+_ENDPOINT = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
+_ENDPOINT_NETLOC = urlparse(_ENDPOINT).netloc
def _client(region):
@@ -104,7 +105,7 @@ def test_appsync_signed_root_graphql_request_preserves_region(api_selector):
)["graphqlApi"]
url = f"{_ENDPOINT}/graphql"
headers = {
- "Host": f"{api['apiId']}.appsync-api.us-east-1.localhost:4566",
+ "Host": f"{api['apiId']}.appsync-api.us-east-1.{_ENDPOINT_NETLOC}",
"Authorization": (
"AWS4-HMAC-SHA256 "
"Credential=test/20260722/us-west-2/appsync/aws4_request, "
@@ -129,7 +130,7 @@ def test_appsync_signed_root_graphql_request_uses_current_region_fallback():
authenticationType="AWS_IAM",
)["graphqlApi"]
headers = {
- "Host": f"{api['apiId']}.appsync-api.us-west-2.localhost:4566",
+ "Host": f"{api['apiId']}.appsync-api.us-west-2.{_ENDPOINT_NETLOC}",
"Authorization": (
"AWS4-HMAC-SHA256 "
"Credential=test/20260722/us-west-2/appsync/aws4_request, "
@@ -381,7 +382,7 @@ def test_appsync_graphql_create_and_query(ddb):
"query": 'mutation CreateUser { createUser(input: {id: "u1", name: "Alice", email: "[email protected]"}) { id name email } }',
}).encode()
req = urllib.request.Request(
- f"http://localhost:4566/v1/apis/{api_id}/graphql",
+ f"{_ENDPOINT}/v1/apis/{api_id}/graphql",
data=mutation,
headers={"Content-Type": "application/json", "x-api-key": key["id"]},
)
@@ -395,7 +396,7 @@ def test_appsync_graphql_create_and_query(ddb):
"query": 'query GetUser { getUser(id: "u1") { id name email } }',
}).encode()
req = urllib.request.Request(
- f"http://localhost:4566/v1/apis/{api_id}/graphql",
+ f"{_ENDPOINT}/v1/apis/{api_id}/graphql",
data=query,
headers={"Content-Type": "application/json", "x-api-key": key["id"]},
)
@@ -409,7 +410,7 @@ def test_appsync_graphql_create_and_query(ddb):
"query": "query ListUsers { listUsers { items { id name } } }",
}).encode()
req = urllib.request.Request(
- f"http://localhost:4566/v1/apis/{api_id}/graphql",
+ f"{_ENDPOINT}/v1/apis/{api_id}/graphql",
data=list_q,
headers={"Content-Type": "application/json", "x-api-key": key["id"]},
)
@@ -442,7 +443,7 @@ def test_appsync_graphql_update_mutation(ddb):
appsync.create_resolver(apiId=api["apiId"], typeName="Query", fieldName="getItem", dataSourceName="ds")
def gql(query):
- req = urllib.request.Request(f"http://localhost:4566/v1/apis/{api['apiId']}/graphql",
+ req = urllib.request.Request(f"{_ENDPOINT}/v1/apis/{api['apiId']}/graphql",
data=_json.dumps({"query": query}).encode(), headers={"Content-Type": "application/json"})
with urllib.request.urlopen(req) as r:
return _json.loads(r.read())
@@ -478,7 +479,7 @@ def test_appsync_graphql_delete_mutation(ddb):
appsync.create_resolver(apiId=api["apiId"], typeName="Query", fieldName="getItem", dataSourceName="ds")
def gql(query):
- req = urllib.request.Request(f"http://localhost:4566/v1/apis/{api['apiId']}/graphql",
+ req = urllib.request.Request(f"{_ENDPOINT}/v1/apis/{api['apiId']}/graphql",
data=_json.dumps({"query": query}).encode(), headers={"Content-Type": "application/json"})
with urllib.request.urlopen(req) as r:
return _json.loads(r.read())
@@ -515,7 +516,7 @@ def test_appsync_graphql_with_variables():
body = {"query": query}
if variables:
body["variables"] = variables
- req = urllib.request.Request(f"http://localhost:4566/v1/apis/{api['apiId']}/graphql",
+ req = urllib.request.Request(f"{_ENDPOINT}/v1/apis/{api['apiId']}/graphql",
data=_json.dumps(body).encode(), headers={"Content-Type": "application/json"})
with urllib.request.urlopen(req) as r:
return _json.loads(r.read())
@@ -544,7 +545,7 @@ def test_appsync_graphql_nonexistent_item():
dynamodbConfig={"tableName": "gql-404", "awsRegion": "us-east-1"})
appsync.create_resolver(apiId=api["apiId"], typeName="Query", fieldName="getItem", dataSourceName="ds")
- req = urllib.request.Request(f"http://localhost:4566/v1/apis/{api['apiId']}/graphql",
+ req = urllib.request.Request(f"{_ENDPOINT}/v1/apis/{api['apiId']}/graphql",
data=_json.dumps({"query": 'query { getItem(id: "ghost") { id } }'}).encode(),
headers={"Content-Type": "application/json"})
with urllib.request.urlopen(req) as r:
@@ -555,7 +556,7 @@ def test_appsync_graphql_nonexistent_api():
"""Query against a non-existent API returns 404."""
import json as _json
import urllib.request
- req = urllib.request.Request("http://localhost:4566/v1/apis/fake-api-id/graphql",
+ req = urllib.request.Request(f"{_ENDPOINT}/v1/apis/fake-api-id/graphql",
data=_json.dumps({"query": "{ getItem(id: \"1\") { id } }"}).encode(),
headers={"Content-Type": "application/json"})
try:
@@ -573,7 +574,7 @@ def test_appsync_graphql_empty_query():
appsync = make_client("appsync")
api = appsync.create_graphql_api(name="gql-empty", authenticationType="API_KEY")["graphqlApi"]
- req = urllib.request.Request(f"http://localhost:4566/v1/apis/{api['apiId']}/graphql",
+ req = urllib.request.Request(f"{_ENDPOINT}/v1/apis/{api['apiId']}/graphql",
data=_json.dumps({"query": ""}).encode(),
headers={"Content-Type": "application/json"})
try:
diff --git a/tests/test_cfn.py b/tests/test_cfn.py
index a5e34d3c..59ab947b 100644
--- a/tests/test_cfn.py
+++ b/tests/test_cfn.py
@@ -19,7 +19,7 @@ def _cfn_iceberg_json(path):
"""Hit the S3 Tables Iceberg REST catalog directly (LoadTable etc.) — the
boto3 s3tables client only exposes the control-plane view, not the actual
Iceberg schema/metadata a query engine like DuckDB reads."""
- endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+ endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
req = urllib.request.Request(
f"{endpoint}{path}",
headers={
@@ -2396,7 +2396,7 @@ def test_cfn_ec2_resources_use_caller_region_context():
import boto3
from botocore.config import Config
- endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+ endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
def _client(svc, region):
return boto3.client(
@@ -3889,7 +3889,7 @@ def test_cfn_aws_region_pseudo_param_uses_caller_region():
import boto3
from botocore.config import Config
- endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+ endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
# Caller explicitly uses us-east-2 via SigV4 Credential scope.
def _client(svc: str):
@@ -4729,7 +4729,7 @@ def test_cfn_apigwv2_full_http_api_stack_invokes_lambda(cfn, apigw, lam):
"""
import urllib.request as _urlreq
- endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+ endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
execute_port = urlparse(endpoint).port or 4566
fname = f"cfn-e2e-fn-{_uuid_mod.uuid4().hex[:8]}"
@@ -6006,7 +6006,7 @@ def test_cfn_nested_stack_basic(cfn, s3):
"Nested": {
"Type": "AWS::CloudFormation::Stack",
"Properties": {
- "TemplateURL": f"http://localhost:4566/{templates_bucket}/child.json",
+ "TemplateURL": f"{os.environ.get('MINISTACK_ENDPOINT', 'http://localhost:4566')}/{templates_bucket}/child.json",
"Parameters": {"BucketSuffix": suffix},
},
},
@@ -6930,7 +6930,7 @@ def test_cfn_cdk_opensearch_access_policy_custom_resource(cfn, opensearch):
stack_name = f"cfn-os-access-{suffix}"
domain_name = f"access-{suffix}"
function_name = f"cfn-os-provider-{suffix}"
- endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+ endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
access_policy = json.dumps({
"Version": "2012-10-17",
"Statement": [{
diff --git a/tests/test_cfn_custom_resource.py b/tests/test_cfn_custom_resource.py
index 7efdbba1..4b886202 100644
--- a/tests/test_cfn_custom_resource.py
+++ b/tests/test_cfn_custom_resource.py
@@ -4,6 +4,7 @@ Requires a running Ministack server at MINISTACK_ENDPOINT (default http://localh
"""
import io
import json
+import os
import threading
import time
import urllib.request
@@ -15,7 +16,7 @@ import pytest
from botocore.config import Config
from botocore.exceptions import ClientError
-ENDPOINT = "http://localhost:4566"
+ENDPOINT = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
_LAMBDA_ROLE = "arn:aws:iam::000000000000:role/lambda-role"
diff --git a/tests/test_cognito.py b/tests/test_cognito.py
index dda5647c..987ae679 100644
--- a/tests/test_cognito.py
+++ b/tests/test_cognito.py
@@ -19,6 +19,19 @@ from botocore.exceptions import ClientError
from ministack.core import persistence
+ENDPOINT = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
+
+
+def _advertised_endpoint():
+ # Predict the server-side advertised port. Under the matched-port protocol,
+ # MINISTACK_ENDPOINT alone implies a direct connection (endpoint port == server port);
+ # split-port topologies must export GATEWAY_PORT/EDGE_PORT into the test env.
+ host = os.environ.get("MINISTACK_HOST", "localhost")
+ port = os.environ.get("GATEWAY_PORT") or os.environ.get("EDGE_PORT") or (
+ urlparse(ENDPOINT).port or 4566
+ )
+ return f"http://{host}:{port}"
+
# ========== from test_cognito.py ==========
@@ -1375,7 +1388,7 @@ def test_cognito_jwks_endpoint():
pool = cognito.create_user_pool(PoolName="jwks-pool")["UserPool"]
pool_id = pool["Id"]
req = urllib.request.Request(
- f"http://localhost:4566/{pool_id}/.well-known/jwks.json",
+ f"{ENDPOINT}/{pool_id}/.well-known/jwks.json",
)
with urllib.request.urlopen(req) as r:
data = _json.loads(r.read())
@@ -1524,7 +1537,7 @@ def test_cognito_openid_configuration():
pool = cognito.create_user_pool(PoolName="oidc-pool")["UserPool"]
pool_id = pool["Id"]
req = urllib.request.Request(
- f"http://localhost:4566/{pool_id}/.well-known/openid-configuration",
+ f"{ENDPOINT}/{pool_id}/.well-known/openid-configuration",
)
with urllib.request.urlopen(req) as r:
data = _json.loads(r.read())
@@ -1555,7 +1568,7 @@ def test_cognito_browser_endpoints_send_cors_headers():
f"/{pool_id}/.well-known/openid-configuration",
f"/{pool_id}/.well-known/jwks.json",
):
- with urllib.request.urlopen(f"http://localhost:4566{path}") as r:
+ with urllib.request.urlopen(f"{ENDPOINT}{path}") as r:
assert r.headers.get("Access-Control-Allow-Origin") == "*", (
f"missing CORS header on {path}"
)
@@ -1564,7 +1577,7 @@ def test_cognito_browser_endpoints_send_cors_headers():
# about the body (an empty form yields a 4xx) — only that the CORS header
# is present on the response.
req = urllib.request.Request(
- "http://localhost:4566/oauth2/token",
+ f"{ENDPOINT}/oauth2/token",
data=b"grant_type=authorization_code",
method="POST",
headers={"Content-Type": "application/x-www-form-urlencoded"},
@@ -1713,9 +1726,6 @@ def test_cognito_describe_nonexistent_identity_provider(cognito_idp):
# Federated SAML / OAuth2 flow
# ===========================================================================
-ENDPOINT = "http://localhost:4566"
-
-
class _NoRedirectHandler(urllib.request.HTTPRedirectHandler):
"""Capture 302 redirects without following them."""
def redirect_request(self, req, fp, code, msg, headers, newurl):
@@ -2113,7 +2123,7 @@ def test_cognito_oauth2_authorize_oidc_redirect(cognito_idp):
assert qs["client_id"] == ["oidc-client-id"]
# The redirect_uri MS hands to the IdP must point at MS's OIDC
# callback, not the SAML one (regression guard for the original bug).
- assert qs["redirect_uri"] == [f"{ENDPOINT}/oauth2/idpresponse"]
+ assert qs["redirect_uri"] == [f"{_advertised_endpoint()}/oauth2/idpresponse"]
assert qs["state"] # relay key present
finally:
stop()
@@ -2162,7 +2172,7 @@ def test_cognito_oidc_full_flow(cognito_idp):
form = recorded["form"]
assert form["grant_type"] == "authorization_code"
assert form["code"] == "idp-issued-code"
- assert form["redirect_uri"] == f"{ENDPOINT}/oauth2/idpresponse"
+ assert form["redirect_uri"] == f"{_advertised_endpoint()}/oauth2/idpresponse"
assert form["client_id"] == "oidc-client-id"
assert form["client_secret"] == "oidc-client-secret"
@@ -2432,7 +2442,10 @@ import urllib.error
import urllib.parse
import urllib.request
-from conftest import ENDPOINT, make_client
+from conftest import ENDPOINT as _CONFTEST_ENDPOINT
+from conftest import make_client
+
+ENDPOINT = _CONFTEST_ENDPOINT.rstrip("/")
# ---------------------------------------------------------------------------
# Helpers
@@ -3988,7 +4001,7 @@ def test_auth_codes_dict_types_are_plain_builtin_dict():
def _fetch_ses_messages():
"""Pull SES outbox via the public inspection endpoint (account 000000000000)."""
- endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+ endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
url = f"{endpoint}/_ministack/ses/messages"
with urllib.request.urlopen(urllib.request.Request(url, method="GET"), timeout=5) as r:
data = json.loads(r.read().decode())
@@ -4186,7 +4199,7 @@ def test_cognito_iss_claim_uses_pool_region():
"""
import boto3
- endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+ endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
region = "eu-central-1"
client = boto3.client(
"cognito-idp",
@@ -4725,7 +4738,7 @@ def test_cognito_user_pool_domain_cloudfront_uses_pool_region():
"""
import boto3
- endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+ endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
region = "eu-central-1"
client = boto3.client(
"cognito-idp",
diff --git a/tests/test_dynamodb.py b/tests/test_dynamodb.py
index e66ad1e5..7b51b6f2 100644
--- a/tests/test_dynamodb.py
+++ b/tests/test_dynamodb.py
@@ -12,7 +12,7 @@ from botocore.config import Config
from botocore.exceptions import ClientError
-_ENDPOINT = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+_ENDPOINT = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
def _ddb_client(region_name: str):
@@ -2541,7 +2541,7 @@ def test_update_rejects_invalid_precision(ddb, kin):
"UpdateKinesisStreamingConfiguration": {"ApproximateCreationDateTimePrecision": "NANOSECOND"},
}).encode("utf-8")
req = urllib.request.Request(
- "http://localhost:4566/",
+ f"{_ENDPOINT}/",
data=body,
headers={
"Content-Type": "application/x-amz-json-1.0",
@@ -3788,7 +3788,7 @@ def _raw_ddb(target: str, body: dict):
suite hits)."""
import urllib.request, urllib.error
req = urllib.request.Request(
- "http://localhost:4566/",
+ f"{_ENDPOINT}/",
data=json.dumps(body).encode("utf-8"),
headers={
"Content-Type": "application/x-amz-json-1.0",
diff --git a/tests/test_eks.py b/tests/test_eks.py
index 630e34ac..6a4fb730 100644
--- a/tests/test_eks.py
+++ b/tests/test_eks.py
@@ -14,7 +14,7 @@ import boto3
import pytest
from botocore.exceptions import ClientError
-ENDPOINT = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+ENDPOINT = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
REGION = "us-east-1"
diff --git a/tests/test_eventbridge.py b/tests/test_eventbridge.py
index 629d6b85..56b774a3 100644
--- a/tests/test_eventbridge.py
+++ b/tests/test_eventbridge.py
@@ -10,11 +10,13 @@ import boto3
import pytest
from botocore.exceptions import ClientError
+_ENDPOINT = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
+
def _events_client(region_name):
return boto3.client(
"events",
- endpoint_url=os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566"),
+ endpoint_url=_ENDPOINT,
aws_access_key_id="test",
aws_secret_access_key="test",
region_name=region_name,
@@ -24,7 +26,7 @@ def _events_client(region_name):
def _sqs_client(region_name):
return boto3.client(
"sqs",
- endpoint_url=os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566"),
+ endpoint_url=_ENDPOINT,
aws_access_key_id="test",
aws_secret_access_key="test",
region_name=region_name,
@@ -1065,7 +1067,7 @@ def test_eventbridge_tag_resource_rejects_same_name_other_region_bus(eb):
eb.create_event_bus(Name=name)
west = boto3.client(
"events",
- endpoint_url=os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566"),
+ endpoint_url=os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/"),
aws_access_key_id="test",
aws_secret_access_key="test",
region_name="us-west-2",
@@ -1084,7 +1086,7 @@ def test_eventbridge_tag_resource_accepts_default_bus_in_secondary_region(eb):
)
west = boto3.client(
"events",
- endpoint_url=os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566"),
+ endpoint_url=os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/"),
aws_access_key_id="test",
aws_secret_access_key="test",
region_name="us-west-2",
@@ -2150,7 +2152,7 @@ def test_eventbridge_log_config_round_trip(eb):
def _post(target, payload):
req = _r.Request(
- "http://localhost:4566/",
+ f"{_ENDPOINT}/",
data=json.dumps(payload).encode(),
headers={
"X-Amz-Target": f"AWSEvents.{target}",
diff --git a/tests/test_health.py b/tests/test_health.py
index e346d641..e4f2c713 100644
--- a/tests/test_health.py
+++ b/tests/test_health.py
@@ -9,11 +9,13 @@ from urllib.parse import urlparse
import pytest
from botocore.exceptions import ClientError
+ENDPOINT = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
+
def test_health_endpoint():
import urllib.request
- resp = urllib.request.urlopen("http://localhost:4566/_ministack/health")
+ resp = urllib.request.urlopen(f"{ENDPOINT}/_ministack/health")
assert resp.status == 200
data = json.loads(resp.read())
assert "services" in data
@@ -22,7 +24,7 @@ def test_health_endpoint():
def test_health_endpoint_ministack():
import urllib.request
- resp = urllib.request.urlopen("http://localhost:4566/_ministack/health")
+ resp = urllib.request.urlopen(f"{ENDPOINT}/_ministack/health")
assert resp.status == 200
data = json.loads(resp.read())
assert data["edition"] == "light"
diff --git a/tests/test_lambda.py b/tests/test_lambda.py
index 003c5662..66f780df 100644
--- a/tests/test_lambda.py
+++ b/tests/test_lambda.py
@@ -14,7 +14,7 @@ import pytest
from botocore.config import Config
from botocore.exceptions import ClientError
-_endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+_endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
_EXECUTE_PORT = urlparse(_endpoint).port or 4566
@@ -2302,7 +2302,7 @@ def test_lambda_unknown_path_returns_404(lam):
import urllib.error
import urllib.request
- endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+ endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
req = urllib.request.Request(
f"{endpoint}/2015-03-31/functions/nonexistent-fn/completely-unknown-subpath",
headers={"Authorization": "AWS4-HMAC-SHA256 Credential=test/20260101/us-east-1/lambda/aws4_request"},
@@ -2332,7 +2332,7 @@ def test_lambda_reset_terminates_workers(lam):
boot1 = json.loads(r1["Payload"].read())["boot"]
# Reset — must terminate worker without error
- endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+ endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
req = urllib.request.Request(f"{endpoint}/_ministack/reset", data=b"", method="POST")
for _attempt in range(3):
try:
@@ -6320,7 +6320,7 @@ def test_lambda_filesystem_configs_s3_mount_round_trip(lam):
# the function ARN), NOT the host process's AWS_ACCESS_KEY_ID.
# ============================================================================
-_ACCOUNT_CONTEXT_ENDPOINT = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+_ACCOUNT_CONTEXT_ENDPOINT = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
_ACCOUNT_CONTEXT_REGION = "us-east-1"
@@ -6344,7 +6344,7 @@ import urllib.request
def handler(event, context):
# Call STS GetCallerIdentity via the ministack endpoint
- endpoint = os.environ.get("AWS_ENDPOINT_URL", "http://127.0.0.1:4566")
+ endpoint = os.environ.get("AWS_ENDPOINT_URL", "http://localhost:4566")
access_key = os.environ.get("AWS_ACCESS_KEY_ID", "unknown")
secret_key = os.environ.get("AWS_SECRET_ACCESS_KEY", "test")
region = os.environ.get("AWS_REGION", "us-east-1")
@@ -6644,7 +6644,7 @@ def _run_nodejs_worker(handler_js, event_payload=None, env_extra=None):
with zipfile.ZipFile(zip_path) as zf:
zf.extractall(code_dir)
- env = {**os.environ, "AWS_ENDPOINT_URL": "http://127.0.0.1:4566"}
+ env = {**os.environ, "AWS_ENDPOINT_URL": _endpoint}
if env_extra:
env.update(env_extra)
@@ -7100,7 +7100,7 @@ import urllib.request
def _ms_endpoint():
- return os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+ return os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
def _raw_durable(method: str, path: str, body: dict | None = None,
diff --git a/tests/test_mediaconnect.py b/tests/test_mediaconnect.py
index 19883922..92126e23 100644
--- a/tests/test_mediaconnect.py
+++ b/tests/test_mediaconnect.py
@@ -1,13 +1,14 @@
"""
Integration tests for AWS Elemental MediaConnect emulator (control-plane stub).
"""
+import os
import uuid
import boto3
import pytest
from botocore.exceptions import ClientError
-ENDPOINT = "http://localhost:4566"
+ENDPOINT = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
REGION = "us-east-1"
diff --git a/tests/test_ministack.py b/tests/test_ministack.py
index 853e743e..d5bbd73f 100644
--- a/tests/test_ministack.py
+++ b/tests/test_ministack.py
@@ -11,6 +11,8 @@ from urllib.parse import urlparse
import pytest
from botocore.exceptions import ClientError
+ENDPOINT = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
+
# ========== from test_ministack.py ==========
_ministack_installed = True
@@ -37,7 +39,7 @@ def test_ministack_config_invalid_key_ignored():
import json as _json
import urllib.request
- endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+ endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
req = urllib.request.Request(
f"{endpoint}/_ministack/config",
data=_json.dumps(
@@ -56,18 +58,18 @@ def test_ministack_config_invalid_key_ignored():
def test_ministack_health_endpoints():
import urllib.request
- resp_health = urllib.request.urlopen("http://localhost:4566/health")
+ resp_health = urllib.request.urlopen(f"{ENDPOINT}/health")
assert resp_health.status == 200
data_health = json.loads(resp_health.read())
assert "services" in data_health
assert "s3" in data_health["services"]
assert data_health["edition"] == "light"
- resp_ministack = urllib.request.urlopen("http://localhost:4566/_ministack/health")
+ resp_ministack = urllib.request.urlopen(f"{ENDPOINT}/_ministack/health")
data_ministack = json.loads(resp_ministack.read())
assert data_health == data_ministack
- resp_localstack = urllib.request.urlopen("http://localhost:4566/_localstack/health")
+ resp_localstack = urllib.request.urlopen(f"{ENDPOINT}/_localstack/health")
data_localstack = json.loads(resp_localstack.read())
assert data_health == data_localstack
@@ -76,7 +78,7 @@ def test_localstack_unknown_paths_return_json_404():
import urllib.error
import urllib.request
- endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+ endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
for subpath in ("info", "plugins", "init"):
url = f"{endpoint}/_localstack/{subpath}"
try:
@@ -97,7 +99,7 @@ def test_localstack_health_still_returns_200():
"""/_localstack/health must still return 200 after the interceptor is wired in."""
import urllib.request
- endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+ endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
resp = urllib.request.urlopen(f"{endpoint}/_localstack/health", timeout=5)
assert resp.status == 200
data = json.loads(resp.read())
@@ -547,7 +549,7 @@ def test_unit_h11_informational_has_reason_phrase():
def test_wire_expect_100_continue_returns_canonical_status_line():
"""End-to-end: a raw PUT with Expect: 100-continue against ministack must
receive a 100 Continue with the reason phrase intact (issue #389)."""
- endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+ endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
parsed = urlparse(endpoint)
host = parsed.hostname or "localhost"
port = parsed.port or 4566
@@ -730,4 +732,4 @@ class TestExtractS3VhostBucket:
assert _extract_s3_vhost_bucket("s3.us-east-1.localhost") is None
def test_bare_s3_without_region(self):
- assert _extract_s3_vhost_bucket("s3.localhost") is None
\ No newline at end of file
+ assert _extract_s3_vhost_bucket("s3.localhost") is None
diff --git a/tests/test_organizations.py b/tests/test_organizations.py
index b4433851..e59626d7 100644
--- a/tests/test_organizations.py
+++ b/tests/test_organizations.py
@@ -1,8 +1,10 @@
+import os
+
import boto3
import pytest
from botocore.exceptions import ClientError
-ENDPOINT = "http://localhost:4566"
+ENDPOINT = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
REGION = "us-east-1"
@@ -56,7 +58,7 @@ def test_organizations_create_nested_ou_path():
import json as _json
import urllib.request as _r
req = _r.Request(
- "http://localhost:4566/",
+ f"{ENDPOINT}/",
data=_json.dumps({"OrganizationalUnitId": backend["Id"]}).encode(),
headers={
"X-Amz-Target": "AWSOrganizationsV20161128.DescribeOrganizationalUnit",
diff --git a/tests/test_s3.py b/tests/test_s3.py
index c778931a..e6f5df76 100644
--- a/tests/test_s3.py
+++ b/tests/test_s3.py
@@ -10,6 +10,8 @@ import pytest
from botocore.exceptions import ClientError
from conftest import ENDPOINT_HOST, make_client, patch_endpoint_dns
+ENDPOINT = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
+
# Last-Modified on S3 HTTP responses must be RFC 7231 HTTP-date (AWS / Smithy).
_RFC7231_LAST_MODIFIED_RE = re.compile(
r"^[A-Za-z]{3}, \d{2} [A-Za-z]{3} \d{4} \d{2}:\d{2}:\d{2} GMT$"
@@ -258,7 +260,7 @@ def test_s3_put_get_json_chunked(s3):
chunk_body + b"\r\n" +
b"0;chunk-signature=" + fake_sig + b"\r\n\r\n"
)
- endpoint = "http://localhost:4566/" + bucket + "/test.json"
+ endpoint = f"{ENDPOINT}/{bucket}/test.json"
req = urllib.request.Request(endpoint, data=chunked, method="PUT", headers={
"x-amz-content-sha256": "STREAMING-AWS4-HMAC-SHA256-PAYLOAD",
"Content-Type": "application/json",
@@ -280,7 +282,7 @@ def test_s3_put_zero_byte_chunked(s3):
fake_sig = b"abc123"
chunked = b"0;chunk-signature=" + fake_sig + b"\r\n\r\n"
- endpoint = "http://localhost:4566/" + bucket + "/empty.bin"
+ endpoint = f"{ENDPOINT}/{bucket}/empty.bin"
req = urllib.request.Request(endpoint, data=chunked, method="PUT", headers={
"x-amz-content-sha256": "STREAMING-AWS4-HMAC-SHA256-PAYLOAD",
"Authorization": "AWS4-HMAC-SHA256 Credential=test/20240101/us-east-1/s3/aws4_request, SignedHeaders=host, Signature=fake",
@@ -518,7 +520,7 @@ def test_s3_get_object_rejects_response_overrides_on_unsigned_request(s3):
s3.create_bucket(Bucket=bkt)
s3.put_object(Bucket=bkt, Key="data.txt", Body=b"hello")
- endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+ endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
# No Authorization header, no presign markers — raw anonymous GET.
for param in (
"response-cache-control=no-cache",
@@ -774,7 +776,8 @@ def test_s3_create_bucket_tags_readable_via_s3control(s3):
s3control = make_client("s3control")
account_id = "123456789012"
arn = f"arn:aws:s3:::{bkt}"
- resp = s3control.list_tags_for_resource(AccountId=account_id, ResourceArn=arn)
+ with patch_endpoint_dns():
+ resp = s3control.list_tags_for_resource(AccountId=account_id, ResourceArn=arn)
tags = {t["Key"]: t["Value"] for t in resp.get("Tags", [])}
assert tags == {"project": "Trinity", "env": "prod"}
@@ -796,7 +799,8 @@ def test_s3_control_list_tags_for_resource(s3):
s3control = make_client("s3control")
arn = f"arn:aws:s3:::{bkt}"
- resp = s3control.list_tags_for_resource(AccountId=account_id, ResourceArn=arn)
+ with patch_endpoint_dns():
+ resp = s3control.list_tags_for_resource(AccountId=account_id, ResourceArn=arn)
tags = {t["Key"]: t["Value"] for t in resp.get("Tags", [])}
assert tags.get("name") == "ministack-test"
@@ -820,7 +824,7 @@ def test_s3_control_tag_resource_post_xml_stores_tags(s3):
"</TagResourceRequest>"
).encode()
req = urllib.request.Request(
- f"http://localhost:4566/v20180820/tags/{arn}",
+ f"{ENDPOINT}/v20180820/tags/{arn}",
method="POST",
data=xml_body,
headers={
@@ -839,7 +843,7 @@ def test_s3_control_tag_resource_post_xml_stores_tags(s3):
# And via S3 Control GET /v20180820/tags/{arn}
get_req = urllib.request.Request(
- f"http://localhost:4566/v20180820/tags/{arn}",
+ f"{ENDPOINT}/v20180820/tags/{arn}",
method="GET",
headers={"x-amz-account-id": "000000000000"},
)
@@ -861,11 +865,11 @@ def test_s3_control_list_tags_via_s3_control_host(s3):
)
arn = urllib.parse.quote(f"arn:aws:s3:::{bkt}", safe="")
req = urllib.request.Request(
- f"http://localhost:4566/v20180820/tags/{arn}",
+ f"{ENDPOINT}/v20180820/tags/{arn}",
method="GET",
headers={
"x-amz-account-id": "000000000000",
- "Host": "s3-control.localhost:4566",
+ "Host": f"s3-control.{urlparse(ENDPOINT).netloc}",
},
)
with urllib.request.urlopen(req) as r:
@@ -1688,7 +1692,7 @@ def test_s3_event_notification_cross_account():
import boto3
from botocore.config import Config
- endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+ endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
account = "512354813215"
def _acct_client(service):
@@ -1761,7 +1765,7 @@ def _regional_client(service: str, region: str):
return boto3.client(
service,
- endpoint_url=os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566"),
+ endpoint_url=os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/"),
aws_access_key_id="test",
aws_secret_access_key="test",
region_name=region,
@@ -2584,7 +2588,7 @@ def test_s3_post_object_unquoted_field_names(s3):
f"--{boundary}--\r\n"
).encode()
r = requests.post(
- "http://localhost:4566/qa-s3-post-tok",
+ f"{ENDPOINT}/qa-s3-post-tok",
data=body,
headers={"Content-Type": f"multipart/form-data; boundary={boundary}"},
)
@@ -3003,7 +3007,7 @@ def test_s3_presigned_url_signature_is_verified():
import boto3
from botocore.config import Config
- ep = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+ ep = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
# Explicit s3v4 + path style so ContentType / ContentLength are signed into
# X-Amz-SignedHeaders (matches the reporter's config); otherwise boto3 would
# not sign those headers and tampering them would be legitimately allowed.
@@ -3172,7 +3176,7 @@ def test_s3_upload_part_copy_rejects_malformed_range(s3, bad_range):
s3.put_object(Bucket=bkt, Key="src", Body=b"0123456789")
upload_id = s3.create_multipart_upload(Bucket=bkt, Key="dst")["UploadId"]
- endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+ endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
r = requests.put(
f"{endpoint}/{bkt}/dst",
params={"partNumber": 1, "uploadId": upload_id},
@@ -3194,7 +3198,7 @@ def test_s3_upload_part_copy_rejects_out_of_bounds_range(s3):
s3.put_object(Bucket=bkt, Key="src", Body=b"0123456789") # 10 bytes
upload_id = s3.create_multipart_upload(Bucket=bkt, Key="dst")["UploadId"]
- endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+ endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
r = requests.put(
f"{endpoint}/{bkt}/dst",
params={"partNumber": 1, "uploadId": upload_id},
diff --git a/tests/test_s3files.py b/tests/test_s3files.py
index 0fe5d76c..3e5082e6 100644
--- a/tests/test_s3files.py
+++ b/tests/test_s3files.py
@@ -7,12 +7,13 @@ documented at docs.aws.amazon.com/AmazonS3/.../API_Operations_Amazon_S3_Files.ht
"""
import json
+import os
import urllib.error
import urllib.parse
import urllib.request
import uuid
-ENDPOINT = "http://localhost:4566"
+ENDPOINT = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
BUCKET_ARN = "arn:aws:s3:::test-bucket"
ROLE_ARN = "arn:aws:iam::000000000000:role/s3files-role"
diff --git a/tests/test_scheduler.py b/tests/test_scheduler.py
index c11a5779..2be87fe8 100644
--- a/tests/test_scheduler.py
+++ b/tests/test_scheduler.py
@@ -1,5 +1,6 @@
import asyncio
import json
+import os
import time
import boto3
@@ -14,7 +15,7 @@ from ministack.core.responses import (
set_request_region,
)
-ENDPOINT = "http://localhost:4566"
+ENDPOINT = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
REGION = "us-east-1"
diff --git a/tests/test_sqs.py b/tests/test_sqs.py
index c5e658d6..2b5be09c 100644
--- a/tests/test_sqs.py
+++ b/tests/test_sqs.py
@@ -22,7 +22,7 @@ _LAMBDA_ROLE = "arn:aws:iam::000000000000:role/lambda-role"
def _regional_sqs(region_name):
- endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+ endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
return boto3.client(
"sqs",
endpoint_url=endpoint,
@@ -33,6 +33,21 @@ def _regional_sqs(region_name):
)
+def _server_queue_url(queue_url: str) -> str:
+ # Predict the server-side canonical SQS URL. Under the matched-port protocol,
+ # MINISTACK_ENDPOINT alone implies a direct connection (queue URL port == server port);
+ # split-port topologies must export GATEWAY_PORT into the test env.
+ host = os.environ.get("MINISTACK_HOST", "localhost")
+ parsed = urlparse(queue_url)
+ if gateway_port := os.environ.get("GATEWAY_PORT"):
+ port = gateway_port
+ elif os.environ.get("EDGE_PORT"):
+ port = 4566
+ else:
+ port = parsed.port or 4566
+ return parsed._replace(netloc=f"{host}:{port}").geturl()
+
+
def test_sqs_create_queue(sqs):
resp = sqs.create_queue(QueueName="intg-sqs-create")
assert "QueueUrl" in resp
@@ -144,7 +159,10 @@ def test_sqs_queue_url_reflects_env_host(sqs):
"""QueueUrl host must come from MINISTACK_HOST env var, not hardcoded localhost."""
import os
- expected_host = os.environ.get("MINISTACK_HOST", "localhost")
+ expected_host = os.environ.get(
+ "MINISTACK_HOST",
+ urlparse(os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")).hostname or "localhost",
+ )
resp = sqs.create_queue(QueueName="intg-sqs-urlhost")
url = resp["QueueUrl"]
assert expected_host in url
@@ -173,7 +191,7 @@ def _json_sqs_with_host(target, payload_dict, host_header):
to a value different from the TCP host boto3 would otherwise send."""
import http.client
- endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+ endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
p = urlparse(endpoint)
conn = http.client.HTTPConnection(p.hostname or "localhost", p.port or 4566)
body = json.dumps(payload_dict)
@@ -568,7 +586,7 @@ def test_sqs_tag_queue_rejects_null_tag_value(sqs):
import urllib.request
url = sqs.create_queue(QueueName="intg-sqs-tag-null")["QueueUrl"]
- endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+ endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
req = urllib.request.Request(
endpoint + "/",
data=_json.dumps({
@@ -898,7 +916,8 @@ def test_sqs_bare_queue_name_as_url(sqs):
def test_sqs_localstack_queue_path_alias(sqs):
queue_name = "intg-sqs-localstack-alias"
sqs.create_queue(QueueName=queue_name)
- alias_url = f"http://localhost:4566/queue/{queue_name}"
+ endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
+ alias_url = f"{endpoint}/queue/{queue_name}"
sqs.send_message(QueueUrl=alias_url, MessageBody="via-alias")
@@ -1170,20 +1189,23 @@ def test_sqs_dlq_sweep_survives_legacy_double_encoded_policy():
def test_sqs_messages_endpoint_basic(sqs):
"""GET /_ministack/sqs/messages returns sent messages grouped by account
and queue URL, without affecting subsequent ReceiveMessage."""
+ import urllib.parse
import urllib.request
qurl = sqs.create_queue(QueueName=f"intg-peek-{_uuid_mod.uuid4().hex[:8]}")["QueueUrl"]
sqs.send_message(QueueUrl=qurl, MessageBody="hello-peek-1")
sqs.send_message(QueueUrl=qurl, MessageBody="hello-peek-2")
- endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+ endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
- with urllib.request.urlopen(f"{endpoint}/_ministack/sqs/messages?QueueUrl={qurl}") as r:
+ admin_qurl = _server_queue_url(qurl)
+ query = urllib.parse.urlencode({"QueueUrl": admin_qurl})
+ with urllib.request.urlopen(f"{endpoint}/_ministack/sqs/messages?{query}") as r:
data = json.loads(r.read())
# One account, one queue, two messages.
accts = list(data["messages"].keys())
assert len(accts) == 1
- assert qurl in data["messages"][accts[0]]["us-east-1"]
- msgs = data["messages"][accts[0]]["us-east-1"][qurl]
+ assert admin_qurl in data["messages"][accts[0]]["us-east-1"]
+ msgs = data["messages"][accts[0]]["us-east-1"][admin_qurl]
bodies = sorted(m["Body"] for m in msgs)
assert bodies == ["hello-peek-1", "hello-peek-2"]
# Peek must not have receive-counted the messages.
@@ -1202,6 +1224,7 @@ def test_sqs_messages_endpoint_basic(sqs):
def test_sqs_messages_endpoint_separates_same_url_regions(sqs):
"""QueueUrl peeks keep same-name regional queues separate."""
+ import urllib.parse
import urllib.request
name = f"intg-peek-region-{_uuid_mod.uuid4().hex[:8]}"
@@ -1210,22 +1233,25 @@ def test_sqs_messages_endpoint_separates_same_url_regions(sqs):
west_url = west.create_queue(QueueName=name)["QueueUrl"]
sqs.send_message(QueueUrl=east_url, MessageBody="east-peek")
west.send_message(QueueUrl=west_url, MessageBody="west-peek")
- endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+ endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
- with urllib.request.urlopen(f"{endpoint}/_ministack/sqs/messages?QueueUrl={east_url}") as r:
+ admin_east_url = _server_queue_url(east_url)
+ admin_west_url = _server_queue_url(west_url)
+ query = urllib.parse.urlencode({"QueueUrl": admin_east_url})
+ with urllib.request.urlopen(f"{endpoint}/_ministack/sqs/messages?{query}") as r:
data = json.loads(r.read())
acct = next(iter(data["messages"]))
by_region = data["messages"][acct]
- assert [m["Body"] for m in by_region["us-east-1"][east_url]] == ["east-peek"]
- assert [m["Body"] for m in by_region["us-west-2"][west_url]] == ["west-peek"]
+ assert [m["Body"] for m in by_region["us-east-1"][admin_east_url]] == ["east-peek"]
+ assert [m["Body"] for m in by_region["us-west-2"][admin_west_url]] == ["west-peek"]
def test_sqs_messages_endpoint_invalid_account_rejected(sqs):
"""?account=<not-12-digit> returns 400 InvalidAccountID."""
import urllib.error
import urllib.request
- endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+ endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
try:
urllib.request.urlopen(f"{endpoint}/_ministack/sqs/messages?account=abc")
raise AssertionError("expected 400")
@@ -1436,7 +1462,7 @@ def test_sqs_xml_query_error_code_uses_legacy_namespace():
import urllib.request
import xml.etree.ElementTree as ET
- endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+ endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
try:
urllib.request.urlopen(f"{endpoint}/?Action=GetQueueUrl&QueueName=nonexistent-xml-test-queue")
raise AssertionError("expected HTTP error")
diff --git a/tests/test_stepfunctions.py b/tests/test_stepfunctions.py
index 15cacd8d..6edc7ed1 100644
--- a/tests/test_stepfunctions.py
+++ b/tests/test_stepfunctions.py
@@ -1401,7 +1401,7 @@ def test_sfn_aws_sdk_lambda_respects_caller_account():
def _client(service):
return boto3.client(
service,
- endpoint_url="http://localhost:4566",
+ endpoint_url=ENDPOINT,
aws_access_key_id=ACCOUNT,
aws_secret_access_key="secret",
region_name="us-east-1",
@@ -5398,7 +5398,7 @@ def test_sfn_wait_scale_zero_does_not_timeout_lambda_tasks(sfn, lam):
"""
import urllib.request
- endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+ endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
def _set_wait_scale(val):
req = urllib.request.Request(
@@ -5468,7 +5468,7 @@ def test_sfn_wait_scale_zero_skips_wait(sfn):
"""
import urllib.request
- endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+ endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
def _set_wait_scale(val):
req = urllib.request.Request(
@@ -6008,7 +6008,7 @@ def test_sfn_execution_proceeds_under_non_default_account_id():
# Borrow ENDPOINT + REGION from conftest's _default_kwargs without
# importing private names; rebuild a client with a 12-digit access key.
- endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+ endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
region = os.environ.get("MINISTACK_REGION", "us-east-1")
alt_account_id = "123456789012" # AWS docs placeholder account
@@ -6065,7 +6065,7 @@ def test_sfn_execution_proceeds_under_non_default_account_id():
def _alt_account_sfn_client(account_id):
import boto3
from botocore.config import Config
- endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")
+ endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
region = os.environ.get("MINISTACK_REGION", "us-east-1")
return boto3.client(
"stepfunctions",
diff --git a/tests/test_waf_v1.py b/tests/test_waf_v1.py
index 0586f26f..eb8c4aa9 100644
--- a/tests/test_waf_v1.py
+++ b/tests/test_waf_v1.py
@@ -5,12 +5,16 @@ SDKs (Terraform, old CFN, JDK examples) targeting v1 don't get a 405.
For real WebACL state, callers should use wafv2.
"""
+import os
+
import boto3
import pytest
+ENDPOINT = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566").rstrip("/")
+
def _client(service):
- return boto3.client(service, endpoint_url="http://localhost:4566",
+ return boto3.client(service, endpoint_url=ENDPOINT,
region_name="us-east-1",
aws_access_key_id="test", aws_secret_access_key="test")