Search in sources :

Example 1 with ScanMockData

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);
}
Also used : ScanMockData(com.mercedesbenz.sechub.domain.scan.project.ScanMockData) ScanProjectMockDataConfiguration(com.mercedesbenz.sechub.domain.scan.project.ScanProjectMockDataConfiguration)

Example 2 with ScanMockData

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 */
}
Also used : UseCaseUserRetrievesProjectMockdata(com.mercedesbenz.sechub.sharedkernel.usecases.user.UseCaseUserRetrievesProjectMockdata) ScanMockData(com.mercedesbenz.sechub.domain.scan.project.ScanMockData) ScanProjectMockDataConfiguration(com.mercedesbenz.sechub.domain.scan.project.ScanProjectMockDataConfiguration) WithMockUser(org.springframework.security.test.context.support.WithMockUser) UseCaseRestDoc(com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Example 3 with ScanMockData

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;
}
Also used : ScanMockData(com.mercedesbenz.sechub.domain.scan.project.ScanMockData) ScanProjectMockDataConfiguration(com.mercedesbenz.sechub.domain.scan.project.ScanProjectMockDataConfiguration)

Example 4 with ScanMockData

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 */
}
Also used : ScanMockData(com.mercedesbenz.sechub.domain.scan.project.ScanMockData) ScanProjectMockDataConfiguration(com.mercedesbenz.sechub.domain.scan.project.ScanProjectMockDataConfiguration) UseCaseUserDefinesProjectMockdata(com.mercedesbenz.sechub.sharedkernel.usecases.user.UseCaseUserDefinesProjectMockdata) WithMockUser(org.springframework.security.test.context.support.WithMockUser) UseCaseRestDoc(com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Example 5 with ScanMockData

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));
}
Also used : SecHubConfiguration(com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration) ScanMockData(com.mercedesbenz.sechub.domain.scan.project.ScanMockData) SecHubExecutionContext(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext) ScanProjectConfig(com.mercedesbenz.sechub.domain.scan.project.ScanProjectConfig) ScanProjectMockDataConfiguration(com.mercedesbenz.sechub.domain.scan.project.ScanProjectMockDataConfiguration) DomainMessage(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage) Test(org.junit.Test)

Aggregations

ScanMockData (com.mercedesbenz.sechub.domain.scan.project.ScanMockData)7 ScanProjectMockDataConfiguration (com.mercedesbenz.sechub.domain.scan.project.ScanProjectMockDataConfiguration)7 Test (org.junit.Test)3 SecHubExecutionContext (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext)2 UseCaseRestDoc (com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc)2 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)2 WithMockUser (org.springframework.security.test.context.support.WithMockUser)2 AbstractAdapterConfigBuilder (com.mercedesbenz.sechub.adapter.AbstractAdapterConfigBuilder)1 ProductExecutorData (com.mercedesbenz.sechub.domain.scan.product.ProductExecutorData)1 ScanProjectConfig (com.mercedesbenz.sechub.domain.scan.project.ScanProjectConfig)1 SecHubConfiguration (com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration)1 DomainMessage (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage)1 UseCaseUserDefinesProjectMockdata (com.mercedesbenz.sechub.sharedkernel.usecases.user.UseCaseUserDefinesProjectMockdata)1 UseCaseUserRetrievesProjectMockdata (com.mercedesbenz.sechub.sharedkernel.usecases.user.UseCaseUserRetrievesProjectMockdata)1 Before (org.junit.Before)1