Search in sources :

Example 21 with SecHubConfiguration

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

the class WebConfigBuilderStrategyTest method too_many_excludes.

@Test
public void too_many_excludes() {
    /* prepare */
    List<String> excludes = new LinkedList<>();
    for (int i = 1; i <= 501; i++) {
        excludes.add("/myapp" + i);
    }
    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("A maximum of 500 excludes are allowed.", 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 22 with SecHubConfiguration

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

the class WebConfigBuilderStrategyTest method exclude_too_long.

@Test
public void exclude_too_long() {
    /* prepare */
    // create long string
    StringBuilder sb = new StringBuilder();
    sb.append("/");
    for (int i = 0; i < 64; i++) {
        sb.append("abcdefghijklmnopqrstuvwxyz012345");
    }
    List<String> excludes = new LinkedList<>();
    excludes.add(sb.toString());
    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 */
    assertThat(exception.getMessage(), startsWith("Maximum URL length is 2048 characters. The first 2048 characters of the URL in question: /abcdefghijklmnopqrst"));
}
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 23 with SecHubConfiguration

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

the class LicenseScanProductExecutionServiceImplTest method isExecutionNecessary_unnecessary.

@Test
void isExecutionNecessary_unnecessary() {
    /* prepare */
    UUIDTraceLogID traceId = UUIDTraceLogID.traceLogID(UUID.randomUUID());
    SecHubExecutionContext context = mock(SecHubExecutionContext.class);
    SecHubConfiguration configuration = new SecHubConfiguration();
    /* execute + test */
    assertFalse(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) Test(org.junit.jupiter.api.Test)

Example 24 with SecHubConfiguration

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

the class ScanService method cleanupStorage.

/*
     * Cleans storage for current job
     */
private void cleanupStorage(SecHubExecutionContext context) {
    if (context == null) {
        LOG.warn("No context available so no cleanup possible");
        return;
    }
    SecHubConfiguration configuration = context.getConfiguration();
    if (configuration == null) {
        LOG.warn("No configuration available so no cleanup possible");
        return;
    }
    String projectId = configuration.getProjectId();
    UUID jobUUID = context.getSechubJobUUID();
    JobStorage storage = storageService.getJobStorage(projectId, jobUUID);
    try {
        storage.deleteAll();
    } catch (IOException e) {
        LOG.error("Was not able to delete storage for job {}", jobUUID, e);
    }
}
Also used : SecHubConfiguration(com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration) IOException(java.io.IOException) UUID(java.util.UUID) JobStorage(com.mercedesbenz.sechub.storage.core.JobStorage)

Example 25 with SecHubConfiguration

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

the class PDSStorageContentProviderFactory method createContentProvider.

public PDSStorageContentProvider createContentProvider(SecHubExecutionContext context, ReuseSecHubStorageInfoProvider reuseSecHubStorageProvider, ScanType scanType) {
    JobStorage storage = null;
    SecHubConfiguration model = context.getConfiguration();
    boolean reuseSecHubStorage = reuseSecHubStorageProvider.isReusingSecHubStorage();
    if (!reuseSecHubStorage) {
        String projectId = model.getProjectId();
        UUID jobUUID = context.getSechubJobUUID();
        storage = storageService.getJobStorage(projectId, jobUUID);
    }
    return new PDSStorageContentProvider(storage, reuseSecHubStorage, scanType, modelSupport, model);
}
Also used : SecHubConfiguration(com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration) JobStorage(com.mercedesbenz.sechub.storage.core.JobStorage) UUID(java.util.UUID)

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