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