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