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"));
}
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));
}
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);
}
}
}
}
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;
}
Aggregations