use of com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfig 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.domain.scan.product.config.ProductExecutorConfig 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.domain.scan.product.config.ProductExecutorConfig in project sechub by mercedes-benz.
the class PDSProductExecutorMinimumConfigValidation method validate.
@Override
protected void validate(ValidationContext<ProductExecutorConfig> context) {
/* check not null... */
validateNotNull(context);
ProductExecutorConfig configToValidate = getObjectToValidate(context);
if (configToValidate == null) {
return;
}
ProductExecutorConfigSetup setup = configToValidate.getSetup();
validateNotNull(context, setup, "setup");
if (setup == null) {
return;
}
List<ProductExecutorConfigSetupJobParameter> jobParameters = setup.getJobParameters();
validateNotNull(context, jobParameters, "jobParameters");
if (jobParameters == null) {
return;
}
validateMandatoryPartsSet(context, jobParameters);
}
use of com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfig in project sechub by mercedes-benz.
the class PDSProductExecutorMinimumConfigValidationTest method createConfigWithAllMandatoryParametersSetWith.
private ProductExecutorConfig createConfigWithAllMandatoryParametersSetWith(String value) {
ProductExecutorConfig config = createConfigWithNoParametersSet();
List<ProductExecutorConfigSetupJobParameter> params = config.getSetup().getJobParameters();
for (SecHubProductExecutionPDSKeyProvider provider : SecHubProductExecutionPDSKeyProvider.values()) {
SecHubProductExecutionPDSKey key = provider.getKey();
if (key.isMandatory()) {
params.add(new ProductExecutorConfigSetupJobParameter(key.getId(), value));
}
}
for (PDSConfigDataKeyProvider provider : PDSConfigDataKeyProvider.values()) {
ExecutionPDSKey key = provider.getKey();
if (key.isMandatory()) {
params.add(new ProductExecutorConfigSetupJobParameter(key.getId(), value));
}
}
return config;
}
use of com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfig in project sechub by mercedes-benz.
the class ProductExecutorConfigRestControllerRestDocTest method restdoc_admin_fetches_executor_config.
@Test
@UseCaseRestDoc(useCase = UseCaseAdminFetchesExecutorConfiguration.class)
public void restdoc_admin_fetches_executor_config() throws Exception {
/* prepare */
String apiEndpoint = https(PORT_USED).buildAdminFetchesProductExecutorConfig(UUID_PARAMETER.pathElement());
Class<? extends Annotation> useCase = UseCaseAdminFetchesExecutorConfiguration.class;
UUID uuid = UUID.randomUUID();
TestExecutorConfig testConfig = new TestExecutorConfig();
testConfig.uuid = uuid;
testConfig.enabled = false;
testConfig.name = "New name";
testConfig.productIdentifier = ProductIdentifier.PDS_CODESCAN.name();
testConfig.executorVersion = 1;
testConfig.setup.baseURL = "https://product.example.com";
testConfig.setup.credentials.user = "env:EXAMPLE_USENAME";
testConfig.setup.credentials.password = "env:EXAMPLE_PASSWORD";
TestExecutorSetupJobParam param1 = new TestExecutorSetupJobParam("example.key1", "A value");
testConfig.setup.jobParameters.add(param1);
ProductExecutorConfig config = JSONConverter.get().fromJSON(ProductExecutorConfig.class, JSONConverter.get().toJSON(testConfig));
when(fetchService.fetchProductExecutorConfig(uuid)).thenReturn(config);
/* execute + test @formatter:off */
this.mockMvc.perform(get(apiEndpoint, uuid).contentType(MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk()).andDo(defineRestService().with().useCaseData(useCase).tag(RestDocFactory.extractTag(apiEndpoint)).responseSchema(OpenApiSchema.EXECUTOR_CONFIGURATION_WITH_UUID.getSchema()).and().document(responseFields(fieldWithPath(PROPERTY_UUID).description("The uuid of this configuration"), fieldWithPath(PROPERTY_NAME).description("The name of this configuration"), fieldWithPath(PROPERTY_PRODUCTIDENTIFIER).description("Executor product identifier"), fieldWithPath(PROPERTY_EXECUTORVERSION).description("Executor version"), fieldWithPath(PROPERTY_ENABLED).description("Enabled state of executor").optional(), fieldWithPath(PROPERTY_SETUP + "." + ProductExecutorConfigSetup.PROPERTY_BASEURL).description("Base URL to the product"), fieldWithPath(PROPERTY_SETUP + "." + ProductExecutorConfigSetup.PROPERTY_CREDENTIALS + "." + ProductExecutorConfigSetupCredentials.PROPERTY_USER).description(CREDENTIALS_USER_DESCRIPTION), fieldWithPath(PROPERTY_SETUP + "." + ProductExecutorConfigSetup.PROPERTY_CREDENTIALS + "." + ProductExecutorConfigSetupCredentials.PROPERTY_PASSWORD).description(CREDENTIALS_PWD_DESCRIPTION), fieldWithPath(PROPERTY_SETUP + "." + ProductExecutorConfigSetup.PROPERTY_JOBPARAMETERS + "[]." + ProductExecutorConfigSetupJobParameter.PROPERTY_KEY).description(JOBPARAM_KEY_DESCRIPTION).optional(), fieldWithPath(PROPERTY_SETUP + "." + ProductExecutorConfigSetup.PROPERTY_JOBPARAMETERS + "[]." + ProductExecutorConfigSetupJobParameter.PROPERTY_VALUE).description(JOBPARAM_VALUE_DESCRIPTION).optional()), pathParameters(parameterWithName(UUID_PARAMETER.paramName()).description("The configuration uuid"))));
/* @formatter:on */
}
Aggregations