diff --git a/README.md b/README.md index c208b089..f2ecac69 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ by the Lombok annotations will not be visible (and the project will be littered To build the entire application, including running unit and functional tests: -`./gradlew setupTheKeycloakTestServer && ./gradlew build` +`./gradlew startServer && ./gradlew build` (Note that functional tests share the same port number for embedded database as for the containerised database, if tests fail try running `./gradlew composeDown` first. Free-up port for the keycloak test server as well). diff --git a/src/api/src/main/java/engineering/everest/lhotse/api/rest/controllers/UserController.java b/src/api/src/main/java/engineering/everest/lhotse/api/rest/controllers/UserController.java index f1118ab5..920819c1 100644 --- a/src/api/src/main/java/engineering/everest/lhotse/api/rest/controllers/UserController.java +++ b/src/api/src/main/java/engineering/everest/lhotse/api/rest/controllers/UserController.java @@ -8,7 +8,13 @@ import engineering.everest.starterkit.filestorage.FileService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.PostMapping; import springfox.documentation.annotations.ApiIgnore; import org.springframework.beans.factory.annotation.Autowired; diff --git a/src/users/src/main/java/engineering/everest/lhotse/users/domain/KeycloakSynchronizationSaga.java b/src/users/src/main/java/engineering/everest/lhotse/users/domain/KeycloakSynchronizationSaga.java index 373d7ef5..287b2ba6 100644 --- a/src/users/src/main/java/engineering/everest/lhotse/users/domain/KeycloakSynchronizationSaga.java +++ b/src/users/src/main/java/engineering/everest/lhotse/users/domain/KeycloakSynchronizationSaga.java @@ -60,12 +60,12 @@ public void on(UserDetailsUpdatedByAdminEvent event) throws Exception { var user = usersReadService.getById(event.getUserId()); waitForTheProjectionUpdate(() -> user.getEmail() - .equals(event.getEmailChange() ) || user.getDisplayName().equals(event.getDisplayNameChange()), - "user email and displayName projection update"); + .equals(event.getEmailChange()) || user.getDisplayName().equals(event.getDisplayNameChange()), + "user email or displayName projection update"); keycloakSynchronizationService.updateUserAttributes(event.getUserId(), Map.of("attributes", new UserAttribute(user.getOrganizationId(), user.getRoles(), event.getDisplayNameChange()), - "email", event.getEmailChange()) ); + "email", event.getEmailChange())); } @StartSaga diff --git a/src/users/src/test/java/engineering/everest/lhotse/users/domain/UserAggregateTest.java b/src/users/src/test/java/engineering/everest/lhotse/users/domain/UserAggregateTest.java index 64e461e2..7becc441 100644 --- a/src/users/src/test/java/engineering/everest/lhotse/users/domain/UserAggregateTest.java +++ b/src/users/src/test/java/engineering/everest/lhotse/users/domain/UserAggregateTest.java @@ -47,15 +47,14 @@ class UserAggregateTest { private static final UUID PROFILE_PHOTO_FILE_ID = randomUUID(); private static final String USERNAME = "user@email.com"; private static final String USER_DISPLAY_NAME = "user-display-name"; - private static final String USER_ENCODED_PASSWORD = "encoded-password"; private static final String DISPLAY_NAME_CHANGE = "display-name-change"; - private static final String ENCODED_PASSWORD_CHANGE = "encoded-password-change"; private static final String EMAIL_CHANGE = "email@change.com"; private static final String NO_CHANGE = null; private static final String BLANK_FIELD = ""; private static final UserCreatedByAdminEvent USER_CREATED_BY_ADMIN_EVENT = - new UserCreatedByAdminEvent(USER_ID, ORGANIZATION_ID, ADMIN_ID, USER_DISPLAY_NAME, USERNAME, USER_ENCODED_PASSWORD); + new UserCreatedByAdminEvent(USER_ID, ORGANIZATION_ID, ADMIN_ID, USER_DISPLAY_NAME, USERNAME); + public static final UUID CONFIRMATION_CODE = randomUUID(); private FixtureConfiguration testFixture; @@ -88,20 +87,20 @@ void aggregateHasExplicitlyDefinedRepository() { @Test void createUserCommandEmits_WhenAllMandatoryFieldsArePresentInCreationCommand() { testFixture.givenNoPriorActivity() - .when(new CreateUserCommand(USER_ID, ORGANIZATION_ID, ADMIN_ID, USERNAME, USER_ENCODED_PASSWORD, USER_DISPLAY_NAME)) - .expectEvents(new UserCreatedByAdminEvent(USER_ID, ORGANIZATION_ID, ADMIN_ID, USER_DISPLAY_NAME, USERNAME, USER_ENCODED_PASSWORD)); + .when(new CreateUserCommand(USER_ID, ORGANIZATION_ID, ADMIN_ID, USERNAME, USER_DISPLAY_NAME)) + .expectEvents(new UserCreatedByAdminEvent(USER_ID, ORGANIZATION_ID, ADMIN_ID, USER_DISPLAY_NAME, USERNAME)); } @Test void createUserForNewlyRegisteredOrganizationCommandEmits_WhenAllMandatoryFieldsArePresentInCreationCommand() { testFixture.givenNoPriorActivity() - .when(new CreateUserForNewlyRegisteredOrganizationCommand(ORGANIZATION_ID, USER_ID, USERNAME, USER_ENCODED_PASSWORD, USER_DISPLAY_NAME)) - .expectEvents(new UserCreatedForNewlyRegisteredOrganizationEvent(ORGANIZATION_ID, USER_ID, USER_DISPLAY_NAME, USERNAME, USER_ENCODED_PASSWORD)); + .when(new CreateUserForNewlyRegisteredOrganizationCommand(ORGANIZATION_ID, USER_ID, USERNAME, USER_DISPLAY_NAME)) + .expectEvents(new UserCreatedForNewlyRegisteredOrganizationEvent(ORGANIZATION_ID, USER_ID, USER_DISPLAY_NAME, USERNAME)); } @Test void rejectsCreateUserCommand_WhenEmailValidatorFails() { - CreateUserCommand command = new CreateUserCommand(USER_ID, ORGANIZATION_ID, ADMIN_ID, null, USER_ENCODED_PASSWORD, USER_DISPLAY_NAME); + CreateUserCommand command = new CreateUserCommand(USER_ID, ORGANIZATION_ID, ADMIN_ID, null, USER_DISPLAY_NAME); testFixture.givenNoPriorActivity() .when(command) @@ -112,7 +111,7 @@ void rejectsCreateUserCommand_WhenEmailValidatorFails() { @Test void rejectsCreateUserForNewlyRegisteredOrganizationCommand_WhenEmailValidatorFails() { testFixture.givenNoPriorActivity() - .when(new CreateUserForNewlyRegisteredOrganizationCommand(ORGANIZATION_ID, USER_ID,null, USER_ENCODED_PASSWORD, USER_DISPLAY_NAME)) + .when(new CreateUserForNewlyRegisteredOrganizationCommand(ORGANIZATION_ID, USER_ID,null, USER_DISPLAY_NAME)) .expectNoEvents() .expectException(ConstraintViolationException.class); } @@ -120,7 +119,7 @@ void rejectsCreateUserForNewlyRegisteredOrganizationCommand_WhenEmailValidatorFa @Test void rejectsCreateUserCommand_WhenDisplayNameIsBlank() { testFixture.givenNoPriorActivity() - .when(new CreateUserCommand(USER_ID, ORGANIZATION_ID, ADMIN_ID, USERNAME, USER_ENCODED_PASSWORD, "")) + .when(new CreateUserCommand(USER_ID, ORGANIZATION_ID, ADMIN_ID, USERNAME, "")) .expectNoEvents() .expectException(ConstraintViolationException.class); } @@ -128,7 +127,7 @@ void rejectsCreateUserCommand_WhenDisplayNameIsBlank() { @Test void rejectsCreateUserForNewlyRegisteredOrganizationCommand_WhenDisplayNameIsBlank() { testFixture.givenNoPriorActivity() - .when(new CreateUserForNewlyRegisteredOrganizationCommand(ORGANIZATION_ID, USER_ID, USERNAME, USER_ENCODED_PASSWORD, "")) + .when(new CreateUserForNewlyRegisteredOrganizationCommand(ORGANIZATION_ID, USER_ID, USERNAME, "")) .expectNoEvents() .expectException(ConstraintViolationException.class); } @@ -136,7 +135,7 @@ void rejectsCreateUserForNewlyRegisteredOrganizationCommand_WhenDisplayNameIsBla @Test void rejectsCreateUserCommand_WhenDisplayNameIsNull() { testFixture.givenNoPriorActivity() - .when(new CreateUserCommand(USER_ID, ORGANIZATION_ID, ADMIN_ID, USERNAME, USER_ENCODED_PASSWORD, null)) + .when(new CreateUserCommand(USER_ID, ORGANIZATION_ID, ADMIN_ID, USERNAME, null)) .expectNoEvents() .expectException(ConstraintViolationException.class); } @@ -144,14 +143,14 @@ void rejectsCreateUserCommand_WhenDisplayNameIsNull() { @Test void rejectsCreateUserForNewlyRegisteredOrganizationCommand_WhenDisplayNameIsNull() { testFixture.givenNoPriorActivity() - .when(new CreateUserForNewlyRegisteredOrganizationCommand(ORGANIZATION_ID, USER_ID, USERNAME, USER_ENCODED_PASSWORD, null)) + .when(new CreateUserForNewlyRegisteredOrganizationCommand(ORGANIZATION_ID, USER_ID, USERNAME, null)) .expectNoEvents() .expectException(ConstraintViolationException.class); } @Test void rejectsCreateUserCommand_WhenRequestingUserIsNull() { - CreateUserCommand command = new CreateUserCommand(USER_ID, ORGANIZATION_ID, null, USERNAME, USER_ENCODED_PASSWORD, USER_DISPLAY_NAME); + CreateUserCommand command = new CreateUserCommand(USER_ID, ORGANIZATION_ID, null, USERNAME, USER_DISPLAY_NAME); testFixture.givenNoPriorActivity() .when(command) @@ -162,14 +161,14 @@ void rejectsCreateUserCommand_WhenRequestingUserIsNull() { @Test void rejectsCreateUserForNewlyRegisteredOrganizationCommand_WhenRequestingUserIsNull() { testFixture.givenNoPriorActivity() - .when(new CreateUserForNewlyRegisteredOrganizationCommand(ORGANIZATION_ID, null, USERNAME, USER_ENCODED_PASSWORD, USER_DISPLAY_NAME)) + .when(new CreateUserForNewlyRegisteredOrganizationCommand(ORGANIZATION_ID, null, USERNAME, USER_DISPLAY_NAME)) .expectNoEvents() .expectException(ConstraintViolationException.class); } @Test void rejectsCreateUserCommand_WhenOrganizationIdIsInvalid() { - var command = new CreateUserCommand(USER_ID, ORGANIZATION_ID, ADMIN_ID, USERNAME, USER_ENCODED_PASSWORD, USER_DISPLAY_NAME); + var command = new CreateUserCommand(USER_ID, ORGANIZATION_ID, ADMIN_ID, USERNAME, USER_DISPLAY_NAME); doThrow(IllegalStateException.class).when(organizationStatusValidator).validate(command); testFixture.givenNoPriorActivity() @@ -180,7 +179,7 @@ void rejectsCreateUserCommand_WhenOrganizationIdIsInvalid() { @Test void rejectsCreateUserCommand_WhenUniqueUserEmailValidatorFails() { - var command = new CreateUserCommand(USER_ID, ORGANIZATION_ID, ADMIN_ID, USERNAME, USER_DISPLAY_NAME, USER_ENCODED_PASSWORD); + var command = new CreateUserCommand(USER_ID, ORGANIZATION_ID, ADMIN_ID, USERNAME, USER_DISPLAY_NAME); doThrow(IllegalArgumentException.class).when(usersUniqueEmailValidator).validate(command); testFixture.givenNoPriorActivity() @@ -192,24 +191,24 @@ void rejectsCreateUserCommand_WhenUniqueUserEmailValidatorFails() { @Test void createUserForNewlyRegisteredOrganizationCommandEmits() { testFixture.givenNoPriorActivity() - .when(new CreateUserForNewlyRegisteredOrganizationCommand(USER_ID, ORGANIZATION_ID, USERNAME, USER_ENCODED_PASSWORD, USER_DISPLAY_NAME)) - .expectEvents(new UserCreatedForNewlyRegisteredOrganizationEvent(USER_ID, ORGANIZATION_ID, USER_DISPLAY_NAME, USERNAME, USER_ENCODED_PASSWORD)); + .when(new CreateUserForNewlyRegisteredOrganizationCommand(USER_ID, ORGANIZATION_ID, USERNAME, USER_DISPLAY_NAME)) + .expectEvents(new UserCreatedForNewlyRegisteredOrganizationEvent(USER_ID, ORGANIZATION_ID, USER_DISPLAY_NAME, USERNAME)); } @Test void createUserCommandEmits() { testFixture.givenNoPriorActivity() - .when(new CreateUserCommand(USER_ID, ORGANIZATION_ID, ADMIN_ID, USERNAME, USER_ENCODED_PASSWORD, USER_DISPLAY_NAME)) - .expectEvents(new UserCreatedByAdminEvent(USER_ID, ORGANIZATION_ID, ADMIN_ID, USER_DISPLAY_NAME, USERNAME, USER_ENCODED_PASSWORD)); + .when(new CreateUserCommand(USER_ID, ORGANIZATION_ID, ADMIN_ID, USERNAME, USER_DISPLAY_NAME)) + .expectEvents(new UserCreatedByAdminEvent(USER_ID, ORGANIZATION_ID, ADMIN_ID, USER_DISPLAY_NAME, USERNAME)); } @Test void updateUserDetailsCommandEmits_WhenCommandAccepted() { testFixture.given(USER_CREATED_BY_ADMIN_EVENT) .when(new UpdateUserDetailsCommand(USER_ID, EMAIL_CHANGE, - DISPLAY_NAME_CHANGE, ENCODED_PASSWORD_CHANGE, ADMIN_ID)) + DISPLAY_NAME_CHANGE, ADMIN_ID)) .expectEvents(new UserDetailsUpdatedByAdminEvent(USER_ID, ORGANIZATION_ID, DISPLAY_NAME_CHANGE, - EMAIL_CHANGE, ENCODED_PASSWORD_CHANGE, ADMIN_ID)); + EMAIL_CHANGE, ADMIN_ID)); } @Test @@ -239,7 +238,7 @@ void rejectsUpdateUserRolesCommand_WhenAdminRoleProvided() { @Test void rejectsUpdateUserDetailsCommand_WhenEmailValidatorFails() { - var command = new UpdateUserDetailsCommand(USER_ID, "not-a-valid-email", DISPLAY_NAME_CHANGE, ENCODED_PASSWORD_CHANGE, ADMIN_ID); + var command = new UpdateUserDetailsCommand(USER_ID, "not-a-valid-email", DISPLAY_NAME_CHANGE, ADMIN_ID); doThrow(IllegalArgumentException.class).when(emailAddressValidator).validate(command); testFixture.given(USER_CREATED_BY_ADMIN_EVENT) @@ -250,7 +249,7 @@ void rejectsUpdateUserDetailsCommand_WhenEmailValidatorFails() { @Test void rejectsUpdateUserDetailsCommand_WhenRequestingUserIdIsNull() { - var command = new UpdateUserDetailsCommand(USER_ID, EMAIL_CHANGE, DISPLAY_NAME_CHANGE, ENCODED_PASSWORD_CHANGE, null); + var command = new UpdateUserDetailsCommand(USER_ID, EMAIL_CHANGE, DISPLAY_NAME_CHANGE, null); testFixture.given(USER_CREATED_BY_ADMIN_EVENT) .when(command) @@ -261,7 +260,7 @@ void rejectsUpdateUserDetailsCommand_WhenRequestingUserIdIsNull() { @Test void rejectsUpdateUserDetailsCommand_WhenNoFieldsAreBeingChanged() { testFixture.given(USER_CREATED_BY_ADMIN_EVENT) - .when(new UpdateUserDetailsCommand(USER_ID, NO_CHANGE, NO_CHANGE, NO_CHANGE, ADMIN_ID)) + .when(new UpdateUserDetailsCommand(USER_ID, NO_CHANGE, NO_CHANGE, ADMIN_ID)) .expectNoEvents() .expectException(TranslatableIllegalArgumentException.class) .expectExceptionMessage("USER_UPDATE_NO_FIELDS_CHANGED"); @@ -270,7 +269,7 @@ void rejectsUpdateUserDetailsCommand_WhenNoFieldsAreBeingChanged() { @Test void rejectsUpdateUserDetailsCommand_WhenDisplayNameIsBlanked() { testFixture.given(USER_CREATED_BY_ADMIN_EVENT) - .when(new UpdateUserDetailsCommand(USER_ID, NO_CHANGE, BLANK_FIELD, NO_CHANGE, ADMIN_ID)) + .when(new UpdateUserDetailsCommand(USER_ID, NO_CHANGE, BLANK_FIELD, ADMIN_ID)) .expectNoEvents() .expectException(TranslatableIllegalArgumentException.class) .expectExceptionMessage("USER_DISPLAY_NAME_MISSING"); @@ -278,7 +277,7 @@ void rejectsUpdateUserDetailsCommand_WhenDisplayNameIsBlanked() { @Test void rejectsUpdateUserDetailsCommand_WhenUniqueEmailValidatorFails() { - UpdateUserDetailsCommand command = new UpdateUserDetailsCommand(USER_ID, EMAIL_CHANGE, DISPLAY_NAME_CHANGE, NO_CHANGE, ADMIN_ID); + UpdateUserDetailsCommand command = new UpdateUserDetailsCommand(USER_ID, EMAIL_CHANGE, DISPLAY_NAME_CHANGE, ADMIN_ID); doThrow(IllegalStateException.class).when(usersUniqueEmailValidator).validate(command);