Search in sources :

Example 16 with UseCaseRestDoc

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

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

the class ScanReportRestControllerRestDocTest method get_report_from_existing_job_returns_information_as_json_when_type_is_APPLICATION_JSON_UTF8.

@UseCaseRestDoc(useCase = UseCaseUserDownloadsJobReport.class, variant = "JSON", wanted = { SpringRestDocOutput.PATH_PARAMETERS, SpringRestDocOutput.REQUEST_FIELDS, SpringRestDocOutput.CURL_REQUEST })
@Test
@WithMockUser
public void get_report_from_existing_job_returns_information_as_json_when_type_is_APPLICATION_JSON_UTF8() throws Exception {
    /* prepare */
    String apiEndpoint = https(PORT_USED).buildGetJobReportUrl(PROJECT_ID.pathElement(), JOB_UUID.pathElement());
    Class<? extends Annotation> useCase = UseCaseUserDownloadsJobReport.class;
    ScanReport report = new ScanReport(jobUUID, PROJECT1_ID);
    report.setResult("{'count':'1'}");
    report.setTrafficLight(TrafficLight.YELLOW);
    ScanSecHubReport scanSecHubReport = new ScanSecHubReport(report);
    when(downloadReportService.getScanSecHubReport(PROJECT1_ID, jobUUID)).thenReturn(scanSecHubReport);
    /* execute + test @formatter:off */
    this.mockMvc.perform(get(apiEndpoint, PROJECT1_ID, jobUUID).accept(MediaType.APPLICATION_JSON_VALUE).contentType(MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk()).andExpect(content().json("{\"jobUUID\":\"" + jobUUID.toString() + "\",\"result\":{\"count\":0,\"findings\":[]},\"trafficLight\":\"YELLOW\"}")).andDo(defineRestService().with().useCaseData(useCase, "JSON").tag(RestDocFactory.extractTag(apiEndpoint)).responseSchema(OpenApiSchema.SECHUB_REPORT.getSchema()).and().document(pathParameters(parameterWithName(PROJECT_ID.paramName()).description("The project Id"), parameterWithName(JOB_UUID.paramName()).description("The job UUID"))));
/* @formatter:on */
}
Also used : ScanSecHubReport(com.mercedesbenz.sechub.domain.scan.report.ScanSecHubReport) ScanReport(com.mercedesbenz.sechub.domain.scan.report.ScanReport) UseCaseUserDownloadsJobReport(com.mercedesbenz.sechub.sharedkernel.usecases.user.execute.UseCaseUserDownloadsJobReport) 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 18 with UseCaseRestDoc

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

the class ScanReportRestControllerRestDocTest method get_report_from_existing_job_returns_information_as_html_when_type_is_APPLICATION_XHTML_XML.

@UseCaseRestDoc(useCase = UseCaseUserDownloadsJobReport.class, variant = "HTML", wanted = { SpringRestDocOutput.PATH_PARAMETERS, SpringRestDocOutput.REQUEST_FIELDS, SpringRestDocOutput.CURL_REQUEST })
@Test
@WithMockUser
public void get_report_from_existing_job_returns_information_as_html_when_type_is_APPLICATION_XHTML_XML() throws Exception {
    /* prepare */
    String apiEndpoint = https(PORT_USED).buildGetJobReportUrl(PROJECT_ID.pathElement(), JOB_UUID.pathElement());
    Class<? extends Annotation> useCase = UseCaseUserDownloadsJobReport.class;
    ScanReport report = new ScanReport(jobUUID, PROJECT1_ID);
    report.setResult("{'count':'1'}");
    report.setTrafficLight(TrafficLight.YELLOW);
    ScanSecHubReport scanSecHubReport = new ScanSecHubReport(report);
    when(downloadReportService.getScanSecHubReport(PROJECT1_ID, jobUUID)).thenReturn(scanSecHubReport);
    /* execute + test @formatter:off */
    this.mockMvc.perform(get(apiEndpoint, PROJECT1_ID, jobUUID).accept(MediaType.APPLICATION_XHTML_XML).contentType(MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk()).andExpect(content().contentType("text/html;charset=UTF-8")).andExpect(content().encoding("UTF-8")).andExpect(content().string(containsString(jobUUID.toString()))).andExpect(content().string(containsString("theRedStyle"))).andDo(defineRestService().with().useCaseData(useCase, "HTML").tag(RestDocFactory.extractTag(apiEndpoint)).responseSchema(OpenApiSchema.SECHUB_REPORT.getSchema()).and().document(pathParameters(parameterWithName(PROJECT_ID.paramName()).description("The project Id"), parameterWithName(JOB_UUID.paramName()).description("The job UUID"))));
/* @formatter:on */
}
Also used : ScanSecHubReport(com.mercedesbenz.sechub.domain.scan.report.ScanSecHubReport) ScanReport(com.mercedesbenz.sechub.domain.scan.report.ScanReport) UseCaseUserDownloadsJobReport(com.mercedesbenz.sechub.sharedkernel.usecases.user.execute.UseCaseUserDownloadsJobReport) 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 19 with UseCaseRestDoc

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

the class SchedulerRestControllerRestDocTest method restDoc_userCreatesNewJob_webScan_login_form_script.

@Test
@UseCaseRestDoc(useCase = UseCaseUserCreatesNewJob.class, variant = "Web Scan login form scripted")
public void restDoc_userCreatesNewJob_webScan_login_form_script() 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").webConfig().addURI("https://localhost/mywebapp").login("https://localhost/mywebapp/login").formScripted("username1", "password1").createPage().createAction().type(ActionType.USERNAME).selector("#example_login_userid").value("username1").description("the username field").add().createAction().type(ActionType.INPUT).selector("#example_login_email_id").value("user@example.com").description("The email id field.").add().add().createPage().createAction().type(ActionType.WAIT).value("2345").unit(SecHubTimeUnit.MILLISECOND).add().createAction().type(ActionType.PASSWORD).selector("#example_login_pwd").value("Super$ecret234!").add().createAction().type(ActionType.CLICK).selector("#example_login_button").add().add().done().build().toJSON())).andExpect(status().isOk()).andExpect(content().json("{jobId:" + randomUUID.toString() + "}")).andDo(defineRestService().with().useCaseData(useCase, "Web Scan login form scripted").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_LOGIN).description("Webscan login definition").optional(), fieldWithPath(PROPERTY_WEB_SCAN + "." + SecHubWebScanConfiguration.PROPERTY_LOGIN + ".url").description("Login URL").optional(), fieldWithPath(PROPERTY_WEB_SCAN + "." + SecHubWebScanConfiguration.PROPERTY_LOGIN + "." + FORM).description("form login definition").optional(), fieldWithPath(PROPERTY_WEB_SCAN + "." + SecHubWebScanConfiguration.PROPERTY_LOGIN + "." + FORM + "." + SCRIPT).description("script").optional(), fieldWithPath(PROPERTY_WEB_SCAN + "." + SecHubWebScanConfiguration.PROPERTY_LOGIN + "." + FORM + "." + SCRIPT + ".pages[].actions[].type").description("action type: username, password, input, click, wait").optional(), fieldWithPath(PROPERTY_WEB_SCAN + "." + SecHubWebScanConfiguration.PROPERTY_LOGIN + "." + FORM + "." + SCRIPT + ".pages[].actions[].selector").description("css selector").optional(), fieldWithPath(PROPERTY_WEB_SCAN + "." + SecHubWebScanConfiguration.PROPERTY_LOGIN + "." + FORM + "." + SCRIPT + ".pages[].actions[].value").description("value").optional(), fieldWithPath(PROPERTY_WEB_SCAN + "." + SecHubWebScanConfiguration.PROPERTY_LOGIN + "." + FORM + "." + SCRIPT + ".pages[].actions[].description").description("description").optional(), fieldWithPath(PROPERTY_WEB_SCAN + "." + SecHubWebScanConfiguration.PROPERTY_LOGIN + "." + FORM + "." + SCRIPT + ".pages[].actions[].unit").description("the time unit to wait: millisecond, second, minute, hour, day.").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 20 with UseCaseRestDoc

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

the class SchedulerRestControllerRestDocTest method restDoc_userChecksJobState.

@Test
@UseCaseRestDoc(useCase = UseCaseUserChecksJobStatus.class)
public void restDoc_userChecksJobState() throws Exception {
    /* prepare */
    String apiEndpoint = https(PORT_USED).buildGetJobStatusUrl(PROJECT_ID.pathElement(), JOB_UUID.pathElement());
    Class<? extends Annotation> useCase = UseCaseUserChecksJobStatus.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(get(apiEndpoint, PROJECT1_ID, randomUUID).contentType(MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk()).andExpect(content().json("{jobUUID:" + randomUUID.toString() + ", result:OK, state:ENDED, trafficLight:GREEN}")).andDo(defineRestService().with().useCaseData(useCase).tag(RestDocFactory.extractTag(apiEndpoint)).responseSchema(OpenApiSchema.JOB_STATUS.getSchema()).and().document(pathParameters(parameterWithName("projectId").description("The id of the project where sechub job was started for"), parameterWithName("jobUUID").description(DESCRIPTION_JOB_UUID)), responseFields(fieldWithPath(ScheduleJobStatus.PROPERTY_JOBUUID).description("The job uuid"), fieldWithPath(ScheduleJobStatus.PROPERTY_CREATED).description("Creation timestamp of job"), fieldWithPath(ScheduleJobStatus.PROPERTY_STARTED).description("Start timestamp of job execution"), fieldWithPath(ScheduleJobStatus.PROPERTY_ENDED).description("End timestamp of job execution"), fieldWithPath(ScheduleJobStatus.PROPERTY_OWNER).description("Owner / initiator of job"), fieldWithPath(ScheduleJobStatus.PROPERTY_STATE).description("State of job"), fieldWithPath(ScheduleJobStatus.PROPERTY_RESULT).description("Result of job"), fieldWithPath(ScheduleJobStatus.PROPERTY_TRAFFICLIGHT).description("Trafficlight of job - but only available when job has been done. Possible states are " + StringUtils.arrayToDelimitedString(TrafficLight.values(), ", ")))));
/* @formatter:on */
}
Also used : UseCaseUserChecksJobStatus(com.mercedesbenz.sechub.sharedkernel.usecases.user.execute.UseCaseUserChecksJobStatus) 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