Search in sources :

Example 1 with UserManagementDescriptorKey

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());
}
Also used : UserModel(com.synopsys.integration.alert.common.persistence.model.UserModel) 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 2 with UserManagementDescriptorKey

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

Example 3 with UserManagementDescriptorKey

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());
}
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) AuthenticationType(com.synopsys.integration.alert.common.enumeration.AuthenticationType) Test(org.junit.jupiter.api.Test)

Example 4 with UserManagementDescriptorKey

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));
}
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)

Aggregations

ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)4 UserModel (com.synopsys.integration.alert.common.persistence.model.UserModel)4 UserManagementDescriptorKey (com.synopsys.integration.alert.component.users.UserManagementDescriptorKey)4 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)4 Test (org.junit.jupiter.api.Test)4 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)2 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)2 AuthenticationType (com.synopsys.integration.alert.common.enumeration.AuthenticationType)1 AuthenticationTypeDetails (com.synopsys.integration.alert.common.persistence.model.AuthenticationTypeDetails)1