Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.
Python awsaws-emulatoraws-localaws-sdkdevtoolsdockerdynamodbec2emulatorlambdalocalstacklocalstack-alternativeministackmock-awsopen-sourcepythons3sqsterraform
relase v1.3.46 (#682)
Nahuel Nuceraf422cc636d5a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 8a46092f..66b04a46 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,16 @@ Versioning follows [Semantic Versioning](https://semver.org/).---+## [1.3.46] — 2026-05-21++### Added+- **S3 `PutObject` conditional writes** — `If-None-Match: "*"` (create-once) and `If-Match: "<etag>"` (optimistic concurrency) are now enforced on `PutObject`, matching the AWS feature shipped November 2024. Precondition violations return 412 `PreconditionFailed`, except `If-Match: "<etag>"` against a missing key which returns 404 `NoSuchKey` per the AWS user guide. ETag comparison strips surrounding quotes on both sides. The symmetric `x-amz-copy-source-if-match` headers on `CopyObject` were already supported; this closes the gap on plain `PutObject`. Contributed by @mattcookio.++### Fixed+- **Cognito JWT `iss` claim uses the pool's region, not the request region** — when a SigV4 scope carried a different region from the pool's creation region, the JWT `iss` mismatched the pool ID prefix and standards-compliant validators rejected the token. A new `_pool_region(pool_id)` resolver parses the region from the pool ID (`{region}_{suffix}`) and is applied to the `iss` claim, the PreTokenGeneration trigger event region, the user-pool ARN, the OIDC discovery `issuer`, and the hosted-UI CloudFront URL on `CreateUserPoolDomain` / `DescribeUserPoolDomain`. The parser accepts 3-segment commercial regions and 4-segment GovCloud / ISO regions (`us-gov-east-1`, `us-iso-east-1`, etc.). Contributed by @subrotosanyal.++---+## [1.3.45] — 2026-05-20### Fixeddiff --git a/ministack/services/cognito.py b/ministack/services/cognito.pyindex c9e8d030..8cdb7f3f 100644--- a/ministack/services/cognito.py+++ b/ministack/services/cognito.py@@ -168,7 +168,12 @@ def well_known_openid_configuration(pool_id: str, region: str | None = None, hosand /logout are actually served (added by PR #344). Real AWS serves theseon the pool-domain host; MiniStack serves them on the gateway."""- r = region or get_region()+ # The discovery `issuer` MUST match the JWT `iss` claim — OIDC clients that+ # verify `iss == discovery.issuer` break otherwise. _fake_token derives `iss`+ # from the pool's region (encoded in pool_id), so do the same here. The+ # `region` argument from the request scope is only used as a last-resort+ # fallback for malformed pool_ids.+ r = _pool_region(pool_id) if pool_id else (region or get_region())issuer = f"https://cognito-idp.{r}.amazonaws.com/{pool_id}"base = f"http://{host}" if host else f"http://{_MINISTACK_HOST}:{_MINISTACK_PORT}"pool_base = f"{base}/{pool_id}"@@ -310,7 +315,7 @@ def _now_epoch() -> float:def _pool_arn(pool_id: str) -> str:- return f"arn:aws:cognito-idp:{get_region()}:{get_account_id()}:userpool/{pool_id}"+ return f"arn:aws:cognito-idp:{_pool_region(pool_id)}:{get_account_id()}:userpool/{pool_id}"def _pool_id() -> str:@@ -322,11 +327,15 @@ def _pool_region(pool_id: str) -> str:"""Return the region encoded in a pool_id (format ``{region}_{suffix}``).Falls back to get_region() for empty or non-standard IDs so callers- never have to special-case the edge cases.+ never have to special-case the edge cases. The regex accepts both+ 3-segment commercial regions (e.g. ``us-east-1``, ``eu-central-1``) and+ 4-segment GovCloud / ISO regions (e.g. ``us-gov-east-1``, ``us-iso-west-1``,+ ``eu-isoe-west-1``) — Cognito is available in GovCloud, so the parser must+ not silently fall through and reproduce the original `iss` bug there."""if pool_id and "_" in pool_id:candidate = pool_id.rsplit("_", 1)[0]- if re.match(r"^[a-z]+-[a-z]+-\d+$", candidate):+ if re.match(r"^[a-z]+(-[a-z]+)+-\d+$", candidate):return candidatereturn get_region()@@ -2340,7 +2349,7 @@ def _create_user_pool_domain(data):return error_response_json("InvalidParameterException", f"Domain {domain} already exists.", 400)pool["Domain"] = domain_pool_domain_map[domain] = pid- return json_response({"CloudFrontDomain": f"{domain}.auth.{get_region()}.amazoncognito.com"})+ return json_response({"CloudFrontDomain": f"{domain}.auth.{_pool_region(pid)}.amazoncognito.com"})def _delete_user_pool_domain(data):@@ -2366,7 +2375,7 @@ def _describe_user_pool_domain(data):"AWSAccountId": get_account_id(),"Domain": domain,"S3Bucket": "",- "CloudFrontDistribution": f"{domain}.auth.{get_region()}.amazoncognito.com",+ "CloudFrontDistribution": f"{domain}.auth.{_pool_region(pid)}.amazoncognito.com","Version": "1","Status": "ACTIVE","CustomDomainConfig": {},diff --git a/pyproject.toml b/pyproject.tomlindex 652365fa..c3edc4a3 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"[project]name = "ministack"-version = "1.3.45"+version = "1.3.46"description = "Free, open-source local AWS emulator — drop-in LocalStack replacement"readme = "README.md"license = { file = "LICENSE" }diff --git a/tests/test_cognito.py b/tests/test_cognito.pyindex 7943d735..69e4c593 100644--- a/tests/test_cognito.py+++ b/tests/test_cognito.py@@ -3101,6 +3101,100 @@ def test_cognito_iss_claim_uses_pool_region():)+def test_cognito_pool_region_parser_govcloud():+ """`_pool_region` must accept 4-segment GovCloud / ISO region prefixes.++ Cognito is available in GovCloud (us-gov-east-1, us-gov-west-1) and the ISO+ regions. The original `_pool_region` regex (`^[a-z]+-[a-z]+-\\d+$`) only+ matched 3-segment commercial regions, so GovCloud pools silently fell back+ to `get_region()` and reproduced the iss-claim bug there.+ """+ mod = _cognito_module()+ cases = [+ ("us-east-1_abc123def", "us-east-1"),+ ("eu-central-1_abc123def", "eu-central-1"),+ ("us-gov-east-1_abc123def", "us-gov-east-1"),+ ("us-gov-west-1_abc123def", "us-gov-west-1"),+ ("us-iso-east-1_abc123def", "us-iso-east-1"),+ ("us-isob-east-1_abc123def", "us-isob-east-1"),+ ("eu-isoe-west-1_abc123def", "eu-isoe-west-1"),+ ("cn-northwest-1_abc123def", "cn-northwest-1"),+ ("ap-southeast-4_abc123def", "ap-southeast-4"),+ ]+ for pool_id, expected in cases:+ assert mod._pool_region(pool_id) == expected, (+ f"_pool_region({pool_id!r}) should return {expected!r}, got {mod._pool_region(pool_id)!r}"+ )+++def test_cognito_pool_arn_uses_pool_region():+ """`_pool_arn` must encode the pool's region, not the request region.++ A pool created in eu-central-1 and described from any other request context+ must still return an ARN whose region segment is `eu-central-1` — that is+ real-AWS behavior (the pool is a regional resource) and CloudFormation /+ cross-account-trust policies depend on a stable ARN.+ """+ mod = _cognito_module()+ arn = mod._pool_arn("eu-central-1_abcdef")+ assert ":cognito-idp:eu-central-1:" in arn, arn+ arn_gov = mod._pool_arn("us-gov-east-1_abcdef")+ assert ":cognito-idp:us-gov-east-1:" in arn_gov, arn_gov+++def test_cognito_openid_discovery_issuer_uses_pool_region():+ """OIDC discovery's `issuer` must match the JWT `iss` — both derived from pool region.++ OIDC clients verify `iss == discovery.issuer`. If discovery returns the+ request-scope region but the JWT carries the pool-scope region, every+ standards-compliant validator rejects the token. Regression coverage for+ the same root-cause class as #678.+ """+ mod = _cognito_module()+ pool_id = "eu-central-1_abcdef123"+ # Even if the request scope says us-east-1, discovery must return eu-central-1+ # because that's what the JWT iss will encode.+ _status, _headers, body = mod.well_known_openid_configuration(pool_id, region="us-east-1", host="localhost:4566")+ doc = json.loads(body)+ assert doc["issuer"] == f"https://cognito-idp.eu-central-1.amazonaws.com/{pool_id}", doc["issuer"]+++def test_cognito_user_pool_domain_cloudfront_uses_pool_region():+ """CreateUserPoolDomain / DescribeUserPoolDomain CloudFront URL must reflect the pool's region.++ Real AWS user pool domains are regional — the hosted-UI CloudFront URL is+ `{domain}.auth.{pool-region}.amazoncognito.com`. Using the request region+ would point clients at the wrong region's domain.+ """+ import boto3++ endpoint = os.environ.get("MINISTACK_ENDPOINT", "http://localhost:4566")+ region = "eu-central-1"+ client = boto3.client(+ "cognito-idp",+ endpoint_url=endpoint,+ aws_access_key_id="test",+ aws_secret_access_key="test",+ region_name=region,+ )+ pid = client.create_user_pool(PoolName="DomainRegionPool")["UserPool"]["Id"]+ assert pid.startswith("eu-central-1_")++ # Pool ARN should encode eu-central-1.+ desc = client.describe_user_pool(UserPoolId=pid)+ assert ":cognito-idp:eu-central-1:" in desc["UserPool"]["Arn"], desc["UserPool"]["Arn"]++ domain = f"domain-region-{pid.split('_', 1)[1].lower()}"+ create_resp = client.create_user_pool_domain(Domain=domain, UserPoolId=pid)+ assert create_resp["CloudFrontDomain"].endswith(".auth.eu-central-1.amazoncognito.com"), (+ create_resp["CloudFrontDomain"]+ )+ desc_resp = client.describe_user_pool_domain(Domain=domain)+ assert desc_resp["DomainDescription"]["CloudFrontDistribution"].endswith(+ ".auth.eu-central-1.amazoncognito.com"+ ), desc_resp["DomainDescription"]["CloudFrontDistribution"]++def test_cognito_email_disabled_env_skips_send(cognito_idp, monkeypatch):"""COGNITO_EMAIL_ENABLED=false must short-circuit delivery in-process."""mod = _cognito_module()