Search in sources :

Example 31 with UseCaseRestDoc

use of com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc in project sechub by mercedes-benz.

the class ProjectAdministrationRestControllerRestDocTest method restdoc_change_project_access_level.

@Test
@UseCaseRestDoc(useCase = UseCaseAdministratorChangesProjectAccessLevel.class)
public void restdoc_change_project_access_level() throws Exception {
    Class<UseCaseAdministratorChangesProjectAccessLevel> useCase = UseCaseAdministratorChangesProjectAccessLevel.class;
    String apiEndpoint = https(PORT_USED).buildAdminChangesProjectAccessLevelUrl(PROJECT_ID.pathElement(), PROJECT_ACCESS_LEVEL.pathElement());
    /* prepare */
    StringBuilder acceptedValues = new StringBuilder();
    acceptedValues.append("Accepted values: ");
    for (Iterator<ProjectAccessLevel> it = Arrays.asList(ProjectAccessLevel.values()).iterator(); it.hasNext(); ) {
        ProjectAccessLevel level = it.next();
        acceptedValues.append(level.getId());
        String description = level.getDescription();
        if (description != null) {
            acceptedValues.append("(");
            acceptedValues.append(description);
            acceptedValues.append(")");
        }
        if (it.hasNext()) {
            acceptedValues.append(", ");
        }
    }
    /* execute + test @formatter:off */
    this.mockMvc.perform(post(apiEndpoint, "projectId1", ProjectAccessLevel.READ_ONLY.getId()).contentType(MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk()).andDo(defineRestService().with().useCaseData(useCase).tag(RestDocFactory.extractTag(apiEndpoint)).and().document(pathParameters(parameterWithName(PROJECT_ID.paramName()).description("The id for project"), parameterWithName(PROJECT_ACCESS_LEVEL.paramName()).description("The new project access level. " + acceptedValues.toString()))));
/* @formatter:on */
}
Also used : UseCaseAdministratorChangesProjectAccessLevel(com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdministratorChangesProjectAccessLevel) UseCaseAdministratorChangesProjectAccessLevel(com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdministratorChangesProjectAccessLevel) ProjectAccessLevel(com.mercedesbenz.sechub.sharedkernel.project.ProjectAccessLevel) UseCaseRestDoc(com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) Test(org.junit.Test)

Example 32 with UseCaseRestDoc

use of com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc 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 33 with UseCaseRestDoc

use of com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc in project sechub by mercedes-benz.

the class SchedulerRestControllerRestDocTest method restDoc_userCreatesNewJob_infrascan.

@Test
@UseCaseRestDoc(useCase = UseCaseUserCreatesNewJob.class, variant = "Infrastructure scan")
public void restDoc_userCreatesNewJob_infrascan() throws Exception {
    /* prepare */
    String apiEndpoint = https(PORT_USED).buildAddJobUrl(PROJECT_ID.pathElement());
    Class<? extends Annotation> useCase = UseCaseUserCreatesNewJob.class;
    UUID randomUUID = UUID.randomUUID();
    SchedulerResult mockResult = new SchedulerResult(randomUUID);
    when(mockedScheduleCreateJobService.createJob(any(), any(SecHubConfiguration.class))).thenReturn(mockResult);
    /* execute + test @formatter:off */
    this.mockMvc.perform(post(apiEndpoint, PROJECT1_ID).contentType(MediaType.APPLICATION_JSON_VALUE).content(configureSecHub().api("1.0").infraConfig().addURI("https://localhost").addIP("127.0.0.1").build().toJSON())).andExpect(status().isOk()).andExpect(content().json("{jobId:" + randomUUID.toString() + "}")).andDo(defineRestService().with().useCaseData(useCase, "Infrastructure scan").tag(RestDocFactory.extractTag(apiEndpoint)).requestSchema(OpenApiSchema.SCAN_JOB.getSchema()).responseSchema(OpenApiSchema.JOB_ID.getSchema()).and().document(pathParameters(parameterWithName(PROJECT_ID.paramName()).description("The unique id of the project id where a new sechub job shall be created")), requestFields(fieldWithPath(PROPERTY_API_VERSION).description("The api version, currently only 1.0 is supported"), fieldWithPath(PROPERTY_INFRA_SCAN).description("Infrastructure configuration block").optional(), fieldWithPath(PROPERTY_INFRA_SCAN + "." + SecHubInfrastructureScanConfiguration.PROPERTY_URIS).description("Infrastructure URIs to scan for").optional(), fieldWithPath(PROPERTY_INFRA_SCAN + "." + SecHubInfrastructureScanConfiguration.PROPERTY_IPS).description("Infrastructure IPs to scan for").optional()), responseFields(fieldWithPath(SchedulerResult.PROPERTY_JOBID).description("A unique job id"))));
/* @formatter:on */
}
Also used : SchedulerResult(com.mercedesbenz.sechub.domain.schedule.SchedulerResult) SecHubConfiguration(com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration) UseCaseUserCreatesNewJob(com.mercedesbenz.sechub.sharedkernel.usecases.user.execute.UseCaseUserCreatesNewJob) UUID(java.util.UUID) UseCaseRestDoc(com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) Test(org.junit.Test)

Example 34 with UseCaseRestDoc

use of com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc in project sechub by mercedes-benz.

the class SchedulerRestControllerRestDocTest method restDoc_userCreatesNewJob_webscan_anonymous.

@Test
@UseCaseRestDoc(useCase = UseCaseUserCreatesNewJob.class, variant = "Web scan anonymous")
public void restDoc_userCreatesNewJob_webscan_anonymous() throws Exception {
    /* prepare */
    String apiEndpoint = https(PORT_USED).buildAddJobUrl(PROJECT_ID.pathElement());
    Class<? extends Annotation> useCase = UseCaseUserCreatesNewJob.class;
    UUID randomUUID = UUID.randomUUID();
    SchedulerResult mockResult = new SchedulerResult(randomUUID);
    WebScanDurationConfiguration maxScanDuration = new WebScanDurationConfiguration();
    maxScanDuration.setDuration(1);
    maxScanDuration.setUnit(SecHubTimeUnit.HOUR);
    List<String> includes = Arrays.asList("/admin", "/hidden", "/admin.html");
    List<String> excludes = Arrays.asList("/public/media", "/static", "/contaxt.html");
    when(mockedScheduleCreateJobService.createJob(any(), any(SecHubConfiguration.class))).thenReturn(mockResult);
    /* execute + test @formatter:off */
    this.mockMvc.perform(post(apiEndpoint, PROJECT1_ID).contentType(MediaType.APPLICATION_JSON_VALUE).content(configureSecHub().api("1.0").webConfig().addURI("https://localhost/mywebapp/login").maxScanDuration(maxScanDuration).addIncludes(includes).addExcludes(excludes).build().toJSON())).andExpect(status().isOk()).andExpect(content().json("{jobId:" + randomUUID.toString() + "}")).andDo(defineRestService().with().useCaseData(useCase, "Web Scan anonymous").tag(RestDocFactory.extractTag(apiEndpoint)).requestSchema(OpenApiSchema.SCAN_JOB.getSchema()).responseSchema(OpenApiSchema.JOB_ID.getSchema()).and().document(pathParameters(parameterWithName(PROJECT_ID.paramName()).description("The unique id of the project id where a new sechub job shall be created")), requestFields(fieldWithPath(PROPERTY_API_VERSION).description("The api version, currently only 1.0 is supported"), fieldWithPath(PROPERTY_WEB_SCAN).description("Webscan configuration block").optional(), fieldWithPath(PROPERTY_WEB_SCAN + "." + SecHubWebScanConfiguration.PROPERTY_URI).description("Webscan URI to scan for").optional(), fieldWithPath(PROPERTY_WEB_SCAN + "." + SecHubWebScanConfiguration.PROPERTY_MAX_SCAN_DURATION + "." + WebScanDurationConfiguration.PROPERTY_DURATION).description("Duration of the scan as integer").optional(), fieldWithPath(PROPERTY_WEB_SCAN + "." + SecHubWebScanConfiguration.PROPERTY_MAX_SCAN_DURATION + "." + WebScanDurationConfiguration.PROPERTY_UNIT).description("Unit of the duration. Possible values are: millisecond(s), second(s), minute(s), hour(s), day(s)").optional(), fieldWithPath(PROPERTY_WEB_SCAN + "." + SecHubWebScanConfiguration.PROPERTY_INCLUDES + "[]").description("Include URL sub-paths to scan. Example: /hidden").optional(), fieldWithPath(PROPERTY_WEB_SCAN + "." + SecHubWebScanConfiguration.PROPERTY_EXCLUDES + "[]").description("Exclude URL sub-paths to scan. Example: /admin").optional()), responseFields(fieldWithPath(SchedulerResult.PROPERTY_JOBID).description("A unique job id"))));
/* @formatter:on */
}
Also used : SchedulerResult(com.mercedesbenz.sechub.domain.schedule.SchedulerResult) SecHubConfiguration(com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration) WebScanDurationConfiguration(com.mercedesbenz.sechub.commons.model.WebScanDurationConfiguration) UseCaseUserCreatesNewJob(com.mercedesbenz.sechub.sharedkernel.usecases.user.execute.UseCaseUserCreatesNewJob) UUID(java.util.UUID) UseCaseRestDoc(com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) Test(org.junit.Test)

Example 35 with UseCaseRestDoc

use of com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc in project sechub by mercedes-benz.

the class SchedulerRestControllerRestDocTest method restDoc_userApprovesJob.

@Test
@UseCaseRestDoc(useCase = UseCaseUserApprovesJob.class)
public void restDoc_userApprovesJob() throws Exception {
    /* prepare */
    String apiEndpoint = https(PORT_USED).buildApproveJobUrl(PROJECT_ID.pathElement(), JOB_UUID.pathElement());
    Class<? extends Annotation> useCase = UseCaseUserApprovesJob.class;
    ScheduleSecHubJob job = new ScheduleSecHubJob() {

        public UUID getUUID() {
            return randomUUID;
        }
    };
    job.setExecutionResult(ExecutionResult.OK);
    job.setStarted(LocalDateTime.now().minusMinutes(15));
    job.setEnded(LocalDateTime.now());
    job.setExecutionState(ExecutionState.ENDED);
    job.setOwner("CREATOR1");
    job.setTrafficLight(TrafficLight.GREEN);
    ScheduleJobStatus status = new ScheduleJobStatus(job);
    when(mockedScheduleJobStatusService.getJobStatus(PROJECT1_ID, randomUUID)).thenReturn(status);
    /* execute + test @formatter:off */
    this.mockMvc.perform(put(apiEndpoint, PROJECT1_ID, randomUUID).contentType(MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk()).andDo(defineRestService().with().useCaseData(useCase).tag(RestDocFactory.extractTag(apiEndpoint)).and().document(pathParameters(parameterWithName("projectId").description("The id of the project where sechub job shall be approved"), parameterWithName("jobUUID").description(DESCRIPTION_JOB_UUID))));
/* @formatter:on */
}
Also used : UseCaseUserApprovesJob(com.mercedesbenz.sechub.sharedkernel.usecases.user.execute.UseCaseUserApprovesJob) ScheduleJobStatus(com.mercedesbenz.sechub.domain.schedule.ScheduleJobStatus) ScheduleSecHubJob(com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob) UseCaseRestDoc(com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) Test(org.junit.Test)

Aggregations

UseCaseRestDoc (com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc)37 Test (org.junit.Test)35 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)35 UUID (java.util.UUID)17 WithMockUser (org.springframework.security.test.context.support.WithMockUser)7 SchedulerResult (com.mercedesbenz.sechub.domain.schedule.SchedulerResult)5 SecHubConfiguration (com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration)5 UseCaseUserCreatesNewJob (com.mercedesbenz.sechub.sharedkernel.usecases.user.execute.UseCaseUserCreatesNewJob)5 TestExecutorConfig (com.mercedesbenz.sechub.test.executorconfig.TestExecutorConfig)5 ScheduleJobStatus (com.mercedesbenz.sechub.domain.schedule.ScheduleJobStatus)4 ScheduleSecHubJob (com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob)4 TestExecutorSetupJobParam (com.mercedesbenz.sechub.test.executorconfig.TestExecutorSetupJobParam)4 Project (com.mercedesbenz.sechub.domain.administration.project.Project)3 User (com.mercedesbenz.sechub.domain.administration.user.User)3 TestExecutionProfile (com.mercedesbenz.sechub.test.executionprofile.TestExecutionProfile)3 AdministrationAutoCleanupConfig (com.mercedesbenz.sechub.domain.administration.autocleanup.AdministrationAutoCleanupConfig)2 ProjectDetailInformation (com.mercedesbenz.sechub.domain.administration.project.ProjectDetailInformation)2 ProjectMetaDataEntity (com.mercedesbenz.sechub.domain.administration.project.ProjectMetaDataEntity)2 FalsePositiveJobData (com.mercedesbenz.sechub.domain.scan.project.FalsePositiveJobData)2 ScanMockData (com.mercedesbenz.sechub.domain.scan.project.ScanMockData)2