Search in sources :

Example 26 with ValidationActionResponse

use of com.synopsys.integration.alert.common.action.ValidationActionResponse in project hub-alert by blackducksoftware.

the class AbstractConfigResourceActions method update.

@Override
public final ActionResponse<FieldModel> update(Long id, FieldModel resource) {
    if (!authorizationManager.hasWritePermission(resource.getContext(), resource.getDescriptorName())) {
        return ActionResponse.createForbiddenResponse();
    }
    Optional<FieldModel> existingModel = findFieldModel(id);
    if (existingModel.isEmpty()) {
        return new ActionResponse<>(HttpStatus.NOT_FOUND);
    }
    ValidationActionResponse validationResponse = validateWithoutChecks(resource);
    if (validationResponse.isError()) {
        return new ActionResponse<>(validationResponse.getHttpStatus(), validationResponse.getMessage().orElse(null));
    }
    return updateWithoutChecks(id, resource);
}
Also used : ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) MultiFieldModel(com.synopsys.integration.alert.common.rest.model.MultiFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Example 27 with ValidationActionResponse

use of com.synopsys.integration.alert.common.action.ValidationActionResponse in project hub-alert by blackducksoftware.

the class RoleActionsTest method testTest.

@Test
public void testTest() {
    PermissionModel permissionModel = createPermissionModel();
    RolePermissionModel rolePermissionModel = new RolePermissionModel(null, roleName, Set.of(permissionModel));
    Mockito.when(roleAccessor.doesRoleNameExist(Mockito.eq(roleName))).thenReturn(false);
    RoleActions roleActions = new RoleActions(userManagementDescriptorKey, roleAccessor, authorizationManager, descriptorMap);
    ValidationActionResponse validationActionResponse = roleActions.test(rolePermissionModel);
    assertTrue(validationActionResponse.isSuccessful());
    assertEquals(HttpStatus.OK, validationActionResponse.getHttpStatus());
    assertTrue(validationActionResponse.hasContent());
}
Also used : ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) Test(org.junit.jupiter.api.Test)

Example 28 with ValidationActionResponse

use of com.synopsys.integration.alert.common.action.ValidationActionResponse in project hub-alert by blackducksoftware.

the class RoleActionsTest method validateMissingRoleNameTest.

@Test
public void validateMissingRoleNameTest() {
    PermissionModel permissionModel = createPermissionModel();
    RolePermissionModel rolePermissionModel = new RolePermissionModel(null, "", Set.of(permissionModel));
    Mockito.when(roleAccessor.doesRoleNameExist(Mockito.eq(roleName))).thenReturn(true);
    RoleActions roleActions = new RoleActions(userManagementDescriptorKey, roleAccessor, authorizationManager, descriptorMap);
    ValidationActionResponse validationActionResponse = roleActions.validate(rolePermissionModel);
    assertTrue(validationActionResponse.isSuccessful());
    assertEquals(HttpStatus.OK, validationActionResponse.getHttpStatus());
    assertTrue(validationActionResponse.hasContent());
    ValidationResponseModel validationResponseModel = validationActionResponse.getContent().get();
    assertTrue(validationResponseModel.hasErrors());
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) Test(org.junit.jupiter.api.Test)

Example 29 with ValidationActionResponse

use of com.synopsys.integration.alert.common.action.ValidationActionResponse in project hub-alert by blackducksoftware.

the class RoleActionsTest method validateDuplicatePermissionsTest.

@Test
public void validateDuplicatePermissionsTest() {
    PermissionModel permissionModel = createPermissionModel();
    PermissionModel permissionModelDuplicate = new PermissionModel(descriptorKey.getUniversalKey(), context, false, true, true, true, true, true, true, true);
    RolePermissionModel rolePermissionModel = new RolePermissionModel(null, roleName, Set.of(permissionModel, permissionModelDuplicate));
    Mockito.when(roleAccessor.doesRoleNameExist(Mockito.eq(roleName))).thenReturn(false);
    RoleActions roleActions = new RoleActions(userManagementDescriptorKey, roleAccessor, authorizationManager, descriptorMap);
    ValidationActionResponse validationActionResponse = roleActions.validate(rolePermissionModel);
    assertTrue(validationActionResponse.isSuccessful());
    assertEquals(HttpStatus.OK, validationActionResponse.getHttpStatus());
    assertTrue(validationActionResponse.hasContent());
    ValidationResponseModel validationResponseModel = validationActionResponse.getContent().get();
    assertTrue(validationResponseModel.hasErrors());
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) Test(org.junit.jupiter.api.Test)

Example 30 with ValidationActionResponse

use of com.synopsys.integration.alert.common.action.ValidationActionResponse 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

ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)44 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)33 Test (org.junit.jupiter.api.Test)28 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)15 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)13 AlertFieldStatus (com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)10 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)9 PermissionKey (com.synopsys.integration.alert.common.persistence.model.PermissionKey)9 PermissionMatrixModel (com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel)8 ChannelKey (com.synopsys.integration.alert.descriptor.api.model.ChannelKey)8 AuthenticationTestUtils (com.synopsys.integration.alert.test.common.AuthenticationTestUtils)8 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)7 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)7 AlertFieldException (com.synopsys.integration.alert.common.exception.AlertFieldException)7 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)7 FieldModelTestAction (com.synopsys.integration.alert.common.action.FieldModelTestAction)6 FieldUtility (com.synopsys.integration.alert.common.persistence.accessor.FieldUtility)6 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)6 IntegrationException (com.synopsys.integration.exception.IntegrationException)6 IntegrationRestException (com.synopsys.integration.rest.exception.IntegrationRestException)6