Search in sources :

Example 1 with ProductExecutorContext

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

the class CheckmarxProductExecutorMockTest method when_adapter_throws_first_time_adapter_exception_with_exceed_a_retry_is_done.

@Test
public void when_adapter_throws_first_time_adapter_exception_with_exceed_a_retry_is_done() throws Exception {
    /* prepare */
    SecHubExecutionContext context = createExecutionContextForPseudoCodeScan();
    ProductExecutorCallback callback = mock(ProductExecutorCallback.class);
    ProductExecutorConfigSetup setup = createCheckmarxSetupWithAllMandotoryPartsSet();
    ProductExecutorConfig executorConfig = new ProductExecutorConfig(ProductIdentifier.CHECKMARX, 1, setup);
    ProductExecutorContext executorContext = mock(ProductExecutorContext.class);
    when(executorContext.getCallback()).thenReturn(callback);
    when(executorContext.getExecutorConfig()).thenReturn(executorConfig);
    ProductResult currentResult = new ProductResult(JOB_UUID, PROJECT_EXAMPLE, executorConfig, "pseudo-result");
    when(executorContext.getCurrentProductResult()).thenReturn(currentResult);
    /* @formatter:off */
    when(checkmarxAdapter.start(any(), any())).thenThrow(// first fails
    new AdapterException(new AdapterLogId("1", "traceId"), "bla bla - Changes exceeded the threshold limit - bla bla")).thenReturn(// second: access
    "result2");
    /* @formatter:on */
    /* execute */
    executorToTest.execute(context, executorContext);
    /* test */
    // the adapter must be called twice
    verify(checkmarxAdapter, times(2)).start(any(), any());
}
Also used : ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) SecHubExecutionContext(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext) ProductExecutorConfig(com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfig) ProductExecutorContext(com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext) AdapterException(com.mercedesbenz.sechub.adapter.AdapterException) ProductExecutorCallback(com.mercedesbenz.sechub.domain.scan.product.ProductExecutorCallback) AdapterLogId(com.mercedesbenz.sechub.adapter.AdapterLogId) ProductExecutorConfigSetup(com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigSetup) Test(org.junit.Test)

Example 2 with ProductExecutorContext

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

the class CheckmarxProductExecutorMockTest method when_adapter_throws_two_time_adapter_exception_with_exceed_a_retry_is_done_only_one_time.

@Test
public void when_adapter_throws_two_time_adapter_exception_with_exceed_a_retry_is_done_only_one_time() throws Exception {
    /* prepare */
    SecHubExecutionContext context = createExecutionContextForPseudoCodeScan();
    ProductExecutorCallback callback = mock(ProductExecutorCallback.class);
    ProductExecutorConfigSetup setup = createCheckmarxSetupWithAllMandotoryPartsSet();
    ProductExecutorConfig executorConfig = new ProductExecutorConfig(ProductIdentifier.CHECKMARX, 1, setup);
    ProductExecutorContext executorContext = mock(ProductExecutorContext.class);
    when(executorContext.getCallback()).thenReturn(callback);
    when(executorContext.getExecutorConfig()).thenReturn(executorConfig);
    ProductResult currentResult = new ProductResult(JOB_UUID, PROJECT_EXAMPLE, executorConfig, "pseudo-result");
    when(executorContext.getCurrentProductResult()).thenReturn(currentResult);
    /* @formatter:off */
    when(checkmarxAdapter.start(any(), any())).thenThrow(// first fails
    new AdapterException(new AdapterLogId("1", "traceId"), "bla bla - Changes exceeded the threshold limit - bla bla")).thenThrow(// second fails
    new AdapterException(new AdapterLogId("2", "traceId"), "bla bla - Changes exceeded the threshold limit - bla bla")).thenReturn(// third: would be access but should not happen! resilience shall here only work one time!
    "result2");
    /* @formatter:on */
    SecHubExecutionException expected = null;
    /* execute */
    try {
        executorToTest.execute(context, executorContext);
    } catch (SecHubExecutionException e) {
        expected = e;
    }
    /* test */
    assertNotNull("No SecHubExecutionException happened, but must!", expected);
    // the adapter must be called twice - first errr, than one retry, third error
    verify(checkmarxAdapter, times(2)).start(any(), any());
    // means no retry again
    Throwable cause = expected.getCause();
    String message = cause.getMessage();
    assertTrue(message.contains("Changes exceeded the threshold limit"));
}
Also used : SecHubExecutionException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException) ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) SecHubExecutionContext(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext) ProductExecutorConfig(com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfig) ProductExecutorContext(com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext) AdapterException(com.mercedesbenz.sechub.adapter.AdapterException) ProductExecutorCallback(com.mercedesbenz.sechub.domain.scan.product.ProductExecutorCallback) AdapterLogId(com.mercedesbenz.sechub.adapter.AdapterLogId) ProductExecutorConfigSetup(com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigSetup) Test(org.junit.Test)

Example 3 with ProductExecutorContext

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

the class PDSCodeScanProductExecutor method executeByAdapter.

@Override
protected List<ProductResult> executeByAdapter(ProductExecutorData data) throws Exception {
    LOG.debug("Trigger PDS adapter execution");
    ProductExecutorContext executorContext = data.getProductExecutorContext();
    PDSExecutorConfigSuppport configSupport = PDSExecutorConfigSuppport.createSupportAndAssertConfigValid(executorContext.getExecutorConfig(), systemEnvironment);
    SecHubExecutionContext context = data.getSechubExecutionContext();
    PDSStorageContentProvider contentProvider = contentProviderFactory.createContentProvider(context, configSupport, getScanType());
    ProductResult result = resilientActionExecutor.executeResilient(() -> {
        try (InputStream sourceCodeZipFileInputStreamOrNull = contentProvider.getSourceZipFileInputStreamOrNull();
            InputStream binariesTarFileInputStreamOrNull = contentProvider.getBinariesTarFileInputStreamOrNull()) {
            /* @formatter:off */
            PDSCodeScanConfig pdsCodeScanConfig = PDSCodeScanConfigImpl.builder().configure(PDSAdapterConfigurationStrategy.builder().setScanType(getScanType()).setProductExecutorData(data).setConfigSupport(configSupport).setSourceCodeZipFileInputStreamOrNull(sourceCodeZipFileInputStreamOrNull).setBinariesTarFileInputStreamOrNull(binariesTarFileInputStreamOrNull).setContentProvider(contentProvider).setInstallSetup(installSetup).build()).build();
            /* @formatter:on */
            /* inspect */
            MetaDataInspection inspection = scanMetaDataCollector.inspect(ProductIdentifier.PDS_CODESCAN.name());
            inspection.notice(MetaDataInspection.TRACE_ID, pdsCodeScanConfig.getTraceID());
            /* execute PDS by adapter and update product result */
            String pdsResult = pdsAdapter.start(pdsCodeScanConfig, executorContext.getCallback());
            // product result is set by callback
            ProductResult productResult = executorContext.getCurrentProductResult();
            productResult.setResult(pdsResult);
            return productResult;
        }
    });
    return Collections.singletonList(result);
}
Also used : MetaDataInspection(com.mercedesbenz.sechub.sharedkernel.metadata.MetaDataInspection) ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) SecHubExecutionContext(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext) InputStream(java.io.InputStream) PDSCodeScanConfig(com.mercedesbenz.sechub.adapter.pds.PDSCodeScanConfig) ProductExecutorContext(com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext)

Example 4 with ProductExecutorContext

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

the class PDSInfraScanProductExecutor method customize.

@Override
protected void customize(ProductExecutorData data) {
    SecHubConfiguration secHubConfiguration = data.getSechubExecutionContext().getConfiguration();
    data.setNetworkLocationProvider(new InfraScanNetworkLocationProvider(secHubConfiguration));
    ProductExecutorContext executorContext = data.getProductExecutorContext();
    PDSExecutorConfigSuppport configSupport = PDSExecutorConfigSuppport.createSupportAndAssertConfigValid(executorContext.getExecutorConfig(), systemEnvironment);
    data.setNetworkTargetDataProvider(configSupport);
}
Also used : SecHubConfiguration(com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration) ProductExecutorContext(com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext) InfraScanNetworkLocationProvider(com.mercedesbenz.sechub.domain.scan.InfraScanNetworkLocationProvider)

Example 5 with ProductExecutorContext

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

the class PDSLicenseScanProductExecutor method executeByAdapter.

@Override
protected List<ProductResult> executeByAdapter(ProductExecutorData data) throws Exception {
    LOG.debug("Trigger PDS adapter execution");
    ProductExecutorContext executorContext = data.getProductExecutorContext();
    PDSExecutorConfigSuppport configSupport = PDSExecutorConfigSuppport.createSupportAndAssertConfigValid(executorContext.getExecutorConfig(), systemEnvironment);
    SecHubExecutionContext context = data.getSechubExecutionContext();
    PDSStorageContentProvider contentProvider = contentProviderFactory.createContentProvider(context, configSupport, getScanType());
    ProductResult result = resilientActionExecutor.executeResilient(() -> {
        try (InputStream sourceCodeZipFileInputStreamOrNull = contentProvider.getSourceZipFileInputStreamOrNull();
            InputStream binariesTarFileInputStreamOrNull = contentProvider.getBinariesTarFileInputStreamOrNull()) {
            /* @formatter:off */
            PDSLicenseScanConfig pdsLicenseScanConfig = PDSLicenseScanConfigImpl.builder().configure(PDSAdapterConfigurationStrategy.builder().setScanType(getScanType()).setProductExecutorData(data).setConfigSupport(configSupport).setSourceCodeZipFileInputStreamOrNull(sourceCodeZipFileInputStreamOrNull).setBinariesTarFileInputStreamOrNull(binariesTarFileInputStreamOrNull).setContentProvider(contentProvider).setInstallSetup(installSetup).build()).build();
            /* @formatter:on */
            /* inspect */
            MetaDataInspection inspection = scanMetaDataCollector.inspect(ProductIdentifier.PDS_LICENSESCAN.name());
            inspection.notice(MetaDataInspection.TRACE_ID, pdsLicenseScanConfig.getTraceID());
            /* execute PDS by adapter and update product result */
            String pdsResult = pdsAdapter.start(pdsLicenseScanConfig, executorContext.getCallback());
            // product result is set by callback
            ProductResult productResult = executorContext.getCurrentProductResult();
            productResult.setResult(pdsResult);
            return productResult;
        }
    });
    return Collections.singletonList(result);
}
Also used : MetaDataInspection(com.mercedesbenz.sechub.sharedkernel.metadata.MetaDataInspection) ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) SecHubExecutionContext(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext) InputStream(java.io.InputStream) ProductExecutorContext(com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext) PDSLicenseScanConfig(com.mercedesbenz.sechub.adapter.pds.PDSLicenseScanConfig)

Aggregations

ProductExecutorContext (com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext)10 ProductResult (com.mercedesbenz.sechub.domain.scan.product.ProductResult)8 SecHubExecutionContext (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext)6 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 InputStream (java.io.InputStream)3 URI (java.net.URI)3 ArrayList (java.util.ArrayList)3 AdapterException (com.mercedesbenz.sechub.adapter.AdapterException)2 AdapterLogId (com.mercedesbenz.sechub.adapter.AdapterLogId)2 SecHubAdapterOptionsBuilderStrategy (com.mercedesbenz.sechub.domain.scan.SecHubAdapterOptionsBuilderStrategy)2 WebConfigBuilderStrategy (com.mercedesbenz.sechub.domain.scan.WebConfigBuilderStrategy)2 ProductExecutorCallback (com.mercedesbenz.sechub.domain.scan.product.ProductExecutorCallback)2 ProductExecutorConfig (com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfig)2 ProductExecutorConfigSetup (com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigSetup)2 SecHubConfiguration (com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration)2 MetaDataInspection (com.mercedesbenz.sechub.sharedkernel.metadata.MetaDataInspection)2 Test (org.junit.Test)2 NessusAdapterConfig (com.mercedesbenz.sechub.adapter.nessus.NessusAdapterConfig)1