Search in sources :

Example 11 with ProductResult

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

the class DownloadSpdxScanReportServiceTest method service_returns_spdx_json_resolver_result_for_sereco_productresult.

@Test
void service_returns_spdx_json_resolver_result_for_sereco_productresult() {
    /* prepare */
    UUID sechubJobUUID = UUID.randomUUID();
    ProductResult result = mock(ProductResult.class);
    List<ProductResult> results = new ArrayList<>();
    results.add(result);
    String expectedJson = "my result";
    when(productResultRepository.findAllProductResults(eq(sechubJobUUID), eq(ProductIdentifier.SERECO))).thenReturn(results);
    when(spdxJsonResolver.resolveSpdxJson(eq(result))).thenReturn(expectedJson);
    /* execute */
    String spdxJson = serviceToTest.getScanSpdxJsonReport("project_1", sechubJobUUID);
    /* test */
    assertEquals(expectedJson, spdxJson);
}
Also used : ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) ArrayList(java.util.ArrayList) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 12 with ProductResult

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

the class SecHubReportProductTransformerServiceTest method when_product_result_repository_returns_only_sereco_report_result__sechubResultFromTransformer_is_returned.

@Test
public void when_product_result_repository_returns_only_sereco_report_result__sechubResultFromTransformer_is_returned() throws Exception {
    /* prepare */
    ReportTransformationResult transformationResult = new ReportTransformationResult();
    ProductResult scanResult = new ProductResult(secHubJobUUID, "project1", new WithoutProductExecutorConfigInfo(ProductIdentifier.SERECO), "scan-result");
    when(reportTransformer.canTransform(ProductIdentifier.SERECO)).thenReturn(true);
    when(reportTransformer.transform(scanResult)).thenReturn(transformationResult);
    when(productResultRepository.findAllProductResults(eq(secHubJobUUID), any())).thenReturn(Arrays.asList(scanResult));
    when(resultMerger.merge(null, transformationResult)).thenReturn(transformationResult);
    /* execute */
    ReportTransformationResult result = serviceToTest.createResult(context);
    /* test */
    assertEquals(transformationResult, result);
}
Also used : ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) WithoutProductExecutorConfigInfo(com.mercedesbenz.sechub.domain.scan.product.config.WithoutProductExecutorConfigInfo) Test(org.junit.Test)

Example 13 with ProductResult

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

the class SecHubReportProductTransformerServiceTest method when_product_result_repository_returns_only_netsparker_result__sechub_execution_is_thrown_with_message.

@Test
public void when_product_result_repository_returns_only_netsparker_result__sechub_execution_is_thrown_with_message() throws Exception {
    /* prepare */
    ProductResult scanResult = new ProductResult(secHubJobUUID, "project1", new WithoutProductExecutorConfigInfo(ProductIdentifier.NETSPARKER), "scan-result");
    when(productResultRepository.findAllProductResults(eq(secHubJobUUID), any())).thenReturn(Arrays.asList(scanResult));
    /* test */
    expected.expect(SecHubExecutionException.class);
    /* execute */
    serviceToTest.createResult(context);
}
Also used : ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) WithoutProductExecutorConfigInfo(com.mercedesbenz.sechub.domain.scan.product.config.WithoutProductExecutorConfigInfo) Test(org.junit.Test)

Example 14 with ProductResult

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

the class NessusProductExecutor method executeByAdapter.

@Override
protected List<ProductResult> executeByAdapter(ProductExecutorData data) throws Exception {
    NetworkTargetInfo info = data.getCurrentNetworkTargetInfo();
    if (info.getURIs().isEmpty() && info.getIPs().isEmpty()) {
        LOG.debug("{} Nessus scan not possible, because no uri or ip defined", data.getTraceLogId());
        return Collections.emptyList();
    }
    NetworkTargetType targetType = info.getTargetType();
    LOG.debug("Trigger Nessus adapter execution for target type {}", targetType);
    /* @formatter:off */
    NessusAdapterConfig nessusConfig = NessusConfig.builder().configure(new SecHubAdapterOptionsBuilderStrategy(data, getScanType())).configure(new NetworkTargetProductServerDataAdapterConfigurationStrategy(installSetup, targetType)).setTimeToWaitForNextCheckOperationInMinutes(scanResultCheckPeriodInMinutes).setTimeOutInMinutes(scanResultCheckTimeOutInMinutes).setProxyHostname(proxyHostname).setProxyPort(proxyPort).setTraceID(data.getTraceLogIdAsString()).setPolicyID(installSetup.getDefaultPolicyId()).setTargetIPs(info.getIPs()).setTargetURIs(info.getURIs()).build();
    /* @formatter:on */
    /* execute NESSUS by adapter and return product result */
    ProductExecutorContext productExecutorContext = data.getProductExecutorContext();
    String xml = nessusAdapter.start(nessusConfig, productExecutorContext.getCallback());
    // product result is set by callback
    ProductResult productResult = productExecutorContext.getCurrentProductResult();
    productResult.setResult(xml);
    return Collections.singletonList(productResult);
}
Also used : NessusAdapterConfig(com.mercedesbenz.sechub.adapter.nessus.NessusAdapterConfig) NetworkTargetType(com.mercedesbenz.sechub.domain.scan.NetworkTargetType) SecHubAdapterOptionsBuilderStrategy(com.mercedesbenz.sechub.domain.scan.SecHubAdapterOptionsBuilderStrategy) ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) NetworkTargetProductServerDataAdapterConfigurationStrategy(com.mercedesbenz.sechub.domain.scan.NetworkTargetProductServerDataAdapterConfigurationStrategy) ProductExecutorContext(com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext) NetworkTargetInfo(com.mercedesbenz.sechub.domain.scan.NetworkTargetRegistry.NetworkTargetInfo)

Example 15 with ProductResult

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

the class NetsparkerProductExecutor method executeByAdapter.

@Override
protected List<ProductResult> executeByAdapter(ProductExecutorData data) throws Exception {
    NetworkTargetInfo info = data.getCurrentNetworkTargetInfo();
    URI targetURI = info.getURI();
    if (targetURI == null) {
        /* no targets defined */
        return Collections.emptyList();
    }
    NetworkTargetType targetType = info.getTargetType();
    LOG.debug("Trigger netsparker adapter execution for target {}", targetType);
    List<ProductResult> results = new ArrayList<>();
    /* NETSPARKER is not able to scan multiple targets */
    /*
         * special behavior, because having multiple results here, we must find former
         * result corresponding to target URI.
         */
    /* @formatter:off */
    ProductExecutorContext productExecutorContext = data.getProductExecutorContext();
    productExecutorContext.useFirstFormerResultHavingMetaData(NetsparkerMetaDataID.KEY_TARGET_URI, targetURI);
    NetsparkerAdapterConfig netsparkerConfig = NetsparkerConfig.builder().configure(new SecHubAdapterOptionsBuilderStrategy(data, getScanType())).configure(new WebConfigBuilderStrategy(data.getSechubExecutionContext())).configure(new NetworkTargetProductServerDataAdapterConfigurationStrategy(installSetup, targetType)).setTimeToWaitForNextCheckOperationInMinutes(installSetup.getScanResultCheckPeriodInMinutes()).setTimeOutInMinutes(installSetup.getScanResultCheckTimeOutInMinutes()).setTraceID(data.getTraceLogIdAsString()).setAgentName(installSetup.getAgentName()).setAgentGroupName(data.getNetworkTargetProductServerDataSupport().getIdentifier(targetType)).setPolicyID(installSetup.getDefaultPolicyId()).setLicenseID(installSetup.getNetsparkerLicenseId()).setTargetType(info.getTargetType().name()).setTargetURI(targetURI).build();
    /* @formatter:on */
    /* execute NETSPARKER by adapter and return product result */
    String xml = netsparkerAdapter.start(netsparkerConfig, productExecutorContext.getCallback());
    ProductResult currentProductResult = productExecutorContext.getCurrentProductResult();
    currentProductResult.setResult(xml);
    results.add(currentProductResult);
    return results;
}
Also used : NetworkTargetType(com.mercedesbenz.sechub.domain.scan.NetworkTargetType) SecHubAdapterOptionsBuilderStrategy(com.mercedesbenz.sechub.domain.scan.SecHubAdapterOptionsBuilderStrategy) ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) NetworkTargetProductServerDataAdapterConfigurationStrategy(com.mercedesbenz.sechub.domain.scan.NetworkTargetProductServerDataAdapterConfigurationStrategy) ArrayList(java.util.ArrayList) ProductExecutorContext(com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext) WebConfigBuilderStrategy(com.mercedesbenz.sechub.domain.scan.WebConfigBuilderStrategy) URI(java.net.URI) NetworkTargetInfo(com.mercedesbenz.sechub.domain.scan.NetworkTargetRegistry.NetworkTargetInfo) NetsparkerAdapterConfig(com.mercedesbenz.sechub.adapter.netsparker.NetsparkerAdapterConfig)

Aggregations

ProductResult (com.mercedesbenz.sechub.domain.scan.product.ProductResult)30 ProductExecutorContext (com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext)10 ArrayList (java.util.ArrayList)10 SecHubExecutionContext (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext)8 UUID (java.util.UUID)8 InputStream (java.io.InputStream)6 URI (java.net.URI)6 WithoutProductExecutorConfigInfo (com.mercedesbenz.sechub.domain.scan.product.config.WithoutProductExecutorConfigInfo)5 MetaDataInspection (com.mercedesbenz.sechub.sharedkernel.metadata.MetaDataInspection)5 NetworkTargetProductServerDataAdapterConfigurationStrategy (com.mercedesbenz.sechub.domain.scan.NetworkTargetProductServerDataAdapterConfigurationStrategy)4 NetworkTargetInfo (com.mercedesbenz.sechub.domain.scan.NetworkTargetRegistry.NetworkTargetInfo)4 NetworkTargetType (com.mercedesbenz.sechub.domain.scan.NetworkTargetType)4 TargetType (com.mercedesbenz.sechub.domain.scan.TargetType)4 WebConfigBuilderStrategy (com.mercedesbenz.sechub.domain.scan.WebConfigBuilderStrategy)4 Test (org.junit.Test)4 AdapterMetaData (com.mercedesbenz.sechub.adapter.AdapterMetaData)3 SecHubAdapterOptionsBuilderStrategy (com.mercedesbenz.sechub.domain.scan.SecHubAdapterOptionsBuilderStrategy)3 ProductExecutorConfig (com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfig)3 JobStorage (com.mercedesbenz.sechub.storage.core.JobStorage)3 Test (org.junit.jupiter.api.Test)3