From ecaaeea0792e9df585428edbb9889ecc44ce2e1a Mon Sep 17 00:00:00 2001 From: Marcel Haag Date: Fri, 19 Aug 2022 13:10:32 +0200 Subject: [PATCH] fix: integration test and ascii documentation --- .../api/project/ProjectService.kt | 17 ++++++++------ .../PentestControllerDocumentationTest.kt | 8 +++---- .../ProjectControllerDocumentationTest.kt | 22 ++++++++++++++----- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/security-c4po-api/src/main/kotlin/com/securityc4po/api/project/ProjectService.kt b/security-c4po-api/src/main/kotlin/com/securityc4po/api/project/ProjectService.kt index 16a18ce..44870c3 100644 --- a/security-c4po-api/src/main/kotlin/com/securityc4po/api/project/ProjectService.kt +++ b/security-c4po-api/src/main/kotlin/com/securityc4po/api/project/ProjectService.kt @@ -72,12 +72,12 @@ class ProjectService(private val projectRepository: ProjectRepository) { * @return status code of deleted [Project] */ fun deleteProject(id: String): Mono { - return projectRepository.findProjectById(id).switchIfEmpty{ + return projectRepository.findProjectById(id).switchIfEmpty { logger.info("Project with id $id not found. Deletion not necessary.") Mono.empty() - }.flatMap{ projectEntity: ProjectEntity -> + }.flatMap { projectEntity: ProjectEntity -> val project = projectEntity.toProject() - projectRepository.deleteProjectById(id).map{project} + projectRepository.deleteProjectById(id).map { project } }.onErrorMap { TransactionInterruptedException( "Deleting Project failed!", @@ -101,15 +101,15 @@ class ProjectService(private val projectRepository: ProjectRepository) { "Project not valid.", Errorcode.ProjectInvalid ) ) - return projectRepository.findProjectById(id).switchIfEmpty{ + return projectRepository.findProjectById(id).switchIfEmpty { logger.warn("Project with id $id not found. Updating not possible.") val msg = "Project with id $id not found." val ex = EntityNotFoundException(msg, Errorcode.ProjectNotFound) throw ex - }.flatMap{projectEntity: ProjectEntity -> + }.flatMap { projectEntity: ProjectEntity -> projectEntity.lastModified = Instant.now() projectEntity.data = buildProject(body, projectEntity) - projectRepository.save(projectEntity).map{ + projectRepository.save(projectEntity).map { it.toProject() }.doOnError { throw wrappedException( @@ -130,7 +130,10 @@ class ProjectService(private val projectRepository: ProjectRepository) { * @throws [TransactionInterruptedException] if the [Project] could not be updated * @return updated list of [ProjectPentest]s */ - fun updateProjectTestingProgress(projectId: String, projectPentests: ProjectPentest)/*: Mono>*/ { + fun updateProjectTestingProgress( + projectId: String, + projectPentests: ProjectPentest + )/*: Mono>*/ { // ToDo: update Project Entity with progress } } diff --git a/security-c4po-api/src/test/kotlin/com/securityc4po/api/pentest/PentestControllerDocumentationTest.kt b/security-c4po-api/src/test/kotlin/com/securityc4po/api/pentest/PentestControllerDocumentationTest.kt index 0bedb10..09567ab 100644 --- a/security-c4po-api/src/test/kotlin/com/securityc4po/api/pentest/PentestControllerDocumentationTest.kt +++ b/security-c4po-api/src/test/kotlin/com/securityc4po/api/pentest/PentestControllerDocumentationTest.kt @@ -81,10 +81,10 @@ class PentestControllerDocumentationTest : BaseDocumentationIntTest() { .description("The reference number of the requested pentest according to the current OWASP Testing Guide"), PayloadDocumentation.fieldWithPath("[].status").type(JsonFieldType.STRING) .description("The status of the requested pentest"), - PayloadDocumentation.fieldWithPath("[].findingIds").type(JsonFieldType.STRING) - .description("The ids of the findings in the requested pentest"), - PayloadDocumentation.fieldWithPath("[].commentIds").type(JsonFieldType.STRING) - .description("The ids of the comments of the requested pentest") + PayloadDocumentation.fieldWithPath("[].findingIds").type(JsonFieldType.ARRAY) + .description("List of ids of the findings in the requested pentest"), + PayloadDocumentation.fieldWithPath("[].commentIds").type(JsonFieldType.ARRAY) + .description("List of ids of the comments of the requested pentest") ) ) ) diff --git a/security-c4po-api/src/test/kotlin/com/securityc4po/api/project/ProjectControllerDocumentationTest.kt b/security-c4po-api/src/test/kotlin/com/securityc4po/api/project/ProjectControllerDocumentationTest.kt index d89c09b..a6641e8 100644 --- a/security-c4po-api/src/test/kotlin/com/securityc4po/api/project/ProjectControllerDocumentationTest.kt +++ b/security-c4po-api/src/test/kotlin/com/securityc4po/api/project/ProjectControllerDocumentationTest.kt @@ -74,7 +74,9 @@ class ProjectControllerDocumentationTest : BaseDocumentationIntTest() { PayloadDocumentation.fieldWithPath("[].tester").type(JsonFieldType.STRING) .description("The user that is assigned as a tester in the project"), PayloadDocumentation.fieldWithPath("[].createdBy").type(JsonFieldType.STRING) - .description("The id of the user that created the project") + .description("The id of the user that created the project"), + PayloadDocumentation.fieldWithPath("[].testingProgress").type(JsonFieldType.NUMBER) + .description("The progress of the project from completed pentests") ) ) ) @@ -139,7 +141,9 @@ class ProjectControllerDocumentationTest : BaseDocumentationIntTest() { PayloadDocumentation.fieldWithPath("tester").type(JsonFieldType.STRING) .description("The user that is assigned as a tester in the project"), PayloadDocumentation.fieldWithPath("createdBy").type(JsonFieldType.STRING) - .description("The id of the user that created the project") + .description("The id of the user that created the project"), + PayloadDocumentation.fieldWithPath("testingProgress").type(JsonFieldType.NUMBER) + .description("The progress of the project from completed pentests") ) ) ) @@ -231,11 +235,11 @@ class ProjectControllerDocumentationTest : BaseDocumentationIntTest() { fun updateProject() { webTestClient.patch().uri("/projects/${projectUpdate.id}") .header("Authorization", "Bearer $tokenAdmin") - .body(Mono.just(projectUpdate), ProjectRequestBody::class.java) + .body(Mono.just(projectUpdateRequest), ProjectRequestBody::class.java) .exchange() .expectStatus().isAccepted .expectHeader().valueEquals("Application-Name", "SecurityC4PO") - .expectBody().json(Json.write(projectUpdate)) + .expectBody().json(Json.write(projectUpdate.toProjectResponseBody())) .consumeWith( WebTestClientRestDocumentation.document( "{methodName}", @@ -259,12 +263,20 @@ class ProjectControllerDocumentationTest : BaseDocumentationIntTest() { PayloadDocumentation.fieldWithPath("tester").type(JsonFieldType.STRING) .description("The updated user that is assigned as a tester in the project"), PayloadDocumentation.fieldWithPath("createdBy").type(JsonFieldType.STRING) - .description("The id of the user that created the project") + .description("The id of the user that created the project"), + PayloadDocumentation.fieldWithPath("testingProgress").type(JsonFieldType.NUMBER) + .description("The progress of the project from completed pentests") ) ) ) } + val projectUpdateRequest = ProjectRequestBody( + client = "Novatec_updated", + title = "log4j Pentest_updated", + tester = "Stipe_updated" + ) + val projectUpdate = Project( id = "4f6567a8-76fd-487b-8602-f82d0ca4d1f9", client = "Novatec_updated",