Search in sources :

Example 21 with SecHubExecutionContext

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

the class WebConfigBuilderStrategyTest method exclude_too_long.

@Test
public void exclude_too_long() {
    /* prepare */
    // create long string
    StringBuilder sb = new StringBuilder();
    sb.append("/");
    for (int i = 0; i < 64; i++) {
        sb.append("abcdefghijklmnopqrstuvwxyz012345");
    }
    List<String> excludes = new LinkedList<>();
    excludes.add(sb.toString());
    String json = createExcludesJson(excludes);
    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 */
    assertThat(exception.getMessage(), startsWith("Maximum URL length is 2048 characters. The first 2048 characters of the URL in question: /abcdefghijklmnopqrst"));
}
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)

Example 22 with SecHubExecutionContext

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

the class LicenseScanProductExecutionServiceImplTest method isExecutionNecessary_unnecessary.

@Test
void isExecutionNecessary_unnecessary() {
    /* prepare */
    UUIDTraceLogID traceId = UUIDTraceLogID.traceLogID(UUID.randomUUID());
    SecHubExecutionContext context = mock(SecHubExecutionContext.class);
    SecHubConfiguration configuration = new SecHubConfiguration();
    /* execute + test */
    assertFalse(licenseScanServiceToTest.isExecutionNecessary(context, traceId, configuration));
}
Also used : UUIDTraceLogID(com.mercedesbenz.sechub.sharedkernel.UUIDTraceLogID) SecHubExecutionContext(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext) SecHubConfiguration(com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration) Test(org.junit.jupiter.api.Test)

Example 23 with SecHubExecutionContext

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

the class ScanService method startScan.

@IsSendingSyncMessageAnswer(value = MessageID.SCAN_DONE, answeringTo = MessageID.START_SCAN, branchName = "success")
@IsSendingSyncMessageAnswer(value = MessageID.SCAN_FAILED, answeringTo = MessageID.START_SCAN, branchName = "failure")
@IsSendingSyncMessageAnswer(value = MessageID.SCAN_ABANDONDED, answeringTo = MessageID.START_SCAN, branchName = "failure")
DomainMessageSynchronousResult startScan(DomainMessage request) {
    SecHubExecutionContext context = null;
    try {
        context = createExecutionContext(request);
        executeScan(context, request);
        ScanReport report = reportService.createReport(context);
        DomainMessageSynchronousResult response = new DomainMessageSynchronousResult(MessageID.SCAN_DONE);
        response.set(REPORT_TRAFFIC_LIGHT, report.getTrafficLightAsString());
        return response;
    } catch (ScanReportException e) {
        LOG.error("Execution was possible, but report failed." + traceLogID(request), e);
        return new DomainMessageSynchronousResult(MessageID.SCAN_FAILED, e);
    } catch (SecHubExecutionAbandonedException e) {
        LOG.info("Execution abandoned on scan {} - message: {}", traceLogID(request), e.getMessage());
        return new DomainMessageSynchronousResult(MessageID.SCAN_ABANDONDED, e);
    } catch (SecHubExecutionException e) {
        LOG.error("Execution problems on scan." + traceLogID(request), e);
        return new DomainMessageSynchronousResult(MessageID.SCAN_FAILED, e);
    } catch (Exception e) {
        LOG.error("Was not able to start scan." + traceLogID(request), e);
        return new DomainMessageSynchronousResult(MessageID.SCAN_FAILED, e);
    } finally {
        if (context == null) {
            LOG.warn("No sechub execution context available, so cannot check state or cleanup storage");
        } else {
            if (!context.isAbandonded()) {
                cleanupStorage(context);
            }
        }
    }
}
Also used : SecHubExecutionException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException) DomainMessageSynchronousResult(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageSynchronousResult) SecHubExecutionAbandonedException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionAbandonedException) SecHubExecutionContext(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext) ScanReport(com.mercedesbenz.sechub.domain.scan.report.ScanReport) ScanReportException(com.mercedesbenz.sechub.domain.scan.report.ScanReportException) JSONConverterException(com.mercedesbenz.sechub.commons.model.JSONConverterException) ScanReportException(com.mercedesbenz.sechub.domain.scan.report.ScanReportException) SecHubExecutionAbandonedException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionAbandonedException) IOException(java.io.IOException) SecHubExecutionException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException) IsSendingSyncMessageAnswer(com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingSyncMessageAnswer)

Example 24 with SecHubExecutionContext

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

the class PDSWebScanProductExecutor method executeByAdapter.

@Override
protected List<ProductResult> executeByAdapter(ProductExecutorData data) throws Exception {
    ProductExecutorContext executorContext = data.getProductExecutorContext();
    SecHubExecutionContext context = data.getSechubExecutionContext();
    NetworkTargetInfo info = data.getCurrentNetworkTargetInfo();
    /* we reuse config support created inside customize method */
    PDSExecutorConfigSuppport configSupport = (PDSExecutorConfigSuppport) data.getNetworkTargetDataProvider();
    URI targetURI = info.getURI();
    if (targetURI == null) {
        LOG.warn("NO target URI defined for PDS web scan execution");
        return Collections.emptyList();
    }
    NetworkTargetType targetType = info.getTargetType();
    if (configSupport.isTargetTypeForbidden(targetType)) {
        LOG.info("PDS adapter does not accept target type:{} so cancel execution");
        return Collections.emptyList();
    }
    LOG.debug("Trigger PDS adapter execution for target {} ", targetType);
    List<ProductResult> results = new ArrayList<>();
    /* @formatter:off */
    executorContext.useFirstFormerResultHavingMetaData(PDSMetaDataID.KEY_TARGET_URI, targetURI);
    PDSStorageContentProvider contentProvider = contentProviderFactory.createContentProvider(context, configSupport, getScanType());
    ProductResult result = resilientActionExecutor.executeResilient(() -> {
        try (InputStream sourceCodeZipFileInputStreamOrNull = contentProvider.getSourceZipFileInputStreamOrNull()) {
            PDSWebScanConfig pdsWebScanConfig = PDSWebScanConfigImpl.builder().configure(PDSAdapterConfigurationStrategy.builder().setScanType(getScanType()).setProductExecutorData(data).setConfigSupport(configSupport).setSourceCodeZipFileInputStreamOrNull(sourceCodeZipFileInputStreamOrNull).setContentProvider(contentProvider).setInstallSetup(installSetup).build()).configure(new WebConfigBuilderStrategy(context)).configure(new NetworkTargetProductServerDataAdapterConfigurationStrategy(configSupport, data.getCurrentNetworkTargetInfo().getTargetType())).setTargetURI(targetURI).setTargetType(info.getTargetType().name()).build();
            /* @formatter:on */
            /* execute PDS by adapter and return product result */
            String pdsResult = pdsAdapter.start(pdsWebScanConfig, executorContext.getCallback());
            ProductResult currentProductResult = executorContext.getCurrentProductResult();
            currentProductResult.setResult(pdsResult);
            return currentProductResult;
        }
    });
    results.add(result);
    return results;
}
Also used : ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) NetworkTargetProductServerDataAdapterConfigurationStrategy(com.mercedesbenz.sechub.domain.scan.NetworkTargetProductServerDataAdapterConfigurationStrategy) InputStream(java.io.InputStream) ProductExecutorContext(com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext) ArrayList(java.util.ArrayList) URI(java.net.URI) NetworkTargetInfo(com.mercedesbenz.sechub.domain.scan.NetworkTargetRegistry.NetworkTargetInfo) PDSWebScanConfig(com.mercedesbenz.sechub.adapter.pds.PDSWebScanConfig) NetworkTargetType(com.mercedesbenz.sechub.domain.scan.NetworkTargetType) SecHubExecutionContext(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext) WebConfigBuilderStrategy(com.mercedesbenz.sechub.domain.scan.WebConfigBuilderStrategy)

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