Search in sources :

Example 1 with SchedulerResult

use of com.mercedesbenz.sechub.domain.schedule.SchedulerResult 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 2 with SchedulerResult

use of com.mercedesbenz.sechub.domain.schedule.SchedulerResult in project sechub by mercedes-benz.

the class SchedulerRestControllerRestDocTest method restDoc_userCreatesNewJob_codescan.

@Test
@UseCaseRestDoc(useCase = UseCaseUserCreatesNewJob.class, variant = "Code Scan")
public void restDoc_userCreatesNewJob_codescan() 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").codeScanConfig().setFileSystemFolders("testproject1/src/main/java", "testproject2/src/main/java").build().toJSON())).andExpect(status().isOk()).andExpect(content().json("{jobId:" + randomUUID.toString() + "}")).andDo(print()).andDo(defineRestService().with().useCaseData(useCase, "Code 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_CODE_SCAN).description("Code scan configuration block").optional(), fieldWithPath(PROPERTY_CODE_SCAN + "." + SecHubDataConfigurationUsageByName.PROPERTY_USE).description("Referenced data configuration objects by their unique names").optional(), fieldWithPath(PROPERTY_CODE_SCAN + "." + SecHubCodeScanConfiguration.PROPERTY_FILESYSTEM + "." + SecHubFileSystemConfiguration.PROPERTY_FOLDERS).description("Code scan sources from given file system folders").optional(), fieldWithPath(PROPERTY_CODE_SCAN + "." + SecHubCodeScanConfiguration.PROPERTY_FILESYSTEM + "." + SecHubFileSystemConfiguration.PROPERTY_FILES).description("Code scan sources from given file system files").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 3 with SchedulerResult

use of com.mercedesbenz.sechub.domain.schedule.SchedulerResult in project sechub by mercedes-benz.

the class SchedulerRestControllerRestDocTest method restDoc_userCreatesNewJob_webscan_login_basic.

@Test
@UseCaseRestDoc(useCase = UseCaseUserCreatesNewJob.class, variant = "Web Scan login basic")
public void restDoc_userCreatesNewJob_webscan_login_basic() 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").basic("username1", "password1").build().toJSON())).andExpect(status().isOk()).andExpect(content().json("{jobId:" + randomUUID.toString() + "}")).andDo(defineRestService().with().useCaseData(useCase, "Web Scan login basic").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 + "." + WebLoginConfiguration.PROPERTY_BASIC).description("basic login definition").optional(), fieldWithPath(PROPERTY_WEB_SCAN + "." + SecHubWebScanConfiguration.PROPERTY_LOGIN + "." + WebLoginConfiguration.PROPERTY_BASIC + ".user").description("username").optional(), fieldWithPath(PROPERTY_WEB_SCAN + "." + SecHubWebScanConfiguration.PROPERTY_LOGIN + "." + WebLoginConfiguration.PROPERTY_BASIC + ".password").description("password").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 4 with SchedulerResult

use of com.mercedesbenz.sechub.domain.schedule.SchedulerResult 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 5 with SchedulerResult

use of com.mercedesbenz.sechub.domain.schedule.SchedulerResult 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)

Aggregations

SchedulerResult (com.mercedesbenz.sechub.domain.schedule.SchedulerResult)5 SecHubConfiguration (com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration)5 UseCaseRestDoc (com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc)5 UseCaseUserCreatesNewJob (com.mercedesbenz.sechub.sharedkernel.usecases.user.execute.UseCaseUserCreatesNewJob)5 UUID (java.util.UUID)5 Test (org.junit.Test)5 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)5 WebScanDurationConfiguration (com.mercedesbenz.sechub.commons.model.WebScanDurationConfiguration)1