use of com.synopsys.integration.alert.component.users.UserManagementDescriptorKey in project hub-alert by blackducksoftware.
the class UserActionsTest method testReadWithoutChecks.
@Test
public void testReadWithoutChecks() {
UserModel userModel = UserModel.existingUser(id, name, password, emailAddress, authenticationType, roles, true);
Mockito.when(authorizationManager.hasReadPermission(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class))).thenReturn(true);
Mockito.when(userAccessor.getUser(id)).thenReturn(Optional.of(userModel));
Mockito.when(userAccessor.getUser(2L)).thenReturn(Optional.empty());
UserActions userActions = new UserActions(userManagementDescriptorKey, userAccessor, roleAccessor, authorizationManager, authenticationTypeAccessor, userSystemValidator);
ActionResponse<UserConfig> actionResponse = userActions.getOne(id);
ActionResponse<UserConfig> actionResponseEmpty = userActions.getOne(2L);
assertTrue(actionResponse.hasContent());
assertEquals(HttpStatus.OK, actionResponse.getHttpStatus());
UserConfig userConfig = actionResponse.getContent().get();
assertUserConfig(userConfig);
assertFalse(actionResponseEmpty.hasContent());
assertEquals(HttpStatus.NOT_FOUND, actionResponseEmpty.getHttpStatus());
}
use of com.synopsys.integration.alert.component.users.UserManagementDescriptorKey in project hub-alert by blackducksoftware.
the class UserActionsTest method testReadAllWithoutChecks.
@Test
public void testReadAllWithoutChecks() {
UserModel userModel = UserModel.existingUser(id, name, password, emailAddress, authenticationType, roles, true);
AuthenticationTypeDetails authenticationTypeDetails = new AuthenticationTypeDetails(1L, authenticationType.name());
Mockito.when(authorizationManager.hasReadPermission(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class))).thenReturn(true);
Mockito.when(userAccessor.getUsers()).thenReturn(List.of(userModel));
Mockito.when(authenticationTypeAccessor.getAuthenticationTypeDetails(Mockito.any())).thenReturn(Optional.of(authenticationTypeDetails));
UserActions userActions = new UserActions(userManagementDescriptorKey, userAccessor, roleAccessor, authorizationManager, authenticationTypeAccessor, userSystemValidator);
ActionResponse<MultiUserConfigResponseModel> actionResponse = userActions.getAll();
assertTrue(actionResponse.hasContent());
List<UserConfig> userModels = actionResponse.getContent().get().getUsers();
assertEquals(1, userModels.size());
UserConfig userConfig = userModels.get(0);
assertUserConfig(userConfig);
assertEquals(authenticationType.name(), userConfig.getAuthenticationType());
assertNull(userConfig.getPassword());
}
use of com.synopsys.integration.alert.component.users.UserManagementDescriptorKey in project hub-alert by blackducksoftware.
the class UserActionsTest method testExternalUserNoEmailValidation.
@Test
public void testExternalUserNoEmailValidation() throws Exception {
AuthenticationType authenticationTypeLDAP = AuthenticationType.LDAP;
UserModel userModel = UserModel.existingUser(id, name, password, null, authenticationTypeLDAP, roles, true);
Mockito.when(authorizationManager.hasExecutePermission(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class))).thenReturn(true);
Mockito.when(userAccessor.getUser(Mockito.anyLong())).thenReturn(Optional.of(userModel));
Set<String> roleNames = roles.stream().map(UserRoleModel::getName).collect(Collectors.toSet());
roleNames.add(DefaultUserRole.ALERT_ADMIN.name());
UserConfig userConfig = new UserConfig(id.toString(), name, "newPassword", null, roleNames, false, false, false, true, false, authenticationTypeLDAP.name(), true);
UserActions userActions = new UserActions(userManagementDescriptorKey, userAccessor, roleAccessor, authorizationManager, authenticationTypeAccessor, userSystemValidator);
ValidationActionResponse validationActionResponse = userActions.validate(userConfig);
assertFalse(validationActionResponse.isError());
assertTrue(validationActionResponse.hasContent());
ValidationResponseModel validationResponseModel = validationActionResponse.getContent().get();
assertFalse(validationResponseModel.hasErrors());
assertEquals("The user is valid", validationActionResponse.getMessage().get());
}
use of com.synopsys.integration.alert.component.users.UserManagementDescriptorKey in project hub-alert by blackducksoftware.
the class UserActionsTest method testInternalUserNoEmailValidation.
@Test
public void testInternalUserNoEmailValidation() throws Exception {
UserModel userModel = UserModel.existingUser(id, name, password, null, authenticationType, roles, true);
Mockito.when(authorizationManager.hasExecutePermission(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class))).thenReturn(true);
Mockito.when(userAccessor.getUser(Mockito.anyLong())).thenReturn(Optional.of(userModel));
Set<String> roleNames = roles.stream().map(UserRoleModel::getName).collect(Collectors.toSet());
UserConfig userConfig = new UserConfig(id.toString(), name, "newPassword", null, roleNames, false, false, false, true, false, authenticationType.name(), false);
UserActions userActions = new UserActions(userManagementDescriptorKey, userAccessor, roleAccessor, authorizationManager, authenticationTypeAccessor, userSystemValidator);
ValidationActionResponse validationActionResponse = userActions.validate(userConfig);
assertFalse(validationActionResponse.isError());
assertTrue(validationActionResponse.hasContent());
ValidationResponseModel validationResponseModel = validationActionResponse.getContent().get();
assertTrue(validationResponseModel.hasErrors());
assertTrue(validationResponseModel.getErrors().containsKey(UserActions.FIELD_KEY_USER_MGMT_EMAILADDRESS));
}
Aggregations