use of com.synopsys.integration.alert.api.common.model.ValidationResponseModel in project hub-alert by blackducksoftware.
the class CertificateActions method validateWithoutChecks.
@Override
protected ValidationActionResponse validateWithoutChecks(CertificateModel resource) {
ValidationResponseModel responseModel;
if (StringUtils.isNotBlank(resource.getId()) && !NumberUtils.isCreatable(resource.getId())) {
responseModel = ValidationResponseModel.generalError("Invalid resource id");
return new ValidationActionResponse(HttpStatus.BAD_REQUEST, responseModel);
}
List<AlertFieldStatus> fieldErrors = validateCertificateFields(resource);
if (fieldErrors.isEmpty()) {
responseModel = ValidationResponseModel.success("The certificate configuration is valid");
return new ValidationActionResponse(HttpStatus.OK, responseModel);
}
responseModel = ValidationResponseModel.fromStatusCollection("There were problems with the certificate configuration", fieldErrors);
return new ValidationActionResponse(HttpStatus.BAD_REQUEST, responseModel);
}
use of com.synopsys.integration.alert.api.common.model.ValidationResponseModel in project hub-alert by blackducksoftware.
the class RoleActionsTest method validateBadRequestTest.
@Test
public void validateBadRequestTest() {
PermissionModel permissionModel = createPermissionModel();
RolePermissionModel rolePermissionModel = new RolePermissionModel(null, roleName, 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 UserActionsTest method testExternalUserNoEmailValidation.
@Test
public void testExternalUserNoEmailValidation() throws Exception {
AuthenticationType authenticationTypeLDAP = AuthenticationType.LDAP;
UserModel userModel = UserModel.existingUser(id, name, password, null, authenticationTypeLDAP, roles, true);
Mockito.when(authorizationManager.hasExecutePermission(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class))).thenReturn(true);
Mockito.when(userAccessor.getUser(Mockito.anyLong())).thenReturn(Optional.of(userModel));
Set<String> roleNames = roles.stream().map(UserRoleModel::getName).collect(Collectors.toSet());
roleNames.add(DefaultUserRole.ALERT_ADMIN.name());
UserConfig userConfig = new UserConfig(id.toString(), name, "newPassword", null, roleNames, false, false, false, true, false, authenticationTypeLDAP.name(), true);
UserActions userActions = new UserActions(userManagementDescriptorKey, userAccessor, roleAccessor, authorizationManager, authenticationTypeAccessor, userSystemValidator);
ValidationActionResponse validationActionResponse = userActions.validate(userConfig);
assertFalse(validationActionResponse.isError());
assertTrue(validationActionResponse.hasContent());
ValidationResponseModel validationResponseModel = validationActionResponse.getContent().get();
assertFalse(validationResponseModel.hasErrors());
assertEquals("The user is valid", validationActionResponse.getMessage().get());
}
use of com.synopsys.integration.alert.api.common.model.ValidationResponseModel in project hub-alert by blackducksoftware.
the class SettingsProxyTestActionTestIT method malformedTargetUrlTest.
@Test
void malformedTargetUrlTest() {
SettingsProxyModel settingsProxyModel = createSettingsProxyModel(testProperties);
AuthorizationManager authorizationManager = createAuthorizationManager(AuthenticationTestUtils.FULL_PERMISSIONS);
settingsProxyTestAction = new SettingsProxyTestAction(authorizationManager, settingsProxyValidator, settingsDescriptorKey, proxyTestService, settingsProxyConfigAccessor);
ActionResponse<ValidationResponseModel> testResult = settingsProxyTestAction.testWithPermissionCheck("Not a valid url", 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 SettingsProxyTestActionTestIT method testUrlWithBadResponseTest.
@Test
void testUrlWithBadResponseTest() {
SettingsProxyModel settingsProxyModel = createSettingsProxyModel(testProperties);
AuthorizationManager authorizationManager = createAuthorizationManager(AuthenticationTestUtils.FULL_PERMISSIONS);
settingsProxyTestAction = new SettingsProxyTestAction(authorizationManager, settingsProxyValidator, settingsDescriptorKey, proxyTestService, settingsProxyConfigAccessor);
ActionResponse<ValidationResponseModel> testResult = settingsProxyTestAction.testWithPermissionCheck("http://thisUrlWillReturnFailures", settingsProxyModel);
assertTrue(testResult.isSuccessful());
assertTrue(testResult.getContent().isPresent());
ValidationResponseModel validationResponseModel = testResult.getContent().get();
assertTrue(validationResponseModel.hasErrors());
}
Aggregations