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 */
}
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 */
}
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 */
}
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 */
}
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 */
}
Aggregations