use of com.mercedesbenz.sechub.adapter.AdapterLogId 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());
}
use of com.mercedesbenz.sechub.adapter.AdapterLogId 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"));
}
use of com.mercedesbenz.sechub.adapter.AdapterLogId in project sechub by mercedes-benz.
the class NessusAdapterV1 method startExport.
private void startExport(NessusContext context) throws AdapterException {
NessusAdapterConfig config = context.getConfig();
AdapterLogId adapterLogId = getAdapterLogId(config);
LOG.debug("{} started scan result export", adapterLogId);
String apiUrl = createScanExportApiURL(context);
String json = "{\n" + " \"history_id\": " + context.getHistoryId() + ",\n" + " \"format\":\"nessus\"\n" + "}\n" + "";
MultiValueMap<String, String> headers = createHeader(config);
HttpEntity<String> request = new HttpEntity<>(json, headers);
ResponseEntity<String> response = context.getRestOperations().postForEntity(apiUrl, request, String.class);
if (!OK.equals(response.getStatusCode())) {
throw new NessusRESTFailureException(response.getStatusCode(), response.getBody());
}
String fileId = context.json().fetch("file", response).asText();
context.setExportFileId(fileId);
LOG.debug("{} fetched export data, fileId={}", adapterLogId, fileId);
}
Aggregations