Skip to content

armgit / floci

Public Imported from GitHub
0

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

fix(cognito): accept USER_SRP_AUTH in AdminInitiateAuth (#3973)

Priamo Germosen2d56d85e9eb8
diff --git a/docs/services/cognito.md b/docs/services/cognito.md
index cd0c459e42..dd74c1ab6b 100644
--- a/docs/services/cognito.md
+++ b/docs/services/cognito.md
@@ -199,7 +199,7 @@ further divergences, both deliberate:
`InitiateAuth` accepts `USER_PASSWORD_AUTH`, `USER_SRP_AUTH`, `CUSTOM_AUTH`, `USER_AUTH`,
`REFRESH_TOKEN_AUTH` and `REFRESH_TOKEN`. `AdminInitiateAuth` accepts `ADMIN_USER_PASSWORD_AUTH`,
-`ADMIN_NO_SRP_AUTH`, `ADMIN_USER_SRP_AUTH`, `USER_PASSWORD_AUTH`, `CUSTOM_AUTH`, `USER_AUTH`,
+`ADMIN_NO_SRP_AUTH`, `ADMIN_USER_SRP_AUTH`, `USER_SRP_AUTH`, `USER_PASSWORD_AUTH`, `CUSTOM_AUTH`, `USER_AUTH`,
`REFRESH_TOKEN_AUTH` and `REFRESH_TOKEN`.
`USER_AUTH` is the choice-based flow: with no `PREFERRED_CHALLENGE` it returns
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 0d5e42dd26..478fb78e97 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
@@ -126,7 +126,7 @@ final class CognitoAuthFlowHandler {
case "ADMIN_USER_PASSWORD_AUTH", "ADMIN_NO_SRP_AUTH", "USER_PASSWORD_AUTH" ->
authenticateWithPassword(pool, client, authParameters, clientMetadata);
case "REFRESH_TOKEN_AUTH", "REFRESH_TOKEN" -> handleRefreshToken(pool, client, authParameters, clientMetadata);
- case "ADMIN_USER_SRP_AUTH" -> handleUserSrpAuth(pool, client, authParameters, clientMetadata);
+ case "ADMIN_USER_SRP_AUTH", "USER_SRP_AUTH" -> handleUserSrpAuth(pool, client, authParameters, clientMetadata);
case "CUSTOM_AUTH" -> handleCustomAuth(pool, client, authParameters, clientMetadata);
case "USER_AUTH" -> handleUserAuth(pool, client, authParameters, clientMetadata);
default -> throw unsupportedAuthFlow(authFlow);
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 396bfa299a..137353e7b0 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
@@ -191,6 +191,19 @@ class CognitoServiceTest {
assertTrue(result.containsKey("AuthenticationResult"));
}
+ @Test
+ void adminInitiateAuthAcceptsTheSdkSpellingOfSrpAuth() {
+ UserPool pool = createPoolAndUser();
+ UserPoolClient client = service.createUserPoolClient(
+ pool.getId(), "client", false, false, List.of(), List.of());
+
+ AwsException exception = assertThrows(AwsException.class, () ->
+ service.adminInitiateAuth(pool.getId(), client.getClientId(), "USER_SRP_AUTH",
+ Map.of("USERNAME", "alice")));
+
+ assertEquals("USERNAME and SRP_A are required", exception.getMessage());
+ }
+
@ParameterizedTest
@CsvSource({
"Short1!a",