Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(cognito): default ExplicitAuthFlows to refresh, SRP and custom auth (#4081)

Priamo Germosen06007deea8b0
diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/CognitoFeaturesTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/CognitoFeaturesTest.java
index 7b459c5b63..53ee06d718 100644
--- a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/CognitoFeaturesTest.java
+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/CognitoFeaturesTest.java
@@ -171,6 +171,10 @@ class CognitoFeaturesTest {
assertThat(client.refreshTokenRotation())
.as("refreshTokenRotation must be null when not set")
.isNull();
+ assertThat(client.explicitAuthFlows())
+ .as("ExplicitAuthFlows must be empty when not set, matching AWS; the default"
+ + " (refresh, SRP and custom auth) is enforced at auth time, not stored")
+ .isEmpty();
}
// ── Issue #229 — InitiateAuth rejects when no password hash is set ────────
diff --git a/compatibility-tests/sdk-test-node/tests/cognito.test.ts b/compatibility-tests/sdk-test-node/tests/cognito.test.ts
index 9502cca4fb..9d078df616 100644
--- a/compatibility-tests/sdk-test-node/tests/cognito.test.ts
+++ b/compatibility-tests/sdk-test-node/tests/cognito.test.ts
@@ -7,6 +7,7 @@ import {
CognitoIdentityProviderClient,
CreateUserPoolCommand,
CreateUserPoolClientCommand,
+ ExplicitAuthFlowsType,
AdminCreateUserCommand,
AdminSetUserPasswordCommand,
InitiateAuthCommand,
@@ -62,6 +63,7 @@ describe('Cognito', () => {
new CreateUserPoolClientCommand({
UserPoolId: poolId,
ClientName: `test-client-${uniqueName()}`,
+ ExplicitAuthFlows: [ExplicitAuthFlowsType.ALLOW_USER_PASSWORD_AUTH],
})
);
clientId = response.UserPoolClient!.ClientId!;
diff --git a/compatibility-tests/sdk-test-python/tests/test_cognito.py b/compatibility-tests/sdk-test-python/tests/test_cognito.py
index 53e8e80191..edb0735efb 100644
--- a/compatibility-tests/sdk-test-python/tests/test_cognito.py
+++ b/compatibility-tests/sdk-test-python/tests/test_cognito.py
@@ -126,7 +126,9 @@ class TestCognitoAuth:
pool_id = pool_response["UserPool"]["Id"]
client_response = cognito_client.create_user_pool_client(
- UserPoolId=pool_id, ClientName=client_name
+ UserPoolId=pool_id,
+ ClientName=client_name,
+ ExplicitAuthFlows=["ALLOW_ADMIN_USER_PASSWORD_AUTH"],
)
client_id = client_response["UserPoolClient"]["ClientId"]
@@ -165,7 +167,9 @@ class TestCognitoAuth:
pool_id = pool_response["UserPool"]["Id"]
client_response = cognito_client.create_user_pool_client(
- UserPoolId=pool_id, ClientName=client_name
+ UserPoolId=pool_id,
+ ClientName=client_name,
+ ExplicitAuthFlows=["ALLOW_ADMIN_USER_PASSWORD_AUTH"],
)
client_id = client_response["UserPoolClient"]["ClientId"]
diff --git a/docs/services/cognito.md b/docs/services/cognito.md
index 8f93522934..162c78e78c 100644
--- a/docs/services/cognito.md
+++ b/docs/services/cognito.md
@@ -210,11 +210,16 @@ challenge. It requires the user pool's tier to be Essentials or higher. `WEB_AUT
Any other `AuthFlow` value is rejected with `InvalidParameterException` and no tokens are issued.
-When an app client sets `ExplicitAuthFlows`, only the flows it lists are accepted (`ALLOW_USER_PASSWORD_AUTH`,
-`ALLOW_USER_SRP_AUTH`, `ALLOW_CUSTOM_AUTH`, `ALLOW_USER_AUTH`, `ALLOW_ADMIN_USER_PASSWORD_AUTH`,
-`ALLOW_REFRESH_TOKEN_AUTH`, and the legacy `USER_PASSWORD_AUTH`, `ADMIN_NO_SRP_AUTH` and
-`CUSTOM_AUTH_FLOW_ONLY`); any other flow fails with `InvalidParameterException`. A client created without `ExplicitAuthFlows` is not gated, unlike AWS, which defaults
-such a client to SRP, custom and refresh auth.
+An app client only accepts the flows in its `ExplicitAuthFlows`: `ALLOW_USER_PASSWORD_AUTH`,
+`ALLOW_USER_SRP_AUTH`, `ALLOW_CUSTOM_AUTH`, `ALLOW_USER_AUTH`, `ALLOW_ADMIN_USER_PASSWORD_AUTH` and
+`ALLOW_REFRESH_TOKEN_AUTH`, or the legacy `USER_PASSWORD_AUTH`, `ADMIN_NO_SRP_AUTH` and
+`CUSTOM_AUTH_FLOW_ONLY`. Any other flow fails with `InvalidParameterException`.
+
+A client created without `ExplicitAuthFlows`, or with it cleared to an empty list, stores and describes an
+empty list, matching AWS. It is enforced as if it had `ALLOW_REFRESH_TOKEN_AUTH`, `ALLOW_USER_SRP_AUTH` and
+`ALLOW_CUSTOM_AUTH`, the default AWS documents for such a client: only the enforcement uses that default, not
+the stored or returned value. A client that signs in with `USER_PASSWORD_AUTH`, `ADMIN_USER_PASSWORD_AUTH` or
+`USER_AUTH` must list the matching `ALLOW_` value.
## User Attribute Update Verification
diff --git a/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoAuthFlowHandler.java b/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoAuthFlowHandler.java
index 56bb18d616..1888608149 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoAuthFlowHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoAuthFlowHandler.java
@@ -172,15 +172,11 @@ final class CognitoAuthFlowHandler {
}
/**
- * Enforces the app client's {@code ExplicitAuthFlows}. A client with no explicit list is left
- * ungated so clients created without one keep working; once a list is set, the flow must be
- * covered by one of {@code acceptedValues}.
+ * Enforces the app client's {@code ExplicitAuthFlows}: the flow must be covered by one of
+ * {@code acceptedValues}.
*/
private static void requireFlowEnabled(UserPoolClient client, String authFlow, String... acceptedValues) {
- List<String> enabled = client.getExplicitAuthFlows();
- if (enabled == null || enabled.isEmpty()) {
- return;
- }
+ List<String> enabled = enabledAuthFlows(client);
for (String accepted : acceptedValues) {
if (enabled.contains(accepted)) {
return;
@@ -189,13 +185,21 @@ final class CognitoAuthFlowHandler {
throw new AwsException("InvalidParameterException", authFlow + " flow not enabled for this client", 400);
}
+ /**
+ * A client with no stored list, as one persisted before the default was materialised, gets the
+ * AWS default rather than every flow.
+ */
+ private static List<String> enabledAuthFlows(UserPoolClient client) {
+ List<String> enabled = client.getExplicitAuthFlows();
+ return enabled == null || enabled.isEmpty() ? CognitoService.DEFAULT_EXPLICIT_AUTH_FLOWS : enabled;
+ }
+
/**
* Refresh has to be listed explicitly via {@code ALLOW_REFRESH_TOKEN_AUTH}, except on clients that
* only use legacy (non {@code ALLOW_}) values, where refresh was never gated.
*/
private static void requireRefreshEnabled(UserPoolClient client, String authFlow) {
- List<String> enabled = client.getExplicitAuthFlows();
- if (enabled == null || enabled.stream().noneMatch(flow -> flow.startsWith("ALLOW_"))) {
+ if (enabledAuthFlows(client).stream().noneMatch(flow -> flow.startsWith("ALLOW_"))) {
return;
}
requireFlowEnabled(client, authFlow, "ALLOW_REFRESH_TOKEN_AUTH");
diff --git a/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoService.java b/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoService.java
index cf4e6983e9..0c3766b69b 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoService.java
@@ -84,6 +84,8 @@ import static io.github.hectorvent.floci.core.common.ReservedTags.rejectUnknownR
@ApplicationScoped
public class CognitoService implements ResourceProvider {
private static final int DEFAULT_REFRESH_TOKEN_VALIDITY_DAYS = 30;
+ static final List<String> DEFAULT_EXPLICIT_AUTH_FLOWS =
+ List.of("ALLOW_REFRESH_TOKEN_AUTH", "ALLOW_USER_SRP_AUTH", "ALLOW_CUSTOM_AUTH");
private static final String COGNITO_PASSWORD_SYMBOLS =
"^$*.[]{}()?\"!@#%&/\\,><':;|_~`=+-";
// JVM-local stripes bound lock memory without retaining one lock for every user key.
diff --git a/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoAttributeVerificationConcurrencyTest.java b/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoAttributeVerificationConcurrencyTest.java
index 09fd7196cc..473a2e4849 100644
--- a/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoAttributeVerificationConcurrencyTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoAttributeVerificationConcurrencyTest.java
@@ -441,7 +441,9 @@ class CognitoAttributeVerificationConcurrencyTest {
"AttributesRequireVerificationBeforeUpdate", List.of("email"))),
"us-east-1");
UserPoolClient client = service.createUserPoolClient(
- pool.getId(), "concurrency-client", false, false, List.of(), List.of());
+ pool.getId(), "concurrency-client", false, false, List.of(), List.of(),
+ null, List.of(), null, List.of("ALLOW_USER_PASSWORD_AUTH"), null, null, List.of(), null,
+ List.of(), null, null, null, List.of(), null, null);
service.adminCreateUser(pool.getId(), "alice", Map.of(
"email", OLD_EMAIL,
"email_verified", "true"), "TempPass1!");
diff --git a/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoAttributeVerificationIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoAttributeVerificationIntegrationTest.java
index 17d8bf48d8..c98e36e041 100644
--- a/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoAttributeVerificationIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoAttributeVerificationIntegrationTest.java
@@ -55,7 +55,8 @@ class CognitoAttributeVerificationIntegrationTest {
JsonNode clientResponse = cognitoJson("CreateUserPoolClient", """
{
"UserPoolId": "%s",
- "ClientName": "attribute-verification-client"
+ "ClientName": "attribute-verification-client",
+ "ExplicitAuthFlows": ["ALLOW_USER_PASSWORD_AUTH"]
}
""".formatted(poolId));
clientId = clientResponse.path("UserPoolClient").path("ClientId").asText();
diff --git a/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoCustomDomainFixtures.java b/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoCustomDomainFixtures.java
index c84420dbac..480e6f7d23 100644
--- a/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoCustomDomainFixtures.java
+++ b/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoCustomDomainFixtures.java
@@ -85,7 +85,7 @@ final class CognitoCustomDomainFixtures {
/** A public client, a confirmed user and the access token USER_PASSWORD_AUTH issues for it. */
static String signInNewUser(String poolId) throws Exception {
String publicClient = cognitoJson("CreateUserPoolClient", """
- {"UserPoolId": "%s", "ClientName": "routing-user-client"}
+ {"UserPoolId": "%s", "ClientName": "routing-user-client", "ExplicitAuthFlows": ["ALLOW_USER_PASSWORD_AUTH"]}
""".formatted(poolId)).path("UserPoolClient").path("ClientId").asText();
String username = "user-" + System.nanoTime() + "@example.com";
cognitoAction("AdminCreateUser", """
diff --git a/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoIntegrationTest.java
index 7ed20d3774..60dd7be806 100644
--- a/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoIntegrationTest.java
@@ -81,7 +81,9 @@ class CognitoIntegrationTest {
JsonNode clientResponse = cognitoJson("CreateUserPoolClient", """
{
"UserPoolId": "%s",
- "ClientName": "jwt-client"
+ "ClientName": "jwt-client",
+ "ExplicitAuthFlows": ["ALLOW_USER_PASSWORD_AUTH", "ALLOW_ADMIN_USER_PASSWORD_AUTH",
+ "ALLOW_REFRESH_TOKEN_AUTH"]
}
""".formatted(poolId));
clientId = clientResponse.path("UserPoolClient").path("ClientId").asText();
@@ -1999,7 +2001,8 @@ class CognitoIntegrationTest {
JsonNode clientResponse = cognitoJson("CreateUserPoolClient", """
{
"UserPoolId": "%s",
- "ClientName": "del-client"
+ "ClientName": "del-client",
+ "ExplicitAuthFlows": ["ALLOW_USER_PASSWORD_AUTH"]
}
""".formatted(delPoolId));
String delClientId = clientResponse.path("UserPoolClient").path("ClientId").asText();
@@ -2680,7 +2683,7 @@ class CognitoIntegrationTest {
{ "PoolName": "UserAuthWirePool" }
""").path("UserPool").path("Id").asText();
String userAuthClientId = cognitoJson("CreateUserPoolClient", """
- { "UserPoolId": "%s", "ClientName": "user-auth-client" }
+ { "UserPoolId": "%s", "ClientName": "user-auth-client", "ExplicitAuthFlows": ["ALLOW_USER_AUTH"] }
""".formatted(userAuthPoolId)).path("UserPoolClient").path("ClientId").asText();
cognitoAction("AdminCreateUser", """
{ "UserPoolId": "%s", "Username": "dana",
@@ -2714,7 +2717,7 @@ class CognitoIntegrationTest {
{ "PoolName": "UserAuthWirePasswordPool" }
""").path("UserPool").path("Id").asText();
String userAuthClientId = cognitoJson("CreateUserPoolClient", """
- { "UserPoolId": "%s", "ClientName": "user-auth-client" }
+ { "UserPoolId": "%s", "ClientName": "user-auth-client", "ExplicitAuthFlows": ["ALLOW_USER_AUTH"] }
""".formatted(userAuthPoolId)).path("UserPoolClient").path("ClientId").asText();
cognitoAction("AdminCreateUser", """
{ "UserPoolId": "%s", "Username": "erin",
@@ -2758,7 +2761,7 @@ class CognitoIntegrationTest {
{ "PoolName": "UserAuthWireSelectChallengePool" }
""").path("UserPool").path("Id").asText();
String userAuthClientId = cognitoJson("CreateUserPoolClient", """
- { "UserPoolId": "%s", "ClientName": "user-auth-client" }
+ { "UserPoolId": "%s", "ClientName": "user-auth-client", "ExplicitAuthFlows": ["ALLOW_USER_AUTH"] }
""".formatted(userAuthPoolId)).path("UserPoolClient").path("ClientId").asText();
cognitoAction("AdminCreateUser", """
{ "UserPoolId": "%s", "Username": "gale",
@@ -2802,7 +2805,7 @@ class CognitoIntegrationTest {
{ "PoolName": "UserAuthLiteTierPool", "UserPoolTier": "LITE" }
""").path("UserPool").path("Id").asText();
String liteTierClientId = cognitoJson("CreateUserPoolClient", """
- { "UserPoolId": "%s", "ClientName": "user-auth-client" }
+ { "UserPoolId": "%s", "ClientName": "user-auth-client", "ExplicitAuthFlows": ["ALLOW_USER_AUTH"] }
""".formatted(liteTierPoolId)).path("UserPoolClient").path("ClientId").asText();
cognitoAction("AdminCreateUser", """
{ "UserPoolId": "%s", "Username": "finn",
@@ -2836,7 +2839,7 @@ class CognitoIntegrationTest {
{ "PoolName": "UserAuthWireNoSessionPool" }
""").path("UserPool").path("Id").asText();
String userAuthClientId = cognitoJson("CreateUserPoolClient", """
- { "UserPoolId": "%s", "ClientName": "user-auth-client" }
+ { "UserPoolId": "%s", "ClientName": "user-auth-client", "ExplicitAuthFlows": ["ALLOW_USER_AUTH"] }
""".formatted(userAuthPoolId)).path("UserPoolClient").path("ClientId").asText();
cognitoAction("AdminCreateUser", """
{ "UserPoolId": "%s", "Username": "gale",
@@ -2861,6 +2864,57 @@ class CognitoIntegrationTest {
.body("__type", equalTo("NotAuthorizedException"));
}
+ @Test
+ @Order(110)
+ void clientWithoutExplicitAuthFlowsGetsTheAwsDefaultOverTheWire() throws Exception {
+ String defaultPoolId = cognitoJson("CreateUserPool", """
+ { "PoolName": "DefaultFlowsPool" }
+ """).path("UserPool").path("Id").asText();
+ JsonNode created = cognitoJson("CreateUserPoolClient", """
+ { "UserPoolId": "%s", "ClientName": "default-flows-client" }
+ """.formatted(defaultPoolId)).path("UserPoolClient");
+ String defaultClientId = created.path("ClientId").asText();
+
+ // As on AWS, the stored and described value is empty; only the auth-time gate applies the default.
+ assertEquals(List.of(), textValues(created.path("ExplicitAuthFlows")));
+ JsonNode described = cognitoJson("DescribeUserPoolClient", """
+ { "UserPoolId": "%s", "ClientId": "%s" }
+ """.formatted(defaultPoolId, defaultClientId)).path("UserPoolClient");
+ assertEquals(List.of(), textValues(described.path("ExplicitAuthFlows")));
+
+ cognitoAction("AdminCreateUser", """
+ { "UserPoolId": "%s", "Username": "flora",
+ "UserAttributes": [{ "Name": "email", "Value": "[email protected]" }] }
+ """.formatted(defaultPoolId)).then().statusCode(200);
+ cognitoAction("AdminSetUserPassword", """
+ { "UserPoolId": "%s", "Username": "flora", "Password": "Perm1234!", "Permanent": true }
+ """.formatted(defaultPoolId)).then().statusCode(200);
+
+ cognitoAction("InitiateAuth", """
+ { "ClientId": "%s", "AuthFlow": "USER_PASSWORD_AUTH",
+ "AuthParameters": { "USERNAME": "flora", "PASSWORD": "Perm1234!" } }
+ """.formatted(defaultClientId))
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParameterException"))
+ .body("message", equalTo("USER_PASSWORD_AUTH flow not enabled for this client"));
+ cognitoAction("AdminInitiateAuth", """
+ { "UserPoolId": "%s", "ClientId": "%s", "AuthFlow": "ADMIN_USER_PASSWORD_AUTH",
+ "AuthParameters": { "USERNAME": "flora", "PASSWORD": "Perm1234!" } }
+ """.formatted(defaultPoolId, defaultClientId))
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParameterException"));
+ }
+
+ private static List<String> textValues(JsonNode array) {
+ List<String> values = new ArrayList<>();
+ for (JsonNode value : array) {
+ values.add(value.asText());
+ }
+ return values;
+ }
+
private static JsonNode decodeJwtPayload(String token) throws Exception {
return decodeJwtPart(token, 1);
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoLambdaTriggersTest.java b/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoLambdaTriggersTest.java
index 110bd8c23e..8675830da3 100644
--- a/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoLambdaTriggersTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoLambdaTriggersTest.java
@@ -55,6 +55,9 @@ import static org.mockito.Mockito.when;
* triggerSource, and that their responses are correctly applied to the auth flow.
*/
class CognitoLambdaTriggersTest {
+ private static final List<String> AUTH_FLOWS = List.of("ALLOW_USER_PASSWORD_AUTH",
+ "ALLOW_ADMIN_USER_PASSWORD_AUTH", "ALLOW_CUSTOM_AUTH", "ALLOW_USER_SRP_AUTH", "ALLOW_REFRESH_TOKEN_AUTH");
+
private static final ObjectMapper MAPPER = new ObjectMapper();
@@ -97,7 +100,9 @@ class CognitoLambdaTriggersTest {
}
private UserPoolClient createClient(UserPool pool) {
- return service.createUserPoolClient(pool.getId(), "c", false, false, List.of(), List.of());
+ return service.createUserPoolClient(pool.getId(), "c", false, false, List.of(), List.of(),
+ null, List.of(), null, AUTH_FLOWS, null, null, List.of(), null, List.of(), null,
+ null, null, List.of(), null, null);
}
private void seedUser(UserPool pool, String username, String password) {
diff --git a/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoServiceTest.java
index 0d6f767daa..268e90e917 100644
--- a/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoServiceTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoServiceTest.java
@@ -178,8 +178,7 @@ class CognitoServiceTest {
@Test
void adminInitiateAuthNoSrpFlowRequiresTheCorrectPassword() {
UserPool pool = createPoolAndUser();
- UserPoolClient client = service.createUserPoolClient(
- pool.getId(), "client", false, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "client", false);
AwsException exception = assertThrows(AwsException.class, () ->
service.adminInitiateAuth(pool.getId(), client.getClientId(), "ADMIN_NO_SRP_AUTH",
@@ -311,6 +310,63 @@ class CognitoServiceTest {
assertEquals("SELECT_CHALLENGE", admin.get("ChallengeName"));
}
+ @Test
+ void clientWithoutExplicitAuthFlowsIsStoredAndDescribedAsEmptyLikeAws() {
+ UserPool pool = createPoolAndUser();
+ UserPoolClient client = service.createUserPoolClient(
+ pool.getId(), "client", false, false, List.of(), List.of());
+
+ assertEquals(List.of(), client.getExplicitAuthFlows());
+ assertEquals(List.of(), service.describeUserPoolClient(client.getClientId()).getExplicitAuthFlows());
+ }
+
+ @Test
+ void clientWithoutExplicitAuthFlowsRejectsPasswordFlowsAndAllowsTheDefaultOnes() {
+ UserPool pool = createPoolAndUser();
+ UserPoolClient client = service.createUserPoolClient(
+ pool.getId(), "client", false, false, List.of(), List.of());
+ Map<String, String> passwordParams = Map.of("USERNAME", "alice", "PASSWORD", "Perm1234!");
+
+ assertEquals("USER_PASSWORD_AUTH flow not enabled for this client", assertThrows(AwsException.class, () ->
+ service.initiateAuth(client.getClientId(), "USER_PASSWORD_AUTH", passwordParams)).getMessage());
+ assertEquals("ADMIN_USER_PASSWORD_AUTH flow not enabled for this client", assertThrows(AwsException.class,
+ () -> service.adminInitiateAuth(pool.getId(), client.getClientId(), "ADMIN_USER_PASSWORD_AUTH",
+ passwordParams)).getMessage());
+
+ assertEquals("USERNAME and SRP_A are required", assertThrows(AwsException.class, () ->
+ service.initiateAuth(client.getClientId(), "USER_SRP_AUTH", Map.of("USERNAME", "alice")))
+ .getMessage());
+ assertEquals("REFRESH_TOKEN is required", assertThrows(AwsException.class, () ->
+ service.initiateAuth(client.getClientId(), "REFRESH_TOKEN_AUTH", Map.of())).getMessage());
+ assertEquals("USER_AUTH flow not enabled for this client", assertThrows(AwsException.class, () ->
+ service.initiateAuth(client.getClientId(), "USER_AUTH", Map.of("USERNAME", "alice"))).getMessage());
+ }
+
+ @Test
+ void clientStoredWithAnEmptyListIsTreatedAsTheDefault() {
+ UserPool pool = createPoolAndUser();
+ UserPoolClient client = service.createUserPoolClient(
+ pool.getId(), "client", false, false, List.of(), List.of());
+ service.describeUserPoolClient(client.getClientId()).setExplicitAuthFlows(List.of());
+
+ AwsException exception = assertThrows(AwsException.class, () ->
+ service.initiateAuth(client.getClientId(), "USER_PASSWORD_AUTH",
+ Map.of("USERNAME", "alice", "PASSWORD", "Perm1234!")));
+
+ assertEquals("USER_PASSWORD_AUTH flow not enabled for this client", exception.getMessage());
+ }
+
+ private static final List<String> ALL_AUTH_FLOWS = List.of("ALLOW_USER_PASSWORD_AUTH",
+ "ALLOW_ADMIN_USER_PASSWORD_AUTH", "ALLOW_USER_AUTH", "ALLOW_USER_SRP_AUTH", "ALLOW_CUSTOM_AUTH",
+ "ALLOW_REFRESH_TOKEN_AUTH");
+
+ private static UserPoolClient openClient(CognitoService service, String poolId, String clientName,
+ boolean generateSecret) {
+ return service.createUserPoolClient(poolId, clientName, generateSecret, false, List.of(), List.of(),
+ null, List.of(), null, ALL_AUTH_FLOWS, null, null, List.of(), null, List.of(), null,
+ null, null, List.of(), null, null);
+ }
+
private UserPoolClient clientWithFlows(UserPool pool, String... explicitAuthFlows) {
return service.createUserPoolClient(pool.getId(), "flows-client", false, false, List.of(), List.of(),
null, List.of(), null, List.of(explicitAuthFlows), null, null, List.of(), null, List.of(), null,
@@ -1548,7 +1604,7 @@ class CognitoServiceTest {
@SuppressWarnings("unchecked")
void jwtContainsGroupsClaim() {
UserPool pool = createPoolAndUser();
- UserPoolClient client = service.createUserPoolClient(pool.getId(), "test-client", false, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "test-client", false);
String clientId = client.getClientId();
service.createGroup(pool.getId(), "admins", "Admin group", 1, null);
@@ -1574,7 +1630,7 @@ class CognitoServiceTest {
@SuppressWarnings("unchecked")
void jwtEscapesSpecialCharsInGroupName() {
UserPool pool = createPoolAndUser();
- UserPoolClient client = service.createUserPoolClient(pool.getId(), "test-client", false, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "test-client", false);
String specialGroup = "group\"with\\special\nchars";
service.createGroup(pool.getId(), specialGroup, null, null, null);
@@ -1703,8 +1759,7 @@ class CognitoServiceTest {
UserPool pool = serviceWithVerification.createUserPool(Map.of("PoolName", "TestPool"), "us-east-1");
pool.setAutoVerifiedAttributes(List.of("email"));
- UserPoolClient client = serviceWithVerification.createUserPoolClient(pool.getId(), "test-client",
- false, false, List.of(), List.of());
+ UserPoolClient client = openClient(serviceWithVerification, pool.getId(), "test-client", false);
AwsException ex = assertThrows(AwsException.class, () ->
serviceWithVerification.signUp(client.getClientId(), "carol", "Pass1234!", Map.of()));
@@ -1744,8 +1799,7 @@ class CognitoServiceTest {
UserPool pool = serviceWithVerification.createUserPool(Map.of("PoolName", "TestPool"), "us-east-1");
pool.setAutoVerifiedAttributes(List.of("email"));
- UserPoolClient client = serviceWithVerification.createUserPoolClient(pool.getId(), "test-client",
- false, false, List.of(), List.of());
+ UserPoolClient client = openClient(serviceWithVerification, pool.getId(), "test-client", false);
AwsException ex = assertThrows(AwsException.class, () ->
serviceWithVerification.signUp(client.getClientId(), "carol", "Pass1234!",
@@ -1813,8 +1867,7 @@ class CognitoServiceTest {
void updateUserAttributesRejectsSelfManagedVerificationStatusWithoutPartialPersistence(
String verificationStatusAttribute) {
UserPool pool = createPoolAndUser();
- UserPoolClient client = service.createUserPoolClient(
- pool.getId(), "verification-status-client", false, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "verification-status-client", false);
Map<String, Object> authResult = service.initiateAuth(
client.getClientId(), "USER_PASSWORD_AUTH",
Map.of("USERNAME", "alice", "PASSWORD", "Perm1234!"));
@@ -1869,8 +1922,7 @@ class CognitoServiceTest {
"UserAttributeUpdateSettings", Map.of(
"AttributesRequireVerificationBeforeUpdate", List.of("email"))),
"us-east-1");
- UserPoolClient client = serviceWithVerification.createUserPoolClient(
- pool.getId(), "pending-email-expiry-client", false, false, List.of(), List.of());
+ UserPoolClient client = openClient(serviceWithVerification, pool.getId(), "pending-email-expiry-client", false);
serviceWithVerification.adminCreateUser(pool.getId(), "alice", Map.of(
"email", "[email protected]",
"email_verified", "true"), "TempPass1!");
@@ -1933,8 +1985,7 @@ class CognitoServiceTest {
"UserAttributeUpdateSettings", Map.of(
"AttributesRequireVerificationBeforeUpdate", List.of("email"))),
"us-east-1");
- UserPoolClient client = serviceWithVerification.createUserPoolClient(
- pool.getId(), "pending-email-delivery-client", false, false, List.of(), List.of());
+ UserPoolClient client = openClient(serviceWithVerification, pool.getId(), "pending-email-delivery-client", false);
serviceWithVerification.adminCreateUser(pool.getId(), "alice", Map.of(
"email", "[email protected]",
"email_verified", "true"), "TempPass1!");
@@ -2044,8 +2095,7 @@ class CognitoServiceTest {
"UserAttributeUpdateSettings", Map.of(
"AttributesRequireVerificationBeforeUpdate", List.of("email", "phone_number"))),
"us-east-1");
- UserPoolClient client = serviceWithVerification.createUserPoolClient(
- pool.getId(), "admin-pending-contact-client", false, false, List.of(), List.of());
+ UserPoolClient client = openClient(serviceWithVerification, pool.getId(), "admin-pending-contact-client", false);
serviceWithVerification.adminCreateUser(pool.getId(), "alice", Map.of(
"email", "[email protected]",
"email_verified", "true",
@@ -2072,8 +2122,7 @@ class CognitoServiceTest {
@SuppressWarnings("unchecked")
void jwtSubMatchesStoredSubAttribute() {
UserPool pool = createPoolAndUser();
- UserPoolClient client = service.createUserPoolClient(pool.getId(), "test-client",
- false, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "test-client", false);
String storedSub = service.adminGetUser(pool.getId(), "alice")
.getAttributes().get("sub");
@@ -2096,8 +2145,7 @@ class CognitoServiceTest {
@SuppressWarnings("unchecked")
void jwtSubIsConsistentAcrossMultipleLogins() {
UserPool pool = createPoolAndUser();
- UserPoolClient client = service.createUserPoolClient(pool.getId(), "test-client",
- false, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "test-client", false);
Function<String, String> extractSub = token -> {
String payload = new String(Base64.getUrlDecoder().decode(token.split("\\.")[1]), StandardCharsets.UTF_8);
@@ -2140,7 +2188,7 @@ class CognitoServiceTest {
void initiateAuthRejectsAnyPasswordWhenNoHashSet() {
UserPool pool = service.createUserPool(Map.of("PoolName", "TestPool"), "us-east-1");
service.adminCreateUser(pool.getId(), "bob", Map.of("email", "[email protected]"), null);
- UserPoolClient client = service.createUserPoolClient(pool.getId(), "c", false, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "c", false);
AwsException ex = assertThrows(AwsException.class, () ->
service.initiateAuth(client.getClientId(), "USER_PASSWORD_AUTH",
@@ -2154,7 +2202,7 @@ class CognitoServiceTest {
UserPool pool = service.createUserPool(Map.of("PoolName", "TestPool"), "us-east-1");
service.adminCreateUser(pool.getId(), "bob", Map.of("email", "[email protected]"), null);
service.adminSetUserPassword(pool.getId(), "bob", "Perm1!", true);
- UserPoolClient client = service.createUserPoolClient(pool.getId(), "c", false, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "c", false);
Map<String, Object> result = service.initiateAuth(client.getClientId(), "USER_PASSWORD_AUTH",
Map.of("USERNAME", "bob", "PASSWORD", "Perm1!"));
@@ -2168,7 +2216,7 @@ class CognitoServiceTest {
@Test
void adminSetUserPasswordPermanentFalseChangesPassword() {
UserPool pool = createPoolAndUser(); // alice has permanent "Perm1234!"
- UserPoolClient client = service.createUserPoolClient(pool.getId(), "c", false, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "c", false);
service.adminSetUserPassword(pool.getId(), "alice", "NewTemp1!", false);
@@ -2281,7 +2329,7 @@ class CognitoServiceTest {
@SuppressWarnings("unchecked")
void initiateAuthWithUserAuthNoPreferredChallengeReturnsSelectChallenge() {
UserPool pool = createPoolAndUser();
- UserPoolClient client = service.createUserPoolClient(pool.getId(), "c", false, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "c", false);
Map<String, Object> result = service.initiateAuth(client.getClientId(), "USER_AUTH",
Map.of("USERNAME", "alice"));
@@ -2333,7 +2381,7 @@ class CognitoServiceTest {
@Test
void initiateAuthWithUserAuthPreferredChallengePasswordThenRespondCompletesAuth() {
UserPool pool = createPoolAndUser();
- UserPoolClient client = service.createUserPoolClient(pool.getId(), "c", false, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "c", false);
Map<String, Object> initResult = service.initiateAuth(client.getClientId(), "USER_AUTH",
Map.of("USERNAME", "alice", "PREFERRED_CHALLENGE", "PASSWORD"));
@@ -2351,7 +2399,7 @@ class CognitoServiceTest {
@Test
void initiateAuthWithUserAuthPreferredChallengePasswordSrpThenRespondReturnsPasswordVerifier() {
UserPool pool = createPoolAndUser();
- UserPoolClient client = service.createUserPoolClient(pool.getId(), "c", false, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "c", false);
Map<String, Object> initResult = service.initiateAuth(client.getClientId(), "USER_AUTH",
Map.of("USERNAME", "alice", "PREFERRED_CHALLENGE", "PASSWORD_SRP"));
@@ -2369,7 +2417,7 @@ class CognitoServiceTest {
@SuppressWarnings("unchecked")
void selectChallengeWithPasswordAnswerAndPasswordCompletesInOneRoundTrip() {
UserPool pool = createPoolAndUser();
- UserPoolClient client = service.createUserPoolClient(pool.getId(), "c", false, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "c", false);
Map<String, Object> initResult = service.initiateAuth(client.getClientId(), "USER_AUTH",
Map.of("USERNAME", "alice"));
@@ -2388,7 +2436,7 @@ class CognitoServiceTest {
// RespondToAuthChallengeResponse is AuthenticationResult, ChallengeName,
// ChallengeParameters and Session only.
UserPool pool = createPoolAndUser();
- UserPoolClient client = service.createUserPoolClient(pool.getId(), "c", false, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "c", false);
Map<String, Object> initResult = service.initiateAuth(client.getClientId(), "USER_AUTH",
Map.of("USERNAME", "alice"));
@@ -2407,7 +2455,7 @@ class CognitoServiceTest {
@Test
void adminSelectChallengeResponseDoesNotCarryAvailableChallenges() {
UserPool pool = createPoolAndUser();
- UserPoolClient client = service.createUserPoolClient(pool.getId(), "c", false, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "c", false);
Map<String, Object> initResult = service.adminInitiateAuth(pool.getId(), client.getClientId(), "USER_AUTH",
Map.of("USERNAME", "alice"));
@@ -2426,7 +2474,7 @@ class CognitoServiceTest {
@Test
void selectChallengeWithPasswordSrpAnswerAndSrpAReturnsPasswordVerifier() {
UserPool pool = createPoolAndUser();
- UserPoolClient client = service.createUserPoolClient(pool.getId(), "c", false, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "c", false);
Map<String, Object> initResult = service.initiateAuth(client.getClientId(), "USER_AUTH",
Map.of("USERNAME", "alice"));
@@ -2482,7 +2530,7 @@ class CognitoServiceTest {
// that would let a caller answer PASSWORD without ever going through SELECT_CHALLENGE's
// requireSignInEligible/availableUserAuthChallenges checks.
UserPool pool = createPoolAndUser();
- UserPoolClient client = service.createUserPoolClient(pool.getId(), "c", false, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "c", false);
Map<String, Object> initResult = service.initiateAuth(client.getClientId(), "USER_AUTH",
Map.of("USERNAME", "alice"));
@@ -2498,7 +2546,7 @@ class CognitoServiceTest {
@Test
void respondToAuthChallengeRejectsASessionAlreadyConsumed() {
UserPool pool = createPoolAndUser();
- UserPoolClient client = service.createUserPoolClient(pool.getId(), "c", false, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "c", false);
Map<String, Object> initResult = service.initiateAuth(client.getClientId(), "USER_AUTH",
Map.of("USERNAME", "alice", "PREFERRED_CHALLENGE", "PASSWORD"));
@@ -2517,9 +2565,8 @@ class CognitoServiceTest {
@Test
void respondToAuthChallengeRejectsASessionRedeemedAgainstADifferentClient() {
UserPool pool = createPoolAndUser();
- UserPoolClient client = service.createUserPoolClient(pool.getId(), "c", false, false, List.of(), List.of());
- UserPoolClient otherClient = service.createUserPoolClient(pool.getId(), "other", false, false,
- List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "c", false);
+ UserPoolClient otherClient = openClient(service, pool.getId(), "other", false);
Map<String, Object> initResult = service.initiateAuth(client.getClientId(), "USER_AUTH",
Map.of("USERNAME", "alice", "PREFERRED_CHALLENGE", "PASSWORD"));
@@ -2534,7 +2581,7 @@ class CognitoServiceTest {
@Test
void adminInitiateAuthWithUserAuthPreferredChallengePasswordWorks() {
UserPool pool = createPoolAndUser();
- UserPoolClient client = service.createUserPoolClient(pool.getId(), "c", false, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "c", false);
Map<String, Object> initResult = service.adminInitiateAuth(pool.getId(), client.getClientId(), "USER_AUTH",
Map.of("USERNAME", "alice", "PREFERRED_CHALLENGE", "PASSWORD"));
@@ -2573,8 +2620,7 @@ class CognitoServiceTest {
);
UserPool pool = serviceWithVerification.createUserPool(Map.of("PoolName", "TestPool"), "us-east-1");
- UserPoolClient client = serviceWithVerification.createUserPoolClient(pool.getId(), "c",
- false, false, List.of(), List.of());
+ UserPoolClient client = openClient(serviceWithVerification, pool.getId(), "c", false);
serviceWithVerification.adminCreateUser(pool.getId(), "alice",
Map.of("email", "[email protected]", "email_verified", "true"), "TempPass1!");
serviceWithVerification.adminSetUserPassword(pool.getId(), "alice", "Perm1234!", true);
@@ -2629,8 +2675,7 @@ class CognitoServiceTest {
);
UserPool pool = serviceWithVerification.createUserPool(Map.of("PoolName", "TestPool"), "us-east-1");
- UserPoolClient client = serviceWithVerification.createUserPoolClient(pool.getId(), "c",
- false, false, List.of(), List.of());
+ UserPoolClient client = openClient(serviceWithVerification, pool.getId(), "c", false);
serviceWithVerification.adminCreateUser(pool.getId(), "alice",
Map.of("phone_number", "+15551234567", "phone_number_verified", "true"), "TempPass1!");
serviceWithVerification.adminSetUserPassword(pool.getId(), "alice", "Perm1234!", true);
@@ -2687,8 +2732,7 @@ class CognitoServiceTest {
);
UserPool pool = serviceWithVerification.createUserPool(Map.of("PoolName", "TestPool"), "us-east-1");
- UserPoolClient client = serviceWithVerification.createUserPoolClient(pool.getId(), "c",
- false, false, List.of(), List.of());
+ UserPoolClient client = openClient(serviceWithVerification, pool.getId(), "c", false);
serviceWithVerification.adminCreateUser(pool.getId(), "alice",
Map.of("email", "[email protected]", "email_verified", "true"), "TempPass1!");
serviceWithVerification.adminSetUserPassword(pool.getId(), "alice", "Perm1234!", true);
@@ -2706,8 +2750,7 @@ class CognitoServiceTest {
@Test
void initiateAuthWithUserAuthRejectsMissingSecretHashWhenClientHasSecret() {
UserPool pool = createPoolAndUser();
- UserPoolClient client = service.createUserPoolClient(
- pool.getId(), "c", true, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "c", true);
AwsException ex = assertThrows(AwsException.class, () -> service.initiateAuth(
client.getClientId(), "USER_AUTH", Map.of("USERNAME", "alice")));
@@ -2741,8 +2784,7 @@ class CognitoServiceTest {
);
UserPool pool = serviceWithVerification.createUserPool(Map.of("PoolName", "TestPool"), "us-east-1");
- UserPoolClient client = serviceWithVerification.createUserPoolClient(pool.getId(), "c",
- false, false, List.of(), List.of());
+ UserPoolClient client = openClient(serviceWithVerification, pool.getId(), "c", false);
serviceWithVerification.adminCreateUser(pool.getId(), "alice",
Map.of("email", "[email protected]", "email_verified", "true"), "TempPass1!");
serviceWithVerification.adminSetUserPassword(pool.getId(), "alice", "Perm1234!", true);
@@ -2783,8 +2825,7 @@ class CognitoServiceTest {
);
UserPool pool = serviceWithVerification.createUserPool(Map.of("PoolName", "TestPool"), "us-east-1");
- UserPoolClient client = serviceWithVerification.createUserPoolClient(pool.getId(), "c",
- false, false, List.of(), List.of());
+ UserPoolClient client = openClient(serviceWithVerification, pool.getId(), "c", false);
serviceWithVerification.adminCreateUser(pool.getId(), "alice",
Map.of("email", "[email protected]", "email_verified", "true"), "TempPass1!");
serviceWithVerification.adminSetUserPassword(pool.getId(), "alice", "Perm1234!", true);
@@ -2806,7 +2847,7 @@ class CognitoServiceTest {
@SuppressWarnings("unchecked")
void accessTokenContainsClientId() {
UserPool pool = createPoolAndUser();
- UserPoolClient client = service.createUserPoolClient(pool.getId(), "c", false, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "c", false);
Map<String, Object> authResult = service.initiateAuth(
client.getClientId(), "USER_PASSWORD_AUTH",
@@ -2824,7 +2865,7 @@ class CognitoServiceTest {
@SuppressWarnings("unchecked")
void idTokenDoesNotContainClientId() {
UserPool pool = createPoolAndUser();
- UserPoolClient client = service.createUserPoolClient(pool.getId(), "c", false, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "c", false);
Map<String, Object> authResult = service.initiateAuth(
client.getClientId(), "USER_PASSWORD_AUTH",
@@ -3099,7 +3140,7 @@ class CognitoServiceTest {
@SuppressWarnings("unchecked")
void refreshTokenIsStructuredAndDecodable() {
UserPool pool = createPoolAndUser();
- UserPoolClient client = service.createUserPoolClient(pool.getId(), "c", false, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "c", false);
Map<String, Object> authResult = service.initiateAuth(
client.getClientId(), "USER_PASSWORD_AUTH",
@@ -3123,7 +3164,7 @@ class CognitoServiceTest {
@SuppressWarnings("unchecked")
void getTokensFromRefreshTokenReturnsNewAccessAndIdTokens() {
UserPool pool = createPoolAndUser();
- UserPoolClient client = service.createUserPoolClient(pool.getId(), "c", false, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "c", false);
Map<String, Object> authResult = service.initiateAuth(
client.getClientId(), "USER_PASSWORD_AUTH",
@@ -3190,7 +3231,7 @@ class CognitoServiceTest {
@Test
void refreshTokenAuthFlowReturnsNewTokens() {
UserPool pool = createPoolAndUser();
- UserPoolClient client = service.createUserPoolClient(pool.getId(), "c", false, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "c", false);
@SuppressWarnings("unchecked")
Map<String, Object> firstAuth = (Map<String, Object>) service.initiateAuth(
@@ -3257,8 +3298,8 @@ class CognitoServiceTest {
// thing that can reject it against poolA's client is the embedded pool-id check.
UserPool poolA = createPoolAndUser();
UserPool poolB = createPoolAndUser();
- UserPoolClient clientA = service.createUserPoolClient(poolA.getId(), "ca", false, false, List.of(), List.of());
- UserPoolClient clientB = service.createUserPoolClient(poolB.getId(), "cb", false, false, List.of(), List.of());
+ UserPoolClient clientA = openClient(service, poolA.getId(), "ca", false);
+ UserPoolClient clientB = openClient(service, poolB.getId(), "cb", false);
Map<String, Object> authB = (Map<String, Object>) service.initiateAuth(
clientB.getClientId(), "USER_PASSWORD_AUTH",
@@ -3296,7 +3337,7 @@ class CognitoServiceTest {
UserPool pool = createPoolAndUser();
service.adminCreateUser(pool.getId(), "mallory", Map.of("email", "[email protected]"), "TempPass1!");
service.adminSetUserPassword(pool.getId(), "mallory", "Perm1234!", true);
- UserPoolClient client = service.createUserPoolClient(pool.getId(), "c", false, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "c", false);
Map<String, Object> authResult = service.initiateAuth(
client.getClientId(), "USER_PASSWORD_AUTH",
@@ -3318,7 +3359,7 @@ class CognitoServiceTest {
void getTokensFromRefreshTokenRejectsSwappedPoolId() {
UserPool poolA = createPoolAndUser();
UserPool poolB = service.createUserPool(Map.of("PoolName", "OtherPool"), "us-east-1");
- UserPoolClient client = service.createUserPoolClient(poolA.getId(), "c", false, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, poolA.getId(), "c", false);
Map<String, Object> authResult = service.initiateAuth(
client.getClientId(), "USER_PASSWORD_AUTH",
@@ -3413,8 +3454,7 @@ class CognitoServiceTest {
@Test
void disabledUserCannotAuthenticate() {
UserPool pool = createPoolAndUser();
- UserPoolClient client = service.createUserPoolClient(
- pool.getId(), "c", false, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "c", false);
service.adminDisableUser(pool.getId(), "alice");
@@ -3428,8 +3468,7 @@ class CognitoServiceTest {
@SuppressWarnings("unchecked")
void reEnabledUserCanAuthenticate() {
UserPool pool = createPoolAndUser();
- UserPoolClient client = service.createUserPoolClient(
- pool.getId(), "c", false, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "c", false);
service.adminDisableUser(pool.getId(), "alice");
service.adminEnableUser(pool.getId(), "alice");
@@ -3506,8 +3545,7 @@ class CognitoServiceTest {
UserPool pool = service.createUserPool(Map.of("PoolName", "TestPool"), "us-east-1");
service.adminCreateUser(pool.getId(), "carol",
Map.of("email", "[email protected]", "given_name", "Carol"), "TempPass1!");
- UserPoolClient client = service.createUserPoolClient(
- pool.getId(), "c", false, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "c", false);
Map<String, Object> result = service.initiateAuth(client.getClientId(), "USER_PASSWORD_AUTH",
Map.of("USERNAME", "carol", "PASSWORD", "TempPass1!"));
@@ -3527,8 +3565,7 @@ class CognitoServiceTest {
void newPasswordRequiredAppliesUserAttributeUpdates() {
UserPool pool = service.createUserPool(Map.of("PoolName", "TestPool"), "us-east-1");
service.adminCreateUser(pool.getId(), "carol", Map.of("email", "[email protected]"), "TempPass1!");
- UserPoolClient client = service.createUserPoolClient(
- pool.getId(), "c", false, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "c", false);
Map<String, Object> challengeResp = service.initiateAuth(client.getClientId(), "USER_PASSWORD_AUTH",
Map.of("USERNAME", "carol", "PASSWORD", "TempPass1!"));
@@ -3557,8 +3594,7 @@ class CognitoServiceTest {
@Test
void initiateAuthRejectsMissingSecretHashWhenClientHasSecret() {
UserPool pool = createPoolAndUser();
- UserPoolClient client = service.createUserPoolClient(
- pool.getId(), "c", true, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "c", true);
AwsException ex = assertThrows(AwsException.class, () ->
service.initiateAuth(client.getClientId(), "USER_PASSWORD_AUTH",
@@ -3570,8 +3606,7 @@ class CognitoServiceTest {
@Test
void initiateAuthRejectsWrongSecretHash() {
UserPool pool = createPoolAndUser();
- UserPoolClient client = service.createUserPoolClient(
- pool.getId(), "c", true, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "c", true);
AwsException ex = assertThrows(AwsException.class, () ->
service.initiateAuth(client.getClientId(), "USER_PASSWORD_AUTH",
@@ -3585,8 +3620,7 @@ class CognitoServiceTest {
@SuppressWarnings("unchecked")
void initiateAuthAcceptsCorrectSecretHash() throws Exception {
UserPool pool = createPoolAndUser();
- UserPoolClient client = service.createUserPoolClient(
- pool.getId(), "c", true, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "c", true);
javax.crypto.Mac mac = javax.crypto.Mac.getInstance("HmacSHA256");
mac.init(new javax.crypto.spec.SecretKeySpec(
@@ -3612,8 +3646,7 @@ class CognitoServiceTest {
void adminRespondToAuthChallengeNewPasswordRequired() {
UserPool pool = service.createUserPool(Map.of("PoolName", "TestPool"), "us-east-1");
service.adminCreateUser(pool.getId(), "bob", Map.of("email", "[email protected]"), "TempPass1!");
- UserPoolClient client = service.createUserPoolClient(
- pool.getId(), "c", false, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "c", false);
Map<String, Object> challengeResp = service.adminInitiateAuth(
pool.getId(), client.getClientId(), "ADMIN_USER_PASSWORD_AUTH",
@@ -3654,8 +3687,7 @@ class CognitoServiceTest {
void adminRespondToAuthChallengeWithUserAttributes() {
UserPool pool = service.createUserPool(Map.of("PoolName", "TestPool"), "us-east-1");
service.adminCreateUser(pool.getId(), "carol", Map.of("email", "[email protected]"), "TempPass1!");
- UserPoolClient client = service.createUserPoolClient(
- pool.getId(), "c", false, false, List.of(), List.of());
+ UserPoolClient client = openClient(service, pool.getId(), "c", false);
Map<String, Object> challengeResp = service.adminInitiateAuth(
pool.getId(), client.getClientId(), "ADMIN_USER_PASSWORD_AUTH",
diff --git a/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoUserInfoIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoUserInfoIntegrationTest.java
index f51a78869a..d0b5ccac04 100644
--- a/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoUserInfoIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoUserInfoIntegrationTest.java
@@ -49,7 +49,8 @@ class CognitoUserInfoIntegrationTest {
JsonNode clientResponse = cognitoJson("CreateUserPoolClient", """
{
"UserPoolId": "%s",
- "ClientName": "userinfo-client"
+ "ClientName": "userinfo-client",
+ "ExplicitAuthFlows": ["ALLOW_USER_PASSWORD_AUTH", "ALLOW_REFRESH_TOKEN_AUTH"]
}
""".formatted(poolId));
clientId = clientResponse.path("UserPoolClient").path("ClientId").asText();