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.");
}
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);
}
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");
}
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");
}
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");
}
Aggregations