fix(cognito): return sub UUID as UserSub in SignUp response (#351)

The SignUp handler was returning the username (email) as UserSub instead
of the generated UUID. Real AWS Cognito returns the user's immutable sub
attribute, and SDKs/terraform rely on this to get a stable identifier.

CognitoService.signUp already generates and stores the sub UUID on the
user, so the fix is a one-line handler change plus a handler-level test
that asserts UserSub is a UUID, not the username.

Fixes #346
This commit is contained in:
TiM authored and GitHub committed 2026-04-11 11:34:57 -05:00
1 parent 3d3f12d912
commit a067db0117
2 files changed
+34 -1

No files matched your search

@@ -36,6 +36,39 @@ class CognitoJsonHandlerTest {
handler = new CognitoJsonHandler(service, mapper);
}
@Test
void signUpReturnsGeneratedSubAsUserSub() {
ObjectNode poolReq = mapper.createObjectNode();
poolReq.put("PoolName", "signup-pool");
JsonNode poolBody = (JsonNode) handler.handle("CreateUserPool", poolReq, "us-east-1").getEntity();
String poolId = poolBody.get("UserPool").get("Id").asText();
ObjectNode clientReq = mapper.createObjectNode();
clientReq.put("UserPoolId", poolId);
clientReq.put("ClientName", "signup-client");
JsonNode clientBody = (JsonNode) handler.handle("CreateUserPoolClient", clientReq, "us-east-1").getEntity();
String clientId = clientBody.get("UserPoolClient").get("ClientId").asText();
ObjectNode signUpReq = mapper.createObjectNode();
signUpReq.put("ClientId", clientId);
signUpReq.put("Username", "test@example.com");
signUpReq.put("Password", "Password123!");
ArrayNode attrs = signUpReq.putArray("UserAttributes");
ObjectNode emailAttr = attrs.addObject();
emailAttr.put("Name", "email");
emailAttr.put("Value", "test@example.com");
Response response = handler.handle("SignUp", signUpReq, "us-east-1");
assertEquals(200, response.getStatus());
JsonNode body = (JsonNode) response.getEntity();
String userSub = body.get("UserSub").asText();
assertNotEquals("test@example.com", userSub,
"UserSub must be the generated UUID, not the username");
assertTrue(userSub.matches("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"),
"UserSub should be a UUID, got: " + userSub);
}
@Test
void createUserPoolReturnsRichResponse() {
ObjectNode request = mapper.createObjectNode();