use of com.mercedesbenz.sechub.domain.scan.project.ScanMockData in project sechub by mercedes-benz.
the class ExampleJSONGenerator method generateScanProjectMockDataConfiguration2.
public String generateScanProjectMockDataConfiguration2() {
ScanProjectMockDataConfiguration config = new ScanProjectMockDataConfiguration();
config.setCodeScan(new ScanMockData(TrafficLight.YELLOW));
return prettyPrint(config);
}
use of com.mercedesbenz.sechub.domain.scan.project.ScanMockData in project sechub by mercedes-benz.
the class ScanProjectMockDataRestControllerRestDocTest method get_project_mock_configuration.
@UseCaseRestDoc(useCase = UseCaseUserRetrievesProjectMockdata.class)
@Test
@WithMockUser
public void get_project_mock_configuration() throws Exception {
/* prepare */
String apiEndpoint = https(PORT_USED).buildGetProjectMockConfiguration(RestDocPathParameter.PROJECT_ID.pathElement());
Class<? extends Annotation> useCase = UseCaseUserRetrievesProjectMockdata.class;
ScanProjectMockDataConfiguration config = new ScanProjectMockDataConfiguration();
config.setCodeScan(new ScanMockData(TrafficLight.RED));
config.setWebScan(new ScanMockData(TrafficLight.YELLOW));
config.setInfraScan(new ScanMockData(TrafficLight.GREEN));
when(configService.retrieveProjectMockDataConfiguration(PROJECT1_ID)).thenReturn(config);
/* @formatter:off */
/* execute + test @formatter:off */
this.mockMvc.perform(get(apiEndpoint, PROJECT1_ID).accept(MediaType.APPLICATION_JSON_VALUE).contentType(MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk()).andExpect(jsonPath("$.codeScan.result").value("RED")).andExpect(jsonPath("$.webScan.result").value("YELLOW")).andExpect(jsonPath("$.infraScan.result").value("GREEN")).andDo(defineRestService().with().useCaseData(useCase).tag(RestDocFactory.extractTag(apiEndpoint)).responseSchema(OpenApiSchema.MOCK_DATA_CONFIGURATION.getSchema()).and().document());
/* @formatter:on */
}
use of com.mercedesbenz.sechub.domain.scan.project.ScanMockData in project sechub by mercedes-benz.
the class SecHubAdapterOptionsBuilderStrategy method fetchMockConfigurationResultLowerCased.
private String fetchMockConfigurationResultLowerCased() {
String mockConfigurationResult = null;
ScanProjectMockDataConfiguration mockConfiguration = context.getData(ScanKey.PROJECT_MOCKDATA_CONFIGURATION);
Optional<ScanMockData> mockData = Optional.empty();
if (mockConfiguration != null) {
switch(scanType) {
case CODE_SCAN:
mockData = mockConfiguration.getCodeScan();
break;
case WEB_SCAN:
mockData = mockConfiguration.getWebScan();
break;
case INFRA_SCAN:
mockData = mockConfiguration.getInfraScan();
break;
default:
LOG.error("Cannot fetch mock configuration result for scan type:'{}'", scanType);
}
if (mockData.isPresent()) {
ScanMockData scanMockData = mockData.get();
mockConfigurationResult = scanMockData.getResult().name().toLowerCase();
}
}
return mockConfigurationResult;
}
use of com.mercedesbenz.sechub.domain.scan.project.ScanMockData in project sechub by mercedes-benz.
the class ScanProjectMockDataRestControllerRestDocTest method set_project_mock_configuration.
@UseCaseRestDoc(useCase = UseCaseUserDefinesProjectMockdata.class)
@Test
@WithMockUser
public void set_project_mock_configuration() throws Exception {
/* prepare */
String apiEndpoint = https(PORT_USED).buildSetProjectMockConfiguration(RestDocPathParameter.PROJECT_ID.pathElement());
Class<? extends Annotation> useCase = UseCaseUserDefinesProjectMockdata.class;
ScanProjectMockDataConfiguration config = new ScanProjectMockDataConfiguration();
config.setCodeScan(new ScanMockData(TrafficLight.RED));
config.setWebScan(new ScanMockData(TrafficLight.YELLOW));
config.setInfraScan(new ScanMockData(TrafficLight.GREEN));
/* @formatter:off */
/* execute + test @formatter:off */
this.mockMvc.perform(put(apiEndpoint, PROJECT1_ID).accept(MediaType.APPLICATION_JSON_VALUE).contentType(MediaType.APPLICATION_JSON_VALUE).content(config.toJSON())).andExpect(status().isOk()).andDo(defineRestService().with().useCaseData(useCase).tag(RestDocFactory.extractTag(apiEndpoint)).requestSchema(OpenApiSchema.MOCK_DATA_CONFIGURATION.getSchema()).and().document());
/* @formatter:on */
}
use of com.mercedesbenz.sechub.domain.scan.project.ScanMockData 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));
}
Aggregations