Search in sources :

Example 31 with UserModel

use of com.synopsys.integration.alert.common.persistence.model.UserModel in project hub-alert by blackducksoftware.

the class UserActionsTest method testDeleteWithoutChecksException.

@Test
public void testDeleteWithoutChecksException() throws AlertForbiddenOperationException {
    UserModel userModel = UserModel.existingUser(id, name, password, emailAddress, authenticationType, roles, true);
    Mockito.when(userAccessor.getUser(id)).thenReturn(Optional.of(userModel));
    Mockito.doThrow(new AlertForbiddenOperationException("Exception for test")).when(userAccessor).deleteUser(id);
    UserActions userActions = new UserActions(userManagementDescriptorKey, userAccessor, roleAccessor, authorizationManager, authenticationTypeAccessor, userSystemValidator);
    ActionResponse<UserConfig> userConfigActionResponse = userActions.deleteWithoutChecks(id);
    assertFalse(userConfigActionResponse.hasContent());
    assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, userConfigActionResponse.getHttpStatus());
}
Also used : UserModel(com.synopsys.integration.alert.common.persistence.model.UserModel) AlertForbiddenOperationException(com.synopsys.integration.alert.common.exception.AlertForbiddenOperationException) Test(org.junit.jupiter.api.Test)

Example 32 with UserModel

use of com.synopsys.integration.alert.common.persistence.model.UserModel in project hub-alert by blackducksoftware.

the class UserActionsTest method testFindExisting.

@Test
public void testFindExisting() {
    UserModel userModel = UserModel.existingUser(id, name, password, emailAddress, authenticationType, roles, true);
    Mockito.when(userAccessor.getUser(Mockito.anyLong())).thenReturn(Optional.of(userModel));
    UserActions userActions = new UserActions(userManagementDescriptorKey, userAccessor, roleAccessor, authorizationManager, authenticationTypeAccessor, userSystemValidator);
    Optional<UserConfig> userConfigOptional = userActions.findExisting(id);
    assertTrue(userConfigOptional.isPresent());
    UserConfig userConfig = userConfigOptional.get();
    assertUserConfig(userConfig);
}
Also used : UserModel(com.synopsys.integration.alert.common.persistence.model.UserModel) Test(org.junit.jupiter.api.Test)

Example 33 with UserModel

use of com.synopsys.integration.alert.common.persistence.model.UserModel in project hub-alert by blackducksoftware.

the class UserActionsTest method testUpdateWithoutChecksDatabaseError.

@Test
public void testUpdateWithoutChecksDatabaseError() throws Exception {
    UserModel userModel = UserModel.existingUser(id, name, password, emailAddress, authenticationType, roles, true);
    Mockito.when(userAccessor.getUser(id)).thenReturn(Optional.of(userModel));
    Mockito.when(userAccessor.updateUser(Mockito.any(), Mockito.anyBoolean())).thenThrow(new AlertConfigurationException("Exception for test"));
    Set<String> roleNames = roles.stream().map(UserRoleModel::getName).collect(Collectors.toSet());
    UserConfig userConfig = new UserConfig(id.toString(), name, "newPassword", "newEmailAddress", roleNames, false, false, false, true, false, authenticationType.name(), false);
    UserActions userActions = new UserActions(userManagementDescriptorKey, userAccessor, roleAccessor, authorizationManager, authenticationTypeAccessor, userSystemValidator);
    ActionResponse<UserConfig> userConfigActionResponse = userActions.updateWithoutChecks(id, userConfig);
    assertTrue(userConfigActionResponse.isError());
    assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, userConfigActionResponse.getHttpStatus());
}
Also used : UserModel(com.synopsys.integration.alert.common.persistence.model.UserModel) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) Test(org.junit.jupiter.api.Test)

Example 34 with UserModel

use of com.synopsys.integration.alert.common.persistence.model.UserModel 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));
}
Also used : UserModel(com.synopsys.integration.alert.common.persistence.model.UserModel) ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) UserManagementDescriptorKey(com.synopsys.integration.alert.component.users.UserManagementDescriptorKey) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) Test(org.junit.jupiter.api.Test)

Example 35 with UserModel

use of com.synopsys.integration.alert.common.persistence.model.UserModel in project hub-alert by blackducksoftware.

the class UserActionsTest method testCreateWithoutChecks.

@Test
public void testCreateWithoutChecks() throws Exception {
    UserModel userModel = UserModel.existingUser(id, name, password, emailAddress, authenticationType, roles, true);
    Mockito.when(userAccessor.addUser(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenReturn(userModel);
    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", emailAddress, roleNames, false, false, false, true, false, authenticationType.name(), false);
    UserActions userActions = new UserActions(userManagementDescriptorKey, userAccessor, roleAccessor, authorizationManager, authenticationTypeAccessor, userSystemValidator);
    ActionResponse<UserConfig> userConfigActionResponse = userActions.createWithoutChecks(userConfig);
    assertFalse(userConfigActionResponse.isError());
    assertTrue(userConfigActionResponse.hasContent());
    UserConfig testUserConfig = userConfigActionResponse.getContent().get();
    assertUserConfig(testUserConfig);
    assertEquals(HttpStatus.CREATED, userConfigActionResponse.getHttpStatus());
}
Also used : UserModel(com.synopsys.integration.alert.common.persistence.model.UserModel) Test(org.junit.jupiter.api.Test)

Aggregations

UserModel (com.synopsys.integration.alert.common.persistence.model.UserModel)42 Test (org.junit.jupiter.api.Test)32 UserRoleModel (com.synopsys.integration.alert.common.persistence.model.UserRoleModel)17 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)12 UserEntity (com.synopsys.integration.alert.database.user.UserEntity)8 UserRoleRelation (com.synopsys.integration.alert.database.user.UserRoleRelation)7 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)6 UserManagementDescriptorKey (com.synopsys.integration.alert.component.users.UserManagementDescriptorKey)6 AuthenticationTypeDetails (com.synopsys.integration.alert.common.persistence.model.AuthenticationTypeDetails)5 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)4 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)4 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)4 AuthenticationType (com.synopsys.integration.alert.common.enumeration.AuthenticationType)4 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)4 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 DefaultUserRole (com.synopsys.integration.alert.common.enumeration.DefaultUserRole)3 UserAccessor (com.synopsys.integration.alert.common.persistence.accessor.UserAccessor)3 LoginConfig (com.synopsys.integration.alert.component.authentication.web.LoginConfig)3