Search in sources :

Example 6 with SecHubConfiguration

use of com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration in project sechub by mercedes-benz.

the class WebConfigBuilderStrategyTest method excludes_no_slash_infront_multiple.

@Test
public void excludes_no_slash_infront_multiple() {
    /* prepare */
    List<String> excludes = new LinkedList<>();
    excludes.add("/abc");
    excludes.add("contact.html");
    excludes.add("/bca");
    excludes.add("ccb/bca");
    String json = createExcludesJson(excludes);
    SecHubConfiguration configuration = SECHUB_CONFIG.fromJSON(json);
    SecHubExecutionContext context = new SecHubExecutionContext(UUID.randomUUID(), configuration, "test");
    WebConfigBuilderStrategy strategyToTest = new WebConfigBuilderStrategy(context);
    TestAbstractWebScanAdapterConfigBuilder configBuilder = new TestAbstractWebScanAdapterConfigBuilder();
    /* execute */
    IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> {
        strategyToTest.configure(configBuilder);
    });
    /* test */
    assertEquals("The URL does not start with a slash '/'. URL: contact.html", exception.getMessage());
}
Also used : SecHubConfiguration(com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration) SecHubExecutionContext(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext) LinkedList(java.util.LinkedList) Test(org.junit.jupiter.api.Test)

Example 7 with SecHubConfiguration

use of com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration 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)

Example 8 with SecHubConfiguration

use of com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration in project sechub by mercedes-benz.

the class LicenseScanProductExecutionServiceImplTest method isExecutionNecessary_necessary.

@Test
void isExecutionNecessary_necessary() {
    /* prepare */
    UUIDTraceLogID traceId = UUIDTraceLogID.traceLogID(UUID.randomUUID());
    SecHubExecutionContext context = mock(SecHubExecutionContext.class);
    SecHubConfiguration configuration = new SecHubConfiguration();
    SecHubLicenseScanConfiguration licenseScanConfig = new SecHubLicenseScanConfiguration();
    configuration.setLicenseScan(licenseScanConfig);
    /* execute + test */
    assertTrue(licenseScanServiceToTest.isExecutionNecessary(context, traceId, configuration));
}
Also used : UUIDTraceLogID(com.mercedesbenz.sechub.sharedkernel.UUIDTraceLogID) SecHubExecutionContext(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext) SecHubConfiguration(com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration) SecHubLicenseScanConfiguration(com.mercedesbenz.sechub.commons.model.SecHubLicenseScanConfiguration) Test(org.junit.jupiter.api.Test)

Example 9 with SecHubConfiguration

use of com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration in project sechub by mercedes-benz.

the class ScanService method createExecutionContext.

private SecHubExecutionContext createExecutionContext(DomainMessage message) throws JSONConverterException {
    UUID uuid = message.get(SECHUB_UUID);
    String executedBy = message.get(EXECUTED_BY);
    SecHubConfiguration configuration = message.get(SECHUB_CONFIG);
    if (configuration == null) {
        throw new IllegalStateException("SecHubConfiguration not found in message - so cannot execute!");
    }
    SecHubExecutionContext executionContext = new SecHubExecutionContext(uuid, configuration, executedBy);
    buildOptions(executionContext);
    return executionContext;
}
Also used : SecHubConfiguration(com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration) SecHubExecutionContext(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext) UUID(java.util.UUID)

Example 10 with SecHubConfiguration

use of com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration in project sechub by mercedes-benz.

the class AbstractProductExecutor method execute.

@Override
public final List<ProductResult> execute(SecHubExecutionContext context, ProductExecutorContext executorContext) throws SecHubExecutionException {
    UUIDTraceLogID traceLogId = context.getTraceLogId();
    SecHubConfiguration config = context.getConfiguration();
    if (!canExecute(config)) {
        LOG.debug("Cannot execute given configuration {}", traceLogId);
        return Collections.emptyList();
    }
    ProductExecutorData data = createExecutorData(context, executorContext, traceLogId);
    configureSourceCodeHandlingIfNecessary(data);
    configureNetworkTargetHandlingIfNecessary(data);
    return startExecution(data);
}
Also used : UUIDTraceLogID(com.mercedesbenz.sechub.sharedkernel.UUIDTraceLogID) SecHubConfiguration(com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration)

Aggregations

SecHubConfiguration (com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration)29 SecHubExecutionContext (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext)15 Test (org.junit.jupiter.api.Test)10 LinkedList (java.util.LinkedList)8 UUIDTraceLogID (com.mercedesbenz.sechub.sharedkernel.UUIDTraceLogID)6 DomainMessage (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage)3 UUID (java.util.UUID)3 Test (org.junit.Test)3 SecHubCodeScanConfiguration (com.mercedesbenz.sechub.commons.model.SecHubCodeScanConfiguration)2 InfraScanNetworkLocationProvider (com.mercedesbenz.sechub.domain.scan.InfraScanNetworkLocationProvider)2 WebScanNetworkLocationProvider (com.mercedesbenz.sechub.domain.scan.WebScanNetworkLocationProvider)2 ProductExecutorContext (com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext)2 ProductExecutorConfig (com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfig)2 SecHubExecutionException (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException)2 JobStorage (com.mercedesbenz.sechub.storage.core.JobStorage)2 ScanType (com.mercedesbenz.sechub.commons.model.ScanType)1 SecHubDataConfigurationObject (com.mercedesbenz.sechub.commons.model.SecHubDataConfigurationObject)1 SecHubDataConfigurationObjectInfo (com.mercedesbenz.sechub.commons.model.SecHubDataConfigurationObjectInfo)1 SecHubFileSystemConfiguration (com.mercedesbenz.sechub.commons.model.SecHubFileSystemConfiguration)1 SecHubLicenseScanConfiguration (com.mercedesbenz.sechub.commons.model.SecHubLicenseScanConfiguration)1