fix(cognito): build OIDC URLs from effectiveBaseUrl so FLOCI_HOSTNAME is honored (#1929)

* fix(cognito): build OIDC URLs from effectiveBaseUrl so FLOCI_HOSTNAME is honored

CognitoService was wired from the raw emulatorConfig.baseUrl(), so its
issuer, JWKS URI, and token/userInfo endpoints ignored FLOCI_HOSTNAME.
Every other response-facing service (SQS QueueUrl, SNS, S3 pre-signed
URLs, Lambda function URLs) uses effectiveBaseUrl(), which applies the
hostname override (and the TLS http->https switch).

These Cognito URLs are external-facing — they land in the JWT `iss`
claim and the .well-known/openid-configuration document that clients
must reach — so in a multi-container / Docker Compose setup with
FLOCI_HOSTNAME set they were emitted as http://localhost:4566/... and
unreachable, breaking OIDC discovery and JWT validation.

Switch the injection to effectiveBaseUrl(). It falls back to baseUrl()
when hostname is unset, so the default localhost behavior (and all
existing tests) are unchanged.

* test(cognito): drive real effectiveBaseUrl so the test reproduces the bug

Stub only effectiveBaseUrl()'s inputs (baseUrl, hostname, tls) and call
the real default method, instead of stubbing effectiveBaseUrl() itself.
The previous version asserted little more than "Cognito calls the getter
it was told to" — it stubbed away the very override logic under test and
would not fail against the old raw-baseUrl() wiring.

Now the localhost->floci host swap actually runs, so the test fails on a
revert. Also add a no-hostname case pinning the baseUrl() fallback.

* test(cognito): drop dedicated effectiveBaseUrl wiring test

On review of the repo's testing patterns this test isn't idiomatic and
adds little. Every peer service that reads effectiveBaseUrl() (SQS, SNS,
S3, Lambda, ECS, Pipes, IoT, SSM) either stubs it to a literal or is
constructed with a literal baseUrl — none has a dedicated test proving
the FLOCI_HOSTNAME override reaches its response URLs; the accessor
choice is simply trusted. The removed test was also the only
thenCallRealMethod on effectiveBaseUrl in the suite.

The existing issuerUrlForPinnedPoolResolvesAsBaseUrlSlashPoolId already
covers the getIssuer URL shape, and effectiveBaseUrl()'s own override
logic is exercised via TlsConfigSource tests. The fix is a one-token
consistency change aligning Cognito with its peers.
This commit is contained in:
Huan Jiang authored and GitHub committed 2026-07-23 12:27:46 -04:00
1 parent 9308687f5a
commit 1c8b851bea
1 file changed
+1 -1
@@ -91,7 +91,7 @@ public class CognitoService {
new TypeReference<Map<String, CognitoGroup>>() {}),
storageFactory.create("cognito", "cognito-revoked-tokens.json",
new TypeReference<Map<String, RevokedTokenInfo>>() {}),
trimTrailingSlash(emulatorConfig.baseUrl()),
trimTrailingSlash(emulatorConfig.effectiveBaseUrl()),
regionResolver,
lambdaService,
new VerificationCodeService(storageFactory, clock),