Search in sources :

Example 1 with SecHubExecutionContext

use of com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext 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 SecHubExecutionContext

use of com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext 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 SecHubExecutionContext

use of com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext 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 SecHubExecutionContext

use of com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext 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)

Example 5 with SecHubExecutionContext

use of com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext in project sechub by mercedes-benz.

the class WebConfigBuilderStrategyTest method includes_no_slash_infront_multiple.

@Test
public void includes_no_slash_infront_multiple() {
    /* prepare */
    List<String> includes = new LinkedList<>();
    includes.add("/abc");
    includes.add("contact.html");
    includes.add("/hidden");
    includes.add("ccb/bca");
    String json = createIncludesJson(includes);
    SecHubConfiguration configuration = SECHUB_CONFIG.fromJSON(json);
    SecHubExecutionContext context = new SecHubExecutionContext(UUID.randomUUID(), configuration, "test");
    WebConfigBuilderStrategy strategyToTest = new WebConfigBuilderStrategy(context);
    TestAbstractWebScanAdapterConfigBuilder configBuilder = new TestAbstractWebScanAdapterConfigBuilder();
    /* execute */
    IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> {
        strategyToTest.configure(configBuilder);
    });
    /* test */
    assertEquals("The URL does not start with a slash '/'. URL: contact.html", exception.getMessage());
}
Also used : SecHubConfiguration(com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration) SecHubExecutionContext(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext) LinkedList(java.util.LinkedList) Test(org.junit.jupiter.api.Test)

Aggregations

SecHubExecutionContext (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext)24 SecHubConfiguration (com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration)14 Test (org.junit.jupiter.api.Test)10 LinkedList (java.util.LinkedList)8 ProductExecutorContext (com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext)6 ProductResult (com.mercedesbenz.sechub.domain.scan.product.ProductResult)6 InputStream (java.io.InputStream)3 Test (org.junit.Test)3 AdapterException (com.mercedesbenz.sechub.adapter.AdapterException)2 AdapterLogId (com.mercedesbenz.sechub.adapter.AdapterLogId)2 NetworkTargetProductServerDataAdapterConfigurationStrategy (com.mercedesbenz.sechub.domain.scan.NetworkTargetProductServerDataAdapterConfigurationStrategy)2 NetworkTargetInfo (com.mercedesbenz.sechub.domain.scan.NetworkTargetRegistry.NetworkTargetInfo)2 NetworkTargetType (com.mercedesbenz.sechub.domain.scan.NetworkTargetType)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 ScanMockData (com.mercedesbenz.sechub.domain.scan.project.ScanMockData)2 ScanProjectMockDataConfiguration (com.mercedesbenz.sechub.domain.scan.project.ScanProjectMockDataConfiguration)2 UUIDTraceLogID (com.mercedesbenz.sechub.sharedkernel.UUIDTraceLogID)2 SecHubExecutionException (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException)2