Search in sources :

Example 1 with Target

use of com.mercedesbenz.sechub.domain.scan.Target in project sechub by mercedes-benz.

the class NessusProductExecutorTest method before.

@Before
public void before() throws Exception {
    context = mock(SecHubExecutionContext.class);
    config = mock(SecHubConfiguration.class);
    target1 = new Target(URI_1, TargetType.INTERNET);
    target2 = new Target(URI_2, TargetType.INTERNET);
    target3 = new Target(URI_3, TargetType.INTERNET);
    targetResolver = mock(TargetResolver.class);
    when(targetResolver.resolveTarget(URI_1)).thenReturn(target1);
    when(targetResolver.resolveTarget(URI_2)).thenReturn(target2);
    when(targetResolver.resolveTarget(URI_3)).thenReturn(target3);
    nessusAdapter = mock(NessusAdapter.class);
    executorContext = mock(ProductExecutorContext.class);
    executorConfig = mock(ProductExecutorConfig.class);
    ProductResult productResult = mock(ProductResult.class);
    when(executorContext.getExecutorConfig()).thenReturn(executorConfig);
    when(executorContext.getCurrentProductResult()).thenReturn(productResult);
    installSetup = mock(NessusInstallSetup.class);
    when(installSetup.getBaseURL(any())).thenReturn("baseURL");
    when(installSetup.getUserId(any())).thenReturn("user");
    when(installSetup.getPassword(any())).thenReturn("password");
    when(installSetup.isAbleToScan(TargetType.INTRANET)).thenReturn(false);
    when(context.getConfiguration()).thenReturn(config);
    when(context.getSechubJobUUID()).thenReturn(UUID.randomUUID());
    executorToTest = new TestNessusProductExecutor();
    executorToTest.installSetup = installSetup;
    executorToTest.nessusAdapter = nessusAdapter;
}
Also used : Target(com.mercedesbenz.sechub.domain.scan.Target) ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) NessusAdapter(com.mercedesbenz.sechub.adapter.nessus.NessusAdapter) SecHubExecutionContext(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext) SecHubConfiguration(com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration) ProductExecutorContext(com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext) ProductExecutorConfig(com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfig) TargetResolver(com.mercedesbenz.sechub.domain.scan.resolve.TargetResolver) Before(org.junit.Before)

Example 2 with Target

use of com.mercedesbenz.sechub.domain.scan.Target in project sechub by mercedes-benz.

the class NessusProductExecutorTest method when_three_root_urls_are_configured_and_apter_can_handle_2_targets_of_same_type_the_adapter_is_called_1_times.

@Test
public void when_three_root_urls_are_configured_and_apter_can_handle_2_targets_of_same_type_the_adapter_is_called_1_times() throws Exception {
    /* prepare */
    when(executorConfig.getProductIdentifier()).thenReturn(ProductIdentifier.NETSPARKER);
    Target target2ButIntranet = new Target(URI_2, TargetType.INTRANET);
    when(targetResolver.resolveTarget(URI_2)).thenReturn(target2ButIntranet);
    when(installSetup.isAbleToScan(TargetType.INTERNET)).thenReturn(true);
    when(installSetup.isAbleToScan(TargetType.INTRANET)).thenReturn(false);
    prepareInfraScanWithThreeURIs();
    /* execute */
    executorToTest.execute(context, executorContext);
    /* test */
    verify(nessusAdapter, times(1)).start(any(), any());
}
Also used : Target(com.mercedesbenz.sechub.domain.scan.Target) Test(org.junit.Test)

Example 3 with Target

use of com.mercedesbenz.sechub.domain.scan.Target in project sechub by mercedes-benz.

the class NetsparkerProductExecutorTest method when_one_root_url_is_configured_and_adapter_can_handle_2_targets_the_adapter_is_called_1_time.

@Test
public void when_one_root_url_is_configured_and_adapter_can_handle_2_targets_the_adapter_is_called_1_time() throws Exception {
    /* prepare */
    when(installSetup.isAbleToScan(TargetType.INTERNET)).thenReturn(true);
    when(installSetup.isAbleToScan(TargetType.INTRANET)).thenReturn(false);
    // we "reuse" the URI_2 so its used in prepare method but as INTRANET target!
    URI uriIntranet = URI_2_INTERNET;
    // fake this as INTERNET target...
    Target intranetTarget = new Target(uriIntranet, TargetType.INTRANET);
    when(targetResolver.resolveTarget(uriIntranet)).thenReturn(intranetTarget);
    prepareWebScanWithOneInternetURI();
    /* execute */
    executorToTest.execute(context, executorContext);
    /* test */
    verify(netsparkerAdapter, times(1)).start(any(), any());
}
Also used : Target(com.mercedesbenz.sechub.domain.scan.Target) URI(java.net.URI) Test(org.junit.Test)

Example 4 with Target

use of com.mercedesbenz.sechub.domain.scan.Target in project sechub by mercedes-benz.

the class AbstractInstallSetupProductExecutorTest method before.

@Before
public void before() throws Exception {
    urisForTarget = new ArrayList<>();
    inetAdressesForTarget = new ArrayList<>();
    context = mock(SecHubExecutionContext.class);
    executorContext = mock(ProductExecutorContext.class);
    target1 = new Target(URI_1, TargetType.INTERNET);
    target2 = new Target(URI_2, TargetType.INTRANET);
    target3 = new Target(URI_3, TargetType.INTERNET);
    target4 = new Target(IP_ADRESS1, TargetType.INTRANET);
    targetResolver = mock(TargetResolver.class);
    when(targetResolver.resolveTarget(URI_1)).thenReturn(target1);
    when(targetResolver.resolveTarget(URI_2)).thenReturn(target2);
    when(targetResolver.resolveTarget(URI_3)).thenReturn(target3);
    when(targetResolver.resolveTarget(IP_ADRESS1)).thenReturn(target4);
    when(context.getSechubJobUUID()).thenReturn(UUID.randomUUID());
    installSetup = mock(InstallSetup.class);
    executorToTest = new TestInstallSetupProductExecutor();
    executorToTest.targetResolver = targetResolver;
}
Also used : Target(com.mercedesbenz.sechub.domain.scan.Target) SecHubExecutionContext(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext) TargetResolver(com.mercedesbenz.sechub.domain.scan.resolve.TargetResolver) InstallSetup(com.mercedesbenz.sechub.domain.scan.InstallSetup) Before(org.junit.Before)

Example 5 with Target

use of com.mercedesbenz.sechub.domain.scan.Target in project sechub by mercedes-benz.

the class AbstractCodeScanProductExecutor method tryToRegister.

private void tryToRegister(UUIDTraceLogID traceLogId, S setup, TargetRegistry registry, String folderPath) {
    Target target = targetResolver.resolveTargetForPath(folderPath);
    if (!setup.isAbleToScan(target.getType())) {
        LOG.error("{}: setup not able to scan target {}", getIdentifier(), target);
        return;
    }
    LOG.debug("{} register scan target:{}", traceLogId, target);
    registry.register(target);
}
Also used : Target(com.mercedesbenz.sechub.domain.scan.Target)

Aggregations

Target (com.mercedesbenz.sechub.domain.scan.Target)10 Test (org.junit.Test)4 TargetResolver (com.mercedesbenz.sechub.domain.scan.resolve.TargetResolver)3 SecHubExecutionContext (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext)3 Before (org.junit.Before)3 ProductExecutorContext (com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext)2 ProductResult (com.mercedesbenz.sechub.domain.scan.product.ProductResult)2 SecHubConfiguration (com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration)2 URI (java.net.URI)2 NessusAdapter (com.mercedesbenz.sechub.adapter.nessus.NessusAdapter)1 NetsparkerAdapter (com.mercedesbenz.sechub.adapter.netsparker.NetsparkerAdapter)1 InstallSetup (com.mercedesbenz.sechub.domain.scan.InstallSetup)1 ProductExecutorConfig (com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfig)1 WithoutProductExecutorConfigInfo (com.mercedesbenz.sechub.domain.scan.product.config.WithoutProductExecutorConfigInfo)1 InetAddress (java.net.InetAddress)1 UUID (java.util.UUID)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1