Search in sources :

Example 31 with ValidationActionResponse

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

the class TestHelperConfigurationTest method testMessageSuccess.

@Test
public void testMessageSuccess() {
    AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
    DescriptorKey descriptorKey = new ChannelKey("channel_key", "channel-display-name");
    PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), descriptorKey.getUniversalKey());
    Map<PermissionKey, Integer> permissions = Map.of(permissionKey, AuthenticationTestUtils.FULL_PERMISSIONS);
    AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
    ConfigurationTestHelper testHelper = new ConfigurationTestHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
    ValidationActionResponse response = testHelper.test(() -> new ValidationActionResponse(HttpStatus.OK, ValidationResponseModel.success()), () -> ConfigurationTestResult.success("Success"));
    ValidationResponseModel validationResponseModel = response.getContent().orElseThrow(() -> new IllegalStateException("Validation content missing"));
    assertEquals(HttpStatus.OK, response.getHttpStatus());
    assertFalse(validationResponseModel.hasErrors());
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) ChannelKey(com.synopsys.integration.alert.descriptor.api.model.ChannelKey) AuthenticationTestUtils(com.synopsys.integration.alert.test.common.AuthenticationTestUtils) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) Test(org.junit.jupiter.api.Test)

Example 32 with ValidationActionResponse

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

the class TestHelperConfigurationTest method testValidationWithError.

@Test
public void testValidationWithError() {
    AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
    DescriptorKey descriptorKey = new ChannelKey("channel_key", "channel-display-name");
    PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), descriptorKey.getUniversalKey());
    Map<PermissionKey, Integer> permissions = Map.of(permissionKey, AuthenticationTestUtils.FULL_PERMISSIONS);
    AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
    ConfigurationTestHelper testHelper = new ConfigurationTestHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
    ValidationActionResponse response = testHelper.test(() -> new ValidationActionResponse(HttpStatus.BAD_REQUEST, ValidationResponseModel.generalError("generalError")), () -> ConfigurationTestResult.success("Success"));
    ValidationResponseModel validationResponseModel = response.getContent().orElseThrow(() -> new IllegalStateException("Validation content missing"));
    assertEquals(HttpStatus.BAD_REQUEST, response.getHttpStatus());
    assertTrue(validationResponseModel.hasErrors());
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) ChannelKey(com.synopsys.integration.alert.descriptor.api.model.ChannelKey) AuthenticationTestUtils(com.synopsys.integration.alert.test.common.AuthenticationTestUtils) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) Test(org.junit.jupiter.api.Test)

Example 33 with ValidationActionResponse

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

the class ConfigurationValidationHelperTest method testValidationWithError.

@Test
public void testValidationWithError() {
    AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
    DescriptorKey descriptorKey = new ChannelKey("channel_key", "channel-display-name");
    PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), descriptorKey.getUniversalKey());
    Map<PermissionKey, Integer> permissions = Map.of(permissionKey, AuthenticationTestUtils.FULL_PERMISSIONS);
    AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
    ConfigurationValidationHelper validationHelper = new ConfigurationValidationHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
    ValidationActionResponse response = validationHelper.validate(() -> ValidationResponseModel.generalError("generalError"));
    ValidationResponseModel validationResponseModel = response.getContent().orElseThrow(() -> new IllegalStateException("Validation content missing"));
    assertEquals(HttpStatus.OK, response.getHttpStatus());
    assertTrue(validationResponseModel.hasErrors());
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) ChannelKey(com.synopsys.integration.alert.descriptor.api.model.ChannelKey) AuthenticationTestUtils(com.synopsys.integration.alert.test.common.AuthenticationTestUtils) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) Test(org.junit.jupiter.api.Test)

Example 34 with ValidationActionResponse

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

the class JobConfigActions method validateWithoutChecks.

@Override
protected ValidationActionResponse validateWithoutChecks(JobFieldModel resource) {
    UUID jobId = null;
    if (StringUtils.isNotBlank(resource.getJobId())) {
        jobId = UUID.fromString(resource.getJobId());
    }
    List<AlertFieldStatus> fieldStatuses = new ArrayList<>();
    validateJobNameUnique(jobId, resource).ifPresent(fieldStatuses::add);
    List<AlertFieldStatus> descriptorValidationResults = validateDescriptorFields(resource);
    fieldStatuses.addAll(descriptorValidationResults);
    if (!fieldStatuses.isEmpty()) {
        ValidationResponseModel responseModel = ValidationResponseModel.fromStatusCollection("Invalid Configuration", fieldStatuses);
        return new ValidationActionResponse(HttpStatus.BAD_REQUEST, responseModel);
    }
    ValidationResponseModel responseModel = ValidationResponseModel.success("Valid");
    return new ValidationActionResponse(HttpStatus.OK, responseModel);
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) ArrayList(java.util.ArrayList) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) UUID(java.util.UUID)

Example 35 with ValidationActionResponse

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

the class ConfigActions method validateWithoutChecks.

@Override
protected ValidationActionResponse validateWithoutChecks(FieldModel resource) {
    if (!encryptionUtility.isInitialized() && !settingsDescriptorKey.getUniversalKey().equals(resource.getDescriptorName())) {
        ValidationResponseModel validationResponseModel = ValidationResponseModel.generalError(ConfigurationFieldValidator.ENCRYPTION_MISSING);
        return new ValidationActionResponse(HttpStatus.INTERNAL_SERVER_ERROR, validationResponseModel);
    }
    Set<AlertFieldStatus> fieldStatuses = descriptorProcessor.retrieveDescriptor(resource.getDescriptorName()).flatMap(Descriptor::getGlobalValidator).map(globalValidator -> globalValidator.validate(resource)).orElse(Set.of());
    ValidationResponseModel responseModel;
    HttpStatus status = HttpStatus.OK;
    if (fieldStatuses.isEmpty()) {
        responseModel = ValidationResponseModel.success("The configuration is valid");
    } else {
        status = HttpStatus.BAD_REQUEST;
        responseModel = ValidationResponseModel.fromStatusCollection("There were problems with the configuration", fieldStatuses);
    }
    return new ValidationActionResponse(status, responseModel);
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) Descriptor(com.synopsys.integration.alert.common.descriptor.Descriptor) AlertFieldException(com.synopsys.integration.alert.common.exception.AlertFieldException) IntegrationException(com.synopsys.integration.exception.IntegrationException) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) DescriptorAccessor(com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) SettingsDescriptorKey(com.synopsys.integration.alert.component.settings.descriptor.SettingsDescriptorKey) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) PKIXErrorResponseFactory(com.synopsys.integration.alert.component.certificates.web.PKIXErrorResponseFactory) DescriptorMap(com.synopsys.integration.alert.common.descriptor.DescriptorMap) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) EnumUtils(org.apache.commons.lang3.EnumUtils) Map(java.util.Map) LinkedList(java.util.LinkedList) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) Logger(org.slf4j.Logger) Collection(java.util.Collection) Set(java.util.Set) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) MultiFieldModel(com.synopsys.integration.alert.common.rest.model.MultiFieldModel) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) ConfigurationFieldValidator(com.synopsys.integration.alert.common.descriptor.validator.ConfigurationFieldValidator) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) FieldUtility(com.synopsys.integration.alert.common.persistence.accessor.FieldUtility) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) Component(org.springframework.stereotype.Component) AbstractConfigResourceActions(com.synopsys.integration.alert.common.action.api.AbstractConfigResourceActions) FieldModelProcessor(com.synopsys.integration.alert.common.rest.FieldModelProcessor) IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) Optional(java.util.Optional) EncryptionUtility(com.synopsys.integration.alert.common.security.EncryptionUtility) DescriptorProcessor(com.synopsys.integration.alert.common.descriptor.DescriptorProcessor) FieldModelTestAction(com.synopsys.integration.alert.common.action.FieldModelTestAction) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) HttpStatus(org.springframework.http.HttpStatus) Descriptor(com.synopsys.integration.alert.common.descriptor.Descriptor) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)

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