Search in sources :

Example 6 with ValidationActionResponse

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

the class CertificateActions method validateWithoutChecks.

@Override
protected ValidationActionResponse validateWithoutChecks(CertificateModel resource) {
    ValidationResponseModel responseModel;
    if (StringUtils.isNotBlank(resource.getId()) && !NumberUtils.isCreatable(resource.getId())) {
        responseModel = ValidationResponseModel.generalError("Invalid resource id");
        return new ValidationActionResponse(HttpStatus.BAD_REQUEST, responseModel);
    }
    List<AlertFieldStatus> fieldErrors = validateCertificateFields(resource);
    if (fieldErrors.isEmpty()) {
        responseModel = ValidationResponseModel.success("The certificate configuration is valid");
        return new ValidationActionResponse(HttpStatus.OK, responseModel);
    }
    responseModel = ValidationResponseModel.fromStatusCollection("There were problems with the certificate configuration", fieldErrors);
    return new ValidationActionResponse(HttpStatus.BAD_REQUEST, responseModel);
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)

Example 7 with ValidationActionResponse

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

the class UserActionsTest method testTestWithoutChecks.

@Test
public void testTestWithoutChecks() {
    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", emailAddress, roleNames, false, false, false, true, false, authenticationType.name(), false);
    UserActions userActions = new UserActions(userManagementDescriptorKey, userAccessor, roleAccessor, authorizationManager, authenticationTypeAccessor, userSystemValidator);
    ValidationActionResponse validationActionResponse = userActions.testWithoutChecks(userConfig);
    assertFalse(validationActionResponse.isError());
    assertTrue(validationActionResponse.hasContent());
    assertFalse(validationActionResponse.getContent().get().hasErrors());
}
Also used : ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) Test(org.junit.jupiter.api.Test)

Example 8 with ValidationActionResponse

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

the class RoleActionsTest method validateTest.

@Test
public void validateTest() {
    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.validate(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 9 with ValidationActionResponse

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

the class RoleActionsTest method validateBadRequestTest.

@Test
public void validateBadRequestTest() {
    PermissionModel permissionModel = createPermissionModel();
    RolePermissionModel rolePermissionModel = new RolePermissionModel(null, roleName, 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 10 with ValidationActionResponse

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

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