Search in sources :

Example 1 with ProductExecutorConfigSetup

use of com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigSetup in project sechub by mercedes-benz.

the class CheckmarxProductExecutorMockTest method createCheckmarxSetupWithAllMandotoryPartsSet.

private ProductExecutorConfigSetup createCheckmarxSetupWithAllMandotoryPartsSet() {
    ProductExecutorConfigSetup setup = mock(ProductExecutorConfigSetup.class);
    ProductExecutorConfigSetupCredentials credentials = mock(ProductExecutorConfigSetupCredentials.class);
    when(setup.getCredentials()).thenReturn(credentials);
    when(credentials.getUser()).thenReturn("user");
    when(credentials.getPassword()).thenReturn("pwd");
    List<ProductExecutorConfigSetupJobParameter> jobParameters = new ArrayList<>();
    MappingData data = new MappingData();
    data.getEntries().add(new MappingEntry(".*", "teamId1", ""));
    jobParameters.add(new ProductExecutorConfigSetupJobParameter(MappingIdentifier.CHECKMARX_NEWPROJECT_TEAM_ID.getId(), data.toJSON()));
    when(setup.getJobParameters()).thenReturn(jobParameters);
    return setup;
}
Also used : MappingEntry(com.mercedesbenz.sechub.sharedkernel.mapping.MappingEntry) ProductExecutorConfigSetupCredentials(com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigSetupCredentials) ProductExecutorConfigSetupJobParameter(com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigSetupJobParameter) ArrayList(java.util.ArrayList) MappingData(com.mercedesbenz.sechub.sharedkernel.mapping.MappingData) ProductExecutorConfigSetup(com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigSetup)

Example 2 with ProductExecutorConfigSetup

use of com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigSetup 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 3 with ProductExecutorConfigSetup

use of com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigSetup 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 4 with ProductExecutorConfigSetup

use of com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigSetup 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 5 with ProductExecutorConfigSetup

use of com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigSetup in project sechub by mercedes-benz.

the class AbstractProductExecutionServiceTest method before.

@Before
public void before() throws Exception {
    serviceToTest = new TestImplAbstractProductExecutionService();
    serviceToTest.allAvailableProductExecutors = new ArrayList<>();
    SecHubConfiguration configuration = new SecHubConfiguration();
    configuration.setProjectId("projectid1");
    sechubJobUUID = UUID.randomUUID();
    logger = mock(Logger.class);
    traceLogID = mock(UUIDTraceLogID.class);
    executors = new ArrayList<>();
    executor = mock(ProductExecutor.class);
    when(executor.getIdentifier()).thenReturn(USED_PRODUCT_IDENTIFIER);
    when(executor.getVersion()).thenReturn(USED_PRODUCT_EXECUTOR_VERSION);
    executors.add(executor);
    context = mock(SecHubExecutionContext.class);
    when(context.getSechubJobUUID()).thenReturn(sechubJobUUID);
    when(context.getConfiguration()).thenReturn(configuration);
    ProductExecutorConfigRepository productExecutorConfigRepository = mock(ProductExecutorConfigRepository.class);
    serviceToTest.productExecutorConfigRepository = productExecutorConfigRepository;
    config1 = new ProductExecutorConfig(USED_PRODUCT_IDENTIFIER, 0, new ProductExecutorConfigSetup());
    when(productExecutorConfigRepository.findExecutableConfigurationsForProject(any(), eq(USED_PRODUCT_IDENTIFIER), eq(USED_PRODUCT_EXECUTOR_VERSION))).thenReturn(Arrays.asList(config1));
    productResultRepository = mock(ProductResultRepository.class);
    serviceToTest.productResultRepository = productResultRepository;
    productExecutorContextFactory = mock(ProductExecutorContextFactory.class);
    serviceToTest.productExecutorContextFactory = productExecutorContextFactory;
    productExecutorContext = mock(ProductExecutorContext.class);
    when(productExecutorContextFactory.create(any(), any(), any(), any())).thenReturn(productExecutorContext);
}
Also used : UUIDTraceLogID(com.mercedesbenz.sechub.sharedkernel.UUIDTraceLogID) ProductExecutorConfig(com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfig) Logger(org.slf4j.Logger) SecHubConfiguration(com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration) SecHubExecutionContext(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext) ProductExecutorConfigRepository(com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigRepository) ProductExecutorConfigSetup(com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigSetup) Before(org.junit.Before)

Aggregations

ProductExecutorConfigSetup (com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigSetup)10 ProductExecutorConfig (com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfig)9 SecHubExecutionContext (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext)5 ProductExecutorConfigRepository (com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigRepository)3 ProductExecutorConfigSetupJobParameter (com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigSetupJobParameter)3 SecHubConfiguration (com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration)3 ArrayList (java.util.ArrayList)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 Test (org.junit.Test)2 SecHubInfrastructureScanConfiguration (com.mercedesbenz.sechub.commons.model.SecHubInfrastructureScanConfiguration)1 SecHubWebScanConfiguration (com.mercedesbenz.sechub.commons.model.SecHubWebScanConfiguration)1 ProductExecutorConfigSetupCredentials (com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigSetupCredentials)1 WithoutProductExecutorConfigInfo (com.mercedesbenz.sechub.domain.scan.product.config.WithoutProductExecutorConfigInfo)1 UUIDTraceLogID (com.mercedesbenz.sechub.sharedkernel.UUIDTraceLogID)1