From 4ba45ad76e71bccdfb61b4604dd86de66612e778 Mon Sep 17 00:00:00 2001 From: Mike Friesen Date: Wed, 3 Jul 2024 20:36:15 -0500 Subject: [PATCH] update --- docs/openapi/openapi-iam.yaml | 6 ++++++ docs/openapi/openapi-jwt.yaml | 6 ++++++ docs/openapi/openapi-key.yaml | 6 ++++++ .../resources/cloudformation/openapi-iam.yaml | 6 ++++++ .../resources/cloudformation/openapi-jwt.yaml | 6 ++++++ .../resources/cloudformation/openapi-key.yaml | 6 ++++++ .../stacks/api/awstest/CognitoRequestTest.java | 17 ++++++++++++++++- .../api/transformers/UsersResponseToMap.java | 12 ++++++++---- 8 files changed, 60 insertions(+), 5 deletions(-) diff --git a/docs/openapi/openapi-iam.yaml b/docs/openapi/openapi-iam.yaml index 275034fe7..676b28164 100644 --- a/docs/openapi/openapi-iam.yaml +++ b/docs/openapi/openapi-iam.yaml @@ -9594,6 +9594,12 @@ username: type: string description: Username of user + email: + type: string + description: Email of user + enabled: + type: boolean + description: whether the user is enabled userStatus: type: string description: Status of user diff --git a/docs/openapi/openapi-jwt.yaml b/docs/openapi/openapi-jwt.yaml index 0f7840678..56cca2cb6 100644 --- a/docs/openapi/openapi-jwt.yaml +++ b/docs/openapi/openapi-jwt.yaml @@ -9594,6 +9594,12 @@ username: type: string description: Username of user + email: + type: string + description: Email of user + enabled: + type: boolean + description: whether the user is enabled userStatus: type: string description: Status of user diff --git a/docs/openapi/openapi-key.yaml b/docs/openapi/openapi-key.yaml index 251a0d2fb..583b335bd 100644 --- a/docs/openapi/openapi-key.yaml +++ b/docs/openapi/openapi-key.yaml @@ -9594,6 +9594,12 @@ username: type: string description: Username of user + email: + type: string + description: Email of user + enabled: + type: boolean + description: whether the user is enabled userStatus: type: string description: Status of user diff --git a/lambda-api-graalvm/src/main/resources/cloudformation/openapi-iam.yaml b/lambda-api-graalvm/src/main/resources/cloudformation/openapi-iam.yaml index a94766116..b41807c5e 100644 --- a/lambda-api-graalvm/src/main/resources/cloudformation/openapi-iam.yaml +++ b/lambda-api-graalvm/src/main/resources/cloudformation/openapi-iam.yaml @@ -9680,6 +9680,12 @@ Resources: username: type: "string" description: "Username of user" + email: + type: "string" + description: "Email of user" + enabled: + type: "boolean" + description: "whether the user is enabled" userStatus: type: "string" description: "Status of user" diff --git a/lambda-api-graalvm/src/main/resources/cloudformation/openapi-jwt.yaml b/lambda-api-graalvm/src/main/resources/cloudformation/openapi-jwt.yaml index 9780b5020..4968dd9f4 100644 --- a/lambda-api-graalvm/src/main/resources/cloudformation/openapi-jwt.yaml +++ b/lambda-api-graalvm/src/main/resources/cloudformation/openapi-jwt.yaml @@ -9680,6 +9680,12 @@ Resources: username: type: "string" description: "Username of user" + email: + type: "string" + description: "Email of user" + enabled: + type: "boolean" + description: "whether the user is enabled" userStatus: type: "string" description: "Status of user" diff --git a/lambda-api-graalvm/src/main/resources/cloudformation/openapi-key.yaml b/lambda-api-graalvm/src/main/resources/cloudformation/openapi-key.yaml index 26037c527..f0bdbecb7 100644 --- a/lambda-api-graalvm/src/main/resources/cloudformation/openapi-key.yaml +++ b/lambda-api-graalvm/src/main/resources/cloudformation/openapi-key.yaml @@ -9680,6 +9680,12 @@ Resources: username: type: "string" description: "Username of user" + email: + type: "string" + description: "Email of user" + enabled: + type: "boolean" + description: "whether the user is enabled" userStatus: type: "string" description: "Status of user" diff --git a/lambda-api/src/integration/java/com/formkiq/stacks/api/awstest/CognitoRequestTest.java b/lambda-api/src/integration/java/com/formkiq/stacks/api/awstest/CognitoRequestTest.java index 885406d29..40080238c 100644 --- a/lambda-api/src/integration/java/com/formkiq/stacks/api/awstest/CognitoRequestTest.java +++ b/lambda-api/src/integration/java/com/formkiq/stacks/api/awstest/CognitoRequestTest.java @@ -28,6 +28,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import java.util.Arrays; @@ -110,7 +111,7 @@ public void testGetUsers01() throws Exception { // given List clients = getApiClients(null); - for (ApiClient client : clients) { + for (ApiClient client : getAdminClients(clients)) { UserManagementApi userApi = new UserManagementApi(client); @@ -124,9 +125,23 @@ public void testGetUsers01() throws Exception { User user = users.get(0); assertNotNull(user.getUsername()); assertNotNull(user.getUserStatus()); + assertNotNull(user.getEmail()); + assertTrue(user.getEnabled()); assertNotNull(user.getInsertedDate()); assertNotNull(user.getLastModifiedDate()); } + + // given + UserManagementApi userApi = new UserManagementApi(clients.get(2)); + + // when + try { + userApi.getUsers(null, null); + fail(); + } catch (ApiException e) { + // then + assertEquals(ApiResponseStatus.SC_UNAUTHORIZED.getStatusCode(), e.getCode()); + } } /** diff --git a/lambda-api/src/main/java/com/formkiq/stacks/api/transformers/UsersResponseToMap.java b/lambda-api/src/main/java/com/formkiq/stacks/api/transformers/UsersResponseToMap.java index 9e15ea165..9577c8ddc 100644 --- a/lambda-api/src/main/java/com/formkiq/stacks/api/transformers/UsersResponseToMap.java +++ b/lambda-api/src/main/java/com/formkiq/stacks/api/transformers/UsersResponseToMap.java @@ -24,6 +24,7 @@ package com.formkiq.stacks.api.transformers; import com.formkiq.aws.dynamodb.objects.DateUtil; +import software.amazon.awssdk.services.cognitoidentityprovider.model.AttributeType; import software.amazon.awssdk.services.cognitoidentityprovider.model.UserType; import java.text.SimpleDateFormat; @@ -41,11 +42,14 @@ public class UsersResponseToMap implements Function apply(final UserType u) { + public Map apply(final UserType ut) { - return Map.of("username", u.username(), "userStatus", u.userStatus().name(), "enabled", - String.valueOf(u.enabled()), "insertedDate", toString(u.userCreateDate()), - "lastModifiedDate", toString(u.userLastModifiedDate())); + String email = ut.attributes().stream().filter(u -> "email".equalsIgnoreCase(u.name())) + .map(AttributeType::value).findAny().orElse(""); + + return Map.of("username", ut.username(), "email", email, "userStatus", ut.userStatus().name(), + "enabled", ut.enabled(), "insertedDate", toString(ut.userCreateDate()), "lastModifiedDate", + toString(ut.userLastModifiedDate())); } private String toString(final Instant date) {