feat(cognito): support AdminCreateUser MessageAction=RESEND (#755)

- Parse MessageAction in CognitoJsonHandler#handleAdminCreateUser.
- Add a new 5-arg CognitoService#adminCreateUser overload that accepts MessageAction.
- Keep the existing 4-arg adminCreateUser signature and delegate it to the new overload to preserve existing callers.
- Handle RESEND for FORCE_CHANGE_PASSWORD users by refreshing lastModifiedDate and returning the existing user instead of throwing UsernameExistsException.
- Treat RESEND as a no-op invitation refresh because Floci does not have email transport.
- Keep RESEND behavior consistent with other notification-bearing APIs in the emulator.
- Throw UserNotFoundException when RESEND is requested for a missing user.
- Throw UnsupportedUserStateException when RESEND is requested for a CONFIRMED user.
- Align RESEND error behavior with real AWS Cognito.
- Add 3 unit tests in CognitoServiceTest.
- Add 1 wire-level test in CognitoIntegrationTest.
This commit is contained in:
Sai Manohar Veerubhotla authored and GitHub committed 2026-05-10 10:21:40 -05:00
1 parent 5befe8b619
commit bb810a1c64
4 files changed
+114 -4

No files matched your search

@@ -265,12 +265,15 @@ public class CognitoJsonHandler {
request.path("UserAttributes").forEach(a -> attrs.put(a.path("Name").asText(), a.path("Value").asText()));
String tempPassword = request.path("TemporaryPassword").isMissingNode() ? null
: request.path("TemporaryPassword").asText(null);
String messageAction = request.path("MessageAction").isMissingNode() ? null
: request.path("MessageAction").asText(null);
CognitoUser user = service.adminCreateUser(
request.path("UserPoolId").asText(),
request.path("Username").asText(),
attrs,
tempPassword
tempPassword,
messageAction
);
ObjectNode response = objectMapper.createObjectNode();
response.set("User", userToNode(user));
@@ -437,8 +437,41 @@ public class CognitoService {
public CognitoUser adminCreateUser(String userPoolId, String username, Map<String, String> attributes,
String temporaryPassword) {
return adminCreateUser(userPoolId, username, attributes, temporaryPassword, null);
}
/**
* AdminCreateUser with optional MessageAction.
*
* <p>{@code messageAction = "RESEND"} resends the invitation for an existing
* user in {@code FORCE_CHANGE_PASSWORD} status without recreating it; floci
* has no email transport, so this only refreshes {@code lastModifiedDate}.
* {@code "SUPPRESS"} or {@code null} retain the default create behavior.</p>
*/
public CognitoUser adminCreateUser(String userPoolId,
String username,
Map<String, String> attributes,
String temporaryPassword,
String messageAction) {
describeUserPool(userPoolId);
String key = userKey(userPoolId, username);
boolean resend = "RESEND".equalsIgnoreCase(messageAction);
if (resend) {
CognitoUser existing = userStore.get(key)
.orElseThrow(() -> new AwsException("UserNotFoundException", "User not found", 404));
if (!"FORCE_CHANGE_PASSWORD".equals(existing.getUserStatus())) {
final String userStateExceptionMessage = """
User is in %s state and cannot be resent an invitation.
""".formatted(existing.getUserStatus());
throw new AwsException("UnsupportedUserStateException", userStateExceptionMessage, 400);
}
existing.setLastModifiedDate(System.currentTimeMillis() / 1000L);
userStore.put(key, existing);
LOG.infov("Resent invitation for user {0} in pool {1}", username, userPoolId);
return existing;
}
if (userStore.get(key).isPresent()) {
throw new AwsException("UsernameExistsException", "User already exists", 400);
}