Search in sources :

Example 1 with ValidationResult

use of com.mercedesbenz.sechub.sharedkernel.validation.ValidationResult in project sechub by mercedes-benz.

the class ProjectUpdateWhitelistServiceTest method before.

@Before
public void before() throws Exception {
    serviceToTest = new ProjectUpdateWhitelistService();
    repository = mock(ProjectRepository.class);
    eventBus = mock(DomainMessageService.class);
    uriValidation = mock(URIValidation.class);
    serviceToTest.repository = repository;
    serviceToTest.auditLog = mock(AuditLogService.class);
    serviceToTest.assertion = mock(UserInputAssertion.class);
    serviceToTest.eventBus = eventBus;
    serviceToTest.uriValidation = uriValidation;
    serviceToTest.logSanitizer = mock(LogSanitizer.class);
    project = mock(Project.class);
    whitelist = new LinkedHashSet<>();
    whitelist.add(new URI("127.0.0.1"));
    when(project.getWhiteList()).thenReturn(whitelist);
    when(uriValidation.validate(any())).thenReturn(new ValidationResult());
}
Also used : DomainMessageService(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageService) AuditLogService(com.mercedesbenz.sechub.sharedkernel.logging.AuditLogService) LogSanitizer(com.mercedesbenz.sechub.sharedkernel.logging.LogSanitizer) UserInputAssertion(com.mercedesbenz.sechub.sharedkernel.validation.UserInputAssertion) ValidationResult(com.mercedesbenz.sechub.sharedkernel.validation.ValidationResult) URIValidation(com.mercedesbenz.sechub.sharedkernel.validation.URIValidation) URI(java.net.URI) Before(org.junit.Before)

Example 2 with ValidationResult

use of com.mercedesbenz.sechub.sharedkernel.validation.ValidationResult in project sechub by mercedes-benz.

the class ProjectJsonInputValidation method checkApiVersion.

public void checkApiVersion(Errors errors, ProjectJsonInput input) {
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, ProjectJsonInput.PROPERTY_API_VERSION, "field.required");
    String apiVersion = input.getApiVersion();
    if (apiVersion == null) {
        return;
    /* handled before */
    }
    ValidationResult apiValidationResult = apiVersionValidation.validate(apiVersion);
    if (!apiValidationResult.isValid()) {
        errors.rejectValue(ProjectJsonInput.PROPERTY_API_VERSION, "api.error.unsupported.version", apiValidationResult.getErrorDescription());
    }
}
Also used : ValidationResult(com.mercedesbenz.sechub.sharedkernel.validation.ValidationResult)

Example 3 with ValidationResult

use of com.mercedesbenz.sechub.sharedkernel.validation.ValidationResult in project sechub by mercedes-benz.

the class SignupJsonInputValidator method validate.

@Override
public void validate(Object target, Errors errors) {
    SignupJsonInput selfRegistration = (SignupJsonInput) target;
    LOG.debug("Start validation for self registration of: {}", selfRegistration.getUserId());
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, PROPERTY_API_VERSION, "field.required");
    ValidationResult apiVersionValidationResult = apiVersionValidation.validate(selfRegistration.getApiVersion());
    if (!apiVersionValidationResult.isValid()) {
        errors.rejectValue(PROPERTY_API_VERSION, "api.error.unsupported.version", apiVersionValidationResult.getErrorDescription());
        return;
    }
    ValidationResult userIdValidationResult = useridValidation.validate(selfRegistration.getUserId());
    if (!userIdValidationResult.isValid()) {
        errors.rejectValue(PROPERTY_USER_ID, "api.error.registration.userid.invalid", userIdValidationResult.getErrorDescription());
        return;
    }
    ValidationResult emailValidationResult = emailValidation.validate(selfRegistration.getEmailAdress());
    if (!emailValidationResult.isValid()) {
        errors.rejectValue(PROPERTY_EMAIL_ADRESS, "api.error.email.invalid", "Invalid email adress");
        return;
    }
    LOG.debug("Selfregistration of {} was accepted", selfRegistration.getUserId());
}
Also used : SignupJsonInput(com.mercedesbenz.sechub.domain.administration.signup.SignupJsonInput) ValidationResult(com.mercedesbenz.sechub.sharedkernel.validation.ValidationResult)

Example 4 with ValidationResult

use of com.mercedesbenz.sechub.sharedkernel.validation.ValidationResult in project sechub by mercedes-benz.

the class ProductExecutionrProfileValidationImplTest method oneError.

private ValidationResult oneError(String message) {
    ValidationResult validationResult = new ValidationResult();
    validationResult.addError(message);
    return validationResult;
}
Also used : ValidationResult(com.mercedesbenz.sechub.sharedkernel.validation.ValidationResult)

Example 5 with ValidationResult

use of com.mercedesbenz.sechub.sharedkernel.validation.ValidationResult in project sechub by mercedes-benz.

the class ProductExecutionrProfileValidationImplTest method calls_subvalidators_with_values_and_missign_uuid_in_config_is_also_recognized_so_5_errors.

@Test
public void calls_subvalidators_with_values_and_missign_uuid_in_config_is_also_recognized_so_5_errors() {
    /* prepare */
    ProductExecutionProfile profile = new ProductExecutionProfile();
    profile.id = "pid";
    profile.description = "desc";
    ProductExecutorConfig configuration = mock(ProductExecutorConfig.class);
    profile.configurations.add(configuration);
    profile.projectIds.add("1234");
    profile.projectIds.add("54333");
    /* execute */
    ValidationResult result = validationToTest.validate(profile);
    /* test */
    verify(validationToTest.profileIdValidation, times(1)).validate("pid");
    verify(validationToTest.descriptionValidation, times(1)).validate("desc");
    verify(validationToTest.projectIdValidation).validate("1234");
    verify(validationToTest.projectIdValidation).validate("54333");
    /* fith error si because of missing uuid */
    if (result.getErrors().size() != 5) {
        fail("Expected 5 error, but got:" + result.getErrors());
    }
}
Also used : ValidationResult(com.mercedesbenz.sechub.sharedkernel.validation.ValidationResult) Test(org.junit.Test)

Aggregations

ValidationResult (com.mercedesbenz.sechub.sharedkernel.validation.ValidationResult)27 Test (org.junit.Test)16 AuditLogService (com.mercedesbenz.sechub.sharedkernel.logging.AuditLogService)4 ProductExecutorConfig (com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfig)3 Before (org.junit.Before)3 ProductExecutionProfileIdValidation (com.mercedesbenz.sechub.sharedkernel.validation.ProductExecutionProfileIdValidation)2 UserInputAssertion (com.mercedesbenz.sechub.sharedkernel.validation.UserInputAssertion)2 JSONConverterException (com.mercedesbenz.sechub.commons.model.JSONConverterException)1 SignupJsonInput (com.mercedesbenz.sechub.domain.administration.signup.SignupJsonInput)1 ScanAssertService (com.mercedesbenz.sechub.domain.scan.ScanAssertService)1 NotFoundException (com.mercedesbenz.sechub.sharedkernel.error.NotFoundException)1 LogSanitizer (com.mercedesbenz.sechub.sharedkernel.logging.LogSanitizer)1 DomainMessageService (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageService)1 ProjectIdValidation (com.mercedesbenz.sechub.sharedkernel.validation.ProjectIdValidation)1 URIValidation (com.mercedesbenz.sechub.sharedkernel.validation.URIValidation)1 JobStorage (com.mercedesbenz.sechub.storage.core.JobStorage)1 DataInputStream (java.io.DataInputStream)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1