use of com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext in project sechub by mercedes-benz.
the class ScanServiceTest method scan_service_fetches_mock_configuration_and_puts_mock_project_configuration_complete_in_execution_context.
@Test
public void scan_service_fetches_mock_configuration_and_puts_mock_project_configuration_complete_in_execution_context() throws Exception {
/* prepare */
SecHubConfiguration configNoProjectId = prepareValidConfiguration();
DomainMessage request = prepareRequest(configNoProjectId);
ScanProjectMockDataConfiguration projectMockDataConfig = new ScanProjectMockDataConfiguration();
projectMockDataConfig.setCodeScan(new ScanMockData(TrafficLight.YELLOW));
ScanProjectConfig projectConfig = new ScanProjectConfig(ScanProjectConfigID.MOCK_CONFIGURATION, TEST_PROJECT_ID1);
projectConfig.setData(projectMockDataConfig.toJSON());
when(scanProjectConfigService.get("test-project-id1", ScanProjectConfigID.MOCK_CONFIGURATION, false)).thenReturn(projectConfig);
/* execute */
simulateEventSend(request, serviceToTest);
/* test */
ArgumentCaptor<SecHubExecutionContext> contextCaptor = ArgumentCaptor.forClass(SecHubExecutionContext.class);
verify(codeScanProductExecutionService).executeProductsAndStoreResults(contextCaptor.capture());
SecHubExecutionContext context = contextCaptor.getValue();
assertEquals(projectMockDataConfig, context.getData(ScanKey.PROJECT_MOCKDATA_CONFIGURATION));
}
use of com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext in project sechub by mercedes-benz.
the class SecHubAdapterOptionsBuilderStrategyTest method before.
@Before
public void before() {
data = mock(ProductExecutorData.class);
SecHubExecutionContext context = mock(SecHubExecutionContext.class);
configBuilder = mock(AbstractAdapterConfigBuilder.class);
scanProjectMockDataConfig = new ScanProjectMockDataConfiguration();
ScanMockData codeScan = new ScanMockData(TrafficLight.RED);
ScanMockData webScan = new ScanMockData(TrafficLight.YELLOW);
ScanMockData infraScan = new ScanMockData(TrafficLight.GREEN);
scanProjectMockDataConfig.setCodeScan(codeScan);
scanProjectMockDataConfig.setWebScan(webScan);
scanProjectMockDataConfig.setInfraScan(infraScan);
when(context.getData(ScanKey.PROJECT_MOCKDATA_CONFIGURATION)).thenReturn(scanProjectMockDataConfig);
when(data.getSechubExecutionContext()).thenReturn(context);
}
use of com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext in project sechub by mercedes-benz.
the class WebConfigBuilderStrategyTest method too_many_includes.
@Test
public void too_many_includes() {
/* prepare */
List<String> includes = new LinkedList<>();
for (int i = 1; i <= 501; i++) {
includes.add("/myapp" + i);
}
String json = createIncludesJson(includes);
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 includes are allowed.", exception.getMessage());
}
use of com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext in project sechub by mercedes-benz.
the class WebConfigBuilderStrategyTest method include_too_long.
@Test
public void include_too_long() {
/* prepare */
// create long string
StringBuilder sb = new StringBuilder();
sb.append("/");
for (int i = 0; i < 64; i++) {
sb.append("abcdefghijklmnopqrstuvwxyz012345");
}
List<String> includes = new LinkedList<>();
includes.add(sb.toString());
String json = createIncludesJson(includes);
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"));
}
use of com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext 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());
}
Aggregations