Search in sources :

Example 1 with ScanProjectMockDataConfiguration

use of com.mercedesbenz.sechub.domain.scan.project.ScanProjectMockDataConfiguration 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 ScanProjectMockDataConfiguration

use of com.mercedesbenz.sechub.domain.scan.project.ScanProjectMockDataConfiguration 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 ScanProjectMockDataConfiguration

use of com.mercedesbenz.sechub.domain.scan.project.ScanProjectMockDataConfiguration in project sechub by mercedes-benz.

the class ScanService method buildOptions.

private void buildOptions(SecHubExecutionContext executionContext) {
    /* project specific setup */
    String projectId = executionContext.getConfiguration().getProjectId();
    if (projectId == null) {
        throw new IllegalStateException("projectId not found in configuration - so cannot prepare context options!");
    }
    ScanProjectConfig scanProjectMockConfig = scanProjectConfigService.get(projectId, ScanProjectConfigID.MOCK_CONFIGURATION, false);
    if (scanProjectMockConfig != null) {
        String data = scanProjectMockConfig.getData();
        ScanProjectMockDataConfiguration mockDataConfig = ScanProjectMockDataConfiguration.fromString(data);
        executionContext.putData(ScanKey.PROJECT_MOCKDATA_CONFIGURATION, mockDataConfig);
    }
}
Also used : ScanProjectConfig(com.mercedesbenz.sechub.domain.scan.project.ScanProjectConfig) ScanProjectMockDataConfiguration(com.mercedesbenz.sechub.domain.scan.project.ScanProjectMockDataConfiguration)

Example 4 with ScanProjectMockDataConfiguration

use of com.mercedesbenz.sechub.domain.scan.project.ScanProjectMockDataConfiguration 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 5 with ScanProjectMockDataConfiguration

use of com.mercedesbenz.sechub.domain.scan.project.ScanProjectMockDataConfiguration 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)

Aggregations

ScanProjectMockDataConfiguration (com.mercedesbenz.sechub.domain.scan.project.ScanProjectMockDataConfiguration)8 ScanMockData (com.mercedesbenz.sechub.domain.scan.project.ScanMockData)7 Test (org.junit.Test)3 ScanProjectConfig (com.mercedesbenz.sechub.domain.scan.project.ScanProjectConfig)2 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 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