Skip to content

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

fix(wire): match real-AWS error envelopes — CTs, routing, validation order (#2110)

Lisandro Pintos9d33e2220478
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 38ee978d..2437754b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,13 @@ Versioning follows [Semantic Versioning](https://semver.org/).
## [Unreleased]
### Fixed
+- **Error envelope Content-Types now match AWS per protocol** — real AWS picks an error's `Content-Type` from the service's protocol, and services disagree: `application/x-amz-json-1.1` for jsonVersion-1.1 services (Kinesis, KMS, Secrets Manager, Athena, Cognito, EventBridge, WAFv2, CloudWatch Logs) vs `1.0` (DynamoDB, Step Functions, SQS); `text/xml` for query services (IAM, SNS, RDS, CloudFormation) and `text/xml;charset=UTF-8` for EC2; `application/json` for rest-json (Lambda, AppSync, API Gateway) vs `application/x-amz-json-1.1` for SESv2; `text/xml` for rest-xml except S3's `application/xml`. Errors are now normalized at dispatch using the botocore service model plus wire-captured quirks. Evidence: real AWS wire captures diffed per probe (7/28 → 23/28 probes conforming).
+- **Unimplemented services no longer answered by S3** — a request whose SigV4 credential scope names a real AWS service MiniStack does not implement (e.g. Glacier, Pinpoint, Route53 Resolver) used to fall through to the S3 path catch-all and return `NoSuchBucket`. It now surfaces as `Unsupported service: <name>`. Evidence: same conformance run — `describe_vault`/`get_app` previously returned an S3 error body.
+- **CloudFormation error namespace** — `ErrorResponse` xmlns was `doc/2010-05-08/`; AWS emits `doc/2010-05-15/` (matches the botocore apiVersion).
+- **SESv2 error Content-Type** — errors now answer `application/x-amz-json-1.1`, matching the AWS capture (most rest-json services answer `application/json`; SESv2 does not).
+- **EC2 `DescribeInstances` validates ID format before existence** — a malformed `InstanceId` (e.g. `i-0000000000000000x`) now returns `InvalidInstanceID.Malformed`, matching the AWS capture; a well-formed unknown id still returns `InvalidInstanceID.NotFound`.
+- **ELBv2 `DescribeLoadBalancers` validates name length before existence** — a `Names` entry over 32 characters returns `ValidationError`, matching the AWS capture.
+- **WAFv2 `GetWebACL` validates the `Id` shape before existence** — a non-UUID or >36-char `Id` returns `ValidationException` listing the failed constraints, matching the AWS capture; a well-formed unknown id still returns `WAFNonexistentItemException`.
- **Step Functions — optimized DynamoDB error names** — conditional failures and other service errors now use the `DynamoDB.` prefix so exact `Catch` and `Retry` handlers match AWS.
- **Step Functions — Lambda `GetFunction` SDK integration** — workflows can read function configuration, code metadata and tags through `aws-sdk:lambda:getFunction`, including qualified reads.
- **Secrets Manager — force delete of a secret scheduled for deletion** — `DeleteSecret` with `ForceDeleteWithoutRecovery` returned `InvalidRequestException` for a secret already scheduled for deletion. It now deletes the secret permanently. Reported by @fabio-andre-rodrigues.
diff --git a/ministack/app.py b/ministack/app.py
index 969d34f4..406927d3 100644
--- a/ministack/app.py
+++ b/ministack/app.py
@@ -219,6 +219,7 @@ from ministack.core.iam_evaluator import (
from ministack.core.persistence import PERSIST_STATE, load_state, save_all
from ministack.core.responses import (
_12_DIGIT_RE,
+ fix_error_content_type,
set_request_account_id,
set_request_region,
)
@@ -2717,6 +2718,11 @@ async def _dispatch_service_request(
json.dumps({"__type": "InternalError", "message": str(e)}).encode(),
)
+ # Real AWS picks an error's Content-Type from the service's protocol —
+ # normalize any generic envelope the service emitted to the wire value
+ # (evidence: diffs against committed real-AWS wire captures).
+ fix_error_content_type(service, status, resp_headers)
+
_maybe_record_cloudtrail(service, method, path, headers, body, query_params, request_id, region)
resp_headers.update(
diff --git a/ministack/core/responses.py b/ministack/core/responses.py
index 076c8eb8..bddbe74e 100644
--- a/ministack/core/responses.py
+++ b/ministack/core/responses.py
@@ -8,6 +8,7 @@ JSON responses (DynamoDB, Lambda, SecretsManager, CloudWatch Logs).
import contextlib
import contextvars
+import functools
import hashlib
import json
import os
@@ -530,6 +531,120 @@ class StreamingResponse:
self.runner = runner
+# ---------------------------------------------------------------------------
+# Error-envelope Content-Type normalization
+#
+# Real AWS picks an error's Content-Type from the *service's protocol*, not
+# from a generic default — and services disagree: DynamoDB answers
+# ``application/x-amz-json-1.0`` while Kinesis answers
+# ``application/x-amz-json-1.1``; query-protocol services answer
+# ``text/xml`` while EC2 answers ``text/xml;charset=UTF-8``. The botocore
+# service model carries everything needed to reproduce this: ``protocol``
+# and ``jsonVersion``. A small override table covers wire quirks the model
+# does not declare.
+#
+# Evidence: real AWS wire captures diffed per service (us-east-1) — the
+# model values below matched the captured Content-Type on every probed
+# service.
+# ---------------------------------------------------------------------------
+
+# Ministack registry/service names that differ from the botocore client name.
+_BOTOCORE_NAME = {
+ "states": "stepfunctions",
+ "monitoring": "cloudwatch",
+ "elasticloadbalancing": "elbv2",
+ "airflow": "mwaa",
+ "elasticmapreduce": "emr",
+ "tagging": "resourcegroupstaggingapi",
+}
+
+# Wire-observed Content-Types that contradict what the model implies.
+# sesv2 — rest-json service, but AWS emits application/x-amz-json-1.1 on
+# errors (capture: get_email_identity 404).
+# s3 — rest-xml, but S3 answers application/xml where the other
+# rest-xml services (route53) answer text/xml.
+_WIRE_CT_OVERRIDE = {
+ "sesv2": "application/x-amz-json-1.1",
+ "s3": "application/xml",
+}
+
+_JSON_FAMILY = {
+ "application/json",
+ "application/x-amz-json-1.0",
+ "application/x-amz-json-1.1",
+}
+_XML_FAMILY = {"application/xml", "text/xml"}
+
+
[email protected]_cache(maxsize=None)
+def _service_model(service: str):
+ """The botocore service model for a ministack service name, or None."""
+ try:
+ import botocore.session
+ except ImportError:
+ return None
+ name = _BOTOCORE_NAME.get(service, service)
+ try:
+ return botocore.session.get_session().get_service_model(name)
+ except Exception:
+ return None
+
+
+def expected_error_content_type(service: str, emitted_ct: str) -> str | None:
+ """The Content-Type real AWS emits for this service's error envelope.
+
+ ``emitted_ct`` decides which family to correct within: a service that
+ answered an XML envelope gets the XML value for its protocol, a JSON
+ envelope gets the JSON value. Returns None when there is nothing
+ evidence-backed to enforce (unknown service, non-envelope type, or a
+ protocol ministack does not wire-map, e.g. declared-cbor services it
+ serves as query-compatible JSON).
+ """
+ base = emitted_ct.split(";", 1)[0].strip().lower()
+ families = _JSON_FAMILY | _XML_FAMILY
+ if base in families and service in _WIRE_CT_OVERRIDE:
+ return _WIRE_CT_OVERRIDE[service]
+
+ model = _service_model(service)
+ if model is None:
+ return None
+ protocol = model.metadata.get("protocol")
+
+ if base in _JSON_FAMILY:
+ if protocol == "json":
+ version = model.metadata.get("jsonVersion") or "1.0"
+ return f"application/x-amz-json-{version}"
+ if protocol == "rest-json":
+ return "application/json"
+ return None
+ if base in _XML_FAMILY:
+ if protocol == "query":
+ return "text/xml"
+ if protocol == "ec2":
+ return "text/xml;charset=UTF-8"
+ if protocol == "rest-xml":
+ return "text/xml" # s3's application/xml is the override above
+ return None
+
+
+def fix_error_content_type(service: str, status: int, headers: dict) -> None:
+ """Rewrite ``headers['Content-Type']`` in place when an error envelope
+ carries the wrong wire value for the service's protocol.
+
+ Scoped to error responses: the captures that drive this table are
+ error probes, and success payloads (e.g. an S3 object that happens to
+ be JSON) must never be rewritten.
+ """
+ if status < 400:
+ return
+ emitted = headers.get("Content-Type", "")
+ if not emitted:
+ return
+ expected = expected_error_content_type(service, emitted)
+ if expected and emitted != expected:
+ headers["Content-Type"] = expected
+
+
def now_iso() -> str:
"""Current time in AWS ISO format."""
return datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + "Z"
diff --git a/ministack/core/router.py b/ministack/core/router.py
index 65387cf2..d0e708be 100644
--- a/ministack/core/router.py
+++ b/ministack/core/router.py
@@ -20,6 +20,40 @@ from ministack.core.arn import ArnParseError, parse_arn
logger = logging.getLogger("ministack")
+_KNOWN_AWS_SERVICE_NAMES: frozenset | None = None
+
+
+def _is_aws_service_name(scope_name: str) -> bool:
+ """Whether a SigV4 credential scope names a real AWS service.
+
+ Built lazily from the botocore catalog — service name, endpoint prefix,
+ and signing name per model — so new AWS services are recognized without a
+ table to maintain. Only consulted for scopes that matched no registered
+ service or alias, so a miss never changes routing for implemented
+ services.
+ """
+ global _KNOWN_AWS_SERVICE_NAMES
+ if _KNOWN_AWS_SERVICE_NAMES is None:
+ names = set()
+ try:
+ import botocore.session
+
+ session = botocore.session.get_session()
+ for service in session.get_available_services():
+ names.add(service)
+ try:
+ meta = session.get_service_model(service).metadata
+ except Exception:
+ continue
+ names.add(meta.get("endpointPrefix", ""))
+ names.add(meta.get("signingName", ""))
+ except Exception:
+ pass
+ names.discard("")
+ _KNOWN_AWS_SERVICE_NAMES = frozenset(names)
+ return scope_name in _KNOWN_AWS_SERVICE_NAMES
+
+
# Lambda API paths are versioned by date prefix. Resources enumerated per
# AWS Lambda API Reference (functions, layers, event-source-mappings,
# account-settings, runtime, tags, code-signing-configs). Matches any
@@ -819,6 +853,13 @@ def detect_service(method: str, path: str, headers: dict, query_params: dict) ->
}
if svc_name in scope_map:
return scope_map[svc_name]
+ # A request signed for a real AWS service MiniStack does not
+ # implement must not fall through to the S3 path catch-all —
+ # answering NoSuchBucket for a glacier/pinpoint call lies about
+ # which service failed. Surface it as its (unsupported) service
+ # so dispatch returns "Unsupported service: <name>".
+ if _is_aws_service_name(svc_name):
+ return svc_name
# 3. Check query parameters for Action-based APIs (SQS, SNS, IAM, STS, CloudWatch)
action = (
diff --git a/ministack/services/alb.py b/ministack/services/alb.py
index 804e4617..10bb1221 100644
--- a/ministack/services/alb.py
+++ b/ministack/services/alb.py
@@ -597,6 +597,16 @@ def _describe_lbs(params):
if not results:
return _error("LoadBalancerNotFound", "One or more load balancers not found", 400)
if name_filter:
+ # AWS validates the name before checking existence — evidence: real
+ # AWS wire capture answered ValidationError for a name over 32
+ # chars.
+ for name in name_filter:
+ if len(name) > 32:
+ return _error(
+ "ValidationError",
+ f"The load balancer name '{name}' cannot be longer than '32' characters",
+ 400,
+ )
results = [lb for lb in results if lb["LoadBalancerName"] in name_filter]
if not results:
return _error("LoadBalancerNotFound", "One or more load balancers not found", 400)
diff --git a/ministack/services/cloudformation/helpers.py b/ministack/services/cloudformation/helpers.py
index 174b9a00..b2bd2139 100644
--- a/ministack/services/cloudformation/helpers.py
+++ b/ministack/services/cloudformation/helpers.py
@@ -13,7 +13,9 @@ from ministack.core.responses import new_uuid
logger = logging.getLogger("cloudformation")
-CFN_NS = "http://cloudformation.amazonaws.com/doc/2010-05-08/"
+# Evidence: real AWS wire capture — AWS emits xmlns doc/2010-05-15,
+# matching the apiVersion in the botocore model.
+CFN_NS = "http://cloudformation.amazonaws.com/doc/2010-05-15/"
# The CloudFormation quotas page: the template body of a request and of an
# S3 object behind TemplateURL. CreateStack documents the stack name as
diff --git a/ministack/services/ec2.py b/ministack/services/ec2.py
index 3fbc47f9..c30e6afd 100644
--- a/ministack/services/ec2.py
+++ b/ministack/services/ec2.py
@@ -92,6 +92,10 @@ DOCKER_NETWORK = os.environ.get("DOCKER_NETWORK", "")
# for a systemd guest). Parsed by _parse_ec2_docker_flags; --init is refused.
EC2_DOCKER_FLAGS = os.environ.get("EC2_DOCKER_FLAGS", "")
+# AWS instance IDs are i- + 8 or 17 lowercase hex chars — malformed IDs are
+# rejected before any existence check.
+_INSTANCE_ID_RE = re.compile(r"^i-(?:[0-9a-f]{8}|[0-9a-f]{17})$")
+
# Docker client, created on first use. Only registered images reach for it, so
# an emulator nobody registered an AMI with never imports docker-py at all.
_docker = None
@@ -940,6 +944,11 @@ def _describe_instances(p):
if filter_ids:
for iid in filter_ids:
+ # AWS validates the ID format before checking existence —
+ # evidence: real AWS wire capture answered
+ # InvalidInstanceID.Malformed for a non-hex id.
+ if not _INSTANCE_ID_RE.match(iid):
+ return _error("InvalidInstanceID.Malformed", f'Invalid id: "{iid}"', 400)
if iid not in _instances:
return _error("InvalidInstanceID.NotFound", f"The instance ID '{iid}' does not exist", 400)
diff --git a/ministack/services/ses_v2.py b/ministack/services/ses_v2.py
index 3a4983a5..638151f7 100644
--- a/ministack/services/ses_v2.py
+++ b/ministack/services/ses_v2.py
@@ -127,7 +127,10 @@ def _legacy_resource_arn_for_region(resource_arn, account_id, region):
def _json_err(code, message, status=400):
body = json.dumps({"message": message, "name": code}).encode("utf-8")
- headers = {"Content-Type": "application/json", "x-amzn-errortype": code}
+ # Evidence: real AWS wire capture — SESv2 answers errors with
+ # application/x-amz-json-1.1, not application/json like most rest-json
+ # services.
+ headers = {"Content-Type": "application/x-amz-json-1.1", "x-amzn-errortype": code}
return status, headers, body
diff --git a/ministack/services/waf.py b/ministack/services/waf.py
index 772578d3..3d500c54 100644
--- a/ministack/services/waf.py
+++ b/ministack/services/waf.py
@@ -15,6 +15,7 @@ import copy
import json
import logging
import os
+import re
from ministack.core.arn import ArnParseError, parse_arn
from ministack.core.responses import (
@@ -275,6 +276,34 @@ def _waf_err(code, message):
return error_response_json(code, message, 400)
+_WAFV2_ID_PATTERN = r"^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$"
+_WAFV2_ID_RE = re.compile(_WAFV2_ID_PATTERN)
+
+
+def _validate_web_acl_id(uid):
+ """AWS validates the WebACL Id shape before checking existence — a non-UUID
+ or >36-char value is a ValidationException, never WAFNonexistentItem.
+ Evidence: real AWS wire capture observation."""
+ errors = []
+ if not _WAFV2_ID_RE.match(uid):
+ errors.append(
+ f"Value '{uid}' at 'id' failed to satisfy constraint: "
+ f"Member must satisfy regular expression pattern: {_WAFV2_ID_PATTERN}"
+ )
+ if len(uid) > 36:
+ errors.append(
+ f"Value '{uid}' at 'id' failed to satisfy constraint: "
+ "Member must have length less than or equal to 36"
+ )
+ if errors:
+ n = len(errors)
+ return _waf_err(
+ "ValidationException",
+ f"{n} validation error{'s' if n > 1 else ''} detected: {'; '.join(errors)}",
+ )
+ return None
+
+
def _waf_invalid_arn(arn):
return _waf_err("WAFInvalidParameterException", f"Invalid WAFv2 resource ARN: {arn}")
@@ -418,6 +447,8 @@ def _create_web_acl(data):
def _get_web_acl(data):
uid = data.get("Id", "")
+ if err := _validate_web_acl_id(uid):
+ return err
acl = _resource_from_scope(_web_acls, uid, data.get("Scope", "REGIONAL"))
if not acl:
return _waf_err("WAFNonexistentItemException", f"WebACL {uid} not found")
diff --git a/tests/test_alb.py b/tests/test_alb.py
index 2987d4bd..43f1ab4b 100644
--- a/tests/test_alb.py
+++ b/tests/test_alb.py
@@ -1884,3 +1884,15 @@ def test_abandoned_login_attempts_are_pruned_after_the_15_minute_bound():
assert status == 302
assert "stale-1" not in alb._oidc_pending, "abandoned attempt survived the prune"
assert "fresh-1" in alb._oidc_pending, "a live attempt must not be pruned"
+
+
+def test_alb_describe_lbs_validates_name_length_before_existence(elbv2):
+ """AWS validates the Names filter before lookup — evidence: real AWS
+ wire capture answered ValidationError for a name over 32 chars."""
+ with pytest.raises(ClientError) as exc:
+ elbv2.describe_load_balancers(Names=["x" * 33])
+ assert exc.value.response["Error"]["Code"] == "ValidationError"
+
+ with pytest.raises(ClientError) as exc:
+ elbv2.describe_load_balancers(Names=["definitely-not-there"])
+ assert exc.value.response["Error"]["Code"] == "LoadBalancerNotFound"
diff --git a/tests/test_ec2.py b/tests/test_ec2.py
index e01e0eb7..cb410b33 100644
--- a/tests/test_ec2.py
+++ b/tests/test_ec2.py
@@ -4742,3 +4742,15 @@ def test_ec2_cross_account_ami_sharing():
assert f"Not authorized for image:{ami}" in exc.value.response["Error"]["Message"]
owner.deregister_image(ImageId=ami)
+
+
+def test_ec2_describe_instances_validates_id_format_before_existence(ec2):
+ """AWS rejects a malformed instance ID before checking existence —
+ evidence: real AWS wire capture answered InvalidInstanceID.Malformed."""
+ with pytest.raises(ClientError) as exc:
+ ec2.describe_instances(InstanceIds=["i-0000000000000000x"])
+ assert exc.value.response["Error"]["Code"] == "InvalidInstanceID.Malformed"
+
+ with pytest.raises(ClientError) as exc:
+ ec2.describe_instances(InstanceIds=["i-00000000000000000"])
+ assert exc.value.response["Error"]["Code"] == "InvalidInstanceID.NotFound"
diff --git a/tests/test_ministack.py b/tests/test_ministack.py
index e54665f2..3918d282 100644
--- a/tests/test_ministack.py
+++ b/tests/test_ministack.py
@@ -1049,3 +1049,108 @@ def test_drop_containers_logs_the_ids_it_could_not_remove(caplog):
removed = container_reaper.drop_containers([_C("a" * 64, False), _C("b" * 64, True)])
assert removed == 1
assert "bbbbbbbbbbbb" in caplog.text and "aaaaaaaaaaaa" not in caplog.text
+
+
+# ---------------------------------------------------------------------------
+# Error-envelope Content-Type fidelity + credential-scope honesty
+#
+# The expected values are real AWS observations: MiniStack responses were
+# diffed against committed real-AWS wire captures on the fields SDKs read
+# (status, parsed Error.Code, Content-Type).
+# ---------------------------------------------------------------------------
+
+from ministack.core.responses import ( # noqa: E402
+ expected_error_content_type,
+ fix_error_content_type,
+)
+from ministack.core.router import detect_service # noqa: E402
+
+
+def _auth(scope_name):
+ return {
+ "host": "localhost:4566",
+ "authorization": (
+ "AWS4-HMAC-SHA256 Credential=test/20260101/us-east-1/"
+ f"{scope_name}/aws4_request, SignedHeaders=host, Signature=x"
+ ),
+ }
+
+
[email protected]("service,emitted,expected", [
+ # json protocol: jsonVersion decides — kinesis/athena/kms answer 1.1,
+ # dynamodb/states/sqs answer 1.0.
+ ("kinesis", "application/x-amz-json-1.0", "application/x-amz-json-1.1"),
+ ("athena", "application/x-amz-json-1.0", "application/x-amz-json-1.1"),
+ ("kms", "application/x-amz-json-1.0", "application/x-amz-json-1.1"),
+ ("dynamodb", "application/x-amz-json-1.1", "application/x-amz-json-1.0"),
+ ("states", "application/x-amz-json-1.1", "application/x-amz-json-1.0"),
+ ("sqs", "application/x-amz-json-1.0", "application/x-amz-json-1.0"),
+ # rest-json answers application/json.
+ ("lambda", "application/x-amz-json-1.0", "application/json"),
+ ("appsync", "application/x-amz-json-1.0", "application/json"),
+ ("apigateway", "application/json", "application/json"),
+ # Wire quirks the model does not declare.
+ ("sesv2", "application/json", "application/x-amz-json-1.1"),
+ # query protocol answers text/xml; ec2 adds charset.
+ ("iam", "application/xml", "text/xml"),
+ ("sns", "application/xml", "text/xml"),
+ ("rds", "application/xml", "text/xml"),
+ ("cloudformation", "application/xml", "text/xml"),
+ ("elasticloadbalancing", "application/xml", "text/xml"),
+ ("ec2", "application/xml", "text/xml;charset=UTF-8"),
+ # rest-xml answers text/xml — except S3, which answers application/xml.
+ ("route53", "application/xml", "text/xml"),
+ ("route53", "text/xml", "text/xml"),
+ ("s3", "application/xml", "application/xml"),
+ ("s3", "text/xml", "application/xml"),
+])
+def test_expected_error_content_type(service, emitted, expected):
+ assert expected_error_content_type(service, emitted) == expected
+
+
+def test_family_mismatch_is_not_rewritten():
+ # A query-protocol service that emitted a JSON body stays as-is: the
+ # family guard only corrects within the emitted envelope family.
+ assert expected_error_content_type("iam", "application/json") is None
+ # Declared-cbor services ministack serves as query-compat JSON are
+ # left alone.
+ assert expected_error_content_type("monitoring", "application/x-amz-json-1.0") is None
+
+
+def test_fix_error_content_type_scopes():
+ headers = {"Content-Type": "application/x-amz-json-1.0"}
+ fix_error_content_type("kinesis", 400, headers)
+ assert headers["Content-Type"] == "application/x-amz-json-1.1"
+
+ # success responses are never rewritten — an S3 object that happens to
+ # be JSON must keep its real content type.
+ headers = {"Content-Type": "application/json"}
+ fix_error_content_type("s3", 200, headers)
+ assert headers["Content-Type"] == "application/json"
+
+ # non-envelope payloads and unknown services are untouched
+ headers = {"Content-Type": "image/png"}
+ fix_error_content_type("s3", 400, headers)
+ assert headers["Content-Type"] == "image/png"
+ headers = {"Content-Type": "application/xml"}
+ fix_error_content_type("not-a-service", 400, headers)
+ assert headers["Content-Type"] == "application/xml"
+
+
[email protected]("scope", ["glacier", "pinpoint", "route53resolver"])
+def test_unimplemented_real_service_surfaces_by_name(scope):
+ # A request signed for a real AWS service ministack does not implement
+ # must not fall through to the S3 catch-all — it routes to its own
+ # (unsupported) name so dispatch answers "Unsupported service".
+ assert detect_service("GET", "/anything", _auth(scope), {}) == scope
+
+
+def test_unknown_scope_still_falls_through_to_s3():
+ # A scope that is not a real AWS service keeps legacy path routing —
+ # e.g. unsigned/garbage credentials hitting S3 path style.
+ assert detect_service("GET", "/bucket/key", _auth("totally-fake-svc"), {}) == "s3"
+
+
+def test_implemented_scope_routes_normally():
+ assert detect_service("POST", "/", _auth("dynamodb"), {}) == "dynamodb"
+ assert detect_service("POST", "/", _auth("states"), {}) == "states"
diff --git a/tests/test_waf.py b/tests/test_waf.py
index 5ac9076f..470c5f78 100644
--- a/tests/test_waf.py
+++ b/tests/test_waf.py
@@ -843,3 +843,19 @@ def test_waf_list_resources_for_web_acl(wafv2):
WebACLArn=acl_arn, ResourceType="APPLICATION_LOAD_BALANCER"
)
assert resource_arn in list_resp.get("ResourceArns", [])
+
+
+def test_wafv2_get_web_acl_validates_id_shape_before_existence(wafv2):
+ """AWS validates the Id shape before lookup — evidence: real AWS wire
+ capture answered ValidationException listing the failed constraints."""
+ from botocore.exceptions import ClientError
+
+ with pytest.raises(ClientError) as exc:
+ wafv2.get_web_acl(Name="nope", Scope="REGIONAL", Id="not-a-uuid")
+ assert exc.value.response["Error"]["Code"] == "ValidationException"
+
+ with pytest.raises(ClientError) as exc:
+ wafv2.get_web_acl(
+ Name="nope", Scope="REGIONAL", Id=str(_uuid_mod.uuid4())
+ )
+ assert exc.value.response["Error"]["Code"] == "WAFNonexistentItemException"