Search in sources :

Example 1 with SecHubInfrastructureScanConfiguration

use of com.mercedesbenz.sechub.commons.model.SecHubInfrastructureScanConfiguration in project sechub by mercedes-benz.

the class SecHubConfigurationValidatorTest method empty_infrascanconfig_is_rejected.

@Test
public void empty_infrascanconfig_is_rejected() throws Exception {
    /* prepare */
    SecHubInfrastructureScanConfiguration infraScan = mock(SecHubInfrastructureScanConfiguration.class);
    List<URI> list = new ArrayList<>();
    when(infraScan.getUris()).thenReturn(list);
    when(target.getInfraScan()).thenReturn(Optional.of(infraScan));
    /* execute */
    validatorToTest.validate(target, errors);
    /* test */
    assertError("api.error.infrascan.target.missing", Mockito.times(1));
}
Also used : ArrayList(java.util.ArrayList) SecHubInfrastructureScanConfiguration(com.mercedesbenz.sechub.commons.model.SecHubInfrastructureScanConfiguration) URI(java.net.URI) Test(org.junit.Test)

Example 2 with SecHubInfrastructureScanConfiguration

use of com.mercedesbenz.sechub.commons.model.SecHubInfrastructureScanConfiguration in project sechub by mercedes-benz.

the class SecHubConfigurationValidatorTest method infraconfig_with_uri_as_ftp_is_NOT_rejected.

@Test
public void infraconfig_with_uri_as_ftp_is_NOT_rejected() throws Exception {
    /* prepare */
    SecHubInfrastructureScanConfiguration webscan = mock(SecHubInfrastructureScanConfiguration.class);
    List<URI> list = new ArrayList<>();
    list.add(URI.create("http://www.example.com"));
    when(webscan.getUris()).thenReturn(list);
    when(target.getInfraScan()).thenReturn(Optional.of(webscan));
    /* execute */
    validatorToTest.validate(target, errors);
    /* test */
    assertNoIllegalSchemaError();
}
Also used : ArrayList(java.util.ArrayList) SecHubInfrastructureScanConfiguration(com.mercedesbenz.sechub.commons.model.SecHubInfrastructureScanConfiguration) URI(java.net.URI) Test(org.junit.Test)

Example 3 with SecHubInfrastructureScanConfiguration

use of com.mercedesbenz.sechub.commons.model.SecHubInfrastructureScanConfiguration in project sechub by mercedes-benz.

the class InfraScanNetworkLocationProvider method getURIs.

@Override
public List<URI> getURIs() {
    /* assert INFRASCAN configuration available */
    Optional<SecHubInfrastructureScanConfiguration> infraScan = config.getInfraScan();
    if (!infraScan.isPresent()) {
        throw new IllegalStateException("At this state there must be a infrascan setup!");
    }
    /* Fetch URI */
    SecHubInfrastructureScanConfiguration infraScanConfiguration = infraScan.get();
    List<URI> uris = infraScanConfiguration.getUris();
    if (uris == null) {
        throw new IllegalStateException("At this state URIs must be set - validation failed!");
    }
    return uris;
}
Also used : SecHubInfrastructureScanConfiguration(com.mercedesbenz.sechub.commons.model.SecHubInfrastructureScanConfiguration) URI(java.net.URI)

Example 4 with SecHubInfrastructureScanConfiguration

use of com.mercedesbenz.sechub.commons.model.SecHubInfrastructureScanConfiguration in project sechub by mercedes-benz.

the class ProjectWhiteListSecHubConfigurationValidationService method assertAllowedForProject.

public void assertAllowedForProject(SecHubConfigurationModel configuration) {
    List<URI> allowed = fetchAllowedUris(configuration);
    Optional<SecHubInfrastructureScanConfiguration> infrascanOpt = configuration.getInfraScan();
    if (infrascanOpt.isPresent()) {
        SecHubInfrastructureScanConfiguration infraconf = infrascanOpt.get();
        assertWhitelisted(allowed, infraconf.getUris());
        assertWhitelisted(allowed, asUris(infraconf.getIps()));
    }
    Optional<SecHubWebScanConfiguration> webscanopt = configuration.getWebScan();
    if (webscanopt.isPresent()) {
        SecHubWebScanConfiguration webconf = webscanopt.get();
        assertWhitelisted(allowed, webconf.getUri());
    }
}
Also used : SecHubWebScanConfiguration(com.mercedesbenz.sechub.commons.model.SecHubWebScanConfiguration) SecHubInfrastructureScanConfiguration(com.mercedesbenz.sechub.commons.model.SecHubInfrastructureScanConfiguration) URI(java.net.URI)

Example 5 with SecHubInfrastructureScanConfiguration

use of com.mercedesbenz.sechub.commons.model.SecHubInfrastructureScanConfiguration in project sechub by mercedes-benz.

the class SecHubConfigurationValidator method validateInfraScan.

private void validateInfraScan(SecHubConfiguration configuration, Errors errors) {
    if (errors.hasErrors()) {
        return;
    }
    Optional<SecHubInfrastructureScanConfiguration> infraScanOption = configuration.getInfraScan();
    if (!infraScanOption.isPresent()) {
        return;
    }
    SecHubInfrastructureScanConfiguration infraScan = infraScanOption.get();
    if (infraScan.getUris().isEmpty() && infraScan.getIps().isEmpty()) {
        errors.reject("api.error.infrascan.target.missing", new Object[] {}, "Webscan configuration contains no target at all - but at least one URI or IP is necessary for scans!");
    }
}
Also used : SecHubInfrastructureScanConfiguration(com.mercedesbenz.sechub.commons.model.SecHubInfrastructureScanConfiguration)

Aggregations

SecHubInfrastructureScanConfiguration (com.mercedesbenz.sechub.commons.model.SecHubInfrastructureScanConfiguration)8 URI (java.net.URI)6 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)3 SecHubWebScanConfiguration (com.mercedesbenz.sechub.commons.model.SecHubWebScanConfiguration)1 InetAddress (java.net.InetAddress)1