Search in sources :

Example 16 with ValidationResponseModel

use of com.synopsys.integration.alert.common.rest.model.ValidationResponseModel in project hub-alert by blackducksoftware.

the class JiraServerGlobalConfigurationValidatorTest method verifyValidConfig.

@Test
void verifyValidConfig() {
    JiraServerGlobalConfigurationValidator validator = new JiraServerGlobalConfigurationValidator();
    JiraServerGlobalConfigModel model = new JiraServerGlobalConfigModel(ID, NAME, CREATED_AT, LAST_UPDATED, URL, USER_NAME, PASSWORD, Boolean.FALSE, Boolean.FALSE);
    ValidationResponseModel validationResponseModel = validator.validate(model);
    Collection<AlertFieldStatus> alertFieldStatuses = validationResponseModel.getErrors().values();
    assertEquals(0, alertFieldStatuses.size(), "There were errors in the configuration when none were expected.");
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) JiraServerGlobalConfigModel(com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) Test(org.junit.jupiter.api.Test)

Example 17 with ValidationResponseModel

use of com.synopsys.integration.alert.common.rest.model.ValidationResponseModel in project hub-alert by blackducksoftware.

the class AbstractJobResourceActions method validate.

public final ValidationActionResponse validate(JobFieldModel resource) {
    boolean hasPermissions = resource.getFieldModels().stream().allMatch(model -> authorizationManager.hasCreatePermission(model.getContext(), model.getDescriptorName()) || authorizationManager.hasWritePermission(model.getContext(), model.getDescriptorName()) || authorizationManager.hasExecutePermission(model.getContext(), model.getDescriptorName()));
    if (!hasPermissions) {
        ValidationResponseModel responseModel = ValidationResponseModel.generalError(ActionResponse.FORBIDDEN_MESSAGE);
        return new ValidationActionResponse(HttpStatus.FORBIDDEN, responseModel);
    }
    // Clean input
    correctProjectsField(resource);
    ValidationActionResponse response = validateWithoutChecks(resource);
    return ValidationActionResponse.createOKResponseWithContent(response);
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse)

Example 18 with ValidationResponseModel

use of com.synopsys.integration.alert.common.rest.model.ValidationResponseModel in project hub-alert by blackducksoftware.

the class EmailGlobalTestActionTest method testPermissionConfigInvalidDestinationTest.

@Test
public void testPermissionConfigInvalidDestinationTest() {
    AuthorizationManager authorizationManager = createAuthorizationManager(AuthenticationTestUtils.FULL_PERMISSIONS);
    EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
    EmailGlobalTestAction emailGlobalTestAction = new EmailGlobalTestAction(authorizationManager, validator, null, null, configurationAccessor);
    ActionResponse<ValidationResponseModel> response = emailGlobalTestAction.testWithPermissionCheck("not a valid email address", new EmailGlobalConfigModel());
    assertEquals(HttpStatus.OK, response.getHttpStatus());
    assertTrue(response.hasContent());
    assertTrue(response.getContent().get().hasErrors(), "Expected the message result to not have errors");
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) EmailGlobalConfigurationValidator(com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) Test(org.junit.jupiter.api.Test)

Example 19 with ValidationResponseModel

use of com.synopsys.integration.alert.common.rest.model.ValidationResponseModel in project hub-alert by blackducksoftware.

the class EmailGlobalTestActionTest method testPermissionConfigMissingDestinationTest.

@Test
public void testPermissionConfigMissingDestinationTest() {
    AuthorizationManager authorizationManager = createAuthorizationManager(AuthenticationTestUtils.FULL_PERMISSIONS);
    EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
    EmailAddressGatherer emailAddressGatherer = Mockito.mock(EmailAddressGatherer.class);
    Mockito.when(emailAddressGatherer.gatherEmailAddresses(Mockito.any(), Mockito.any())).thenReturn(Set.of());
    JobEmailAddressValidator emailAddressValidator = Mockito.mock(JobEmailAddressValidator.class);
    Mockito.when(emailAddressValidator.validate(Mockito.any(), Mockito.anyCollection())).thenReturn(new ValidatedEmailAddresses(Set.of(), Set.of()));
    MockAlertProperties testAlertProperties = new MockAlertProperties();
    MessageContentGroupCsvCreator messageContentGroupCsvCreator = new MessageContentGroupCsvCreator();
    Gson gson = new Gson();
    EmailAttachmentFileCreator emailAttachmentFileCreator = new EmailAttachmentFileCreator(testAlertProperties, messageContentGroupCsvCreator, gson);
    FreemarkerTemplatingService freemarkerTemplatingService = new FreemarkerTemplatingService();
    EmailMessagingService emailMessagingService = new EmailMessagingService(freemarkerTemplatingService);
    EmailChannelMessagingService emailChannelMessagingService = new EmailChannelMessagingService(testAlertProperties, emailMessagingService, emailAttachmentFileCreator);
    JavamailPropertiesFactory javamailPropertiesFactory = new JavamailPropertiesFactory();
    EmailGlobalTestAction emailGlobalTestAction = new EmailGlobalTestAction(authorizationManager, validator, emailChannelMessagingService, javamailPropertiesFactory, configurationAccessor);
    ActionResponse<ValidationResponseModel> response = emailGlobalTestAction.testWithPermissionCheck("", new EmailGlobalConfigModel());
    assertEquals(HttpStatus.OK, response.getHttpStatus());
    assertTrue(response.hasContent());
    assertTrue(response.getContent().get().hasErrors(), "Expected the message result to not have errors");
}
Also used : MessageContentGroupCsvCreator(com.synopsys.integration.alert.channel.email.attachment.MessageContentGroupCsvCreator) EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) EmailMessagingService(com.synopsys.integration.alert.service.email.EmailMessagingService) EmailAttachmentFileCreator(com.synopsys.integration.alert.channel.email.attachment.EmailAttachmentFileCreator) Gson(com.google.gson.Gson) EmailAddressGatherer(com.synopsys.integration.alert.channel.email.distribution.address.EmailAddressGatherer) ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) EmailGlobalConfigurationValidator(com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator) FreemarkerTemplatingService(com.synopsys.integration.alert.service.email.template.FreemarkerTemplatingService) JobEmailAddressValidator(com.synopsys.integration.alert.channel.email.distribution.address.JobEmailAddressValidator) MockAlertProperties(com.synopsys.integration.alert.test.common.MockAlertProperties) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) ValidatedEmailAddresses(com.synopsys.integration.alert.channel.email.distribution.address.ValidatedEmailAddresses) EmailChannelMessagingService(com.synopsys.integration.alert.channel.email.distribution.EmailChannelMessagingService) JavamailPropertiesFactory(com.synopsys.integration.alert.service.email.JavamailPropertiesFactory) Test(org.junit.jupiter.api.Test)

Example 20 with ValidationResponseModel

use of com.synopsys.integration.alert.common.rest.model.ValidationResponseModel in project hub-alert by blackducksoftware.

the class EmailGlobalTestActionTest method testPermissionConfigITTest.

@Test
@Tags(value = { @Tag(TestTags.DEFAULT_INTEGRATION), @Tag(TestTags.CUSTOM_EXTERNAL_CONNECTION) })
public void testPermissionConfigITTest() {
    AuthorizationManager authorizationManager = createAuthorizationManager(AuthenticationTestUtils.FULL_PERMISSIONS);
    EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
    TestProperties testProperties = new TestProperties();
    String emailAddress = testProperties.getProperty(TestPropertyKey.TEST_EMAIL_RECIPIENT);
    JavamailPropertiesFactory javamailPropertiesFactory = new JavamailPropertiesFactory();
    EmailChannelMessagingService validEmailChannelMessagingService = createValidEmailChannelMessagingService(emailAddress);
    EmailGlobalTestAction emailGlobalTestAction = new EmailGlobalTestAction(authorizationManager, validator, validEmailChannelMessagingService, javamailPropertiesFactory, configurationAccessor);
    EmailGlobalConfigModel globalConfigModel = createValidEmailGlobalConfigModel(testProperties);
    ActionResponse<ValidationResponseModel> response = emailGlobalTestAction.testWithPermissionCheck(emailAddress, globalConfigModel);
    assertEquals(HttpStatus.OK, response.getHttpStatus());
    assertTrue(response.hasContent());
    assertFalse(response.getContent().get().hasErrors(), "Expected the message result to not have errors");
}
Also used : TestProperties(com.synopsys.integration.alert.test.common.TestProperties) EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) EmailGlobalConfigurationValidator(com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) JavamailPropertiesFactory(com.synopsys.integration.alert.service.email.JavamailPropertiesFactory) EmailChannelMessagingService(com.synopsys.integration.alert.channel.email.distribution.EmailChannelMessagingService) Test(org.junit.jupiter.api.Test) TestTags(com.synopsys.integration.alert.test.common.TestTags) Tags(org.junit.jupiter.api.Tags)

Aggregations

ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)84 Test (org.junit.jupiter.api.Test)66 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)33 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)25 AlertFieldStatus (com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)23 SettingsProxyModel (com.synopsys.integration.alert.common.rest.model.SettingsProxyModel)18 EmailGlobalConfigModel (com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel)15 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)13 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)9 SettingsProxyTestAction (com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyTestAction)9 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)7 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)7 EmailGlobalConfigurationValidator (com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator)7 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)7 AlertFieldException (com.synopsys.integration.alert.common.exception.AlertFieldException)7 PermissionKey (com.synopsys.integration.alert.common.persistence.model.PermissionKey)7 IntegrationException (com.synopsys.integration.exception.IntegrationException)7 IntegrationRestException (com.synopsys.integration.rest.exception.IntegrationRestException)7 Map (java.util.Map)7 FieldModelTestAction (com.synopsys.integration.alert.common.action.FieldModelTestAction)6