Search in sources :

Example 21 with UseCaseRestDoc

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

the class SchedulerRestControllerRestDocTest method restDoc_userUploadsBinaries.

@Test
@UseCaseRestDoc(useCase = UseCaseUserUploadsBinaries.class)
public void restDoc_userUploadsBinaries() throws Exception {
    /* prepare */
    String apiEndpoint = https(PORT_USED).buildUploadBinariesUrl(PROJECT_ID.pathElement(), JOB_UUID.pathElement());
    Class<? extends Annotation> useCase = UseCaseUserUploadsBinaries.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.INITIALIZING);
    job.setOwner("CREATOR1");
    job.setTrafficLight(TrafficLight.GREEN);
    ScheduleJobStatus status = new ScheduleJobStatus(job);
    when(mockedScheduleJobStatusService.getJobStatus(PROJECT1_ID, randomUUID)).thenReturn(status);
    InputStream inputStreamTo = RestDocTestFileSupport.getTestfileSupport().getInputStreamTo("upload/tarfile_contains_only_test1.txt.tar");
    MockMultipartFile file1 = new MockMultipartFile("file", inputStreamTo);
    /* execute + test @formatter:off */
    this.mockMvc.perform(multipart(apiEndpoint, PROJECT1_ID, randomUUID).file(file1).param("checkSum", "mychecksum")).andExpect(status().isOk()).andDo(defineRestService().with().useCaseData(useCase).tag(RestDocFactory.extractTag(apiEndpoint)).and().document(pathParameters(parameterWithName("projectId").description("The id of the project for which the binaries are uploaded for"), parameterWithName("jobUUID").description(DESCRIPTION_JOB_UUID)), requestParameters(parameterWithName("checkSum").description("A sha256 checksum for file upload validation")), // See: https://github.com/ePages-de/restdocs-api-spec/issues/105
    requestParts(partWithName("file").description("The binaries as tarfile to upload"))));
/* @formatter:on */
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) InputStream(java.io.InputStream) UseCaseUserUploadsBinaries(com.mercedesbenz.sechub.sharedkernel.usecases.user.execute.UseCaseUserUploadsBinaries) 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)

Example 22 with UseCaseRestDoc

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

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

the class SchedulerRestControllerRestDocTest method restDoc_userUploadsSourceCode.

@Test
@UseCaseRestDoc(useCase = UseCaseUserUploadsSourceCode.class)
public void restDoc_userUploadsSourceCode() throws Exception {
    /* prepare */
    String apiEndpoint = https(PORT_USED).buildUploadSourceCodeUrl(PROJECT_ID.pathElement(), JOB_UUID.pathElement());
    Class<? extends Annotation> useCase = UseCaseUserUploadsSourceCode.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.INITIALIZING);
    job.setOwner("CREATOR1");
    job.setTrafficLight(TrafficLight.GREEN);
    ScheduleJobStatus status = new ScheduleJobStatus(job);
    when(mockedScheduleJobStatusService.getJobStatus(PROJECT1_ID, randomUUID)).thenReturn(status);
    InputStream inputStreamTo = RestDocTestFileSupport.getTestfileSupport().getInputStreamTo("upload/zipfile_contains_only_test1.txt.zip");
    MockMultipartFile file1 = new MockMultipartFile("file", inputStreamTo);
    /* execute + test @formatter:off */
    this.mockMvc.perform(multipart(apiEndpoint, PROJECT1_ID, randomUUID).file(file1).param("checkSum", "mychecksum")).andExpect(status().isOk()).andDo(defineRestService().with().useCaseData(useCase).tag(RestDocFactory.extractTag(apiEndpoint)).and().document(pathParameters(parameterWithName("projectId").description("The id of the project where sourcecode shall be uploaded for"), parameterWithName("jobUUID").description(DESCRIPTION_JOB_UUID)), requestParameters(parameterWithName("checkSum").description("A sha256 checksum for file upload validation")), // See: https://github.com/ePages-de/restdocs-api-spec/issues/105
    requestParts(partWithName("file").description("The sourcecode as zipfile to upload"))));
/* @formatter:on */
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) InputStream(java.io.InputStream) ScheduleJobStatus(com.mercedesbenz.sechub.domain.schedule.ScheduleJobStatus) ScheduleSecHubJob(com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob) UseCaseUserUploadsSourceCode(com.mercedesbenz.sechub.sharedkernel.usecases.user.execute.UseCaseUserUploadsSourceCode) UseCaseRestDoc(com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) Test(org.junit.Test)

Example 24 with UseCaseRestDoc

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

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

the class SignupAdministrationRestControllerRestDocTest method restdoc_list_user_signups.

@Test
@UseCaseRestDoc(useCase = UseCaseAdminListsOpenUserSignups.class)
public void restdoc_list_user_signups() throws Exception {
    /* prepare */
    String apiEndpoint = https(PORT_USED).buildAdminListsUserSignupsUrl();
    Class<? extends Annotation> useCase = UseCaseAdminListsOpenUserSignups.class;
    Signup signup1 = new Signup();
    signup1.setEmailAdress("john.smith@example.com");
    signup1.setUserId("johnsmith");
    Signup signup2 = new Signup();
    signup2.setEmailAdress("jane.smith@example.com");
    signup2.setUserId("janesmith");
    List<Signup> signupList = new ArrayList<>();
    signupList.add(signup1);
    signupList.add(signup2);
    when(signupRepository.findAll()).thenReturn(signupList);
    /* execute + test @formatter:off */
    this.mockMvc.perform(get(apiEndpoint)).andExpect(status().isOk()).andExpect(content().json("[{\"userId\":\"johnsmith\",\"emailAdress\":\"john.smith@example.com\"},{\"userId\":\"janesmith\",\"emailAdress\":\"jane.smith@example.com\"}]")).andDo(defineRestService().with().useCaseData(useCase).tag(RestDocFactory.extractTag(apiEndpoint)).responseSchema(OpenApiSchema.SIGNUP_LIST.getSchema()).and().document(responseFields(fieldWithPath("[]").description("List of user signups").optional(), fieldWithPath("[]." + RestDocPathParameter.USER_ID.paramName()).type(JsonFieldType.STRING).description("The user id"), fieldWithPath("[].emailAdress").type(JsonFieldType.STRING).description("The email address"))));
/* @formatter:on */
}
Also used : Signup(com.mercedesbenz.sechub.domain.administration.signup.Signup) UseCaseAdminDeletesSignup(com.mercedesbenz.sechub.sharedkernel.usecases.admin.signup.UseCaseAdminDeletesSignup) UseCaseAdminListsOpenUserSignups(com.mercedesbenz.sechub.sharedkernel.usecases.admin.signup.UseCaseAdminListsOpenUserSignups) ArrayList(java.util.ArrayList) UseCaseRestDoc(com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

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