use of com.synopsys.integration.alert.common.rest.model.ValidationResponseModel 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);
}
use of com.synopsys.integration.alert.common.rest.model.ValidationResponseModel 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);
}
use of com.synopsys.integration.alert.common.rest.model.ValidationResponseModel in project hub-alert by blackducksoftware.
the class EmailGlobalValidationActionTest method testValidationSuccess.
@Test
public void testValidationSuccess() {
AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
DescriptorKey descriptorKey = ChannelKeys.EMAIL;
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));
EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
EmailGlobalValidationAction validationAction = new EmailGlobalValidationAction(validator, authorizationManager);
EmailGlobalConfigModel model = new EmailGlobalConfigModel();
model.setSmtpHost("host");
model.setSmtpFrom("from");
model.setSmtpAuth(true);
model.setSmtpUsername("user");
model.setSmtpPassword("password");
ActionResponse<ValidationResponseModel> response = validationAction.validate(model);
assertEquals(HttpStatus.OK, response.getHttpStatus());
}
use of com.synopsys.integration.alert.common.rest.model.ValidationResponseModel in project hub-alert by blackducksoftware.
the class EmailGlobalValidationActionTest method testValidationForbidden.
@Test
public void testValidationForbidden() {
AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
DescriptorKey descriptorKey = ChannelKeys.EMAIL;
PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), descriptorKey.getUniversalKey());
Map<PermissionKey, Integer> permissions = Map.of(permissionKey, AuthenticationTestUtils.NO_PERMISSIONS);
AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
EmailGlobalValidationAction validationAction = new EmailGlobalValidationAction(validator, authorizationManager);
EmailGlobalConfigModel model = new EmailGlobalConfigModel();
model.setSmtpHost("host");
model.setSmtpFrom("from");
model.setSmtpAuth(true);
model.setSmtpUsername("user");
model.setSmtpPassword("password");
ActionResponse<ValidationResponseModel> response = validationAction.validate(model);
assertEquals(HttpStatus.FORBIDDEN, response.getHttpStatus());
}
use of com.synopsys.integration.alert.common.rest.model.ValidationResponseModel in project hub-alert by blackducksoftware.
the class EmailGlobalTestActionTest method testPermissionConfigValidTest.
@Test
public void testPermissionConfigValidTest() throws AlertException {
TestProperties testProperties = new TestProperties();
AuthorizationManager authorizationManager = createAuthorizationManager(AuthenticationTestUtils.FULL_PERMISSIONS);
EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
EmailChannelMessagingService emailChannelMessagingService = Mockito.mock(EmailChannelMessagingService.class);
Mockito.when(emailChannelMessagingService.sendMessage(Mockito.any(), Mockito.any())).thenReturn(new MessageResult("PASS"));
JavamailPropertiesFactory javamailPropertiesFactory = new JavamailPropertiesFactory();
EmailGlobalTestAction emailGlobalTestAction = new EmailGlobalTestAction(authorizationManager, validator, emailChannelMessagingService, javamailPropertiesFactory, configurationAccessor);
EmailGlobalConfigModel globalConfigModel = createValidEmailGlobalConfigModel(testProperties);
ActionResponse<ValidationResponseModel> response = emailGlobalTestAction.testWithPermissionCheck("noreply@synopsys.com", globalConfigModel);
assertEquals(HttpStatus.OK, response.getHttpStatus());
assertTrue(response.isSuccessful());
assertTrue(response.hasContent());
assertFalse(response.getContent().get().hasErrors(), "Expected the message result to not have errors");
}
Aggregations