use of com.synopsys.integration.alert.api.common.model.ValidationResponseModel in project hub-alert by blackducksoftware.
the class SettingsProxyTestActionTestIT method missingTargetUrlTest.
@Test
void missingTargetUrlTest() {
SettingsProxyModel settingsProxyModel = createSettingsProxyModel(testProperties);
AuthorizationManager authorizationManager = createAuthorizationManager(AuthenticationTestUtils.FULL_PERMISSIONS);
settingsProxyTestAction = new SettingsProxyTestAction(authorizationManager, settingsProxyValidator, settingsDescriptorKey, proxyTestService, settingsProxyConfigAccessor);
ActionResponse<ValidationResponseModel> testResult = settingsProxyTestAction.testWithPermissionCheck("", settingsProxyModel);
assertTrue(testResult.isSuccessful());
assertTrue(testResult.getContent().isPresent());
ValidationResponseModel validationResponseModel = testResult.getContent().get();
assertTrue(validationResponseModel.hasErrors());
}
use of com.synopsys.integration.alert.api.common.model.ValidationResponseModel in project hub-alert by blackducksoftware.
the class RoleActionsTest method validateMissingRoleNameTest.
@Test
public void validateMissingRoleNameTest() {
PermissionModel permissionModel = createPermissionModel();
RolePermissionModel rolePermissionModel = new RolePermissionModel(null, "", 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());
}
use of com.synopsys.integration.alert.api.common.model.ValidationResponseModel in project hub-alert by blackducksoftware.
the class RoleActionsTest method validateDuplicatePermissionsTest.
@Test
public void validateDuplicatePermissionsTest() {
PermissionModel permissionModel = createPermissionModel();
PermissionModel permissionModelDuplicate = new PermissionModel(descriptorKey.getUniversalKey(), context, false, true, true, true, true, true, true, true);
RolePermissionModel rolePermissionModel = new RolePermissionModel(null, roleName, Set.of(permissionModel, permissionModelDuplicate));
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());
ValidationResponseModel validationResponseModel = validationActionResponse.getContent().get();
assertTrue(validationResponseModel.hasErrors());
}
use of com.synopsys.integration.alert.api.common.model.ValidationResponseModel in project hub-alert by blackducksoftware.
the class AbstractJobResourceActions method test.
public final ValidationActionResponse test(JobFieldModel resource) {
boolean hasPermissions = hasRequiredPermissions(resource.getFieldModels(), authorizationManager::hasExecutePermission);
if (!hasPermissions) {
ValidationResponseModel responseModel = ValidationResponseModel.generalError(ActionResponse.FORBIDDEN_MESSAGE);
return new ValidationActionResponse(HttpStatus.FORBIDDEN, responseModel);
}
// Clean input
correctProjectsField(resource);
ValidationActionResponse validationResponse = validateWithoutChecks(resource);
if (validationResponse.isError()) {
return ValidationActionResponse.createOKResponseWithContent(validationResponse);
}
return testWithoutChecks(resource);
}
use of com.synopsys.integration.alert.api.common.model.ValidationResponseModel in project hub-alert by blackducksoftware.
the class ConfigurationManagerV2 method createGlobalConfiguration.
public <T extends Obfuscated<T>> Optional<T> createGlobalConfiguration(String apiConfigurationPath, T globalConfigModel, Class<T> modelType) {
try {
String requestBody = gson.toJson(globalConfigModel);
String validationResponseString = alertRequestUtility.executePostRequest(String.format("%s/validate", apiConfigurationPath), requestBody, "Validating the global configuration failed.");
ValidationResponseModel validationResponse = gson.fromJson(validationResponseString, ValidationResponseModel.class);
if (validationResponse.hasErrors()) {
intLogger.error(String.format("Could not validate global configuration model. Error: %s", validationResponse.getErrors()));
return Optional.empty();
}
String testResponseString = alertRequestUtility.executePostRequest(String.format("%s/test", apiConfigurationPath), requestBody, "Testing the global configuration failed.");
ValidationResponseModel testResponse = gson.fromJson(testResponseString, ValidationResponseModel.class);
if (testResponse.hasErrors() && !ValidationResponseModel.VALIDATION_SUCCESS_MESSAGE.equals(validationResponse.getMessage())) {
intLogger.error(String.format("Testing the global config model error message: %s", validationResponse.getMessage()));
intLogger.error(String.format("Testing the global config model failed. Error: %s", validationResponse.getErrors()));
return Optional.empty();
}
String globalConfigCreateResponse = alertRequestUtility.executePostRequest(apiConfigurationPath, requestBody, "Could not create the global configuration");
JsonObject globalConfigSearchJsonObject = gson.fromJson(globalConfigCreateResponse, JsonObject.class);
T savedGlobalConfig = gson.fromJson(globalConfigSearchJsonObject, modelType);
return Optional.of(savedGlobalConfig);
} catch (IntegrationException e) {
intLogger.error("Unexpected error occurred while creating the global configuration.", e);
return Optional.empty();
}
}
Aggregations