Search in sources :

Example 1 with ProductExecutorConfig

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());
}
Also used : ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) SecHubExecutionContext(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext) ProductExecutorConfig(com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfig) ProductExecutorContext(com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext) AdapterException(com.mercedesbenz.sechub.adapter.AdapterException) ProductExecutorCallback(com.mercedesbenz.sechub.domain.scan.product.ProductExecutorCallback) AdapterLogId(com.mercedesbenz.sechub.adapter.AdapterLogId) ProductExecutorConfigSetup(com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigSetup) Test(org.junit.Test)

Example 2 with ProductExecutorConfig

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"));
}
Also used : SecHubExecutionException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException) ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) SecHubExecutionContext(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext) ProductExecutorConfig(com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfig) ProductExecutorContext(com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext) AdapterException(com.mercedesbenz.sechub.adapter.AdapterException) ProductExecutorCallback(com.mercedesbenz.sechub.domain.scan.product.ProductExecutorCallback) AdapterLogId(com.mercedesbenz.sechub.adapter.AdapterLogId) ProductExecutorConfigSetup(com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigSetup) Test(org.junit.Test)

Example 3 with ProductExecutorConfig

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);
}
Also used : ProductExecutorConfigSetupJobParameter(com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigSetupJobParameter) ProductExecutorConfig(com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfig) ProductExecutorConfigSetup(com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigSetup)

Example 4 with ProductExecutorConfig

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;
}
Also used : ProductExecutorConfigSetupJobParameter(com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigSetupJobParameter) ProductExecutorConfig(com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfig) PDSConfigDataKeyProvider(com.mercedesbenz.sechub.commons.pds.PDSConfigDataKeyProvider) ExecutionPDSKey(com.mercedesbenz.sechub.commons.pds.ExecutionPDSKey)

Example 5 with ProductExecutorConfig

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 */
}
Also used : UseCaseAdminFetchesExecutorConfiguration(com.mercedesbenz.sechub.sharedkernel.usecases.admin.config.UseCaseAdminFetchesExecutorConfiguration) TestExecutorConfig(com.mercedesbenz.sechub.test.executorconfig.TestExecutorConfig) TestExecutorSetupJobParam(com.mercedesbenz.sechub.test.executorconfig.TestExecutorSetupJobParam) ProductExecutorConfig(com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfig) UUID(java.util.UUID) UseCaseRestDoc(com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) Test(org.junit.Test)

Aggregations

ProductExecutorConfig (com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfig)16 ProductExecutorConfigSetup (com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigSetup)9 Test (org.junit.Test)6 SecHubExecutionContext (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext)5 SecHubConfiguration (com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration)4 ProductExecutorConfigRepository (com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigRepository)3 ProductExecutorConfigSetupJobParameter (com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigSetupJobParameter)3 ValidationResult (com.mercedesbenz.sechub.sharedkernel.validation.ValidationResult)3 Before (org.junit.Before)3 AdapterException (com.mercedesbenz.sechub.adapter.AdapterException)2 AdapterLogId (com.mercedesbenz.sechub.adapter.AdapterLogId)2 ProductExecutorCallback (com.mercedesbenz.sechub.domain.scan.product.ProductExecutorCallback)2 ProductExecutorContext (com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext)2 ProductResult (com.mercedesbenz.sechub.domain.scan.product.ProductResult)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 ScanType (com.mercedesbenz.sechub.commons.model.ScanType)1 SecHubInfrastructureScanConfiguration (com.mercedesbenz.sechub.commons.model.SecHubInfrastructureScanConfiguration)1 SecHubWebScanConfiguration (com.mercedesbenz.sechub.commons.model.SecHubWebScanConfiguration)1