diff --git a/api/build.gradle.kts b/api/build.gradle.kts index ebaafb8e7..746f5d2b7 100644 --- a/api/build.gradle.kts +++ b/api/build.gradle.kts @@ -71,7 +71,8 @@ tasks.register("copySubProjectsOpenAPIFiles") { into("${layout.buildDirectory.get()}/tmp/openapi") } else { logger.warn( - "Unable to find OpenAPI definitions in project dependencies => 'copySubProjectsOpenAPIFiles' not configured!") + "Unable to find OpenAPI definitions in project dependencies => 'copySubProjectsOpenAPIFiles' not configured!" + ) } } @@ -114,7 +115,8 @@ tasks.register("openApiTypescriptGenerate") { additionalProperties.set( mapOf( "npmName" to "@cosmotech/api-ts", - )) + ) + ) } tasks.register("copyTypescriptGitPushScript") { @@ -155,7 +157,9 @@ tasks.register("openApiPythonGenerate") { mapOf( "projectName" to "cosmotech-api", "packageName" to "cosmotech_api", - "pythonAttrNoneIfUnset" to true)) + "pythonAttrNoneIfUnset" to true, + ) + ) } // PROD-14252: temporary fix waiting for upstream resolution of @@ -233,7 +237,8 @@ tasks.register("generateClients") { "generateTypescriptClient", "generatePythonClient", "openApiUmlGenerate", - "openApiMarkdownGenerate") + "openApiMarkdownGenerate", + ) } tasks.getByName("bootJar") { finalizedBy("generateClients") } @@ -260,5 +265,7 @@ tasks.register("generateDocumentation") { "disallowAdditionalPropertiesIfNotPresent" to false, "infoEmail" to "platform@cosmotech.com", "snippetDir" to "${rootDir}/doc/generated-snippets/", - "infoUrl" to "https://github.com/Cosmo-Tech/cosmotech-api")) + "infoUrl" to "https://github.com/Cosmo-Tech/cosmotech-api", + ) + ) } diff --git a/api/src/integrationTest/kotlin/com/cosmotech/api/home/ControllerTestBase.kt b/api/src/integrationTest/kotlin/com/cosmotech/api/home/ControllerTestBase.kt index 8110948a1..eb6fcdd47 100644 --- a/api/src/integrationTest/kotlin/com/cosmotech/api/home/ControllerTestBase.kt +++ b/api/src/integrationTest/kotlin/com/cosmotech/api/home/ControllerTestBase.kt @@ -80,7 +80,8 @@ abstract class ControllerTestBase : AbstractTestcontainersRedisTestBase() { ${response.contentAsString} """ - .trimIndent()) + .trimIndent() + ) } } .apply(springSecurity()) @@ -91,7 +92,8 @@ abstract class ControllerTestBase : AbstractTestcontainersRedisTestBase() { modifyHeaders().remove(HttpHeaders.CONTENT_LENGTH), modifyHeaders().remove(PLATFORM_ADMIN_EMAIL), modifyHeaders().remove(ORGANIZATION_USER_EMAIL), - prettyPrint()) + prettyPrint(), + ) .withResponseDefaults( modifyHeaders() .remove("X-Content-Type-Options") @@ -99,18 +101,22 @@ abstract class ControllerTestBase : AbstractTestcontainersRedisTestBase() { .remove("X-Frame-Options") .remove(HttpHeaders.CONTENT_LENGTH) .remove(HttpHeaders.CACHE_CONTROL), - prettyPrint())) + prettyPrint(), + ) + ) .build() } companion object { private const val DEFAULT_REDIS_PORT = 6379 - private const val LOCALSTACK_FULL_IMAGE_NAME = "localstack/localstack:3.5.0" + private const val LOCALSTACK_FULL_IMAGE_NAME = "localstack/localstack:latest" var postgres: PostgreSQLContainer<*> = - PostgreSQLContainer("postgres:alpine3.19") + PostgreSQLContainer("postgres:latest") .withCopyFileToContainer( - MountableFile.forClasspathResource("init-db.sql"), "/docker-entrypoint-initdb.d/") + MountableFile.forClasspathResource("init-db.sql"), + "/docker-entrypoint-initdb.d/", + ) var redisStackServer = RedisStackContainer(RedisStackContainer.DEFAULT_IMAGE_NAME) diff --git a/api/src/integrationTest/kotlin/com/cosmotech/api/home/ControllerTestUtils.kt b/api/src/integrationTest/kotlin/com/cosmotech/api/home/ControllerTestUtils.kt index 0616d7c39..d08ab68dd 100644 --- a/api/src/integrationTest/kotlin/com/cosmotech/api/home/ControllerTestUtils.kt +++ b/api/src/integrationTest/kotlin/com/cosmotech/api/home/ControllerTestUtils.kt @@ -46,7 +46,7 @@ class ControllerTestUtils { @JvmStatic fun createOrganizationAndReturnId( mvc: MockMvc, - organizationCreateRequest: OrganizationCreateRequest + organizationCreateRequest: OrganizationCreateRequest, ): String = JSONObject( mvc.perform( @@ -55,16 +55,18 @@ class ControllerTestUtils { .contentType(MediaType.APPLICATION_JSON) .content(JSONObject(organizationCreateRequest).toString()) .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andReturn() .response - .contentAsString) + .contentAsString + ) .getString("id") @JvmStatic fun constructOrganizationCreateRequest( name: String = ORGANIZATION_NAME, - security: OrganizationSecurity? = null + security: OrganizationSecurity? = null, ): OrganizationCreateRequest { return OrganizationCreateRequest(name = name, security = security) } @@ -76,7 +78,7 @@ class ControllerTestUtils { fun createSolutionAndReturnId( mvc: MockMvc, organizationId: String, - solutionCreateRequest: SolutionCreateRequest + solutionCreateRequest: SolutionCreateRequest, ): String = JSONObject( mvc.perform( @@ -85,10 +87,12 @@ class ControllerTestUtils { .contentType(MediaType.APPLICATION_JSON) .content(JSONObject(solutionCreateRequest).toString()) .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andReturn() .response - .contentAsString) + .contentAsString + ) .getString("id") @JvmStatic @@ -104,7 +108,7 @@ class ControllerTestUtils { parameterGroups: MutableList = mutableListOf(), runTemplates: MutableList = mutableListOf(), url: String = "", - security: SolutionSecurity? = null + security: SolutionSecurity? = null, ): SolutionCreateRequest { return SolutionCreateRequest( key = key, @@ -141,7 +145,8 @@ class ControllerTestUtils { description = description, alwaysPull = alwaysPull, tags = tags, - url = url) + url = url, + ) } } @@ -152,7 +157,7 @@ class ControllerTestUtils { mvc: MockMvc, organizationId: String, workspaceId: String, - runnerCreateRequest: RunnerCreateRequest + runnerCreateRequest: RunnerCreateRequest, ): String = JSONObject( mvc.perform( @@ -161,10 +166,12 @@ class ControllerTestUtils { .contentType(MediaType.APPLICATION_JSON) .content(JSONObject(runnerCreateRequest).toString()) .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andReturn() .response - .contentAsString) + .contentAsString + ) .getString("id") @JvmStatic @@ -197,7 +204,8 @@ class ControllerTestUtils { runTemplateName = runTemplateName, security = security, runSizing = runSizing, - parametersValues = parametersValues) + parametersValues = parametersValues, + ) } @JvmStatic @@ -224,7 +232,8 @@ class ControllerTestUtils { parametersValues = parametersValues, additionalData = additionalData, solutionName = solutionName, - runTemplateName = runTemplateName) + runTemplateName = runTemplateName, + ) } } @@ -236,7 +245,7 @@ class ControllerTestUtils { organizationId: String, workspaceKey: String, workspaceName: String, - solutionId: String + solutionId: String, ): String = JSONObject( mvc.perform( @@ -248,20 +257,25 @@ class ControllerTestUtils { constructWorkspaceCreateRequest( key = workspaceKey, name = workspaceName, - solutionId = solutionId)) - .toString()) + solutionId = solutionId, + ) + ) + .toString() + ) .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andReturn() .response - .contentAsString) + .contentAsString + ) .getString("id") @JvmStatic fun createWorkspaceAndReturnId( mvc: MockMvc, organizationId: String, - workspaceCreateRequest: WorkspaceCreateRequest + workspaceCreateRequest: WorkspaceCreateRequest, ): String = JSONObject( mvc.perform( @@ -270,10 +284,12 @@ class ControllerTestUtils { .contentType(MediaType.APPLICATION_JSON) .content(JSONObject(workspaceCreateRequest).toString()) .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andReturn() .response - .contentAsString) + .contentAsString + ) .getString("id") @JvmStatic @@ -288,7 +304,7 @@ class ControllerTestUtils { datasetCopy: Boolean? = null, security: WorkspaceSecurity? = null, additionalData: MutableMap = mutableMapOf(), - tags: MutableList = mutableListOf() + tags: MutableList = mutableListOf(), ): WorkspaceCreateRequest { return WorkspaceCreateRequest( key = key, @@ -297,13 +313,15 @@ class ControllerTestUtils { WorkspaceSolution( solutionId = solutionId, datasetId = datasetId, - defaultParameterValues = defaultParameterValues), + defaultParameterValues = defaultParameterValues, + ), description = description, version = version, datasetCopy = datasetCopy, security = security, tags = tags, - additionalData = additionalData) + additionalData = additionalData, + ) } @JvmStatic @@ -316,7 +334,7 @@ class ControllerTestUtils { description: String = "", datasetCopy: Boolean? = null, additionalData: MutableMap = mutableMapOf(), - tags: MutableList = mutableListOf() + tags: MutableList = mutableListOf(), ): WorkspaceUpdateRequest { return WorkspaceUpdateRequest( @@ -326,11 +344,13 @@ class ControllerTestUtils { WorkspaceSolution( solutionId = solutionId, datasetId = datasetId, - defaultParameterValues = defaultParameterValues), + defaultParameterValues = defaultParameterValues, + ), description = description, datasetCopy = datasetCopy, tags = tags, - additionalData = additionalData) + additionalData = additionalData, + ) } } @@ -347,20 +367,23 @@ class ControllerTestUtils { val fileToUpload = this::class.java.getResourceAsStream("/dataset/$TEST_FILE_NAME") ?: throw IllegalStateException( - "$TEST_FILE_NAME file used for endpoints test documentation cannot be null") + "$TEST_FILE_NAME file used for endpoints test documentation cannot be null" + ) val datasetCreateRequestFile = MockMultipartFile( "datasetCreateRequest", null, MediaType.APPLICATION_JSON_VALUE, - JSONObject(datasetCreateRequest).toString().byteInputStream()) + JSONObject(datasetCreateRequest).toString().byteInputStream(), + ) val files = MockMultipartFile( "files", TEST_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToUpload)) + IOUtils.toByteArray(fileToUpload), + ) return JSONObject( mvc.perform( multipart("/organizations/$organizationId/workspaces/$workspaceId/datasets") @@ -368,10 +391,12 @@ class ControllerTestUtils { .file(files) .withPlatformAdminHeader() .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andReturn() .response - .contentAsString) + .contentAsString + ) .getString("id") } @@ -386,13 +411,16 @@ class ControllerTestUtils { JSONObject( mvc.perform( get( - "/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId") + "/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId" + ) .withPlatformAdminHeader() .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andReturn() .response - .contentAsString) + .contentAsString + ) .getJSONArray("parts") return Array(parts.length()) { i -> parts.getJSONObject(i).getString("id") } @@ -410,32 +438,38 @@ class ControllerTestUtils { val fileToUpload = this::class.java.getResourceAsStream("/dataset/$TEST_FILE_NAME") ?: throw IllegalStateException( - "$TEST_FILE_NAME file used for endpoints test documentation cannot be null") + "$TEST_FILE_NAME file used for endpoints test documentation cannot be null" + ) val datasetPartCreateRequestFile = MockMultipartFile( "datasetPartCreateRequest", null, MediaType.APPLICATION_JSON_VALUE, - JSONObject(datasetPartCreateRequest).toString().byteInputStream()) + JSONObject(datasetPartCreateRequest).toString().byteInputStream(), + ) val file = MockMultipartFile( "file", TEST_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToUpload)) + IOUtils.toByteArray(fileToUpload), + ) return JSONObject( mvc.perform( multipart( - "/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId/parts") + "/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId/parts" + ) .file(datasetPartCreateRequestFile) .file(file) .withPlatformAdminHeader() .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andReturn() .response - .contentAsString) + .contentAsString + ) .getString("id") } @@ -459,13 +493,16 @@ class ControllerTestUtils { tags = mutableListOf("tag_part1", "tag_part2"), additionalData = mutableMapOf("customClient" to "customDatasetPartData"), type = type, - sourceName = sourceName)), - security = security) + sourceName = sourceName, + ) + ), + security = security, + ) } fun constructDatasetPartCreateRequest( name: String = DATASET_PART_NAME, - type: DatasetPartTypeEnum = DatasetPartTypeEnum.File + type: DatasetPartTypeEnum = DatasetPartTypeEnum.File, ): DatasetPartCreateRequest { return DatasetPartCreateRequest( name = name, @@ -473,7 +510,8 @@ class ControllerTestUtils { tags = mutableListOf("tag_part1", "tag_part3"), additionalData = mutableMapOf("customClient" to "customDatasetPartData"), type = type, - sourceName = TEST_FILE_NAME) + sourceName = TEST_FILE_NAME, + ) } } } diff --git a/api/src/integrationTest/kotlin/com/cosmotech/api/home/dataset/DatasetControllerTests.kt b/api/src/integrationTest/kotlin/com/cosmotech/api/home/dataset/DatasetControllerTests.kt index af1338dee..dec9a1e3e 100644 --- a/api/src/integrationTest/kotlin/com/cosmotech/api/home/dataset/DatasetControllerTests.kt +++ b/api/src/integrationTest/kotlin/com/cosmotech/api/home/dataset/DatasetControllerTests.kt @@ -44,7 +44,6 @@ import com.cosmotech.dataset.domain.DatasetSecurity import com.cosmotech.dataset.domain.DatasetUpdateRequest import com.cosmotech.solution.domain.RunTemplateCreateRequest import com.cosmotech.solution.domain.RunTemplateResourceSizing -import java.io.InputStream import kotlin.test.assertEquals import org.apache.commons.io.IOUtils import org.hamcrest.Matchers.empty @@ -86,7 +85,8 @@ class DatasetControllerTests : ControllerTestBase() { val runTemplateRunSizing = RunTemplateResourceSizing( com.cosmotech.solution.domain.ResourceSizeInfo("cpu_requests", "memory_requests"), - com.cosmotech.solution.domain.ResourceSizeInfo("cpu_limits", "memory_limits")) + com.cosmotech.solution.domain.ResourceSizeInfo("cpu_limits", "memory_limits"), + ) val runTemplates = mutableListOf( @@ -99,74 +99,102 @@ class DatasetControllerTests : ControllerTestBase() { RUN_TEMPLATE_COMPUTE_SIZE, runTemplateRunSizing, mutableListOf(PARAMETER_GROUP_ID), - 10)) + 10, + ) + ) organizationId = createOrganizationAndReturnId(mvc, constructOrganizationCreateRequest()) solutionId = createSolutionAndReturnId( - mvc, organizationId, constructSolutionCreateRequest(runTemplates = runTemplates)) + mvc, + organizationId, + constructSolutionCreateRequest(runTemplates = runTemplates), + ) workspaceId = createWorkspaceAndReturnId( - mvc, organizationId, constructWorkspaceCreateRequest(solutionId = solutionId)) + mvc, + organizationId, + constructWorkspaceCreateRequest(solutionId = solutionId), + ) } @Test fun get_dataset_part_with_wrong_ids_format() { mvc.perform( get( - "/organizations/wrong-orgId/workspaces/wrong-workspaceId/datasets/wrong-datasetId/parts/wrong-datasetPartId") + "/organizations/wrong-orgId/workspaces/wrong-workspaceId/datasets/wrong-datasetId/parts/wrong-datasetPartId" + ) .contentType(MediaType.APPLICATION_JSON) .withPlatformAdminHeader() - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().isBadRequest) .andExpect(jsonPath("$.detail", containsString("wrong-orgId:must match \"^o-\\w{10,20}\""))) .andExpect( - jsonPath("$.detail", containsString("wrong-workspaceId:must match \"^w-\\w{10,20}\""))) + jsonPath("$.detail", containsString("wrong-workspaceId:must match \"^w-\\w{10,20}\"")) + ) .andExpect( - jsonPath("$.detail", containsString("wrong-datasetId:must match \"^d-\\w{10,20}\""))) + jsonPath("$.detail", containsString("wrong-datasetId:must match \"^d-\\w{10,20}\"")) + ) .andExpect( jsonPath( - "$.detail", containsString("wrong-datasetPartId:must match \"^dp-\\w{10,20}\""))) + "$.detail", + containsString("wrong-datasetPartId:must match \"^dp-\\w{10,20}\""), + ) + ) mvc.perform( get( - "/organizations/wrong-orgId/workspaces/w-123456abcdef/datasets/d-123456azerty/parts/dp-123456azert") + "/organizations/wrong-orgId/workspaces/w-123456abcdef/datasets/d-123456azerty/parts/dp-123456azert" + ) .contentType(MediaType.APPLICATION_JSON) .withPlatformAdminHeader() - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().isBadRequest) .andExpect(jsonPath("$.detail", containsString("wrong-orgId:must match \"^o-\\w{10,20}\""))) mvc.perform( get( - "/organizations/o-1233456azer/workspaces/wrong-workspaceId/datasets/d-123456azerty/parts/dp-123456azert") + "/organizations/o-1233456azer/workspaces/wrong-workspaceId/datasets/d-123456azerty/parts/dp-123456azert" + ) .contentType(MediaType.APPLICATION_JSON) .withPlatformAdminHeader() - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().isBadRequest) .andExpect( - jsonPath("$.detail", containsString("wrong-workspaceId:must match \"^w-\\w{10,20}\""))) + jsonPath("$.detail", containsString("wrong-workspaceId:must match \"^w-\\w{10,20}\"")) + ) mvc.perform( get( - "/organizations/o-1233456azer/workspaces/w-123456abcdef/datasets/wrong-datasetId/parts/dp-123456azert") + "/organizations/o-1233456azer/workspaces/w-123456abcdef/datasets/wrong-datasetId/parts/dp-123456azert" + ) .contentType(MediaType.APPLICATION_JSON) .withPlatformAdminHeader() - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().isBadRequest) .andExpect( - jsonPath("$.detail", containsString("wrong-datasetId:must match \"^d-\\w{10,20}\""))) + jsonPath("$.detail", containsString("wrong-datasetId:must match \"^d-\\w{10,20}\"")) + ) mvc.perform( get( - "/organizations/o-1233456azer/workspaces/w-123456abcdef/datasets/d-123456azerty/parts/wrong-datasetPartId") + "/organizations/o-1233456azer/workspaces/w-123456abcdef/datasets/d-123456azerty/parts/wrong-datasetPartId" + ) .contentType(MediaType.APPLICATION_JSON) .withPlatformAdminHeader() - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().isBadRequest) .andExpect( jsonPath( - "$.detail", containsString("wrong-datasetPartId:must match \"^dp-\\w{10,20}\""))) + "$.detail", + containsString("wrong-datasetPartId:must match \"^dp-\\w{10,20}\""), + ) + ) } @Test @@ -176,25 +204,29 @@ class DatasetControllerTests : ControllerTestBase() { "datasetCreateRequest", null, MediaType.APPLICATION_JSON_VALUE, - JSONObject(constructDatasetCreateRequest()).toString().byteInputStream()) + JSONObject(constructDatasetCreateRequest()).toString().byteInputStream(), + ) val fileToUpload = this::class.java.getResourceAsStream("/dataset/$TEST_FILE_NAME") ?: throw IllegalStateException( - "$TEST_FILE_NAME file used for organizations/{organization_id}/workspaces/{workspace_id}/datasets/POST endpoint documentation cannot be null") + "$TEST_FILE_NAME file used for organizations/{organization_id}/workspaces/{workspace_id}/datasets/POST endpoint documentation cannot be null" + ) val files = MockMultipartFile( "files", TEST_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToUpload)) + IOUtils.toByteArray(fileToUpload), + ) mvc.perform( multipart("/organizations/$organizationId/workspaces/$workspaceId/datasets") .file(datasetCreateRequest) .file(files) .withPlatformAdminHeader() .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.name").value(DATASET_NAME)) .andExpect(jsonPath("$.description").value(DATASET_DESCRIPTION)) @@ -238,16 +270,20 @@ class DatasetControllerTests : ControllerTestBase() { DatasetCreateRequest( name = DATASET_NAME, description = DATASET_DESCRIPTION, - tags = mutableListOf("tag1", "tag2"))) + tags = mutableListOf("tag1", "tag2"), + ) + ) .toString() - .byteInputStream()) + .byteInputStream(), + ) mvc.perform( multipart("/organizations/$organizationId/workspaces/$workspaceId/datasets") .file(datasetCreateRequest) .withPlatformAdminHeader() .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.name").value(DATASET_NAME)) .andExpect(jsonPath("$.description").value(DATASET_DESCRIPTION)) @@ -279,16 +315,20 @@ class DatasetControllerTests : ControllerTestBase() { name = DATASET_NAME, description = DATASET_DESCRIPTION, tags = mutableListOf("tag1", "tag2"), - parts = mutableListOf())) + parts = mutableListOf(), + ) + ) .toString() - .byteInputStream()) + .byteInputStream(), + ) mvc.perform( multipart("/organizations/$organizationId/workspaces/$workspaceId/datasets") .file(datasetCreateRequest) .accept(MediaType.APPLICATION_JSON) .withPlatformAdminHeader() - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.name").value(DATASET_NAME)) .andExpect(jsonPath("$.description").value(DATASET_DESCRIPTION)) @@ -315,18 +355,26 @@ class DatasetControllerTests : ControllerTestBase() { createDatasetAndReturnId(mvc, organizationId, workspaceId, constructDatasetCreateRequest()) val datasetPartId = createDatasetPartAndReturnId( - mvc, organizationId, workspaceId, datasetId, constructDatasetPartCreateRequest()) + mvc, + organizationId, + workspaceId, + datasetId, + constructDatasetPartCreateRequest(), + ) val fileUploaded = this::class.java.getResourceAsStream("/dataset/$TEST_FILE_NAME") ?: throw IllegalStateException( - "$TEST_FILE_NAME file used for endpoints test documentation cannot be null") + "$TEST_FILE_NAME file used for endpoints test documentation cannot be null" + ) mvc.perform( get( - "/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId/parts/$datasetPartId/download") + "/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId/parts/$datasetPartId/download" + ) .accept(MediaType.APPLICATION_OCTET_STREAM) - .withPlatformAdminHeader()) + .withPlatformAdminHeader() + ) .andExpect(status().is2xxSuccessful) .andExpect { result -> result.response.contentAsString == fileUploaded.bufferedReader().readText() @@ -334,7 +382,9 @@ class DatasetControllerTests : ControllerTestBase() { .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/parts/{dataset_part_id}/download/GET")) + "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/parts/{dataset_part_id}/download/GET" + ) + ) } @Test @@ -345,7 +395,8 @@ class DatasetControllerTests : ControllerTestBase() { mvc.perform( get("/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId") .withPlatformAdminHeader() - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.name").value(DATASET_NAME)) .andExpect(jsonPath("$.description").value(DATASET_DESCRIPTION)) @@ -377,7 +428,9 @@ class DatasetControllerTests : ControllerTestBase() { .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/GET")) + "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/GET" + ) + ) } @Test @@ -390,12 +443,15 @@ class DatasetControllerTests : ControllerTestBase() { delete("/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId") .accept(MediaType.APPLICATION_JSON) .withPlatformAdminHeader() - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/DELETE")) + "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/DELETE" + ) + ) } @Test @@ -406,7 +462,8 @@ class DatasetControllerTests : ControllerTestBase() { mvc.perform( post( - "/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId/security/access") + "/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId/security/access" + ) .contentType(MediaType.APPLICATION_JSON) .withPlatformAdminHeader() .content( @@ -414,17 +471,22 @@ class DatasetControllerTests : ControllerTestBase() { DatasetAccessControl( role = ROLE_ADMIN, id = ORGANIZATION_USER_EMAIL, - )) - .toString()) + ) + ) + .toString() + ) .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.role").value(ROLE_ADMIN)) .andExpect(jsonPath("$.id").value(ORGANIZATION_USER_EMAIL)) .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/security/access/POST")) + "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/security/access/POST" + ) + ) } @Test @@ -436,27 +498,34 @@ class DatasetControllerTests : ControllerTestBase() { accessControlList = mutableListOf( DatasetAccessControl(role = ROLE_ADMIN, id = PLATFORM_ADMIN_EMAIL), - DatasetAccessControl(role = ROLE_EDITOR, id = ORGANIZATION_USER_EMAIL))) + DatasetAccessControl(role = ROLE_EDITOR, id = ORGANIZATION_USER_EMAIL), + ), + ) val datasetId = createDatasetAndReturnId( mvc, organizationId, workspaceId, - constructDatasetCreateRequest(security = datasetSecurity)) + constructDatasetCreateRequest(security = datasetSecurity), + ) mvc.perform( get( - "/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId/security/access/$ORGANIZATION_USER_EMAIL") + "/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId/security/access/$ORGANIZATION_USER_EMAIL" + ) .withPlatformAdminHeader() - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.role").value(ROLE_EDITOR)) .andExpect(jsonPath("$.id").value(ORGANIZATION_USER_EMAIL)) .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/security/access/{identity_id}/GET")) + "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/security/access/{identity_id}/GET" + ) + ) } @Test @@ -468,26 +537,33 @@ class DatasetControllerTests : ControllerTestBase() { accessControlList = mutableListOf( DatasetAccessControl(role = ROLE_ADMIN, id = PLATFORM_ADMIN_EMAIL), - DatasetAccessControl(role = ROLE_EDITOR, id = ORGANIZATION_USER_EMAIL))) + DatasetAccessControl(role = ROLE_EDITOR, id = ORGANIZATION_USER_EMAIL), + ), + ) val datasetId = createDatasetAndReturnId( mvc, organizationId, workspaceId, - constructDatasetCreateRequest(security = datasetSecurity)) + constructDatasetCreateRequest(security = datasetSecurity), + ) mvc.perform( delete( - "/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId/security/access/$ORGANIZATION_USER_EMAIL") + "/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId/security/access/$ORGANIZATION_USER_EMAIL" + ) .withPlatformAdminHeader() .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/security/access/{identity_id}/DELETE")) + "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/security/access/{identity_id}/DELETE" + ) + ) } @Test @@ -499,28 +575,33 @@ class DatasetControllerTests : ControllerTestBase() { val fileToUpload = this::class.java.getResourceAsStream("/dataset/$TEST_FILE_NAME") ?: throw IllegalStateException( - "$TEST_FILE_NAME file used for organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/parts/POST endpoint documentation cannot be null") + "$TEST_FILE_NAME file used for organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/parts/POST endpoint documentation cannot be null" + ) val file = MockMultipartFile( "file", TEST_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToUpload)) + IOUtils.toByteArray(fileToUpload), + ) val datasetPartCreateRequest = MockMultipartFile( "datasetPartCreateRequest", null, MediaType.APPLICATION_JSON_VALUE, - JSONObject(constructDatasetPartCreateRequest()).toString().byteInputStream()) + JSONObject(constructDatasetPartCreateRequest()).toString().byteInputStream(), + ) mvc.perform( multipart( - "/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId/parts") + "/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId/parts" + ) .file(file) .file(datasetPartCreateRequest) .withPlatformAdminHeader() .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.name").value(DATASET_PART_NAME)) .andExpect(jsonPath("$.description").value(DATASET_PART_DESCRIPTION)) @@ -539,7 +620,9 @@ class DatasetControllerTests : ControllerTestBase() { .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/parts/POST")) + "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/parts/POST" + ) + ) } @Test @@ -550,19 +633,28 @@ class DatasetControllerTests : ControllerTestBase() { val datasetPartId = createDatasetPartAndReturnId( - mvc, organizationId, workspaceId, datasetId, constructDatasetPartCreateRequest()) + mvc, + organizationId, + workspaceId, + datasetId, + constructDatasetPartCreateRequest(), + ) mvc.perform( delete( - "/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId/parts/$datasetPartId") + "/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId/parts/$datasetPartId" + ) .withPlatformAdminHeader() .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/parts/{dataset_part_id}/DELETE")) + "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/parts/{dataset_part_id}/DELETE" + ) + ) } @Test @@ -573,13 +665,20 @@ class DatasetControllerTests : ControllerTestBase() { val datasetPartId = createDatasetPartAndReturnId( - mvc, organizationId, workspaceId, datasetId, constructDatasetPartCreateRequest()) + mvc, + organizationId, + workspaceId, + datasetId, + constructDatasetPartCreateRequest(), + ) mvc.perform( get( - "/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId/parts/$datasetPartId") + "/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId/parts/$datasetPartId" + ) .withPlatformAdminHeader() - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.id").value(datasetPartId)) .andExpect(jsonPath("$.name").value(DATASET_PART_NAME)) @@ -599,7 +698,9 @@ class DatasetControllerTests : ControllerTestBase() { .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/parts/{dataset_part_id}/GET")) + "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/parts/{dataset_part_id}/GET" + ) + ) } @Test @@ -610,11 +711,17 @@ class DatasetControllerTests : ControllerTestBase() { val datasetPartId = createDatasetPartAndReturnId( - mvc, organizationId, workspaceId, datasetId, constructDatasetPartCreateRequest()) + mvc, + organizationId, + workspaceId, + datasetId, + constructDatasetPartCreateRequest(), + ) mvc.perform( get("/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId/parts") .withPlatformAdminHeader() - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$[0].name").value(DATASET_PART_NAME)) .andExpect(jsonPath("$[0].description").value(DATASET_PART_DESCRIPTION)) @@ -648,7 +755,9 @@ class DatasetControllerTests : ControllerTestBase() { .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/parts/GET")) + "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/parts/GET" + ) + ) } @Test @@ -659,16 +768,23 @@ class DatasetControllerTests : ControllerTestBase() { val datasetPartId = createDatasetPartAndReturnId( - mvc, organizationId, workspaceId, datasetId, constructDatasetPartCreateRequest()) + mvc, + organizationId, + workspaceId, + datasetId, + constructDatasetPartCreateRequest(), + ) mvc.perform( post( - "/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId/parts/search") + "/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId/parts/search" + ) .contentType(MediaType.APPLICATION_JSON) .withPlatformAdminHeader() .content(JSONArray(listOf("tag_part3")).toString()) .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andDo(MockMvcResultHandlers.print()) .andExpect(jsonPath("$[0].id").value(datasetPartId)) @@ -686,7 +802,9 @@ class DatasetControllerTests : ControllerTestBase() { .andExpect(jsonPath("$[0].updateInfo.timestamp").value(greaterThan(0.toLong()))) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/parts/search/POST")) + "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/parts/search/POST" + ) + ) } @Test @@ -705,20 +823,31 @@ class DatasetControllerTests : ControllerTestBase() { mutableListOf( DatasetAccessControl(id = PLATFORM_ADMIN_EMAIL, role = ROLE_ADMIN), DatasetAccessControl( - id = ORGANIZATION_USER_EMAIL, role = ROLE_EDITOR))))) + id = ORGANIZATION_USER_EMAIL, + role = ROLE_EDITOR, + ), + ), + ) + ), + ) mvc.perform( get( - "/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId/security/users") + "/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId/security/users" + ) .withPlatformAdminHeader() - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().is2xxSuccessful) .andDo(MockMvcResultHandlers.print()) .andExpect( - jsonPath("$").value(mutableListOf(PLATFORM_ADMIN_EMAIL, ORGANIZATION_USER_EMAIL))) + jsonPath("$").value(mutableListOf(PLATFORM_ADMIN_EMAIL, ORGANIZATION_USER_EMAIL)) + ) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/security/users/GET")) + "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/security/users/GET" + ) + ) } @Test @@ -730,7 +859,8 @@ class DatasetControllerTests : ControllerTestBase() { mvc.perform( get("/organizations/$organizationId/workspaces/$workspaceId/datasets") .withPlatformAdminHeader() - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().is2xxSuccessful) .andDo(MockMvcResultHandlers.print()) .andExpect(jsonPath("$[0].id").value(datasetId)) @@ -776,7 +906,8 @@ class DatasetControllerTests : ControllerTestBase() { .content(JSONArray(listOf("tag1")).toString()) .withPlatformAdminHeader() .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andDo(MockMvcResultHandlers.print()) .andExpect(jsonPath("$[0].id").value(datasetId)) @@ -809,7 +940,9 @@ class DatasetControllerTests : ControllerTestBase() { .andExpect(jsonPath("$[0].security.accessControlList[0].id").value(PLATFORM_ADMIN_EMAIL)) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/datasets/search/POST")) + "organizations/{organization_id}/workspaces/{workspace_id}/datasets/search/POST" + ) + ) } @Test @@ -821,21 +954,27 @@ class DatasetControllerTests : ControllerTestBase() { MediaType.APPLICATION_JSON_VALUE, JSONObject( constructDatasetCreateRequest( - type = DatasetPartTypeEnum.DB, sourceName = CUSTOMERS_FILE_NAME)) + type = DatasetPartTypeEnum.DB, + sourceName = CUSTOMERS_FILE_NAME, + ) + ) .toString() - .byteInputStream()) + .byteInputStream(), + ) val fileToUpload = this::class.java.getResourceAsStream("/dataset/$CUSTOMERS_FILE_NAME") ?: throw IllegalStateException( - "$CUSTOMERS_FILE_NAME file used for organizations/{organization_id}/workspaces/{workspace_id}/datasets/POST endpoint documentation should exist") + "$CUSTOMERS_FILE_NAME file used for organizations/{organization_id}/workspaces/{workspace_id}/datasets/POST endpoint documentation should exist" + ) val files = MockMultipartFile( "files", CUSTOMERS_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToUpload)) + IOUtils.toByteArray(fileToUpload), + ) val datasetCreated = JSONObject( @@ -845,11 +984,13 @@ class DatasetControllerTests : ControllerTestBase() { .file(files) .withPlatformAdminHeader() .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andReturn() .response - .contentAsString) + .contentAsString + ) val datasetPartId = datasetCreated.getJSONArray("parts").getJSONObject(0).get("id") @@ -858,14 +999,18 @@ class DatasetControllerTests : ControllerTestBase() { val valueRetrieved = mvc.perform( get( - "/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId/parts/$datasetPartId/query") + "/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId/parts/$datasetPartId/query" + ) .withPlatformAdminHeader() - .accept(MediaType.APPLICATION_OCTET_STREAM)) + .accept(MediaType.APPLICATION_OCTET_STREAM) + ) .andExpect(status().is2xxSuccessful) .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/parts/{dataset_part_id}/query/GET")) + "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/parts/{dataset_part_id}/query/GET" + ) + ) .andReturn() .response .contentAsString @@ -886,7 +1031,12 @@ class DatasetControllerTests : ControllerTestBase() { val datasetPartId = createDatasetPartAndReturnId( - mvc, organizationId, workspaceId, datasetId, constructDatasetPartCreateRequest()) + mvc, + organizationId, + workspaceId, + datasetId, + constructDatasetPartCreateRequest(), + ) val newSourceName = "source_name_updated.csv" val newDescription = "this_a_new_description_for_dataset_part" @@ -899,16 +1049,26 @@ class DatasetControllerTests : ControllerTestBase() { MediaType.APPLICATION_JSON_VALUE, JSONObject( DatasetPartUpdateRequest( - sourceName = newSourceName, description = newDescription, tags = newTags)) + sourceName = newSourceName, + description = newDescription, + tags = newTags, + ) + ) .toString() - .byteInputStream()) + .byteInputStream(), + ) val newFile = MockMultipartFile( - "file", "test.csv", MediaType.MULTIPART_FORM_DATA_VALUE, InputStream.nullInputStream()) + "file", + "test.csv", + MediaType.MULTIPART_FORM_DATA_VALUE, + " ".toByteArray(), + ) mvc.perform( multipart( - "/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId/parts/$datasetPartId") + "/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId/parts/$datasetPartId" + ) .file(datasetPartUpdateRequest) .file(newFile) .withPlatformAdminHeader() @@ -920,7 +1080,8 @@ class DatasetControllerTests : ControllerTestBase() { .with { request -> request.method = "PUT" request - }) + } + ) .andExpect(status().is2xxSuccessful) .andDo(MockMvcResultHandlers.print()) .andExpect(jsonPath("$.id").value(datasetPartId)) @@ -940,7 +1101,9 @@ class DatasetControllerTests : ControllerTestBase() { .andExpect(jsonPath("$.datasetId").value(datasetId)) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/parts/{dataset_part_id}/PUT")) + "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/parts/{dataset_part_id}/PUT" + ) + ) } @Test @@ -951,7 +1114,12 @@ class DatasetControllerTests : ControllerTestBase() { val datasetPartId = createDatasetPartAndReturnId( - mvc, organizationId, workspaceId, datasetId, constructDatasetPartCreateRequest()) + mvc, + organizationId, + workspaceId, + datasetId, + constructDatasetPartCreateRequest(), + ) val newSourceName = "source_name_updated.csv" val newDescription = "this_a_new_description_for_dataset_part" @@ -959,18 +1127,23 @@ class DatasetControllerTests : ControllerTestBase() { mvc.perform( patch( - "/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId/parts/$datasetPartId") + "/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId/parts/$datasetPartId" + ) .content( JSONObject( DatasetPartUpdateRequest( sourceName = newSourceName, description = newDescription, - tags = newTags)) - .toString()) + tags = newTags, + ) + ) + .toString() + ) .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andDo(MockMvcResultHandlers.print()) .andExpect(jsonPath("$.id").value(datasetPartId)) @@ -990,7 +1163,9 @@ class DatasetControllerTests : ControllerTestBase() { .andExpect(jsonPath("$.datasetId").value(datasetId)) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/parts/{dataset_part_id}/PATCH")) + "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/parts/{dataset_part_id}/PATCH" + ) + ) } @Test @@ -1008,7 +1183,13 @@ class DatasetControllerTests : ControllerTestBase() { mutableListOf( DatasetAccessControl(id = PLATFORM_ADMIN_EMAIL, role = ROLE_ADMIN), DatasetAccessControl( - id = ORGANIZATION_USER_EMAIL, role = ROLE_EDITOR))))) + id = ORGANIZATION_USER_EMAIL, + role = ROLE_EDITOR, + ), + ), + ) + ), + ) val newName = "this_a_new_name_for_dataset" val newDescription = "this_a_new_description_for_dataset" @@ -1021,7 +1202,8 @@ class DatasetControllerTests : ControllerTestBase() { val fileToUpload = this::class.java.getResourceAsStream("/dataset/$TEST_FILE_NAME") ?: throw IllegalStateException( - "$TEST_FILE_NAME file used for organizations/{organization_id}/workspaces/{workspace_id}/datasets/POST endpoint documentation cannot be null") + "$TEST_FILE_NAME file used for organizations/{organization_id}/workspaces/{workspace_id}/datasets/POST endpoint documentation cannot be null" + ) val datasetUpdateRequest = DatasetUpdateRequest( @@ -1035,20 +1217,25 @@ class DatasetControllerTests : ControllerTestBase() { sourceName = TEST_FILE_NAME, description = newPartDescription, tags = newPartTags, - type = DatasetPartTypeEnum.File))) + type = DatasetPartTypeEnum.File, + ) + ), + ) val datasetUpdateRequestMultipartFile = MockMultipartFile( "datasetUpdateRequest", null, MediaType.APPLICATION_JSON_VALUE, - JSONObject(datasetUpdateRequest).toString().byteInputStream()) + JSONObject(datasetUpdateRequest).toString().byteInputStream(), + ) val newFile = MockMultipartFile( "files", TEST_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToUpload)) + IOUtils.toByteArray(fileToUpload), + ) mvc.perform( multipart("/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId") @@ -1063,7 +1250,8 @@ class DatasetControllerTests : ControllerTestBase() { .with { request -> request.method = "PATCH" request - }) + } + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.name").value(newName)) .andExpect(jsonPath("$.description").value(newDescription)) @@ -1097,7 +1285,9 @@ class DatasetControllerTests : ControllerTestBase() { .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/PATCH")) + "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/PATCH" + ) + ) } @Test @@ -1115,7 +1305,13 @@ class DatasetControllerTests : ControllerTestBase() { mutableListOf( DatasetAccessControl(id = PLATFORM_ADMIN_EMAIL, role = ROLE_ADMIN), DatasetAccessControl( - id = ORGANIZATION_USER_EMAIL, role = ROLE_EDITOR))))) + id = ORGANIZATION_USER_EMAIL, + role = ROLE_EDITOR, + ), + ), + ) + ), + ) val newName = "this_a_new_name_for_dataset" val newDescription = "this_a_new_description_for_dataset" @@ -1129,7 +1325,8 @@ class DatasetControllerTests : ControllerTestBase() { "datasetUpdateRequest", null, MediaType.APPLICATION_JSON_VALUE, - JSONObject(datasetUpdateRequest).toString().byteInputStream()) + JSONObject(datasetUpdateRequest).toString().byteInputStream(), + ) mvc.perform( multipart("/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId") .file(datasetUpdateRequestMultipartFile) @@ -1142,7 +1339,8 @@ class DatasetControllerTests : ControllerTestBase() { .with { request -> request.method = "PATCH" request - }) + } + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.name").value(newName)) .andExpect(jsonPath("$.description").value(newDescription)) @@ -1191,7 +1389,13 @@ class DatasetControllerTests : ControllerTestBase() { mutableListOf( DatasetAccessControl(id = PLATFORM_ADMIN_EMAIL, role = ROLE_ADMIN), DatasetAccessControl( - id = ORGANIZATION_USER_EMAIL, role = ROLE_EDITOR))))) + id = ORGANIZATION_USER_EMAIL, + role = ROLE_EDITOR, + ), + ), + ) + ), + ) val newName = "this_a_new_name_for_dataset" val newDescription = "this_a_new_description_for_dataset" @@ -1199,14 +1403,19 @@ class DatasetControllerTests : ControllerTestBase() { val datasetUpdateRequest = DatasetUpdateRequest( - name = newName, description = newDescription, tags = newTags, parts = mutableListOf()) + name = newName, + description = newDescription, + tags = newTags, + parts = mutableListOf(), + ) val datasetUpdateRequestMultipartFile = MockMultipartFile( "datasetUpdateRequest", null, MediaType.APPLICATION_JSON_VALUE, - JSONObject(datasetUpdateRequest).toString().byteInputStream()) + JSONObject(datasetUpdateRequest).toString().byteInputStream(), + ) mvc.perform( multipart("/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId") .file(datasetUpdateRequestMultipartFile) @@ -1219,7 +1428,8 @@ class DatasetControllerTests : ControllerTestBase() { .with { request -> request.method = "PATCH" request - }) + } + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.name").value(newName)) .andExpect(jsonPath("$.description").value(newDescription)) @@ -1257,23 +1467,33 @@ class DatasetControllerTests : ControllerTestBase() { mutableListOf( DatasetAccessControl(id = PLATFORM_ADMIN_EMAIL, role = ROLE_ADMIN), DatasetAccessControl( - id = ORGANIZATION_USER_EMAIL, role = ROLE_EDITOR))))) + id = ORGANIZATION_USER_EMAIL, + role = ROLE_EDITOR, + ), + ), + ) + ), + ) mvc.perform( patch( - "/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId/security/access/$ORGANIZATION_USER_EMAIL") + "/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId/security/access/$ORGANIZATION_USER_EMAIL" + ) .contentType(MediaType.APPLICATION_JSON) .withPlatformAdminHeader() .content(JSONObject(DatasetRole(role = ROLE_ADMIN)).toString()) .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.role").value(ROLE_ADMIN)) .andExpect(jsonPath("$.id").value(ORGANIZATION_USER_EMAIL)) .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/security/access/{identity_id}/PATCH")) + "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/security/access/{identity_id}/PATCH" + ) + ) } @Test @@ -1284,12 +1504,14 @@ class DatasetControllerTests : ControllerTestBase() { mvc.perform( patch( - "/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId/security/default") + "/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId/security/default" + ) .contentType(MediaType.APPLICATION_JSON) .withPlatformAdminHeader() .content(JSONObject(DatasetRole(role = ROLE_VIEWER)).toString()) .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.default").value(ROLE_VIEWER)) .andExpect(jsonPath("$.accessControlList[0].id").value(PLATFORM_ADMIN_EMAIL)) @@ -1297,6 +1519,8 @@ class DatasetControllerTests : ControllerTestBase() { .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/security/default/PATCH")) + "organizations/{organization_id}/workspaces/{workspace_id}/datasets/{dataset_id}/security/default/PATCH" + ) + ) } } diff --git a/api/src/integrationTest/kotlin/com/cosmotech/api/home/organization/OrganizationControllerTests.kt b/api/src/integrationTest/kotlin/com/cosmotech/api/home/organization/OrganizationControllerTests.kt index eaf799cfd..d3dc19a21 100644 --- a/api/src/integrationTest/kotlin/com/cosmotech/api/home/organization/OrganizationControllerTests.kt +++ b/api/src/integrationTest/kotlin/com/cosmotech/api/home/organization/OrganizationControllerTests.kt @@ -47,7 +47,8 @@ class OrganizationControllerTests : ControllerTestBase() { .content(MINIMAL_ORGANIZATION_REQUEST_CREATION) .withPlatformAdminHeader() .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.name").value(ORGANIZATION_NAME)) .andExpect(jsonPath("$.createInfo.userId").value(PLATFORM_ADMIN_EMAIL)) @@ -64,7 +65,8 @@ class OrganizationControllerTests : ControllerTestBase() { get("/organizations/wrongid-format") .contentType(MediaType.APPLICATION_JSON) .withPlatformAdminHeader() - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().isBadRequest) .andExpect(jsonPath("$.detail").value("wrongid-format:must match \"^o-\\w{10,20}\"")) } @@ -77,7 +79,8 @@ class OrganizationControllerTests : ControllerTestBase() { .content(ORGANIZATION_REQUEST_CREATION_WITH_ACCESSES) .withPlatformAdminHeader() .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.name").value(ORGANIZATION_NAME)) .andExpect(jsonPath("$.createInfo.userId").value(PLATFORM_ADMIN_EMAIL)) @@ -102,7 +105,8 @@ class OrganizationControllerTests : ControllerTestBase() { .content(MINIMAL_ORGANIZATION_REQUEST_UPDATE) .withPlatformAdminHeader() .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.name").value(NEW_ORGANIZATION_NAME)) .andExpect(jsonPath("$.createInfo.userId").value(PLATFORM_ADMIN_EMAIL)) @@ -119,16 +123,21 @@ class OrganizationControllerTests : ControllerTestBase() { val firstOrganizationId = createOrganizationAndReturnId( - mvc, constructOrganizationCreateRequest("my_first_organization")) + mvc, + constructOrganizationCreateRequest("my_first_organization"), + ) val secondOrganizationId = createOrganizationAndReturnId( - mvc, constructOrganizationCreateRequest("my_second_organization")) + mvc, + constructOrganizationCreateRequest("my_second_organization"), + ) mvc.perform( get("/organizations") .contentType(MediaType.APPLICATION_JSON) .withPlatformAdminHeader() - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$[0].id").value(firstOrganizationId)) .andExpect(jsonPath("$[0].name").value("my_first_organization")) @@ -156,7 +165,8 @@ class OrganizationControllerTests : ControllerTestBase() { mvc.perform( get("/organizations/$organizationId") .contentType(MediaType.APPLICATION_JSON) - .withPlatformAdminHeader()) + .withPlatformAdminHeader() + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.name").value(ORGANIZATION_NAME)) .andExpect(jsonPath("$.createInfo.userId").value(PLATFORM_ADMIN_EMAIL)) @@ -187,7 +197,8 @@ class OrganizationControllerTests : ControllerTestBase() { mvc.perform( get("/organizations/$organizationId/security") .contentType(MediaType.APPLICATION_JSON) - .withPlatformAdminHeader()) + .withPlatformAdminHeader() + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.default").value(ROLE_NONE)) .andExpect(jsonPath("$.accessControlList[0].role").value(ROLE_ADMIN)) @@ -207,7 +218,8 @@ class OrganizationControllerTests : ControllerTestBase() { .withPlatformAdminHeader() .content(MINIMAL_ORGANIZATION_ACCESS_CONTROL_REQUEST) .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.role").value(NEW_USER_ROLE)) .andExpect(jsonPath("$.id").value(NEW_USER_ID)) @@ -223,7 +235,8 @@ class OrganizationControllerTests : ControllerTestBase() { mvc.perform( get("/organizations/$organizationId/security/access/$PLATFORM_ADMIN_EMAIL") .contentType(MediaType.APPLICATION_JSON) - .withPlatformAdminHeader()) + .withPlatformAdminHeader() + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.role").value(ROLE_ADMIN)) .andExpect(jsonPath("$.id").value(PLATFORM_ADMIN_EMAIL)) @@ -242,10 +255,12 @@ class OrganizationControllerTests : ControllerTestBase() { .withPlatformAdminHeader() .content(ORGANIZATION_REQUEST_CREATION_WITH_ACCESSES) .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andReturn() .response - .contentAsString) + .contentAsString + ) .getString("id") mvc.perform( @@ -254,7 +269,8 @@ class OrganizationControllerTests : ControllerTestBase() { .withPlatformAdminHeader() .content("""{"role":"$ROLE_VIEWER"}""") .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.role").value(ROLE_VIEWER)) .andExpect(jsonPath("$.id").value(NEW_USER_ID)) @@ -273,17 +289,20 @@ class OrganizationControllerTests : ControllerTestBase() { .withPlatformAdminHeader() .content(ORGANIZATION_REQUEST_CREATION_WITH_ACCESSES) .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andReturn() .response - .contentAsString) + .contentAsString + ) .getString("id") mvc.perform( delete("/organizations/$organizationId/security/access/$NEW_USER_ID") .contentType(MediaType.APPLICATION_JSON) .withPlatformAdminHeader() - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andDo(MockMvcResultHandlers.print()) .andDo(document("organizations/{organization_id}/security/access/{identity_id}/DELETE")) @@ -300,10 +319,12 @@ class OrganizationControllerTests : ControllerTestBase() { .withPlatformAdminHeader() .content(MINIMAL_ORGANIZATION_REQUEST_CREATION) .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andReturn() .response - .contentAsString) + .contentAsString + ) .getString("id") mvc.perform( @@ -312,7 +333,8 @@ class OrganizationControllerTests : ControllerTestBase() { .withPlatformAdminHeader() .content("""{"role":"$ROLE_VIEWER"}""") .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.default").value(ROLE_VIEWER)) .andExpect(jsonPath("$.accessControlList[0].id").value(PLATFORM_ADMIN_EMAIL)) @@ -332,17 +354,20 @@ class OrganizationControllerTests : ControllerTestBase() { .withPlatformAdminHeader() .content(ORGANIZATION_REQUEST_CREATION_WITH_ACCESSES) .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andReturn() .response - .contentAsString) + .contentAsString + ) .getString("id") mvc.perform( get("/organizations/$organizationId/security/users") .contentType(MediaType.APPLICATION_JSON) .withPlatformAdminHeader() - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$[0]").value(PLATFORM_ADMIN_EMAIL)) .andExpect(jsonPath("$[1]").value(NEW_USER_ID)) @@ -358,7 +383,8 @@ class OrganizationControllerTests : ControllerTestBase() { .withPlatformAdminHeader() .content(EMPTY_NAME_ORGANIZATION_REQUEST_CREATION) .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is4xxClientError) .andExpect(status().isBadRequest) .andExpect(content().string(emptyNameOrganizationCreationRequestError)) @@ -372,7 +398,8 @@ class OrganizationControllerTests : ControllerTestBase() { .contentType(MediaType.APPLICATION_JSON) .withOrganizationUserHeader() .content(MINIMAL_ORGANIZATION_REQUEST_CREATION) - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().isForbidden) .andDo(MockMvcResultHandlers.print()) } @@ -384,7 +411,8 @@ class OrganizationControllerTests : ControllerTestBase() { .contentType(MediaType.APPLICATION_JSON) .withOrganizationUserHeader() .content(MINIMAL_ORGANIZATION_REQUEST_CREATION) - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().isForbidden) .andDo(MockMvcResultHandlers.print()) } diff --git a/api/src/integrationTest/kotlin/com/cosmotech/api/home/run/RunControllerTests.kt b/api/src/integrationTest/kotlin/com/cosmotech/api/home/run/RunControllerTests.kt index 70a166e45..acfa40d1c 100644 --- a/api/src/integrationTest/kotlin/com/cosmotech/api/home/run/RunControllerTests.kt +++ b/api/src/integrationTest/kotlin/com/cosmotech/api/home/run/RunControllerTests.kt @@ -109,7 +109,8 @@ class RunControllerTests : ControllerTestBase() { val runTemplateRunSizing = RunTemplateResourceSizing( com.cosmotech.solution.domain.ResourceSizeInfo("cpu_requests", "memory_requests"), - com.cosmotech.solution.domain.ResourceSizeInfo("cpu_limits", "memory_limits")) + com.cosmotech.solution.domain.ResourceSizeInfo("cpu_limits", "memory_limits"), + ) val runTemplates = mutableListOf( @@ -122,15 +123,23 @@ class RunControllerTests : ControllerTestBase() { RUN_TEMPLATE_COMPUTE_SIZE, runTemplateRunSizing, mutableListOf(PARAMETER_GROUP_ID), - 10)) + 10, + ) + ) organizationId = createOrganizationAndReturnId(mvc, constructOrganizationCreateRequest()) solutionId = createSolutionAndReturnId( - mvc, organizationId, constructSolutionCreateRequest(runTemplates = runTemplates)) + mvc, + organizationId, + constructSolutionCreateRequest(runTemplates = runTemplates), + ) workspaceId = createWorkspaceAndReturnId( - mvc, organizationId, constructWorkspaceCreateRequest(solutionId = solutionId)) + mvc, + organizationId, + constructWorkspaceCreateRequest(solutionId = solutionId), + ) runnerId = createRunnerAndReturnId( @@ -152,7 +161,9 @@ class RunControllerTests : ControllerTestBase() { cpu = "1Gi", memory = "1Gi", ), - ))) + ), + ), + ) every { workflowService.launchRun(any(), any(), any(), any()) } returns mockRun(organizationId, workspaceId, solutionId) @@ -161,15 +172,18 @@ class RunControllerTests : ControllerTestBase() { JSONObject( mvc.perform( post( - "/organizations/$organizationId/workspaces/$workspaceId/runners/$runnerId/start") + "/organizations/$organizationId/workspaces/$workspaceId/runners/$runnerId/start" + ) .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andReturn() .response - .contentAsString) + .contentAsString + ) .getString("id") } @@ -177,86 +191,110 @@ class RunControllerTests : ControllerTestBase() { fun get_run_with_wrong_ids_format() { mvc.perform( get( - "/organizations/wrong-orgId/workspaces/wrong-workspaceId/runners/wrong-runnerId/runs/wrong-runId") + "/organizations/wrong-orgId/workspaces/wrong-workspaceId/runners/wrong-runnerId/runs/wrong-runId" + ) .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().isBadRequest) .andExpect(jsonPath("$.detail", containsString("wrong-orgId:must match \"^o-\\w{10,20}\""))) .andExpect( - jsonPath("$.detail", containsString("wrong-workspaceId:must match \"^w-\\w{10,20}\""))) + jsonPath("$.detail", containsString("wrong-workspaceId:must match \"^w-\\w{10,20}\"")) + ) .andExpect( - jsonPath("$.detail", containsString("wrong-runnerId:must match \"^(r|s)-\\w{10,20}\""))) + jsonPath("$.detail", containsString("wrong-runnerId:must match \"^(r|s)-\\w{10,20}\"")) + ) .andExpect( - jsonPath("$.detail", containsString("wrong-runId:must match \"^(run|sr)-\\w{10,20}\""))) + jsonPath("$.detail", containsString("wrong-runId:must match \"^(run|sr)-\\w{10,20}\"")) + ) mvc.perform( get( - "/organizations/wrong-orgId/workspaces/w-123456abcdef/runners/r-123456azerty/runs/run-123456azerty") + "/organizations/wrong-orgId/workspaces/w-123456abcdef/runners/r-123456azerty/runs/run-123456azerty" + ) .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().isBadRequest) .andExpect(jsonPath("$.detail", containsString("wrong-orgId:must match \"^o-\\w{10,20}\""))) mvc.perform( get( - "/organizations/wrong-orgId/workspaces/w-123456abcdef/runners/s-123456azerty/runs/run-123456azerty") + "/organizations/wrong-orgId/workspaces/w-123456abcdef/runners/s-123456azerty/runs/run-123456azerty" + ) .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().isBadRequest) .andExpect(jsonPath("$.detail", containsString("wrong-orgId:must match \"^o-\\w{10,20}\""))) mvc.perform( get( - "/organizations/o-1233456azer/workspaces/wrong-workspaceId/runners/r-123456azerty/runs/run-123456azerty") + "/organizations/o-1233456azer/workspaces/wrong-workspaceId/runners/r-123456azerty/runs/run-123456azerty" + ) .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().isBadRequest) .andExpect( - jsonPath("$.detail", containsString("wrong-workspaceId:must match \"^w-\\w{10,20}\""))) + jsonPath("$.detail", containsString("wrong-workspaceId:must match \"^w-\\w{10,20}\"")) + ) mvc.perform( get( - "/organizations/o-1233456azer/workspaces/wrong-workspaceId/runners/s-123456azerty/runs/run-123456azerty") + "/organizations/o-1233456azer/workspaces/wrong-workspaceId/runners/s-123456azerty/runs/run-123456azerty" + ) .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().isBadRequest) .andExpect( - jsonPath("$.detail", containsString("wrong-workspaceId:must match \"^w-\\w{10,20}\""))) + jsonPath("$.detail", containsString("wrong-workspaceId:must match \"^w-\\w{10,20}\"")) + ) mvc.perform( get( - "/organizations/o-1233456azer/workspaces/w-123456abcdef/runners/wrong-runnerId/runs/run-123456azerty") + "/organizations/o-1233456azer/workspaces/w-123456abcdef/runners/wrong-runnerId/runs/run-123456azerty" + ) .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().isBadRequest) .andExpect( - jsonPath("$.detail", containsString("wrong-runnerId:must match \"^(r|s)-\\w{10,20}\""))) + jsonPath("$.detail", containsString("wrong-runnerId:must match \"^(r|s)-\\w{10,20}\"")) + ) mvc.perform( get( - "/organizations/o-1233456azer/workspaces/w-123456abcdef/runners/r-123456azerty/runs/wrong-runId") + "/organizations/o-1233456azer/workspaces/w-123456abcdef/runners/r-123456azerty/runs/wrong-runId" + ) .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().isBadRequest) .andExpect( - jsonPath("$.detail", containsString("wrong-runId:must match \"^(run|sr)-\\w{10,20}\""))) + jsonPath("$.detail", containsString("wrong-runId:must match \"^(run|sr)-\\w{10,20}\"")) + ) mvc.perform( get( - "/organizations/o-1233456azer/workspaces/w-123456abcdef/runners/s-123456azerty/runs/wrong-runId") + "/organizations/o-1233456azer/workspaces/w-123456abcdef/runners/s-123456azerty/runs/wrong-runId" + ) .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().isBadRequest) .andExpect( - jsonPath("$.detail", containsString("wrong-runId:must match \"^(run|sr)-\\w{10,20}\""))) + jsonPath("$.detail", containsString("wrong-runId:must match \"^(run|sr)-\\w{10,20}\"")) + ) } @Test @@ -272,7 +310,8 @@ class RunControllerTests : ControllerTestBase() { .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$[0].id").value(runId)) .andExpect(jsonPath("$[0].state").value(RunState.Successful.toString())) @@ -293,7 +332,9 @@ class RunControllerTests : ControllerTestBase() { .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/runs/GET")) + "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/runs/GET" + ) + ) } @Test @@ -306,10 +347,12 @@ class RunControllerTests : ControllerTestBase() { mvc.perform( get( - "/organizations/$organizationId/workspaces/$workspaceId/runners/$runnerId/runs/$runId") + "/organizations/$organizationId/workspaces/$workspaceId/runners/$runnerId/runs/$runId" + ) .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.state").value(RunState.Successful.toString())) .andExpect(jsonPath("$.organizationId").value(organizationId)) @@ -329,7 +372,9 @@ class RunControllerTests : ControllerTestBase() { .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/runs/{run_id}/GET")) + "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/runs/{run_id}/GET" + ) + ) } @Test @@ -351,25 +396,31 @@ class RunControllerTests : ControllerTestBase() { mvc.perform( delete( - "/organizations/$organizationId/workspaces/$workspaceId/runners/$runnerId/runs/$runId") + "/organizations/$organizationId/workspaces/$workspaceId/runners/$runnerId/runs/$runId" + ) .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/runs/{run_id}/DELETE")) + "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/runs/{run_id}/DELETE" + ) + ) } @Test fun get_run_logs() { val logs = - """This is the first line of a log entry - |This is the second line of a log entry - |This is the third line of a log entry""" + """ + |This is the first line of a log entry + |This is the second line of a log entry + |This is the third line of a log entry + """ .trimMargin() every { workflowService.getRunningLogs(any()) } returns logs @@ -381,15 +432,19 @@ class RunControllerTests : ControllerTestBase() { mvc.perform( get( - "/organizations/$organizationId/workspaces/$workspaceId/runners/$runnerId/runs/$runId/logs") + "/organizations/$organizationId/workspaces/$workspaceId/runners/$runnerId/runs/$runId/logs" + ) .withPlatformAdminHeader() - .accept(MediaType.TEXT_PLAIN)) + .accept(MediaType.TEXT_PLAIN) + ) .andExpect(status().is2xxSuccessful) .andExpect(content().string(logs)) .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/runs/{run_id}/logs/GET")) + "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/runs/{run_id}/logs/GET" + ) + ) } @Test @@ -424,15 +479,19 @@ class RunControllerTests : ControllerTestBase() { progress = NODE_PROGRESS, startTime = Date.from(Instant.now()).toString(), endTime = Date.from(Instant.now()).toString(), - )), - state = RunState.Successful) + ) + ), + state = RunState.Successful, + ) mvc.perform( get( - "/organizations/$organizationId/workspaces/$workspaceId/runners/$runnerId/runs/$runId/status") + "/organizations/$organizationId/workspaces/$workspaceId/runners/$runnerId/runs/$runId/status" + ) .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.id").value(runId)) .andExpect(jsonPath("$.organizationId").value(organizationId)) @@ -458,7 +517,9 @@ class RunControllerTests : ControllerTestBase() { .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/runs/{run_id}/status/GET")) + "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/runs/{run_id}/status/GET" + ) + ) } private fun mockRun(organizationId: String, workspaceId: String, solutionId: String) = @@ -483,7 +544,8 @@ class RunControllerTests : ControllerTestBase() { parameterId = RUN_TEMPLATE_PARAMETER_ID, value = RUN_TEMPLATE_VALUE, varType = RUN_TEMPLATE_VAR_TYPE, - )), + ) + ), nodeLabel = NODE_LABEL, containers = mutableListOf( @@ -509,6 +571,10 @@ class RunControllerTests : ControllerTestBase() { ContainerResourceSizeInfo( cpu = "1Gi", memory = "1Gi", - )))), - runnerId = runnerId) + ), + ), + ) + ), + runnerId = runnerId, + ) } diff --git a/api/src/integrationTest/kotlin/com/cosmotech/api/home/runner/RunnerControllerTests.kt b/api/src/integrationTest/kotlin/com/cosmotech/api/home/runner/RunnerControllerTests.kt index 54af213c8..ec4bad673 100644 --- a/api/src/integrationTest/kotlin/com/cosmotech/api/home/runner/RunnerControllerTests.kt +++ b/api/src/integrationTest/kotlin/com/cosmotech/api/home/runner/RunnerControllerTests.kt @@ -87,7 +87,8 @@ class RunnerControllerTests : ControllerTestBase() { val runTemplateRunSizing = RunTemplateResourceSizing( com.cosmotech.solution.domain.ResourceSizeInfo("cpu_requests", "memory_requests"), - com.cosmotech.solution.domain.ResourceSizeInfo("cpu_limits", "memory_limits")) + com.cosmotech.solution.domain.ResourceSizeInfo("cpu_limits", "memory_limits"), + ) val parametersList = mutableListOf( @@ -100,13 +101,16 @@ class RunnerControllerTests : ControllerTestBase() { id = solutionParameterId2, varType = DATASET_PART_VARTYPE_FILE, defaultValue = solutionParameterDefaultValue2, - )) + ), + ) val parameterGroups = mutableListOf( RunTemplateParameterGroupCreateRequest( id = parameterGroupId, - parameters = mutableListOf(solutionParameterId1, solutionParameterId2))) + parameters = mutableListOf(solutionParameterId1, solutionParameterId2), + ) + ) val runTemplates = mutableListOf( RunTemplateCreateRequest( @@ -118,7 +122,9 @@ class RunnerControllerTests : ControllerTestBase() { runTemplateComputeSize, runTemplateRunSizing, mutableListOf(parameterGroupId), - 10)) + 10, + ) + ) organizationId = createOrganizationAndReturnId(mvc, constructOrganizationCreateRequest()) solutionId = @@ -128,17 +134,23 @@ class RunnerControllerTests : ControllerTestBase() { constructSolutionCreateRequest( parameters = parametersList, parameterGroups = parameterGroups, - runTemplates = runTemplates)) + runTemplates = runTemplates, + ), + ) workspaceId = createWorkspaceAndReturnId( - mvc, organizationId, constructWorkspaceCreateRequest(solutionId = solutionId)) + mvc, + organizationId, + constructWorkspaceCreateRequest(solutionId = solutionId), + ) datasetId = createDatasetAndReturnId( mvc, organizationId, workspaceId, - constructDatasetCreateRequest(datasetPartName = solutionParameterId2)) + constructDatasetCreateRequest(datasetPartName = solutionParameterId2), + ) val datasetParts = getDatasetPartsId(mvc, organizationId, workspaceId, datasetId) @@ -154,10 +166,15 @@ class RunnerControllerTests : ControllerTestBase() { solutionId = solutionId, datasetId = datasetId, defaultParameterValues = - mutableMapOf(solutionParameterId2 to datasetParts[0])))) - .toString()) + mutableMapOf(solutionParameterId2 to datasetParts[0]), + ) + ) + ) + .toString() + ) .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) } @@ -167,19 +184,23 @@ class RunnerControllerTests : ControllerTestBase() { get("/organizations/wrong-orgId/workspaces/wrong-workspaceId/runners/wrong-runnerId") .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().isBadRequest) .andExpect(jsonPath("$.detail", containsString("wrong-orgId:must match \"^o-\\w{10,20}\""))) .andExpect( - jsonPath("$.detail", containsString("wrong-workspaceId:must match \"^w-\\w{10,20}\""))) + jsonPath("$.detail", containsString("wrong-workspaceId:must match \"^w-\\w{10,20}\"")) + ) .andExpect( - jsonPath("$.detail", containsString("wrong-runnerId:must match \"^(r|s)-\\w{10,20}\""))) + jsonPath("$.detail", containsString("wrong-runnerId:must match \"^(r|s)-\\w{10,20}\"")) + ) mvc.perform( get("/organizations/wrong-orgId/workspaces/w-123456abcdef/runners/r-123456azerty") .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().isBadRequest) .andExpect(jsonPath("$.detail", containsString("wrong-orgId:must match \"^o-\\w{10,20}\""))) @@ -187,7 +208,8 @@ class RunnerControllerTests : ControllerTestBase() { get("/organizations/wrong-orgId/workspaces/w-123456abcdef/runners/s-123456azerty") .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().isBadRequest) .andExpect(jsonPath("$.detail", containsString("wrong-orgId:must match \"^o-\\w{10,20}\""))) @@ -195,28 +217,34 @@ class RunnerControllerTests : ControllerTestBase() { get("/organizations/o-1233456azer/workspaces/wrong-workspaceId/runners/r-123456azerty") .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().isBadRequest) .andExpect( - jsonPath("$.detail", containsString("wrong-workspaceId:must match \"^w-\\w{10,20}\""))) + jsonPath("$.detail", containsString("wrong-workspaceId:must match \"^w-\\w{10,20}\"")) + ) mvc.perform( get("/organizations/o-1233456azer/workspaces/wrong-workspaceId/runners/s-123456azerty") .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().isBadRequest) .andExpect( - jsonPath("$.detail", containsString("wrong-workspaceId:must match \"^w-\\w{10,20}\""))) + jsonPath("$.detail", containsString("wrong-workspaceId:must match \"^w-\\w{10,20}\"")) + ) mvc.perform( get("/organizations/o-1233456azer/workspaces/w-123456abcdef/runners/wrong-runnerId") .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().isBadRequest) .andExpect( - jsonPath("$.detail", containsString("wrong-runnerId:must match \"^(r|s)-\\w{10,20}\""))) + jsonPath("$.detail", containsString("wrong-runnerId:must match \"^(r|s)-\\w{10,20}\"")) + ) } @Test @@ -230,14 +258,17 @@ class RunnerControllerTests : ControllerTestBase() { val runnerParameterValue = "parameter_value" val additionalData = mutableMapOf( - "you_can_put" to "whatever_you_want_here", "even" to mapOf("object" to "if_you_want")) + "you_can_put" to "whatever_you_want_here", + "even" to mapOf("object" to "if_you_want"), + ) val parentId = createRunnerAndReturnId( mvc, organizationId, workspaceId, - constructRunnerObject(solutionId = solutionId, runTemplateId = RUNNER_RUN_TEMPLATE)) + constructRunnerObject(solutionId = solutionId, runTemplateId = RUNNER_RUN_TEMPLATE), + ) val constructRunnerRequest = constructRunnerObject( @@ -251,7 +282,8 @@ class RunnerControllerTests : ControllerTestBase() { RunnerSecurity( default = ROLE_NONE, accessControlList = - mutableListOf(RunnerAccessControl(id = NEW_USER_ID, role = NEW_USER_ROLE))), + mutableListOf(RunnerAccessControl(id = NEW_USER_ID, role = NEW_USER_ROLE)), + ), runSizing = RunnerResourceSizing( requests = @@ -263,7 +295,8 @@ class RunnerControllerTests : ControllerTestBase() { ResourceSizeInfo( cpu = "cpu_limits", memory = "memory_limits", - )), + ), + ), additionalData = additionalData, description = description, tags = tags, @@ -274,7 +307,10 @@ class RunnerControllerTests : ControllerTestBase() { parameterId = solutionParameterId1, value = runnerParameterValue, varType = solutionParameterVarType1, - isInherited = false))) + isInherited = false, + ) + ), + ) mvc.perform( post("/organizations/$organizationId/workspaces/$workspaceId/runners") @@ -282,7 +318,8 @@ class RunnerControllerTests : ControllerTestBase() { .contentType(MediaType.APPLICATION_JSON) .content(JSONObject(constructRunnerRequest).toString()) .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.name").value(RUNNER_NAME)) .andExpect(jsonPath("$.createInfo.userId").value(PLATFORM_ADMIN_EMAIL)) @@ -326,14 +363,17 @@ class RunnerControllerTests : ControllerTestBase() { val additionalData = mutableMapOf( - "you_can_put" to "whatever_you_want_here", "even" to mapOf("object" to "if_you_want")) + "you_can_put" to "whatever_you_want_here", + "even" to mapOf("object" to "if_you_want"), + ) val parentId = createRunnerAndReturnId( mvc, organizationId, workspaceId, - constructRunnerObject(solutionId = solutionId, runTemplateId = RUNNER_RUN_TEMPLATE)) + constructRunnerObject(solutionId = solutionId, runTemplateId = RUNNER_RUN_TEMPLATE), + ) val runnerId = createRunnerAndReturnId( @@ -352,7 +392,9 @@ class RunnerControllerTests : ControllerTestBase() { default = ROLE_NONE, accessControlList = mutableListOf( - RunnerAccessControl(id = NEW_USER_ID, role = NEW_USER_ROLE))), + RunnerAccessControl(id = NEW_USER_ID, role = NEW_USER_ROLE) + ), + ), runSizing = RunnerResourceSizing( requests = @@ -364,7 +406,8 @@ class RunnerControllerTests : ControllerTestBase() { ResourceSizeInfo( cpu = "cpu_limits", memory = "memory_limits", - )), + ), + ), additionalData = additionalData, description = description, tags = tags, @@ -375,13 +418,18 @@ class RunnerControllerTests : ControllerTestBase() { parameterId = runnerParameterId, value = runnerParameterValue, varType = runnerParameterVarType, - isInherited = false)))) + isInherited = false, + ) + ), + ), + ) mvc.perform( get("/organizations/$organizationId/workspaces/$workspaceId/runners/$runnerId") .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.id").value(runnerId)) .andExpect(jsonPath("$.name").value(RUNNER_NAME)) @@ -411,7 +459,9 @@ class RunnerControllerTests : ControllerTestBase() { .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/GET")) + "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/GET" + ) + ) } @Test @@ -428,14 +478,16 @@ class RunnerControllerTests : ControllerTestBase() { val additionalData = mutableMapOf( "you_can_put_also" to "whatever_you_want_here", - "even" to mapOf("object" to "if_you_want_too")) + "even" to mapOf("object" to "if_you_want_too"), + ) val baseRunnerId = createRunnerAndReturnId( mvc, organizationId, workspaceId, - constructRunnerObject(solutionId = solutionId, runTemplateId = RUNNER_RUN_TEMPLATE)) + constructRunnerObject(solutionId = solutionId, runTemplateId = RUNNER_RUN_TEMPLATE), + ) val updateRunnerObject = constructUpdateRunnerObject( @@ -454,7 +506,8 @@ class RunnerControllerTests : ControllerTestBase() { ResourceSizeInfo( cpu = "cpu_limits", memory = "memory_limits", - )), + ), + ), additionalData = additionalData, description = description, tags = tags, @@ -465,7 +518,10 @@ class RunnerControllerTests : ControllerTestBase() { parameterId = solutionParameterId1, value = runnerParameterValue, varType = runnerParameterVarType, - isInherited = false))) + isInherited = false, + ) + ), + ) mvc.perform( patch("/organizations/$organizationId/workspaces/$workspaceId/runners/$baseRunnerId") @@ -473,7 +529,8 @@ class RunnerControllerTests : ControllerTestBase() { .content(JSONObject(updateRunnerObject).toString()) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.id").value(baseRunnerId)) .andExpect(jsonPath("$.name").value(RUNNER_NAME)) @@ -503,7 +560,9 @@ class RunnerControllerTests : ControllerTestBase() { .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/PATCH")) + "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/PATCH" + ) + ) } @Test @@ -518,7 +577,9 @@ class RunnerControllerTests : ControllerTestBase() { constructRunnerObject( name = firstRunnerName, solutionId = solutionId, - runTemplateId = RUNNER_RUN_TEMPLATE)) + runTemplateId = RUNNER_RUN_TEMPLATE, + ), + ) val secondRunnerName = "my_second_runner" val secondRunnerId = @@ -529,13 +590,16 @@ class RunnerControllerTests : ControllerTestBase() { constructRunnerObject( name = secondRunnerName, solutionId = solutionId, - runTemplateId = RUNNER_RUN_TEMPLATE)) + runTemplateId = RUNNER_RUN_TEMPLATE, + ), + ) mvc.perform( get("/organizations/$organizationId/workspaces/$workspaceId/runners") .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$[0].id").value(firstRunnerId)) .andExpect(jsonPath("$[0].name").value(firstRunnerName)) @@ -548,7 +612,8 @@ class RunnerControllerTests : ControllerTestBase() { .andExpect(jsonPath("$[0].datasets.parameters[0].name").value(solutionParameterId2)) .andExpect(jsonPath("$[0].datasets.parameters[0].sourceName").value(TEST_FILE_NAME)) .andExpect( - jsonPath("$[0].datasets.parameters[0].type").value(DatasetPartTypeEnum.File.name)) + jsonPath("$[0].datasets.parameters[0].type").value(DatasetPartTypeEnum.File.name) + ) .andExpect(jsonPath("$[1].id").value(secondRunnerId)) .andExpect(jsonPath("$[1].name").value(secondRunnerName)) .andExpect(jsonPath("$[1].createInfo.userId").value(PLATFORM_ADMIN_EMAIL)) @@ -560,7 +625,8 @@ class RunnerControllerTests : ControllerTestBase() { .andExpect(jsonPath("$[1].datasets.parameters[0].name").value(solutionParameterId2)) .andExpect(jsonPath("$[1].datasets.parameters[0].sourceName").value(TEST_FILE_NAME)) .andExpect( - jsonPath("$[1].datasets.parameters[0].type").value(DatasetPartTypeEnum.File.name)) + jsonPath("$[1].datasets.parameters[0].type").value(DatasetPartTypeEnum.File.name) + ) .andDo(MockMvcResultHandlers.print()) .andDo(document("organizations/{organization_id}/workspaces/{workspace_id}/runners/GET")) } @@ -573,19 +639,23 @@ class RunnerControllerTests : ControllerTestBase() { mvc, organizationId, workspaceId, - constructRunnerObject(solutionId = solutionId, runTemplateId = RUNNER_RUN_TEMPLATE)) + constructRunnerObject(solutionId = solutionId, runTemplateId = RUNNER_RUN_TEMPLATE), + ) mvc.perform( delete("/organizations/$organizationId/workspaces/$workspaceId/runners/$runnerId") .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/DELETE")) + "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/DELETE" + ) + ) } @Test @@ -596,11 +666,13 @@ class RunnerControllerTests : ControllerTestBase() { mvc, organizationId, workspaceId, - constructRunnerObject(solutionId = solutionId, runTemplateId = RUNNER_RUN_TEMPLATE)) + constructRunnerObject(solutionId = solutionId, runTemplateId = RUNNER_RUN_TEMPLATE), + ) mvc.perform( get("/organizations/$organizationId/workspaces/$workspaceId/runners/$runnerId/security") - .withPlatformAdminHeader()) + .withPlatformAdminHeader() + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.default").value(ROLE_NONE)) .andExpect(jsonPath("$.accessControlList[0].role").value(ROLE_ADMIN)) @@ -608,7 +680,9 @@ class RunnerControllerTests : ControllerTestBase() { .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/security/GET")) + "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/security/GET" + ) + ) } @Test @@ -619,11 +693,13 @@ class RunnerControllerTests : ControllerTestBase() { mvc, organizationId, workspaceId, - constructRunnerObject(solutionId = solutionId, runTemplateId = RUNNER_RUN_TEMPLATE)) + constructRunnerObject(solutionId = solutionId, runTemplateId = RUNNER_RUN_TEMPLATE), + ) mvc.perform( post( - "/organizations/$organizationId/workspaces/$workspaceId/runners/$runnerId/security/access") + "/organizations/$organizationId/workspaces/$workspaceId/runners/$runnerId/security/access" + ) .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) .content( @@ -633,16 +709,20 @@ class RunnerControllerTests : ControllerTestBase() { "role": "${OrganizationConstants.NEW_USER_ROLE}" } """ - .trimMargin()) + .trimMargin() + ) .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.role").value(OrganizationConstants.NEW_USER_ROLE)) .andExpect(jsonPath("$.id").value(OrganizationConstants.NEW_USER_ID)) .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/security/access/POST")) + "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/security/access/POST" + ) + ) } @Test @@ -653,19 +733,24 @@ class RunnerControllerTests : ControllerTestBase() { mvc, organizationId, workspaceId, - constructRunnerObject(solutionId = solutionId, runTemplateId = RUNNER_RUN_TEMPLATE)) + constructRunnerObject(solutionId = solutionId, runTemplateId = RUNNER_RUN_TEMPLATE), + ) mvc.perform( get( - "/organizations/$organizationId/workspaces/$workspaceId/runners/$runnerId/security/access/$PLATFORM_ADMIN_EMAIL") - .withPlatformAdminHeader()) + "/organizations/$organizationId/workspaces/$workspaceId/runners/$runnerId/security/access/$PLATFORM_ADMIN_EMAIL" + ) + .withPlatformAdminHeader() + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.role").value(ROLE_ADMIN)) .andExpect(jsonPath("$.id").value(PLATFORM_ADMIN_EMAIL)) .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/security/access/{identity_id}/GET")) + "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/security/access/{identity_id}/GET" + ) + ) } @Test @@ -679,7 +764,10 @@ class RunnerControllerTests : ControllerTestBase() { RunnerAccessControl(id = PLATFORM_ADMIN_EMAIL, role = ROLE_ADMIN), RunnerAccessControl( id = OrganizationConstants.NEW_USER_ID, - role = OrganizationConstants.NEW_USER_ROLE))) + role = OrganizationConstants.NEW_USER_ROLE, + ), + ), + ) val runnerId = createRunnerAndReturnId( mvc, @@ -688,23 +776,29 @@ class RunnerControllerTests : ControllerTestBase() { constructRunnerObject( solutionId = solutionId, runTemplateId = RUNNER_RUN_TEMPLATE, - security = runnerSecurity)) + security = runnerSecurity, + ), + ) mvc.perform( patch( - "/organizations/$organizationId/workspaces/$workspaceId/runners/$runnerId/security/access/${OrganizationConstants.NEW_USER_ID}") + "/organizations/$organizationId/workspaces/$workspaceId/runners/$runnerId/security/access/${OrganizationConstants.NEW_USER_ID}" + ) .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) .content("""{"role":"$ROLE_VIEWER"}""") .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.role").value(ROLE_VIEWER)) .andExpect(jsonPath("$.id").value(OrganizationConstants.NEW_USER_ID)) .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/security/access/{identity_id}/PATCH")) + "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/security/access/{identity_id}/PATCH" + ) + ) } @Test @@ -718,7 +812,10 @@ class RunnerControllerTests : ControllerTestBase() { RunnerAccessControl(id = PLATFORM_ADMIN_EMAIL, role = ROLE_ADMIN), RunnerAccessControl( id = OrganizationConstants.NEW_USER_ID, - role = OrganizationConstants.NEW_USER_ROLE))) + role = OrganizationConstants.NEW_USER_ROLE, + ), + ), + ) val runnerId = createRunnerAndReturnId( mvc, @@ -727,18 +824,24 @@ class RunnerControllerTests : ControllerTestBase() { constructRunnerObject( solutionId = solutionId, runTemplateId = RUNNER_RUN_TEMPLATE, - security = runnerSecurity)) + security = runnerSecurity, + ), + ) mvc.perform( delete( - "/organizations/$organizationId/workspaces/$workspaceId/runners/$runnerId/security/access/${OrganizationConstants.NEW_USER_ID}") + "/organizations/$organizationId/workspaces/$workspaceId/runners/$runnerId/security/access/${OrganizationConstants.NEW_USER_ID}" + ) .withPlatformAdminHeader() - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/security/access/{identity_id}/DELETE")) + "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/security/access/{identity_id}/DELETE" + ) + ) } @Test @@ -749,16 +852,19 @@ class RunnerControllerTests : ControllerTestBase() { mvc, organizationId, workspaceId, - constructRunnerObject(solutionId = solutionId, runTemplateId = RUNNER_RUN_TEMPLATE)) + constructRunnerObject(solutionId = solutionId, runTemplateId = RUNNER_RUN_TEMPLATE), + ) mvc.perform( patch( - "/organizations/$organizationId/workspaces/$workspaceId/runners/$runnerId/security/default") + "/organizations/$organizationId/workspaces/$workspaceId/runners/$runnerId/security/default" + ) .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) .content("""{"role":"$ROLE_VIEWER"}""") .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.default").value(ROLE_VIEWER)) .andExpect(jsonPath("$.accessControlList[0].id").value(PLATFORM_ADMIN_EMAIL)) @@ -766,7 +872,9 @@ class RunnerControllerTests : ControllerTestBase() { .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/security/default/POST")) + "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/security/default/POST" + ) + ) } @Test @@ -780,7 +888,10 @@ class RunnerControllerTests : ControllerTestBase() { RunnerAccessControl(id = PLATFORM_ADMIN_EMAIL, role = ROLE_ADMIN), RunnerAccessControl( id = OrganizationConstants.NEW_USER_ID, - role = OrganizationConstants.NEW_USER_ROLE))) + role = OrganizationConstants.NEW_USER_ROLE, + ), + ), + ) val runnerId = createRunnerAndReturnId( mvc, @@ -789,21 +900,27 @@ class RunnerControllerTests : ControllerTestBase() { constructRunnerObject( solutionId = solutionId, runTemplateId = RUNNER_RUN_TEMPLATE, - security = runnerSecurity)) + security = runnerSecurity, + ), + ) mvc.perform( get( - "/organizations/$organizationId/workspaces/$workspaceId/runners/$runnerId/security/users") + "/organizations/$organizationId/workspaces/$workspaceId/runners/$runnerId/security/users" + ) .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$[0]").value(PLATFORM_ADMIN_EMAIL)) .andExpect(jsonPath("$[1]").value(OrganizationConstants.NEW_USER_ID)) .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/security/users/GET")) + "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/security/users/GET" + ) + ) } @Test @@ -834,19 +951,24 @@ class RunnerControllerTests : ControllerTestBase() { cpu = "1Gi", memory = "1Gi", ), - ))) + ), + ), + ) mvc.perform( post("/organizations/$organizationId/workspaces/$workspaceId/runners/$runnerId/start") .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/start/POST")) + "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/start/POST" + ) + ) } @Test @@ -873,7 +995,9 @@ class RunnerControllerTests : ControllerTestBase() { cpu = "1Gi", memory = "1Gi", ), - ))) + ), + ), + ) every { eventPublisher.publishEvent(any()) } answers { firstArg().response = expectedRunId @@ -888,7 +1012,8 @@ class RunnerControllerTests : ControllerTestBase() { .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) mvc.perform( @@ -896,11 +1021,14 @@ class RunnerControllerTests : ControllerTestBase() { .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/stop/POST")) + "organizations/{organization_id}/workspaces/{workspace_id}/runners/{runner_id}/stop/POST" + ) + ) } } diff --git a/api/src/integrationTest/kotlin/com/cosmotech/api/home/solution/SolutionControllerTests.kt b/api/src/integrationTest/kotlin/com/cosmotech/api/home/solution/SolutionControllerTests.kt index 8a418a343..05e432b9c 100644 --- a/api/src/integrationTest/kotlin/com/cosmotech/api/home/solution/SolutionControllerTests.kt +++ b/api/src/integrationTest/kotlin/com/cosmotech/api/home/solution/SolutionControllerTests.kt @@ -53,7 +53,10 @@ class SolutionControllerTests : ControllerTestBase() { @BeforeEach fun beforeEach() { ReflectionTestUtils.setField( - solutionApiService, "containerRegistryService", containerRegistryService) + solutionApiService, + "containerRegistryService", + containerRegistryService, + ) every { containerRegistryService.getImageLabel(any(), any(), any()) } returns SOLUTION_SDK_VERSION @@ -66,17 +69,20 @@ class SolutionControllerTests : ControllerTestBase() { get("/organizations/wrong-orgId/solutions/wrong-solutionId") .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().isBadRequest) .andExpect(jsonPath("$.detail", containsString("wrong-orgId:must match \"^o-\\w{10,20}\""))) .andExpect( - jsonPath("$.detail", containsString("wrong-solutionId:must match \"^sol-\\w{10,20}\""))) + jsonPath("$.detail", containsString("wrong-solutionId:must match \"^sol-\\w{10,20}\"")) + ) mvc.perform( get("/organizations/wrong-orgId/solutions/sol-123456abcdef") .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().isBadRequest) .andExpect(jsonPath("$.detail", containsString("wrong-orgId:must match \"^o-\\w{10,20}\""))) @@ -84,10 +90,12 @@ class SolutionControllerTests : ControllerTestBase() { get("/organizations/o-123456abcdef/solutions/wrong-solutionId") .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().isBadRequest) .andExpect( - jsonPath("$.detail", containsString("wrong-solutionId:must match \"^sol-\\w{10,20}\""))) + jsonPath("$.detail", containsString("wrong-solutionId:must match \"^sol-\\w{10,20}\"")) + ) } @Test @@ -101,7 +109,8 @@ class SolutionControllerTests : ControllerTestBase() { constructSolutionCreateRequest( name = firstSolutionName, key = firstSolutionKey, - )) + ), + ) val secondSolutionName = "secondSolutionName" val secondSolutionKey = "secondSolutionKey" val secondSolutionId = @@ -111,12 +120,14 @@ class SolutionControllerTests : ControllerTestBase() { constructSolutionCreateRequest( name = secondSolutionName, key = secondSolutionKey, - )) + ), + ) mvc.perform( get("/organizations/$organizationId/solutions") .contentType(MediaType.APPLICATION_JSON) - .withPlatformAdminHeader()) + .withPlatformAdminHeader() + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$[0].id").value(firstSolutionId)) .andExpect(jsonPath("$[0].key").value(firstSolutionKey)) @@ -158,7 +169,8 @@ class SolutionControllerTests : ControllerTestBase() { val additionalData = mutableMapOf( "you_can_put" to "whatever_you_want_here", - "even" to JSONObject(mapOf("object" to "if_you_want"))) + "even" to JSONObject(mapOf("object" to "if_you_want")), + ) val parameters = mutableListOf( RunTemplateParameterCreateRequest( @@ -169,7 +181,9 @@ class SolutionControllerTests : ControllerTestBase() { parameterDefaultValue, parameterMinValue, parameterMaxValue, - additionalData)) + additionalData, + ) + ) val parameterGroupId = "parameterGroup1" val parameterGroups = mutableListOf( @@ -178,14 +192,17 @@ class SolutionControllerTests : ControllerTestBase() { parameterGroupDescription, parameterLabels, additionalData, - mutableListOf(parameterId))) + mutableListOf(parameterId), + ) + ) val runTemplateId = "runtemplate1" val runTemplateName = "this_is_a_name" val runTemplateComputeSize = "this_is_a_compute_size" val runTemplateRunSizing = RunTemplateResourceSizing( ResourceSizeInfo("cpu_requests", "memory_requests"), - ResourceSizeInfo("cpu_limits", "memory_limits")) + ResourceSizeInfo("cpu_limits", "memory_limits"), + ) val runTemplates = mutableListOf( RunTemplateCreateRequest( @@ -197,7 +214,9 @@ class SolutionControllerTests : ControllerTestBase() { runTemplateComputeSize, runTemplateRunSizing, mutableListOf(parameterGroupId), - 10)) + 10, + ) + ) val url = "this_is_the_solution_url" val security = @@ -206,7 +225,9 @@ class SolutionControllerTests : ControllerTestBase() { accessControlList = mutableListOf( SolutionAccessControl(id = PLATFORM_ADMIN_EMAIL, role = ROLE_ADMIN), - SolutionAccessControl(id = NEW_USER_ID, role = NEW_USER_ROLE))) + SolutionAccessControl(id = NEW_USER_ID, role = NEW_USER_ROLE), + ), + ) val solutionCreateRequest = constructSolutionCreateRequest( SOLUTION_KEY, @@ -220,14 +241,16 @@ class SolutionControllerTests : ControllerTestBase() { parameterGroups, runTemplates, url, - security) + security, + ) mvc.perform( post("/organizations/$organizationId/solutions") .withPlatformAdminHeader() .content(JSONObject(solutionCreateRequest).toString()) .contentType(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.name").value(SOLUTION_NAME)) .andExpect(jsonPath("$.key").value(SOLUTION_KEY)) @@ -257,7 +280,8 @@ class SolutionControllerTests : ControllerTestBase() { .andExpect(jsonPath("$.runTemplates[0].runSizing.limits.cpu").value("cpu_limits")) .andExpect(jsonPath("$.runTemplates[0].runSizing.limits.memory").value("memory_limits")) .andExpect( - jsonPath("$.runTemplates[0].parameterGroups").value(mutableListOf(parameterGroupId))) + jsonPath("$.runTemplates[0].parameterGroups").value(mutableListOf(parameterGroupId)) + ) .andExpect(jsonPath("$.runTemplates[0].executionTimeout").value(10)) .andExpect(jsonPath("$.url").value(url)) .andExpect(jsonPath("$.tags").value(tags)) @@ -287,7 +311,8 @@ class SolutionControllerTests : ControllerTestBase() { val additionalData = mutableMapOf( "you_can_put" to "whatever_you_want_here", - "even" to JSONObject(mapOf("object" to "if_you_want"))) + "even" to JSONObject(mapOf("object" to "if_you_want")), + ) val parameters = mutableListOf( RunTemplateParameterCreateRequest( @@ -298,7 +323,9 @@ class SolutionControllerTests : ControllerTestBase() { parameterDefaultValue, parameterMinValue, parameterMaxValue, - additionalData)) + additionalData, + ) + ) val parameterGroupId = "parameterGroup1" val parameterGroupDescription = "this_is_a_description" val parameterGroups = @@ -308,14 +335,17 @@ class SolutionControllerTests : ControllerTestBase() { parameterGroupDescription, parameterLabels, additionalData, - mutableListOf(parameterId))) + mutableListOf(parameterId), + ) + ) val runTemplateId = "runtemplate1" val runTemplateName = "this_is_a_name" val runTemplateComputeSize = "this_is_a_compute_size" val runTemplateRunSizing = RunTemplateResourceSizing( ResourceSizeInfo("cpu_requests", "memory_requests"), - ResourceSizeInfo("cpu_limits", "memory_limits")) + ResourceSizeInfo("cpu_limits", "memory_limits"), + ) val runTemplates = mutableListOf( RunTemplateCreateRequest( @@ -327,7 +357,9 @@ class SolutionControllerTests : ControllerTestBase() { runTemplateComputeSize, runTemplateRunSizing, mutableListOf(parameterGroupId), - 10)) + 10, + ) + ) val url = "this_is_the_solution_url" val security = @@ -336,7 +368,9 @@ class SolutionControllerTests : ControllerTestBase() { accessControlList = mutableListOf( SolutionAccessControl(id = PLATFORM_ADMIN_EMAIL, role = ROLE_ADMIN), - SolutionAccessControl(id = NEW_USER_ID, role = NEW_USER_ROLE))) + SolutionAccessControl(id = NEW_USER_ID, role = NEW_USER_ROLE), + ), + ) val solutionCreateRequest = constructSolutionCreateRequest( SOLUTION_KEY, @@ -350,14 +384,16 @@ class SolutionControllerTests : ControllerTestBase() { parameterGroups, runTemplates, url, - security) + security, + ) val solutionId = createSolutionAndReturnId(mvc, organizationId, solutionCreateRequest) mvc.perform( get("/organizations/$organizationId/solutions/$solutionId") .withPlatformAdminHeader() - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.id").value(solutionId)) .andExpect(jsonPath("$.name").value(SOLUTION_NAME)) @@ -376,18 +412,22 @@ class SolutionControllerTests : ControllerTestBase() { .andExpect(jsonPath("$.parameters[0].maxValue").value(parameterMaxValue)) .andExpect( jsonPath("$.parameters[0].additionalData[\"you_can_put\"]") - .value("whatever_you_want_here")) + .value("whatever_you_want_here") + ) .andExpect( - jsonPath("$.parameters[0].additionalData[\"even\"][\"object\"]").value("if_you_want")) + jsonPath("$.parameters[0].additionalData[\"even\"][\"object\"]").value("if_you_want") + ) .andExpect(jsonPath("$.parameterGroups[0].id").value(parameterGroupId)) .andExpect(jsonPath("$.parameterGroups[0].labels").value(parameterLabels)) .andExpect(jsonPath("$.parameterGroups[0].parameters").value(mutableListOf(parameterId))) .andExpect( jsonPath("$.parameterGroups[0].additionalData[\"you_can_put\"]") - .value("whatever_you_want_here")) + .value("whatever_you_want_here") + ) .andExpect( jsonPath("$.parameterGroups[0].additionalData[\"even\"][\"object\"]") - .value("if_you_want")) + .value("if_you_want") + ) .andExpect(jsonPath("$.runTemplates[0].id").value(runTemplateId)) .andExpect(jsonPath("$.runTemplates[0].name").value(runTemplateName)) .andExpect(jsonPath("$.runTemplates[0].labels").value(parameterLabels)) @@ -399,7 +439,8 @@ class SolutionControllerTests : ControllerTestBase() { .andExpect(jsonPath("$.runTemplates[0].runSizing.limits.cpu").value("cpu_limits")) .andExpect(jsonPath("$.runTemplates[0].runSizing.limits.memory").value("memory_limits")) .andExpect( - jsonPath("$.runTemplates[0].parameterGroups").value(mutableListOf(parameterGroupId))) + jsonPath("$.runTemplates[0].parameterGroups").value(mutableListOf(parameterGroupId)) + ) .andExpect(jsonPath("$.runTemplates[0].executionTimeout").value(10)) .andExpect(jsonPath("$.url").value(url)) .andExpect(jsonPath("$.tags").value(tags)) @@ -423,7 +464,8 @@ class SolutionControllerTests : ControllerTestBase() { delete("/organizations/$organizationId/solutions/$solutionId") .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andDo(MockMvcResultHandlers.print()) .andDo(document("organizations/{organization_id}/solutions/{solution_id}/DELETE")) @@ -448,14 +490,16 @@ class SolutionControllerTests : ControllerTestBase() { description = description, alwaysPull = true, tags = tags, - url = url) + url = url, + ) mvc.perform( patch("/organizations/$organizationId/solutions/$solutionId") .withPlatformAdminHeader() .content(JSONObject(solutionUpdateRequest).toString()) .contentType(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.id").value(solutionId)) .andExpect(jsonPath("$.name").value(SOLUTION_NAME)) @@ -489,7 +533,8 @@ class SolutionControllerTests : ControllerTestBase() { val additionalData = mutableMapOf( "you_can_put" to "whatever_you_want_here", - "even" to JSONObject(mapOf("object" to "if_you_want"))) + "even" to JSONObject(mapOf("object" to "if_you_want")), + ) val parameterCreateRequest = RunTemplateParameterCreateRequest( parameterId, @@ -499,7 +544,8 @@ class SolutionControllerTests : ControllerTestBase() { parameterDefaultValue, parameterMinValue, parameterMaxValue, - additionalData) + additionalData, + ) val solutionId = createSolutionAndReturnId(mvc, organizationId, constructSolutionCreateRequest()) @@ -509,7 +555,8 @@ class SolutionControllerTests : ControllerTestBase() { .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) .content(JSONObject(parameterCreateRequest).toString()) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.labels").value(parameterLabels)) .andExpect(jsonPath("$.varType").value(parameterVarType)) @@ -537,7 +584,8 @@ class SolutionControllerTests : ControllerTestBase() { val additionalData = mutableMapOf( "you_can_put" to "whatever_you_want_here", - "even" to JSONObject(mapOf("object" to "if_you_want"))) + "even" to JSONObject(mapOf("object" to "if_you_want")), + ) val parameterCreateRequest = RunTemplateParameterCreateRequest( parameterId, @@ -547,7 +595,8 @@ class SolutionControllerTests : ControllerTestBase() { parameterDefaultValue, parameterMinValue, parameterMaxValue, - additionalData) + additionalData, + ) val solutionId = createSolutionAndReturnId(mvc, organizationId, constructSolutionCreateRequest()) @@ -557,13 +606,15 @@ class SolutionControllerTests : ControllerTestBase() { .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) .content(JSONObject(parameterCreateRequest).toString()) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) mvc.perform( get("/organizations/$organizationId/solutions/$solutionId/parameters/$parameterId") .withPlatformAdminHeader() - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.labels").value(parameterLabels)) .andExpect(jsonPath("$.varType").value(parameterVarType)) @@ -577,7 +628,9 @@ class SolutionControllerTests : ControllerTestBase() { .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/solutions/{solution_id}/parameters/{parameter_id}/GET")) + "organizations/{organization_id}/solutions/{solution_id}/parameters/{parameter_id}/GET" + ) + ) } @Test @@ -593,7 +646,8 @@ class SolutionControllerTests : ControllerTestBase() { val newParameterAdditionalData = mutableMapOf( "new_you_can_put" to "new_whatever_you_want_here", - "new_even" to JSONObject(mapOf("new_object" to "new_if_you_want"))) + "new_even" to JSONObject(mapOf("new_object" to "new_if_you_want")), + ) val newParameterUpdateRequest = RunTemplateParameterUpdateRequest( @@ -603,7 +657,8 @@ class SolutionControllerTests : ControllerTestBase() { newParameterDefaultValue, newParameterMinValue, newParameterMaxValue, - newParameterAdditionalData) + newParameterAdditionalData, + ) val solutionId = createSolutionAndReturnId( @@ -622,14 +677,20 @@ class SolutionControllerTests : ControllerTestBase() { "this_is_a_maximal_value", mutableMapOf( "you_can_put" to "whatever_you_want_here", - "even" to JSONObject(mapOf("object" to "if_you_want"))))))) + "even" to JSONObject(mapOf("object" to "if_you_want")), + ), + ) + ) + ), + ) mvc.perform( patch("/organizations/$organizationId/solutions/$solutionId/parameters/$parameterId") .withPlatformAdminHeader() .content(JSONObject(newParameterUpdateRequest).toString()) .contentType(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.labels").value(newParameterLabels)) .andExpect(jsonPath("$.varType").value(newParameterVarType)) @@ -639,13 +700,17 @@ class SolutionControllerTests : ControllerTestBase() { .andExpect(jsonPath("$.minValue").value(newParameterMinValue)) .andExpect(jsonPath("$.maxValue").value(newParameterMaxValue)) .andExpect( - jsonPath("$.additionalData[\"new_you_can_put\"]").value("new_whatever_you_want_here")) + jsonPath("$.additionalData[\"new_you_can_put\"]").value("new_whatever_you_want_here") + ) .andExpect( - jsonPath("$.additionalData[\"new_even\"][\"new_object\"]").value("new_if_you_want")) + jsonPath("$.additionalData[\"new_even\"][\"new_object\"]").value("new_if_you_want") + ) .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/solutions/{solution_id}/parameters/{parameter_id}/PATCH")) + "organizations/{organization_id}/solutions/{solution_id}/parameters/{parameter_id}/PATCH" + ) + ) } @Test @@ -661,7 +726,8 @@ class SolutionControllerTests : ControllerTestBase() { val additionalData = mutableMapOf( "you_can_put" to "whatever_you_want_here", - "even" to JSONObject(mapOf("object" to "if_you_want"))) + "even" to JSONObject(mapOf("object" to "if_you_want")), + ) val parameters = mutableListOf( RunTemplateParameterCreateRequest( @@ -672,14 +738,20 @@ class SolutionControllerTests : ControllerTestBase() { parameterDefaultValue, parameterMinValue, parameterMaxValue, - additionalData)) + additionalData, + ) + ) val solutionId = createSolutionAndReturnId( - mvc, organizationId, constructSolutionCreateRequest(parameters = parameters)) + mvc, + organizationId, + constructSolutionCreateRequest(parameters = parameters), + ) mvc.perform( get("/organizations/$organizationId/solutions/$solutionId/parameters") .withPlatformAdminHeader() - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON) + ) .andExpect(status().is2xxSuccessful) .andDo(MockMvcResultHandlers.print()) .andExpect(jsonPath("$[0].labels").value(parameterLabels)) @@ -707,7 +779,8 @@ class SolutionControllerTests : ControllerTestBase() { val additionalData = mutableMapOf( "you_can_put" to "whatever_you_want_here", - "even" to JSONObject(mapOf("object" to "if_you_want"))) + "even" to JSONObject(mapOf("object" to "if_you_want")), + ) val parameters = mutableListOf( RunTemplateParameterCreateRequest( @@ -718,20 +791,28 @@ class SolutionControllerTests : ControllerTestBase() { parameterDefaultValue, parameterMinValue, parameterMaxValue, - additionalData)) + additionalData, + ) + ) val solutionId = createSolutionAndReturnId( - mvc, organizationId, constructSolutionCreateRequest(parameters = parameters)) + mvc, + organizationId, + constructSolutionCreateRequest(parameters = parameters), + ) mvc.perform( delete("/organizations/$organizationId/solutions/$solutionId/parameters/$parameterId") .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/solutions/{solution_id}/parameters/{parameter_id}/DELETE")) + "organizations/{organization_id}/solutions/{solution_id}/parameters/{parameter_id}/DELETE" + ) + ) } @Test @@ -745,7 +826,8 @@ class SolutionControllerTests : ControllerTestBase() { val additionalData = mutableMapOf( "you_can_put" to "whatever_you_want_here", - "even" to JSONObject(mapOf("object" to "if_you_want"))) + "even" to JSONObject(mapOf("object" to "if_you_want")), + ) val parameterGroupId = "parameterGroup1" val parameterGroupDescription = "this_is_a_description" val parameterGroup = @@ -754,14 +836,16 @@ class SolutionControllerTests : ControllerTestBase() { parameterGroupDescription, parameterLabels, additionalData, - mutableListOf(parameterId)) + mutableListOf(parameterId), + ) mvc.perform( post("/organizations/$organizationId/solutions/$solutionId/parameterGroups") .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) .content(JSONObject(parameterGroup).toString()) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.id").value(parameterGroupId)) .andExpect(jsonPath("$.description").value(parameterGroupDescription)) @@ -771,8 +855,8 @@ class SolutionControllerTests : ControllerTestBase() { .andExpect(jsonPath("$.parameters").value(mutableListOf(parameterId))) .andDo(MockMvcResultHandlers.print()) .andDo( - document( - "organizations/{organization_id}/solutions/{solution_id}/parameterGroups/POST")) + document("organizations/{organization_id}/solutions/{solution_id}/parameterGroups/POST") + ) } @Test @@ -782,7 +866,8 @@ class SolutionControllerTests : ControllerTestBase() { val additionalData = mutableMapOf( "you_can_put" to "whatever_you_want_here", - "even" to JSONObject(mapOf("object" to "if_you_want"))) + "even" to JSONObject(mapOf("object" to "if_you_want")), + ) val parameterGroupId = "parameterGroup1" val parameterGroupDescription = "this_is_a_description" val parameterGroup = @@ -791,19 +876,23 @@ class SolutionControllerTests : ControllerTestBase() { parameterGroupDescription, parameterLabels, additionalData, - mutableListOf(parameterId)) + mutableListOf(parameterId), + ) val solutionId = createSolutionAndReturnId( mvc, organizationId, - constructSolutionCreateRequest(parameterGroups = mutableListOf(parameterGroup))) + constructSolutionCreateRequest(parameterGroups = mutableListOf(parameterGroup)), + ) mvc.perform( get( - "/organizations/$organizationId/solutions/$solutionId/parameterGroups/$parameterGroupId") + "/organizations/$organizationId/solutions/$solutionId/parameterGroups/$parameterGroupId" + ) .withPlatformAdminHeader() - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.id").value(parameterGroupId)) .andExpect(jsonPath("$.description").value(parameterGroupDescription)) @@ -814,7 +903,9 @@ class SolutionControllerTests : ControllerTestBase() { .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/solutions/{solution_id}/parameterGroups/{parameter_group_id}/GET")) + "organizations/{organization_id}/solutions/{solution_id}/parameterGroups/{parameter_group_id}/GET" + ) + ) } @Test @@ -824,7 +915,8 @@ class SolutionControllerTests : ControllerTestBase() { val additionalData = mutableMapOf( "you_can_put" to "whatever_you_want_here", - "even" to JSONObject(mapOf("object" to "if_you_want"))) + "even" to JSONObject(mapOf("object" to "if_you_want")), + ) val parameterGroupId = "parameterGroup1" val parameterGroupDescription = "this_is_a_description" val parameterGroup = @@ -833,19 +925,22 @@ class SolutionControllerTests : ControllerTestBase() { parameterGroupDescription, parameterLabels, additionalData, - mutableListOf(parameterId)) + mutableListOf(parameterId), + ) val solutionId = createSolutionAndReturnId( mvc, organizationId, - constructSolutionCreateRequest(parameterGroups = mutableListOf(parameterGroup))) + constructSolutionCreateRequest(parameterGroups = mutableListOf(parameterGroup)), + ) val newParameterLabels = mutableMapOf("fr" to "this_is_a_new_label") val newadditionalData = mutableMapOf( "you_can_put" to "whatever_you_want_new_here", - "even" to JSONObject(mapOf("new_object" to "if_you_want"))) + "even" to JSONObject(mapOf("new_object" to "if_you_want")), + ) val newParameterGroupDescription = "this_is_a_new_description" val newParameterId = "parameter2" val newParameterGroup = @@ -853,27 +948,33 @@ class SolutionControllerTests : ControllerTestBase() { newParameterGroupDescription, newParameterLabels, newadditionalData, - mutableListOf(newParameterId)) + mutableListOf(newParameterId), + ) mvc.perform( patch( - "/organizations/$organizationId/solutions/$solutionId/parameterGroups/$parameterGroupId") + "/organizations/$organizationId/solutions/$solutionId/parameterGroups/$parameterGroupId" + ) .withPlatformAdminHeader() .content(JSONObject(newParameterGroup).toString()) .contentType(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.id").value(parameterGroupId)) .andExpect(jsonPath("$.description").value(newParameterGroupDescription)) .andExpect(jsonPath("$.labels").value(newParameterLabels)) .andExpect( - jsonPath("$.additionalData[\"you_can_put\"]").value("whatever_you_want_new_here")) + jsonPath("$.additionalData[\"you_can_put\"]").value("whatever_you_want_new_here") + ) .andExpect(jsonPath("$.additionalData[\"even\"][\"new_object\"]").value("if_you_want")) .andExpect(jsonPath("$.parameters").value(mutableListOf(newParameterId))) .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/solutions/{solution_id}/parameterGroups/{parameter_group_id}/PATCH")) + "organizations/{organization_id}/solutions/{solution_id}/parameterGroups/{parameter_group_id}/PATCH" + ) + ) } @Test @@ -884,7 +985,8 @@ class SolutionControllerTests : ControllerTestBase() { val additionalData = mutableMapOf( "you_can_put" to "whatever_you_want_here", - "even" to JSONObject(mapOf("object" to "if_you_want"))) + "even" to JSONObject(mapOf("object" to "if_you_want")), + ) val parameterGroupId = "parameterGroup1" val parameterGroupDescription = "this_is_a_description" val parameterGroup = @@ -893,18 +995,21 @@ class SolutionControllerTests : ControllerTestBase() { parameterGroupDescription, parameterLabels, additionalData, - mutableListOf(parameterId)) + mutableListOf(parameterId), + ) val solutionId = createSolutionAndReturnId( mvc, organizationId, - constructSolutionCreateRequest(parameterGroups = mutableListOf(parameterGroup))) + constructSolutionCreateRequest(parameterGroups = mutableListOf(parameterGroup)), + ) mvc.perform( get("/organizations/$organizationId/solutions/$solutionId/parameterGroups") .withPlatformAdminHeader() - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON) + ) .andExpect(status().is2xxSuccessful) .andDo(MockMvcResultHandlers.print()) .andExpect(jsonPath("$[0].id").value(parameterGroupId)) @@ -914,7 +1019,8 @@ class SolutionControllerTests : ControllerTestBase() { .andExpect(jsonPath("$[0].additionalData[\"even\"][\"object\"]").value("if_you_want")) .andExpect(jsonPath("$[0].parameters").value(mutableListOf(parameterId))) .andDo( - document("organizations/{organization_id}/solutions/{solution_id}/parameterGroups/GET")) + document("organizations/{organization_id}/solutions/{solution_id}/parameterGroups/GET") + ) } @Test @@ -924,7 +1030,8 @@ class SolutionControllerTests : ControllerTestBase() { val additionalData = mutableMapOf( "you_can_put" to "whatever_you_want_here", - "even" to JSONObject(mapOf("object" to "if_you_want"))) + "even" to JSONObject(mapOf("object" to "if_you_want")), + ) val parameterGroupId = "parameterGroup1" val parameterGroupDescription = "this_is_a_description" val parameterGroup = @@ -933,25 +1040,31 @@ class SolutionControllerTests : ControllerTestBase() { parameterGroupDescription, parameterLabels, additionalData, - mutableListOf(parameterId)) + mutableListOf(parameterId), + ) val solutionId = createSolutionAndReturnId( mvc, organizationId, - constructSolutionCreateRequest(parameterGroups = mutableListOf(parameterGroup))) + constructSolutionCreateRequest(parameterGroups = mutableListOf(parameterGroup)), + ) mvc.perform( delete( - "/organizations/$organizationId/solutions/$solutionId/parameterGroups/$parameterGroupId") + "/organizations/$organizationId/solutions/$solutionId/parameterGroups/$parameterGroupId" + ) .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/solutions/{solution_id}/parameterGroups/{parameter_id}/DELETE")) + "organizations/{organization_id}/solutions/{solution_id}/parameterGroups/{parameter_id}/DELETE" + ) + ) } @Test @@ -975,18 +1088,25 @@ class SolutionControllerTests : ControllerTestBase() { runTemplateComputeSize, RunTemplateResourceSizing( ResourceSizeInfo("cpu_requests", "memory_requests"), - ResourceSizeInfo("cpu_limits", "memory_limits")), + ResourceSizeInfo("cpu_limits", "memory_limits"), + ), runTemplateParameterGroups, - 10)) + 10, + ) + ) val solutionId = createSolutionAndReturnId( - mvc, organizationId, constructSolutionCreateRequest(runTemplates = runTemplates)) + mvc, + organizationId, + constructSolutionCreateRequest(runTemplates = runTemplates), + ) mvc.perform( get("/organizations/$organizationId/solutions/$solutionId/runTemplates") .withPlatformAdminHeader() - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$[0].id").value(runTemplateId)) .andExpect(jsonPath("$[0].name").value(runTemplateName)) @@ -1017,7 +1137,8 @@ class SolutionControllerTests : ControllerTestBase() { val runTemplateRunSizing = RunTemplateResourceSizing( ResourceSizeInfo("cpu_requests", "memory_requests"), - ResourceSizeInfo("cpu_limits", "memory_limits")) + ResourceSizeInfo("cpu_limits", "memory_limits"), + ) val runTemplate = RunTemplateCreateRequest( runTemplateId, @@ -1028,7 +1149,8 @@ class SolutionControllerTests : ControllerTestBase() { runTemplateComputeSize, runTemplateRunSizing, mutableListOf(parameterGroupId), - 10) + 10, + ) val solutionId = createSolutionAndReturnId(mvc, organizationId, constructSolutionCreateRequest()) @@ -1038,7 +1160,8 @@ class SolutionControllerTests : ControllerTestBase() { .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) .content(JSONObject(runTemplate).toString()) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.id").value(runTemplateId)) .andExpect(jsonPath("$.name").value(runTemplateName)) @@ -1054,7 +1177,8 @@ class SolutionControllerTests : ControllerTestBase() { .andExpect(jsonPath("$.executionTimeout").value(10)) .andDo(MockMvcResultHandlers.print()) .andDo( - document("organizations/{organization_id}/solutions/{solution_id}/runTemplates/POST")) + document("organizations/{organization_id}/solutions/{solution_id}/runTemplates/POST") + ) } @Test @@ -1078,18 +1202,25 @@ class SolutionControllerTests : ControllerTestBase() { runTemplateComputeSize, RunTemplateResourceSizing( ResourceSizeInfo("cpu_requests", "memory_requests"), - ResourceSizeInfo("cpu_limits", "memory_limits")), + ResourceSizeInfo("cpu_limits", "memory_limits"), + ), runTemplateParameterGroups, - 10)) + 10, + ) + ) val solutionId = createSolutionAndReturnId( - mvc, organizationId, constructSolutionCreateRequest(runTemplates = runTemplates)) + mvc, + organizationId, + constructSolutionCreateRequest(runTemplates = runTemplates), + ) mvc.perform( get("/organizations/$organizationId/solutions/$solutionId/runTemplates/$runTemplateId") .withPlatformAdminHeader() - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.id").value(runTemplateId)) .andExpect(jsonPath("$.name").value(runTemplateName)) @@ -1106,7 +1237,9 @@ class SolutionControllerTests : ControllerTestBase() { .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/solutions/{solution_id}/runTemplates/{run_template_id}/GET")) + "organizations/{organization_id}/solutions/{solution_id}/runTemplates/{run_template_id}/GET" + ) + ) } @Test @@ -1124,13 +1257,19 @@ class SolutionControllerTests : ControllerTestBase() { "this_is_a_compute_size", RunTemplateResourceSizing( ResourceSizeInfo("cpu_requests", "memory_requests"), - ResourceSizeInfo("cpu_limits", "memory_limits")), + ResourceSizeInfo("cpu_limits", "memory_limits"), + ), mutableListOf("parameterGroup1"), - 10)) + 10, + ) + ) val solutionId = createSolutionAndReturnId( - mvc, organizationId, constructSolutionCreateRequest(runTemplates = runTemplates)) + mvc, + organizationId, + constructSolutionCreateRequest(runTemplates = runTemplates), + ) val description = "this_is_a_description2" val tags = mutableListOf("tag1", "tag2", "tag3") @@ -1141,7 +1280,8 @@ class SolutionControllerTests : ControllerTestBase() { val runTemplateRunSizing = RunTemplateResourceSizing( ResourceSizeInfo("cpu_requests2", "memory_requests2"), - ResourceSizeInfo("cpu_limits2", "memory_limits2")) + ResourceSizeInfo("cpu_limits2", "memory_limits2"), + ) val newRunTemplate = RunTemplateUpdateRequest( runTemplateName, @@ -1151,15 +1291,18 @@ class SolutionControllerTests : ControllerTestBase() { runTemplateComputeSize, runTemplateRunSizing, mutableListOf(parameterGroupId), - 100) + 100, + ) mvc.perform( patch( - "/organizations/$organizationId/solutions/$solutionId/runTemplates/$runTemplateId") + "/organizations/$organizationId/solutions/$solutionId/runTemplates/$runTemplateId" + ) .withPlatformAdminHeader() .content(JSONObject(newRunTemplate).toString()) .contentType(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.id").value(runTemplateId)) .andExpect(jsonPath("$.name").value(runTemplateName)) @@ -1176,7 +1319,9 @@ class SolutionControllerTests : ControllerTestBase() { .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/solutions/{solution_id}/runTemplates/{run_template_id}/PATCH")) + "organizations/{organization_id}/solutions/{solution_id}/runTemplates/{run_template_id}/PATCH" + ) + ) } @Test @@ -1192,7 +1337,8 @@ class SolutionControllerTests : ControllerTestBase() { val runTemplateRunSizing = RunTemplateResourceSizing( ResourceSizeInfo("cpu_requests", "memory_requests"), - ResourceSizeInfo("cpu_limits", "memory_limits")) + ResourceSizeInfo("cpu_limits", "memory_limits"), + ) val runTemplates = mutableListOf( RunTemplateCreateRequest( @@ -1204,23 +1350,32 @@ class SolutionControllerTests : ControllerTestBase() { runTemplateComputeSize, runTemplateRunSizing, mutableListOf(parameterGroupId), - 10)) + 10, + ) + ) val solutionId = createSolutionAndReturnId( - mvc, organizationId, constructSolutionCreateRequest(runTemplates = runTemplates)) + mvc, + organizationId, + constructSolutionCreateRequest(runTemplates = runTemplates), + ) mvc.perform( delete( - "/organizations/$organizationId/solutions/$solutionId/runTemplates/$runTemplateId") + "/organizations/$organizationId/solutions/$solutionId/runTemplates/$runTemplateId" + ) .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/solutions/{solution_id}/runTemplates/{run_template_id}/DELETE")) + "organizations/{organization_id}/solutions/{solution_id}/runTemplates/{run_template_id}/DELETE" + ) + ) } @Test @@ -1231,7 +1386,8 @@ class SolutionControllerTests : ControllerTestBase() { mvc.perform( get("/organizations/$organizationId/solutions/$solutionId/security") - .withPlatformAdminHeader()) + .withPlatformAdminHeader() + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.default").value(ROLE_NONE)) .andExpect(jsonPath("$.accessControlList[0].role").value(ROLE_ADMIN)) @@ -1257,16 +1413,18 @@ class SolutionControllerTests : ControllerTestBase() { "role": "$NEW_USER_ROLE" } """ - .trimMargin()) + .trimMargin() + ) .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.role").value(NEW_USER_ROLE)) .andExpect(jsonPath("$.id").value(NEW_USER_ID)) .andDo(MockMvcResultHandlers.print()) .andDo( - document( - "organizations/{organization_id}/solutions/{solution_id}/security/access/POST")) + document("organizations/{organization_id}/solutions/{solution_id}/security/access/POST") + ) } @Test @@ -1277,15 +1435,19 @@ class SolutionControllerTests : ControllerTestBase() { mvc.perform( get( - "/organizations/$organizationId/solutions/$solutionId/security/access/$PLATFORM_ADMIN_EMAIL") - .withPlatformAdminHeader()) + "/organizations/$organizationId/solutions/$solutionId/security/access/$PLATFORM_ADMIN_EMAIL" + ) + .withPlatformAdminHeader() + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.role").value(ROLE_ADMIN)) .andExpect(jsonPath("$.id").value(PLATFORM_ADMIN_EMAIL)) .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/solutions/{solution_id}/security/access/{identity_id}/GET")) + "organizations/{organization_id}/solutions/{solution_id}/security/access/{identity_id}/GET" + ) + ) } @Test @@ -1297,26 +1459,35 @@ class SolutionControllerTests : ControllerTestBase() { accessControlList = mutableListOf( SolutionAccessControl(id = PLATFORM_ADMIN_EMAIL, role = ROLE_ADMIN), - SolutionAccessControl(id = NEW_USER_ID, role = NEW_USER_ROLE))) + SolutionAccessControl(id = NEW_USER_ID, role = NEW_USER_ROLE), + ), + ) val solutionId = createSolutionAndReturnId( - mvc, organizationId, constructSolutionCreateRequest(security = solutionSecurity)) + mvc, + organizationId, + constructSolutionCreateRequest(security = solutionSecurity), + ) mvc.perform( patch( - "/organizations/$organizationId/solutions/$solutionId/security/access/$NEW_USER_ID") + "/organizations/$organizationId/solutions/$solutionId/security/access/$NEW_USER_ID" + ) .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) .content("""{"role":"$ROLE_VIEWER"}""") .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.role").value(ROLE_VIEWER)) .andExpect(jsonPath("$.id").value(NEW_USER_ID)) .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/solutions/{solution_id}/security/access/{identity_id}/PATCH")) + "organizations/{organization_id}/solutions/{solution_id}/security/access/{identity_id}/PATCH" + ) + ) } @Test @@ -1328,21 +1499,30 @@ class SolutionControllerTests : ControllerTestBase() { accessControlList = mutableListOf( SolutionAccessControl(id = PLATFORM_ADMIN_EMAIL, role = ROLE_ADMIN), - SolutionAccessControl(id = NEW_USER_ID, role = NEW_USER_ROLE))) + SolutionAccessControl(id = NEW_USER_ID, role = NEW_USER_ROLE), + ), + ) val solutionId = createSolutionAndReturnId( - mvc, organizationId, constructSolutionCreateRequest(security = solutionSecurity)) + mvc, + organizationId, + constructSolutionCreateRequest(security = solutionSecurity), + ) mvc.perform( delete( - "/organizations/$organizationId/solutions/$solutionId/security/access/$NEW_USER_ID") + "/organizations/$organizationId/solutions/$solutionId/security/access/$NEW_USER_ID" + ) .withPlatformAdminHeader() - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/solutions/{solution_id}/security/access/{identity_id}/DELETE")) + "organizations/{organization_id}/solutions/{solution_id}/security/access/{identity_id}/DELETE" + ) + ) } @Test @@ -1357,7 +1537,8 @@ class SolutionControllerTests : ControllerTestBase() { .contentType(MediaType.APPLICATION_JSON) .content("""{"role":"$ROLE_VIEWER"}""") .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.default").value(ROLE_VIEWER)) .andExpect(jsonPath("$.accessControlList[0].id").value(PLATFORM_ADMIN_EMAIL)) @@ -1365,7 +1546,9 @@ class SolutionControllerTests : ControllerTestBase() { .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/solutions/{solution_id}/security/default/POST")) + "organizations/{organization_id}/solutions/{solution_id}/security/default/POST" + ) + ) } @Test @@ -1377,21 +1560,28 @@ class SolutionControllerTests : ControllerTestBase() { accessControlList = mutableListOf( SolutionAccessControl(id = PLATFORM_ADMIN_EMAIL, role = ROLE_ADMIN), - SolutionAccessControl(id = NEW_USER_ID, role = NEW_USER_ROLE))) + SolutionAccessControl(id = NEW_USER_ID, role = NEW_USER_ROLE), + ), + ) val solutionId = createSolutionAndReturnId( - mvc, organizationId, constructSolutionCreateRequest(security = solutionSecurity)) + mvc, + organizationId, + constructSolutionCreateRequest(security = solutionSecurity), + ) mvc.perform( get("/organizations/$organizationId/solutions/$solutionId/security/users") .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$[0]").value(PLATFORM_ADMIN_EMAIL)) .andExpect(jsonPath("$[1]").value(NEW_USER_ID)) .andDo(MockMvcResultHandlers.print()) .andDo( - document("organizations/{organization_id}/solutions/{solution_id}/security/users/GET")) + document("organizations/{organization_id}/solutions/{solution_id}/security/users/GET") + ) } } diff --git a/api/src/integrationTest/kotlin/com/cosmotech/api/home/workspace/WorkspaceControllerTests.kt b/api/src/integrationTest/kotlin/com/cosmotech/api/home/workspace/WorkspaceControllerTests.kt index f5a1068a3..3c7a79c77 100644 --- a/api/src/integrationTest/kotlin/com/cosmotech/api/home/workspace/WorkspaceControllerTests.kt +++ b/api/src/integrationTest/kotlin/com/cosmotech/api/home/workspace/WorkspaceControllerTests.kt @@ -59,17 +59,20 @@ class WorkspaceControllerTests : ControllerTestBase() { get("/organizations/wrong-orgId/workspaces/wrong-workspaceId") .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().isBadRequest) .andExpect(jsonPath("$.detail", containsString("wrong-orgId:must match \"^o-\\w{10,20}\""))) .andExpect( - jsonPath("$.detail", containsString("wrong-workspaceId:must match \"^w-\\w{10,20}\""))) + jsonPath("$.detail", containsString("wrong-workspaceId:must match \"^w-\\w{10,20}\"")) + ) mvc.perform( get("/organizations/wrong-orgId/workspaces/w-123456abcdef") .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().isBadRequest) .andExpect(jsonPath("$.detail", containsString("wrong-orgId:must match \"^o-\\w{10,20}\""))) @@ -77,10 +80,12 @@ class WorkspaceControllerTests : ControllerTestBase() { get("/organizations/o-123456abcdef/workspaces/wrong-workspaceId") .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().isBadRequest) .andExpect( - jsonPath("$.detail", containsString("wrong-workspaceId:must match \"^w-\\w{10,20}\""))) + jsonPath("$.detail", containsString("wrong-workspaceId:must match \"^w-\\w{10,20}\"")) + ) } @Test @@ -92,14 +97,18 @@ class WorkspaceControllerTests : ControllerTestBase() { val tags = mutableListOf("tag1,tag2") val additionalData = mutableMapOf( - "you_can_put" to "whatever_you_want_here", "even" to mapOf("object" to "if_you_want")) + "you_can_put" to "whatever_you_want_here", + "even" to mapOf("object" to "if_you_want"), + ) val workspaceSecurity = WorkspaceSecurity( default = ROLE_NONE, accessControlList = mutableListOf( WorkspaceAccessControl(id = PLATFORM_ADMIN_EMAIL, role = ROLE_ADMIN), - WorkspaceAccessControl(id = NEW_USER_ID, role = NEW_USER_ROLE))) + WorkspaceAccessControl(id = NEW_USER_ID, role = NEW_USER_ROLE), + ), + ) val workspaceDatasetId = "d-12345678910" mvc.perform( @@ -115,16 +124,21 @@ class WorkspaceControllerTests : ControllerTestBase() { workspaceDatasetId, mutableMapOf( "solution_parameter1" to "solution_parameter1_defaultValue", - "solution_parameter2" to "solution_parameter2_defaultValue"), + "solution_parameter2" to "solution_parameter2_defaultValue", + ), description, version, datasetCopy, workspaceSecurity, additionalData, - tags)) - .toString()) + tags, + ) + ) + .toString() + ) .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.name").value(WORKSPACE_NAME)) .andExpect(jsonPath("$.key").value(WORKSPACE_KEY)) @@ -135,10 +149,12 @@ class WorkspaceControllerTests : ControllerTestBase() { .andExpect(jsonPath("$.solution.datasetId").value(workspaceDatasetId)) .andExpect( jsonPath("$.solution.defaultParameterValues.solution_parameter1") - .value("solution_parameter1_defaultValue")) + .value("solution_parameter1_defaultValue") + ) .andExpect( jsonPath("$.solution.defaultParameterValues.solution_parameter2") - .value("solution_parameter2_defaultValue")) + .value("solution_parameter2_defaultValue") + ) .andExpect(jsonPath("$.datasetCopy").value(datasetCopy)) .andExpect(jsonPath("$.tags").value(tags)) .andExpect(jsonPath("$.additionalData").value(additionalData)) @@ -164,7 +180,9 @@ class WorkspaceControllerTests : ControllerTestBase() { val tags = mutableListOf("tag1,tag2") val additionalData = mutableMapOf( - "you_can_put" to "whatever_you_want_here", "even" to mapOf("object" to "if_you_want")) + "you_can_put" to "whatever_you_want_here", + "even" to mapOf("object" to "if_you_want"), + ) val workspaceDatasetId = "d-12345678910" mvc.perform( @@ -180,14 +198,19 @@ class WorkspaceControllerTests : ControllerTestBase() { workspaceDatasetId, mutableMapOf( "solution_parameter1" to "solution_parameter1_defaultValue", - "solution_parameter2" to "solution_parameter2_defaultValue"), + "solution_parameter2" to "solution_parameter2_defaultValue", + ), description, datasetCopy, additionalData, - tags)) - .toString()) + tags, + ) + ) + .toString() + ) .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.name").value(WORKSPACE_NAME)) .andExpect(jsonPath("$.key").value(WORKSPACE_KEY)) @@ -197,10 +220,12 @@ class WorkspaceControllerTests : ControllerTestBase() { .andExpect(jsonPath("$.solution.datasetId").value(workspaceDatasetId)) .andExpect( jsonPath("$.solution.defaultParameterValues.solution_parameter1") - .value("solution_parameter1_defaultValue")) + .value("solution_parameter1_defaultValue") + ) .andExpect( jsonPath("$.solution.defaultParameterValues.solution_parameter2") - .value("solution_parameter2_defaultValue")) + .value("solution_parameter2_defaultValue") + ) .andExpect(jsonPath("$.datasetCopy").value(datasetCopy)) .andExpect(jsonPath("$.tags").value(tags)) .andExpect(jsonPath("$.additionalData").value(additionalData)) @@ -226,7 +251,8 @@ class WorkspaceControllerTests : ControllerTestBase() { key = firstWorkspaceKey, name = firstWorkspaceName, solutionId = solutionId, - )) + ), + ) val secondWorkspaceKey = "second_workspace_key" val secondWorkspaceName = "second_workspace_name" val secondWorkspaceId = @@ -237,12 +263,14 @@ class WorkspaceControllerTests : ControllerTestBase() { key = secondWorkspaceKey, name = secondWorkspaceName, solutionId = solutionId, - )) + ), + ) mvc.perform( get("/organizations/$organizationId/workspaces") .withPlatformAdminHeader() - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$[0].id").value(firstWorkspaceId)) .andExpect(jsonPath("$[0].key").value(firstWorkspaceKey)) @@ -281,7 +309,9 @@ class WorkspaceControllerTests : ControllerTestBase() { val tags = mutableListOf("tag1,tag2") val additionalData = mutableMapOf( - "you_can_put" to "whatever_you_want_here", "even" to mapOf("object" to "if_you_want")) + "you_can_put" to "whatever_you_want_here", + "even" to mapOf("object" to "if_you_want"), + ) val workspaceDatasetId = "d-12345678910" val workspaceSecurity = @@ -290,7 +320,9 @@ class WorkspaceControllerTests : ControllerTestBase() { accessControlList = mutableListOf( WorkspaceAccessControl(id = PLATFORM_ADMIN_EMAIL, role = ROLE_ADMIN), - WorkspaceAccessControl(id = NEW_USER_ID, role = NEW_USER_ROLE))) + WorkspaceAccessControl(id = NEW_USER_ID, role = NEW_USER_ROLE), + ), + ) val workspaceId = createWorkspaceAndReturnId( mvc, @@ -302,18 +334,22 @@ class WorkspaceControllerTests : ControllerTestBase() { workspaceDatasetId, mutableMapOf( "solution_parameter1" to "solution_parameter1_defaultValue", - "solution_parameter2" to "solution_parameter2_defaultValue"), + "solution_parameter2" to "solution_parameter2_defaultValue", + ), description, version, datasetCopy, workspaceSecurity, additionalData, - tags)) + tags, + ), + ) mvc.perform( get("/organizations/$organizationId/workspaces/$workspaceId") .withPlatformAdminHeader() - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.name").value(WORKSPACE_NAME)) .andExpect(jsonPath("$.key").value(WORKSPACE_KEY)) @@ -329,10 +365,12 @@ class WorkspaceControllerTests : ControllerTestBase() { .andExpect(jsonPath("$.solution.datasetId").value(workspaceDatasetId)) .andExpect( jsonPath("$.solution.defaultParameterValues.solution_parameter1") - .value("solution_parameter1_defaultValue")) + .value("solution_parameter1_defaultValue") + ) .andExpect( jsonPath("$.solution.defaultParameterValues.solution_parameter2") - .value("solution_parameter2_defaultValue")) + .value("solution_parameter2_defaultValue") + ) .andExpect(jsonPath("$.security.default").value(ROLE_NONE)) .andExpect(jsonPath("$.security.accessControlList[0].role").value(ROLE_ADMIN)) .andExpect(jsonPath("$.security.accessControlList[0].id").value(PLATFORM_ADMIN_EMAIL)) @@ -352,7 +390,8 @@ class WorkspaceControllerTests : ControllerTestBase() { delete("/organizations/$organizationId/workspaces/$workspaceId") .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andDo(MockMvcResultHandlers.print()) .andDo(document("organizations/{organization_id}/workspaces/{workspace_id}/DELETE")) @@ -363,11 +402,15 @@ class WorkspaceControllerTests : ControllerTestBase() { val workspaceId = createWorkspaceAndReturnId( - mvc, organizationId, constructWorkspaceCreateRequest(solutionId = solutionId)) + mvc, + organizationId, + constructWorkspaceCreateRequest(solutionId = solutionId), + ) mvc.perform( get("/organizations/$organizationId/workspaces/$workspaceId/security") - .withPlatformAdminHeader()) + .withPlatformAdminHeader() + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.default").value(ROLE_NONE)) .andExpect(jsonPath("$.accessControlList[0].role").value(ROLE_ADMIN)) @@ -381,7 +424,10 @@ class WorkspaceControllerTests : ControllerTestBase() { val workspaceId = createWorkspaceAndReturnId( - mvc, organizationId, constructWorkspaceCreateRequest(solutionId = solutionId)) + mvc, + organizationId, + constructWorkspaceCreateRequest(solutionId = solutionId), + ) mvc.perform( post("/organizations/$organizationId/workspaces/$workspaceId/security/access") @@ -394,16 +440,20 @@ class WorkspaceControllerTests : ControllerTestBase() { "role": "$NEW_USER_ROLE" } """ - .trimMargin()) + .trimMargin() + ) .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.role").value(NEW_USER_ROLE)) .andExpect(jsonPath("$.id").value(NEW_USER_ID)) .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/security/access/POST")) + "organizations/{organization_id}/workspaces/{workspace_id}/security/access/POST" + ) + ) } @Test @@ -411,19 +461,26 @@ class WorkspaceControllerTests : ControllerTestBase() { val workspaceId = createWorkspaceAndReturnId( - mvc, organizationId, constructWorkspaceCreateRequest(solutionId = solutionId)) + mvc, + organizationId, + constructWorkspaceCreateRequest(solutionId = solutionId), + ) mvc.perform( get( - "/organizations/$organizationId/workspaces/$workspaceId/security/access/$PLATFORM_ADMIN_EMAIL") - .withPlatformAdminHeader()) + "/organizations/$organizationId/workspaces/$workspaceId/security/access/$PLATFORM_ADMIN_EMAIL" + ) + .withPlatformAdminHeader() + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.role").value(ROLE_ADMIN)) .andExpect(jsonPath("$.id").value(PLATFORM_ADMIN_EMAIL)) .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/security/access/{identity_id}/GET")) + "organizations/{organization_id}/workspaces/{workspace_id}/security/access/{identity_id}/GET" + ) + ) } @Test @@ -435,7 +492,9 @@ class WorkspaceControllerTests : ControllerTestBase() { accessControlList = mutableListOf( WorkspaceAccessControl(id = PLATFORM_ADMIN_EMAIL, role = ROLE_ADMIN), - WorkspaceAccessControl(id = NEW_USER_ID, role = NEW_USER_ROLE))) + WorkspaceAccessControl(id = NEW_USER_ID, role = NEW_USER_ROLE), + ), + ) val workspaceId = createWorkspaceAndReturnId( mvc, @@ -444,23 +503,29 @@ class WorkspaceControllerTests : ControllerTestBase() { key = WORKSPACE_KEY, name = WORKSPACE_NAME, solutionId = solutionId, - security = workspaceSecurity)) + security = workspaceSecurity, + ), + ) mvc.perform( patch( - "/organizations/$organizationId/workspaces/$workspaceId/security/access/$NEW_USER_ID") + "/organizations/$organizationId/workspaces/$workspaceId/security/access/$NEW_USER_ID" + ) .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) .content("""{"role":"$ROLE_VIEWER"}""") .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.role").value(ROLE_VIEWER)) .andExpect(jsonPath("$.id").value(NEW_USER_ID)) .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/security/access/{identity_id}/PATCH")) + "organizations/{organization_id}/workspaces/{workspace_id}/security/access/{identity_id}/PATCH" + ) + ) } @Test @@ -472,7 +537,9 @@ class WorkspaceControllerTests : ControllerTestBase() { accessControlList = mutableListOf( WorkspaceAccessControl(id = PLATFORM_ADMIN_EMAIL, role = ROLE_ADMIN), - WorkspaceAccessControl(id = NEW_USER_ID, role = NEW_USER_ROLE))) + WorkspaceAccessControl(id = NEW_USER_ID, role = NEW_USER_ROLE), + ), + ) val workspaceId = createWorkspaceAndReturnId( mvc, @@ -481,18 +548,24 @@ class WorkspaceControllerTests : ControllerTestBase() { key = WORKSPACE_KEY, name = WORKSPACE_NAME, solutionId = solutionId, - security = workspaceSecurity)) + security = workspaceSecurity, + ), + ) mvc.perform( delete( - "/organizations/$organizationId/workspaces/$workspaceId/security/access/$NEW_USER_ID") + "/organizations/$organizationId/workspaces/$workspaceId/security/access/$NEW_USER_ID" + ) .withPlatformAdminHeader() - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/security/access/{identity_id}/DELETE")) + "organizations/{organization_id}/workspaces/{workspace_id}/security/access/{identity_id}/DELETE" + ) + ) } @Test @@ -500,7 +573,10 @@ class WorkspaceControllerTests : ControllerTestBase() { val workspaceId = createWorkspaceAndReturnId( - mvc, organizationId, constructWorkspaceCreateRequest(solutionId = solutionId)) + mvc, + organizationId, + constructWorkspaceCreateRequest(solutionId = solutionId), + ) mvc.perform( patch("/organizations/$organizationId/workspaces/$workspaceId/security/default") @@ -508,7 +584,8 @@ class WorkspaceControllerTests : ControllerTestBase() { .contentType(MediaType.APPLICATION_JSON) .content("""{"role":"$ROLE_VIEWER"}""") .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.default").value(ROLE_VIEWER)) .andExpect(jsonPath("$.accessControlList[0].id").value(PLATFORM_ADMIN_EMAIL)) @@ -516,7 +593,9 @@ class WorkspaceControllerTests : ControllerTestBase() { .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/security/default/POST")) + "organizations/{organization_id}/workspaces/{workspace_id}/security/default/POST" + ) + ) } @Test @@ -528,7 +607,9 @@ class WorkspaceControllerTests : ControllerTestBase() { accessControlList = mutableListOf( WorkspaceAccessControl(id = PLATFORM_ADMIN_EMAIL, role = ROLE_ADMIN), - WorkspaceAccessControl(id = NEW_USER_ID, role = NEW_USER_ROLE))) + WorkspaceAccessControl(id = NEW_USER_ID, role = NEW_USER_ROLE), + ), + ) val workspaceId = createWorkspaceAndReturnId( mvc, @@ -537,20 +618,23 @@ class WorkspaceControllerTests : ControllerTestBase() { key = WORKSPACE_KEY, name = WORKSPACE_NAME, solutionId = solutionId, - security = workspaceSecurity)) + security = workspaceSecurity, + ), + ) mvc.perform( get("/organizations/$organizationId/workspaces/$workspaceId/security/users") .withPlatformAdminHeader() .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .accept(MediaType.APPLICATION_JSON) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$[0]").value(PLATFORM_ADMIN_EMAIL)) .andExpect(jsonPath("$[1]").value(NEW_USER_ID)) .andDo(MockMvcResultHandlers.print()) .andDo( - document( - "organizations/{organization_id}/workspaces/{workspace_id}/security/users/GET")) + document("organizations/{organization_id}/workspaces/{workspace_id}/security/users/GET") + ) } @Test @@ -558,12 +642,16 @@ class WorkspaceControllerTests : ControllerTestBase() { val workspaceId = createWorkspaceAndReturnId( - mvc, organizationId, constructWorkspaceCreateRequest(solutionId = solutionId)) + mvc, + organizationId, + constructWorkspaceCreateRequest(solutionId = solutionId), + ) mvc.perform( get("/organizations/$organizationId/workspaces/$workspaceId/files") .withPlatformAdminHeader() - .contentType(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON) + ) .andExpect(status().is2xxSuccessful) .andDo(MockMvcResultHandlers.print()) .andDo(document("organizations/{organization_id}/workspaces/{workspace_id}/files/GET")) @@ -573,16 +661,24 @@ class WorkspaceControllerTests : ControllerTestBase() { fun create_workspace_files() { val workspaceId = createWorkspaceAndReturnId( - mvc, organizationId, constructWorkspaceCreateRequest(solutionId = solutionId)) + mvc, + organizationId, + constructWorkspaceCreateRequest(solutionId = solutionId), + ) val fileName = "test.txt" val fileToUpload = this::class.java.getResourceAsStream("/workspace/$fileName") ?: throw IllegalStateException( - "$fileName file used for organizations/{organization_id}/workspaces/{workspace_id}/files/POST endpoint documentation cannot be null") + "$fileName file used for organizations/{organization_id}/workspaces/{workspace_id}/files/POST endpoint documentation cannot be null" + ) val mockFile = MockMultipartFile( - "file", fileName, MediaType.TEXT_PLAIN_VALUE, IOUtils.toByteArray(fileToUpload)) + "file", + fileName, + MediaType.TEXT_PLAIN_VALUE, + IOUtils.toByteArray(fileToUpload), + ) mvc.perform( multipart("/organizations/$organizationId/workspaces/$workspaceId/files") @@ -591,7 +687,8 @@ class WorkspaceControllerTests : ControllerTestBase() { .param("destination", "path/to/a/directory/") .withPlatformAdminHeader() .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andExpect(jsonPath("$.fileName").value("path/to/a/directory/$fileName")) .andDo(MockMvcResultHandlers.print()) @@ -603,13 +700,17 @@ class WorkspaceControllerTests : ControllerTestBase() { val workspaceId = createWorkspaceAndReturnId( - mvc, organizationId, constructWorkspaceCreateRequest(solutionId = solutionId)) + mvc, + organizationId, + constructWorkspaceCreateRequest(solutionId = solutionId), + ) mvc.perform( delete("/organizations/$organizationId/workspaces/$workspaceId/files") .withPlatformAdminHeader() .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andDo(MockMvcResultHandlers.print()) .andDo(document("organizations/{organization_id}/workspaces/{workspace_id}/files/DELETE")) @@ -619,17 +720,25 @@ class WorkspaceControllerTests : ControllerTestBase() { fun delete_workspace_file() { val workspaceId = createWorkspaceAndReturnId( - mvc, organizationId, constructWorkspaceCreateRequest(solutionId = solutionId)) + mvc, + organizationId, + constructWorkspaceCreateRequest(solutionId = solutionId), + ) val fileName = "test.txt" val fileToUpload = this::class.java.getResourceAsStream("/workspace/$fileName") ?: throw IllegalStateException( - "$fileName file used for organizations/{organization_id}/workspaces/{workspace_id}/files/POST endpoint documentation cannot be null") + "$fileName file used for organizations/{organization_id}/workspaces/{workspace_id}/files/POST endpoint documentation cannot be null" + ) val mockFile = MockMultipartFile( - "file", fileName, MediaType.TEXT_PLAIN_VALUE, IOUtils.toByteArray(fileToUpload)) + "file", + fileName, + MediaType.TEXT_PLAIN_VALUE, + IOUtils.toByteArray(fileToUpload), + ) val destination = "path/to/a/directory/" mvc.perform( @@ -639,19 +748,23 @@ class WorkspaceControllerTests : ControllerTestBase() { .param("destination", destination) .withPlatformAdminHeader() .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) mvc.perform( delete("/organizations/$organizationId/workspaces/$workspaceId/files/delete") .param("file_name", destination + fileName) .withPlatformAdminHeader() .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) .andExpect(status().is2xxSuccessful) .andDo(MockMvcResultHandlers.print()) .andDo( document( - "organizations/{organization_id}/workspaces/{workspace_id}/files/delete/DELETE")) + "organizations/{organization_id}/workspaces/{workspace_id}/files/delete/DELETE" + ) + ) } @Test @@ -659,17 +772,25 @@ class WorkspaceControllerTests : ControllerTestBase() { val workspaceId = createWorkspaceAndReturnId( - mvc, organizationId, constructWorkspaceCreateRequest(solutionId = solutionId)) + mvc, + organizationId, + constructWorkspaceCreateRequest(solutionId = solutionId), + ) val fileName = "test.txt" val fileToUpload = this::class.java.getResourceAsStream("/workspace/$fileName") ?: throw IllegalStateException( - "$fileName file used for organizations/{organization_id}/workspaces/{workspace_id}/files/POST endpoint documentation cannot be null") + "$fileName file used for organizations/{organization_id}/workspaces/{workspace_id}/files/POST endpoint documentation cannot be null" + ) val mockFile = MockMultipartFile( - "file", fileName, MediaType.TEXT_PLAIN_VALUE, IOUtils.toByteArray(fileToUpload)) + "file", + fileName, + MediaType.TEXT_PLAIN_VALUE, + IOUtils.toByteArray(fileToUpload), + ) val destination = "path/to/a/directory/" mvc.perform( @@ -679,18 +800,20 @@ class WorkspaceControllerTests : ControllerTestBase() { .param("destination", destination) .withPlatformAdminHeader() .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) mvc.perform( get("/organizations/$organizationId/workspaces/$workspaceId/files/download") .param("file_name", destination + fileName) .withPlatformAdminHeader() - .accept(MediaType.APPLICATION_OCTET_STREAM)) + .accept(MediaType.APPLICATION_OCTET_STREAM) + ) .andExpect(status().is2xxSuccessful) .andDo(MockMvcResultHandlers.print()) .andDo( - document( - "organizations/{organization_id}/workspaces/{workspace_id}/files/download/GET")) + document("organizations/{organization_id}/workspaces/{workspace_id}/files/download/GET") + ) } @Test @@ -698,17 +821,25 @@ class WorkspaceControllerTests : ControllerTestBase() { val workspaceId = createWorkspaceAndReturnId( - mvc, organizationId, constructWorkspaceCreateRequest(solutionId = solutionId)) + mvc, + organizationId, + constructWorkspaceCreateRequest(solutionId = solutionId), + ) val fileName = "test.txt" val fileToUpload = this::class.java.getResourceAsStream("/workspace/$fileName") ?: throw IllegalStateException( - "$fileName file used for organizations/{organization_id}/workspaces/{workspace_id}/files/POST endpoint documentation cannot be null") + "$fileName file used for organizations/{organization_id}/workspaces/{workspace_id}/files/POST endpoint documentation cannot be null" + ) val mockFile = MockMultipartFile( - "file", fileName, MediaType.TEXT_PLAIN_VALUE, IOUtils.toByteArray(fileToUpload)) + "file", + fileName, + MediaType.TEXT_PLAIN_VALUE, + IOUtils.toByteArray(fileToUpload), + ) val destination = "path/to/a/directory/" mvc.perform( @@ -718,13 +849,15 @@ class WorkspaceControllerTests : ControllerTestBase() { .param("destination", destination) .withPlatformAdminHeader() .accept(MediaType.APPLICATION_JSON) - .with(csrf())) + .with(csrf()) + ) mvc.perform( get("/organizations/$organizationId/workspaces/$workspaceId/files/download") .param("file_name", "Wrong file name") .withPlatformAdminHeader() - .accept(MediaType.APPLICATION_OCTET_STREAM)) + .accept(MediaType.APPLICATION_OCTET_STREAM) + ) .andExpect(status().is4xxClientError) .andExpect(jsonPath("$.detail").value("Wrong file name does not exist.")) .andDo(MockMvcResultHandlers.print()) diff --git a/api/src/main/kotlin/com/cosmotech/api/CsmApiApplication.kt b/api/src/main/kotlin/com/cosmotech/api/CsmApiApplication.kt index 28eb04e32..9f86ccfa1 100644 --- a/api/src/main/kotlin/com/cosmotech/api/CsmApiApplication.kt +++ b/api/src/main/kotlin/com/cosmotech/api/CsmApiApplication.kt @@ -17,7 +17,11 @@ import org.springframework.scheduling.annotation.EnableScheduling excludeFilters = [ ComponentScan.Filter( - type = FilterType.REGEX, pattern = ["com\\.cosmotech\\.\\w+\\.Application"])]) + type = FilterType.REGEX, + pattern = ["com\\.cosmotech\\.\\w+\\.Application"], + ) + ], +) class CsmApiApplication fun main(args: Array) { diff --git a/build.gradle.kts b/build.gradle.kts index c987c1a15..fd54b301a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,8 @@ import com.google.cloud.tools.jib.gradle.JibExtension import io.gitlab.arturbosch.detekt.Detekt import kotlinx.kover.gradle.plugin.dsl.KoverProjectExtension import org.apache.tools.ant.filters.ReplaceTokens -import org.cyclonedx.gradle.CycloneDxTask +import org.cyclonedx.gradle.CyclonedxDirectTask +import org.cyclonedx.model.Component.Type.APPLICATION import org.gradle.api.tasks.testing.logging.TestExceptionFormat import org.gradle.api.tasks.testing.logging.TestLogEvent import org.jetbrains.kotlin.gradle.tasks.KotlinCompile @@ -38,16 +39,16 @@ plugins { kotlin("jvm") version kotlinVersion kotlin("plugin.spring") version kotlinVersion apply false id("pl.allegro.tech.build.axion-release") version "1.18.18" - id("com.diffplug.spotless") version "7.0.3" - id("org.springframework.boot") version "3.4.4" apply false + id("com.diffplug.spotless") version "8.1.0" + id("org.springframework.boot") version "3.5.8" apply false id("project-report") - id("org.owasp.dependencycheck") version "12.1.0" - id("com.github.jk1.dependency-license-report") version "2.9" - id("org.jetbrains.kotlinx.kover") version "0.9.1" + id("org.owasp.dependencycheck") version "12.1.9" + id("com.github.jk1.dependency-license-report") version "3.0.1" + id("org.jetbrains.kotlinx.kover") version "0.9.3" id("io.gitlab.arturbosch.detekt") version "1.23.8" id("org.openapi.generator") version "7.13.0" apply false - id("com.google.cloud.tools.jib") version "3.4.5" apply false - id("org.cyclonedx.bom") version "2.3.1" + id("com.google.cloud.tools.jib") version "3.5.1" apply false + id("org.cyclonedx.bom") version "3.1.0" } scmVersion { tag { prefix.set("") } } @@ -57,36 +58,35 @@ group = "com.cosmotech" version = scmVersion.version // Dependencies version -val jacksonVersion = "2.18.3" -val springWebVersion = "6.2.9" -val bouncyCastleJdk18Version = "1.81" -val springBootVersion = "3.4.4" +val jacksonAnnotationVersion = "2.20" +val jacksonDatabindVersion = "2.20.1" +val jacksonModuleKotlinVersion = "2.20.1" +val springWebVersion = "6.2.14" +val bouncyCastleJdk18Version = "1.83" +val springBootVersion = "3.5.8" val springSecurityJwtVersion = "1.1.1.RELEASE" val springOauthAutoConfigureVersion = "2.6.8" val kotlinJvmTarget = 21 -val cosmotechApiCommonVersion = "2.1.1-SNAPSHOT" -val redisOmSpringVersion = "0.9.7" +val redisOmSpringVersion = "1.1.1" val kotlinCoroutinesVersion = "1.10.2" -val oktaSpringBootVersion = "3.0.7" -val springDocVersion = "2.8.8" -val swaggerParserVersion = "2.1.31" -val commonsCsvVersion = "1.14.0" -val apiValidationVersion = "3.0.2" +val springDocVersion = "2.8.14" +val swaggerParserVersion = "2.1.36" +val commonsCsvVersion = "1.14.1" +val apiValidationVersion = "3.1.1" val kubernetesClientVersion = "22.0.0" -val orgJsonVersion = "20240303" -val jacksonModuleKotlinVersion = "2.18.3" +val orgJsonVersion = "20250517" val testNgVersion = "7.8.0" val testContainersRedisVersion = "1.6.4" -val testContainersPostgreSQLVersion = "1.20.6" -val testContainersLocalStackVersion = "1.20.6" -val commonCompressVersion = "1.27.1" -val awsSpringVersion = "3.3.0" +val testContainersPostgreSQLVersion = "1.21.3" +val testContainersLocalStackVersion = "1.21.3" +val commonCompressVersion = "1.28.0" +val awsSpringVersion = "3.4.2" // Checks val detektVersion = "1.23.8" // Tests -val jUnitBomVersion = "5.12.2" +val jUnitBomVersion = "6.0.1" val mockkVersion = "1.14.0" val awaitilityKVersion = "4.2.0" val springMockkVersion = "4.0.2" @@ -113,7 +113,8 @@ licenseReport { renderers = arrayOf(InventoryHtmlReportRenderer("index.html")) filters = arrayOf( - LicenseBundleNormalizer(uri(bundle).toURL().openStream(), true)) + LicenseBundleNormalizer(uri(bundle).toURL().openStream(), true) + ) } allprojects { @@ -131,7 +132,6 @@ allprojects { sourceCompatibility = JavaVersion.VERSION_21 toolchain { languageVersion.set(JavaLanguageVersion.of(kotlinJvmTarget)) } } - configurations { all { resolutionStrategy { force("com.redis.om:redis-om-spring:0.9.10") } } } repositories { maven { @@ -146,13 +146,6 @@ allprojects { mavenCentral() } - tasks.cyclonedxBom { - includeConfigs = listOf("runtimeClasspath") - outputFormat = "xml" // by default it would also generate json - projectType = "application" - outputName = "cosmotech-api-bom" - } - tasks.withType().configureEach { projects = project.allprojects } configure { @@ -183,6 +176,13 @@ allprojects { } tasks.withType() { options.compilerArgs.add("-parameters") } + + tasks.cyclonedxBom { + componentName = "cosmotech-api" + projectType = APPLICATION + jsonOutput.set(file("build/reports/cosmotech-api-bom.json")) + xmlOutput.set(file("build/reports/cosmotech-api-bom.xml")) + } } subprojects { @@ -191,6 +191,14 @@ subprojects { apply(plugin = "org.openapi.generator") apply(plugin = "com.google.cloud.tools.jib") + tasks.cyclonedxDirectBom { + includeConfigs = listOf("runtimeClasspath") + projectType = APPLICATION + componentName = project.name + jsonOutput.set(file("build/reports/sbom/${project.name}-bom.json")) + xmlOutput.set(file("build/reports/sbom/${project.name}-bom.xml")) + } + val projectDirName = projectDir.relativeTo(rootDir).name val openApiDefinitionFile = file("${projectDir}/src/main/openapi/${projectDirName}.yaml") @@ -200,10 +208,13 @@ subprojects { val testWorkingDirPath = "${layout.buildDirectory.get()}/run" sourceSets { - create("integrationTest") { - compileClasspath += sourceSets.main.get().output + sourceSets.test.get().output - runtimeClasspath += sourceSets.main.get().output + sourceSets.test.get().output - } + create( + "integrationTest", + Action { + compileClasspath += sourceSets.main.get().output + sourceSets.test.get().output + runtimeClasspath += sourceSets.main.get().output + sourceSets.test.get().output + }, + ) if (openApiDefinitionFile.exists()) { main { java.srcDirs("$openApiServerSourcesGenerationDir/src/main/kotlin") } test { java.srcDirs("$openApiServerSourcesGenerationDir/src/test/kotlin") } @@ -234,26 +245,30 @@ subprojects { // observe findings in your browser with structure and code snippets required.set(true) outputLocation.set( - file("${layout.buildDirectory.get()}/reports/detekt/${project.name}-detekt.html")) + file("${layout.buildDirectory.get()}/reports/detekt/${project.name}-detekt.html") + ) } xml { // checkstyle like format mainly for integrations like Jenkins required.set(false) outputLocation.set( - file("${layout.buildDirectory.get()}/reports/detekt/${project.name}-detekt.xml")) + file("${layout.buildDirectory.get()}/reports/detekt/${project.name}-detekt.xml") + ) } txt { // similar to the console output, contains issue signature to manually edit baseline files required.set(true) outputLocation.set( - file("${layout.buildDirectory.get()}/reports/detekt/${project.name}-detekt.txt")) + file("${layout.buildDirectory.get()}/reports/detekt/${project.name}-detekt.txt") + ) } sarif { // standardized SARIF format (https://sarifweb.azurewebsites.net/) to support integrations // with Github Code Scanning required.set(true) outputLocation.set( - file("${layout.buildDirectory.get()}/reports/detekt/${project.name}-detekt.sarif")) + file("${layout.buildDirectory.get()}/reports/detekt/${project.name}-detekt.sarif") + ) } } @@ -271,7 +286,8 @@ subprojects { implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinCoroutinesVersion") implementation( - platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)) + platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES) + ) implementation("org.springframework.boot:spring-boot-starter-actuator") implementation("io.micrometer:micrometer-registry-prometheus") @@ -280,8 +296,8 @@ subprojects { } implementation("org.springframework.boot:spring-boot-starter-undertow") { constraints { - implementation("org.jboss.xnio:xnio-api:3.8.16.Final") - implementation("io.undertow:undertow-core:2.3.18.Final") + implementation("org.jboss.xnio:xnio-api:3.8.17.Final") + implementation("io.undertow:undertow-core:2.3.20.Final") } } implementation("com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonModuleKotlinVersion") @@ -293,25 +309,25 @@ subprojects { implementation("io.swagger.parser.v3:swagger-parser-v3:${swaggerParserVersion}") implementation("org.springframework.boot:spring-boot-starter-security") implementation( - "org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:${springOauthAutoConfigureVersion}") { + "org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:${springOauthAutoConfigureVersion}" + ) { + constraints { + implementation("com.fasterxml.jackson.core:jackson-annotations:$jacksonAnnotationVersion") + implementation("com.fasterxml.jackson.core:jackson-databind:$jacksonDatabindVersion") + implementation("org.springframework:spring-web:$springWebVersion") + implementation("org.springframework.boot:spring-boot-autoconfigure:$springBootVersion") + implementation( + "org.springframework.security:spring-security-jwt:${springSecurityJwtVersion}" + ) { + exclude(group = "org.bouncycastle", module = "bcpkix-jdk15on") constraints { - implementation("com.fasterxml.jackson.core:jackson-annotations:$jacksonVersion") - implementation("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion") - implementation("org.springframework:spring-web:$springWebVersion") - implementation("org.springframework.boot:spring-boot-autoconfigure:$springBootVersion") - implementation( - "org.springframework.security:spring-security-jwt:${springSecurityJwtVersion}") { - exclude(group = "org.bouncycastle", module = "bcpkix-jdk15on") - constraints { - implementation("org.bouncycastle:bcpkix-jdk18on:${bouncyCastleJdk18Version}") - } - } + implementation("org.bouncycastle:bcpkix-jdk18on:${bouncyCastleJdk18Version}") } } + } + } implementation("org.springframework.security:spring-security-oauth2-jose") implementation("org.springframework.security:spring-security-oauth2-resource-server") - implementation("com.okta.spring:okta-spring-boot-starter:${oktaSpringBootVersion}") - implementation("org.apache.commons:commons-csv:$commonsCsvVersion") implementation("com.redis.om:redis-om-spring:${redisOmSpringVersion}") implementation("org.springframework.data:spring-data-redis") @@ -332,7 +348,8 @@ subprojects { testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlinCoroutinesVersion") testImplementation("org.testng:testng:$testNgVersion") testImplementation( - "com.redis.testcontainers:testcontainers-redis-junit:$testContainersRedisVersion") + "com.redis.testcontainers:testcontainers-redis-junit:$testContainersRedisVersion" + ) testImplementation("org.testcontainers:postgresql:$testContainersPostgreSQLVersion") testImplementation("org.testcontainers:localstack:$testContainersLocalStackVersion") testImplementation("org.springframework.boot:spring-boot-starter-test") @@ -343,9 +360,9 @@ subprojects { exclude(module = "mockito-core") } integrationTestImplementation("com.ninja-squad:springmockk:$springMockkVersion") - // developmentOnly("org.springframework.boot:spring-boot-devtools") integrationTestImplementation( - "org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlinCoroutinesVersion") + "org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlinCoroutinesVersion" + ) } tasks.withType { @@ -427,7 +444,8 @@ subprojects { TestLogEvent.FAILED, TestLogEvent.SKIPPED, TestLogEvent.STANDARD_ERROR, - TestLogEvent.STANDARD_OUT) + TestLogEvent.STANDARD_OUT, + ) exceptionFormat = TestExceptionFormat.FULL } @@ -469,7 +487,9 @@ subprojects { // Service Implementation to be present in the 'apiPackage' package, // which is not the case when serviceInterface is true. // We will write our own tests instead. - "apiTests" to "false")) + "apiTests" to "false", + ) + ) additionalProperties.set( mapOf( "title" to "Cosmo Tech ${projectDirName.capitalizeAsciiOnly()} Manager API", @@ -482,7 +502,9 @@ subprojects { "useSpringBoot3" to true, "useTags" to true, "beanQualifiers" to true, - "modelMutable" to true)) + "modelMutable" to true, + ) + ) } } @@ -525,7 +547,9 @@ subprojects { mapOf( "fullVersion" to fullVersion, "releaseVersion" to project.version, - "buildVersion" to buildVersion)) + "buildVersion" to buildVersion, + ) + ) } } @@ -539,7 +563,9 @@ subprojects { mapOf( "fullVersion" to fullVersion, "releaseVersion" to project.version, - "buildVersion" to buildVersion)) + "buildVersion" to buildVersion, + ) + ) } tasks.getByName("processTestResources") { dependsOn("copyOpenApiYamlToTestResources") @@ -567,12 +593,14 @@ subprojects { environment = mapOf( "JAVA_TOOL_OPTIONS" to - "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=localhost:5005") + "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=localhost:5005" + ) jvmFlags = listOf( // Make sure Spring DevTools is disabled in production as running it is a // security risk - "-Dspring.devtools.restart.enabled=false") + "-Dspring.devtools.restart.enabled=false" + ) ports = listOf("5005", "8080", "8081") // Docker Best Practice : run as non-root. // These are the 'nobody' UID and GID inside the image @@ -602,19 +630,21 @@ val copySubProjectsDetektReportsTasks = "detektCopy${formatCapitalized}ReportFor" + "${subProject.projectDir.relativeTo(rootDir)}" .capitalizeAsciiOnly() - .replace("/", "_")) { - group = "detekt" - description = - "Copy sub-projects detekt reports to \$projectDir/build/reports/detekt/\$format" - dependsOn("spotlessKotlin", "spotlessKotlinGradle", "spotlessJava") - from( - file( - "${subProject.projectDir}/build/reports/detekt/${subProject.name}-detekt.$format")) - into( - "${subProject.parent!!.layout.projectDirectory}/build/reports/detekt/$format") - } + .replace("/", "_") + ) { + group = "detekt" + description = + "Copy sub-projects detekt reports to \$projectDir/build/reports/detekt/\$format" + dependsOn("spotlessKotlin", "spotlessKotlinGradle", "spotlessJava") + from( + file( + "${subProject.projectDir}/build/reports/detekt/${subProject.name}-detekt.$format" + ) + ) + into("${subProject.parent!!.layout.projectDirectory}/build/reports/detekt/$format") + } subProject.tasks.getByName("detekt") { finalizedBy(copyTask) } - subProject.tasks.withType { finalizedBy(copyTask) } + subProject.tasks.withType { finalizedBy(copyTask) } copyTask } } @@ -651,9 +681,10 @@ tasks.register("generateLicenseDoc") { tasks.register("generateAllReports") { group = "reporting" description = - """Generates all available reports (test, coverage, dependencies, licenses, detekt) - |/!\ Warning: Please do not run this task locally, tests are really resource consuming - """ + """ + |Generates all available reports (test, coverage, dependencies, licenses, detekt) + |/!\ Warning: Please do not run this task locally, tests are really resource consuming + """ .trimMargin() dependsOn( // Test reports, need to gather them first @@ -667,7 +698,8 @@ tasks.register("generateAllReports") { // License reports "generateLicenseReport", // Code analysis reports - "detekt") + "detekt", + ) doLast { // Create reports directory if it doesn't exist val reportsDir = layout.buildDirectory.get().dir("reports").asFile diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 729b486ff..2f160c478 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -8,17 +8,18 @@ val hashidsVersion = "1.0.3" val testContainersRedisVersion = "1.6.4" val testContainersPostgreSQLVersion = "1.21.3" val testContainersLocalStackVersion = "1.21.3" -val tikaVersion = "3.2.2" +val tikaVersion = "3.2.3" -val jUnitBomVersion = "5.13.4" +val jUnitBomVersion = "6.0.1" dependencies { implementation("org.apache.httpcomponents.client5:httpclient5") implementation("org.hashids:hashids:${hashidsVersion}") implementation( - "com.redis.testcontainers:testcontainers-redis-junit:${testContainersRedisVersion}") { - constraints { implementation("com.redis:lettucemod:4.4.0") } - } + "com.redis.testcontainers:testcontainers-redis-junit:${testContainersRedisVersion}" + ) { + constraints { implementation("com.redis:lettucemod:4.5.0") } + } implementation("org.testcontainers:postgresql:${testContainersPostgreSQLVersion}") implementation("org.testcontainers:localstack:${testContainersLocalStackVersion}") implementation("org.apache.tika:tika-core:${tikaVersion}") diff --git a/common/src/main/kotlin/com/cosmotech/common/config/CsmApiConfiguration.kt b/common/src/main/kotlin/com/cosmotech/common/config/CsmApiConfiguration.kt index 7a15804f2..8d40a258a 100644 --- a/common/src/main/kotlin/com/cosmotech/common/config/CsmApiConfiguration.kt +++ b/common/src/main/kotlin/com/cosmotech/common/config/CsmApiConfiguration.kt @@ -36,7 +36,8 @@ open class CsmApiConfiguration { open fun inProcessEventHandlerExecutor(): Executor = // TODO A better strategy could be with a limited core pool size off an unbounded queue ? Executors.newCachedThreadPool( - BasicThreadFactory.Builder().namingPattern("csm-event-handler-%d").build()) + BasicThreadFactory.builder().namingPattern("csm-event-handler-%d").build() + ) @Bean open fun yamlHttpMessageConverter(): YamlMessageConverter = YamlMessageConverter() } @@ -47,7 +48,7 @@ open class CsmPlatformEnvironmentPostProcessor : EnvironmentPostProcessor { override fun postProcessEnvironment( environment: ConfigurableEnvironment, - application: SpringApplication + application: SpringApplication, ) { addSpringProfile(environment) } @@ -85,7 +86,8 @@ class YamlMessageConverter(objectMapper: ObjectMapper) : MediaType("application", "*+yaml", StandardCharsets.UTF_8), MediaType("application", "yml", StandardCharsets.UTF_8), MediaType("text", "yml", StandardCharsets.UTF_8), - MediaType("application", "*+yml", StandardCharsets.UTF_8)) { + MediaType("application", "*+yml", StandardCharsets.UTF_8), + ) { constructor() : this(yamlObjectMapper()) diff --git a/common/src/main/kotlin/com/cosmotech/common/config/CsmOpenAPIConfiguration.kt b/common/src/main/kotlin/com/cosmotech/common/config/CsmOpenAPIConfiguration.kt index aec9ddd7b..46b2a2081 100644 --- a/common/src/main/kotlin/com/cosmotech/common/config/CsmOpenAPIConfiguration.kt +++ b/common/src/main/kotlin/com/cosmotech/common/config/CsmOpenAPIConfiguration.kt @@ -23,19 +23,22 @@ open class CsmOpenAPIConfiguration(val csmPlatformProperties: CsmPlatformPropert val openApiYamlInputStream = CsmOpenAPIConfiguration::class.java.getResourceAsStream("/static/openapi.yaml") ?: throw IllegalStateException( - "Unable to parse OpenAPI definition from 'classpath:/static/openapi.yaml'") + "Unable to parse OpenAPI definition from 'classpath:/static/openapi.yaml'" + ) val openApiYamlContent = openApiYamlInputStream.use { it.bufferedReader().use(BufferedReader::readText) } val openApiYamlParseResult = OpenAPIV3Parser().readContents(openApiYamlContent) if (!openApiYamlParseResult.messages.isNullOrEmpty()) { throw IllegalStateException( "Unable to parse OpenAPI definition from 'classpath:/static/openapi.yaml' : " + - openApiYamlParseResult.messages) + openApiYamlParseResult.messages + ) } val openAPI = openApiYamlParseResult.openAPI ?: throw IllegalStateException( - "Couldn't parse resource 'classpath:openapi.yaml' : ${openApiYamlParseResult.messages}") + "Couldn't parse resource 'classpath:openapi.yaml' : ${openApiYamlParseResult.messages}" + ) openAPI.info.version = apiVersion @@ -55,7 +58,8 @@ open class CsmOpenAPIConfiguration(val csmPlatformProperties: CsmPlatformPropert OAuthFlow() .scopes(scopes) .tokenUrl(csmPlatformProperties.identityProvider.tokenUrl) - .authorizationUrl(csmPlatformProperties.identityProvider.authorizationUrl)) + .authorizationUrl(csmPlatformProperties.identityProvider.authorizationUrl) + ) openAPI.components.securitySchemes["oAuth2AuthCode"]?.flows(authorizationCodeFlow) diff --git a/common/src/main/kotlin/com/cosmotech/common/config/CsmPlatformProperties.kt b/common/src/main/kotlin/com/cosmotech/common/config/CsmPlatformProperties.kt index 0d4df9db5..6d76304d9 100644 --- a/common/src/main/kotlin/com/cosmotech/common/config/CsmPlatformProperties.kt +++ b/common/src/main/kotlin/com/cosmotech/common/config/CsmPlatformProperties.kt @@ -42,7 +42,7 @@ data class CsmPlatformProperties( val namespace: String = "phoenix", /** Persistent metrics configuration */ - val metrics: Metrics = Metrics() + val metrics: Metrics = Metrics(), ) { data class Metrics( @@ -86,7 +86,7 @@ data class CsmPlatformProperties( val allowedTenants: List = emptyList(), /** List of Api key allowed to access data, besides Oauth2 configuration */ - val allowedApiKeyConsumers: List = emptyList() + val allowedApiKeyConsumers: List = emptyList(), ) { class ApiKeyConsumer( @@ -103,7 +103,7 @@ data class CsmPlatformProperties( val associatedRole: String = ROLE_ORGANIZATION_USER, /** Secured URIs */ - val securedUris: List = emptyList() + val securedUris: List = emptyList(), ) } @@ -117,7 +117,7 @@ data class CsmPlatformProperties( /** Credentials: secret access key */ val secretAccessKey: String = "", /** Storage region */ - val region: String = "" + val region: String = "", ) data class Argo( @@ -162,7 +162,7 @@ data class CsmPlatformProperties( val ignoreNodeSelector: Boolean = false, /** Info on k8s secret to mount on workflow */ - val secrets: List = emptyList() + val secrets: List = emptyList(), ) { data class ExtraSecrets(val name: String, val keyPath: List) { data class KeyPath(val key: String, val path: String) @@ -261,7 +261,7 @@ data class CsmPlatformProperties( data class CsmDatabasesProperties( val resources: CsmResourcesProperties, - val data: CsmDataIOProperties + val data: CsmDataIOProperties, ) { data class CsmResourcesProperties( @@ -305,7 +305,7 @@ data class CsmPlatformProperties( val solution: PageSizing = PageSizing(), /** TLS Platform bundle config */ - val tls: TLSConfig = TLSConfig() + val tls: TLSConfig = TLSConfig(), ) { data class PageSizing( @@ -328,7 +328,7 @@ data class CsmPlatformProperties( val reader: CsmStorageUser, /** Storage writer user configuration */ - val writer: CsmStorageUser + val writer: CsmStorageUser, ) { data class CsmStorageUser(val username: String, val password: String) } diff --git a/common/src/main/kotlin/com/cosmotech/common/config/PostgresConfiguration.kt b/common/src/main/kotlin/com/cosmotech/common/config/PostgresConfiguration.kt index f9792e9f1..b14226e1d 100644 --- a/common/src/main/kotlin/com/cosmotech/common/config/PostgresConfiguration.kt +++ b/common/src/main/kotlin/com/cosmotech/common/config/PostgresConfiguration.kt @@ -25,7 +25,8 @@ class PostgresConfiguration(val csmPlatformProperties: CsmPlatformProperties) { DriverManagerDataSource( jdbcUrl, csmPlatformProperties.databases.data.reader.username, - csmPlatformProperties.databases.data.reader.password) + csmPlatformProperties.databases.data.reader.password, + ) dataSource.setDriverClassName(jdbcDriverClass) return JdbcTemplate(dataSource) } @@ -36,7 +37,8 @@ class PostgresConfiguration(val csmPlatformProperties: CsmPlatformProperties) { DriverManagerDataSource( jdbcUrl, csmPlatformProperties.databases.data.writer.username, - csmPlatformProperties.databases.data.writer.password) + csmPlatformProperties.databases.data.writer.password, + ) dataSource.setDriverClassName(jdbcDriverClass) return JdbcTemplate(dataSource) } @@ -44,6 +46,7 @@ class PostgresConfiguration(val csmPlatformProperties: CsmPlatformProperties) { fun JdbcTemplate.existTable(name: String): Boolean { return this.queryForList( - "select * from pg_tables where schemaname='$DATASET_INPUTS_SCHEMA' and tablename = '$name';") + "select * from pg_tables where schemaname='$DATASET_INPUTS_SCHEMA' and tablename = '$name';" + ) .isNotEmpty() } diff --git a/common/src/main/kotlin/com/cosmotech/common/containerregistry/ContainerRegistryService.kt b/common/src/main/kotlin/com/cosmotech/common/containerregistry/ContainerRegistryService.kt index 7e27b4010..9b648b864 100644 --- a/common/src/main/kotlin/com/cosmotech/common/containerregistry/ContainerRegistryService.kt +++ b/common/src/main/kotlin/com/cosmotech/common/containerregistry/ContainerRegistryService.kt @@ -41,7 +41,9 @@ class ContainerRegistryService(private val csmPlatformProperties: CsmPlatformPro .baseUrl(baseUrl) .requestFactory( HttpComponentsClientHttpRequestFactory( - HttpClientBuilder.create().disableRedirectHandling().build())) + HttpClientBuilder.create().disableRedirectHandling().build() + ) + ) .build() private fun getHeaderAuthorization(): String { @@ -67,7 +69,9 @@ class ContainerRegistryService(private val csmPlatformProperties: CsmPlatformPro } } catch (e: RestClientException) { throw CsmClientException( - "Solution docker image $repository:$tag check error: ${e.message}", e) + "Solution docker image $repository:$tag check error: ${e.message}", + e, + ) } } diff --git a/common/src/main/kotlin/com/cosmotech/common/events/ConnectorEvents.kt b/common/src/main/kotlin/com/cosmotech/common/events/ConnectorEvents.kt index 0e252ab9e..5747c26c5 100644 --- a/common/src/main/kotlin/com/cosmotech/common/events/ConnectorEvents.kt +++ b/common/src/main/kotlin/com/cosmotech/common/events/ConnectorEvents.kt @@ -7,5 +7,5 @@ class ConnectorRemoved(publisher: Any, val connectorId: String) : CsmEvent(publi class ConnectorRemovedForOrganization( publisher: Any, val organizationId: String, - val connectorId: String + val connectorId: String, ) : CsmEvent(publisher) diff --git a/common/src/main/kotlin/com/cosmotech/common/events/OrganizationEvents.kt b/common/src/main/kotlin/com/cosmotech/common/events/OrganizationEvents.kt index 0f7f23595..77517104c 100644 --- a/common/src/main/kotlin/com/cosmotech/common/events/OrganizationEvents.kt +++ b/common/src/main/kotlin/com/cosmotech/common/events/OrganizationEvents.kt @@ -11,7 +11,7 @@ class UserAddedToOrganization( val organizationId: String, val organizationName: String, val userId: String, - val roles: List? = null + val roles: List? = null, ) : CsmEvent(publisher) class UserRemovedFromOrganization(publisher: Any, val organizationId: String, val userId: String) : @@ -20,5 +20,5 @@ class UserRemovedFromOrganization(publisher: Any, val organizationId: String, va class UserUnregisteredForOrganization( publisher: Any, val organizationId: String, - val userId: String + val userId: String, ) : CsmEvent(publisher) diff --git a/common/src/main/kotlin/com/cosmotech/common/events/RunEvents.kt b/common/src/main/kotlin/com/cosmotech/common/events/RunEvents.kt index 6cd55b8ee..25941b822 100644 --- a/common/src/main/kotlin/com/cosmotech/common/events/RunEvents.kt +++ b/common/src/main/kotlin/com/cosmotech/common/events/RunEvents.kt @@ -11,14 +11,14 @@ class AskRunStatusEvent( val organizationId: String, val workspaceId: String, val runnerId: String, - val runId: String + val runId: String, ) : CsmRequestResponseEvent(publisher) class HasRunningRuns( publisher: Any, val organizationId: String, val workspaceId: String, - val runnerId: String + val runnerId: String, ) : CsmRequestResponseEvent(publisher) class RunDeleted( @@ -27,5 +27,5 @@ class RunDeleted( val workspaceId: String, val runnerId: String, val runId: String, - val lastRun: String? + val lastRun: String?, ) : CsmEvent(publisher) diff --git a/common/src/main/kotlin/com/cosmotech/common/events/RunnerEvents.kt b/common/src/main/kotlin/com/cosmotech/common/events/RunnerEvents.kt index c3280c254..490cff838 100644 --- a/common/src/main/kotlin/com/cosmotech/common/events/RunnerEvents.kt +++ b/common/src/main/kotlin/com/cosmotech/common/events/RunnerEvents.kt @@ -6,7 +6,7 @@ class TriggerRunnerEvent( publisher: Any, val organizationId: String, val workspaceId: String, - val runnerId: String + val runnerId: String, ) : CsmRequestResponseEvent(publisher) class RunnerDeleted( @@ -14,7 +14,7 @@ class RunnerDeleted( val organizationId: String, val workspaceId: String, val runnerId: String, - val datasetParameterId: String + val datasetParameterId: String, ) : CsmEvent(publisher) class UpdateRunnerStatus( @@ -29,5 +29,5 @@ class GetRunnerAttachedToDataset( publisher: Any, val organizationId: String, val workspaceId: String, - val datasetId: String + val datasetId: String, ) : CsmRequestResponseEvent(publisher) diff --git a/common/src/main/kotlin/com/cosmotech/common/events/WorkspaceEvents.kt b/common/src/main/kotlin/com/cosmotech/common/events/WorkspaceEvents.kt index ec02f1448..5fd02a013 100644 --- a/common/src/main/kotlin/com/cosmotech/common/events/WorkspaceEvents.kt +++ b/common/src/main/kotlin/com/cosmotech/common/events/WorkspaceEvents.kt @@ -6,14 +6,14 @@ class UserAddedToWorkspace( publisher: Any, val organizationId: String, val userId: String, - val roles: List? = null + val roles: List? = null, ) : CsmEvent(publisher) class UserRemovedFromWorkspace( publisher: Any, val organizationId: String, val workspaceId: String, - val userId: String + val userId: String, ) : CsmEvent(publisher) class WorkspaceDeleted(publisher: Any, val organizationId: String, val workspaceId: String) : diff --git a/common/src/main/kotlin/com/cosmotech/common/events/inprocess/InProcessEventPublisher.kt b/common/src/main/kotlin/com/cosmotech/common/events/inprocess/InProcessEventPublisher.kt index aa4e7414e..4ff4f7ece 100644 --- a/common/src/main/kotlin/com/cosmotech/common/events/inprocess/InProcessEventPublisher.kt +++ b/common/src/main/kotlin/com/cosmotech/common/events/inprocess/InProcessEventPublisher.kt @@ -10,7 +10,10 @@ import org.springframework.stereotype.Service @Service @ConditionalOnProperty( - name = ["csm.platform.event-publisher.type"], havingValue = "in_process", matchIfMissing = true) + name = ["csm.platform.event-publisher.type"], + havingValue = "in_process", + matchIfMissing = true, +) internal class InProcessEventPublisher(private val eventPublisher: ApplicationEventPublisher) : CsmEventPublisher { diff --git a/common/src/main/kotlin/com/cosmotech/common/exceptions/CsmClientExceptions.kt b/common/src/main/kotlin/com/cosmotech/common/exceptions/CsmClientExceptions.kt index 4fbbb52f8..c385dc507 100644 --- a/common/src/main/kotlin/com/cosmotech/common/exceptions/CsmClientExceptions.kt +++ b/common/src/main/kotlin/com/cosmotech/common/exceptions/CsmClientExceptions.kt @@ -12,11 +12,11 @@ open class CsmClientException(override val message: String, override val cause: @ResponseStatus(HttpStatus.NOT_FOUND) class CsmResourceNotFoundException( override val message: String, - override val cause: Throwable? = null + override val cause: Throwable? = null, ) : CsmClientException(message, cause) @ResponseStatus(HttpStatus.FORBIDDEN) class CsmAccessForbiddenException( override val message: String, - override val cause: Throwable? = null + override val cause: Throwable? = null, ) : CsmClientException(message, cause) diff --git a/common/src/main/kotlin/com/cosmotech/common/exceptions/CsmExceptionHandling.kt b/common/src/main/kotlin/com/cosmotech/common/exceptions/CsmExceptionHandling.kt index 420dcc44e..39ce1f8d1 100644 --- a/common/src/main/kotlin/com/cosmotech/common/exceptions/CsmExceptionHandling.kt +++ b/common/src/main/kotlin/com/cosmotech/common/exceptions/CsmExceptionHandling.kt @@ -37,7 +37,7 @@ open class CsmExceptionHandling : ResponseEntityExceptionHandler() { exception: HttpMessageNotReadableException, headers: HttpHeaders, status: HttpStatusCode, - request: WebRequest + request: WebRequest, ): ResponseEntity? { val badRequestStatus = HttpStatus.BAD_REQUEST val problemDetail = ProblemDetail.forStatus(badRequestStatus) @@ -53,7 +53,7 @@ open class CsmExceptionHandling : ResponseEntityExceptionHandler() { exception: MethodArgumentNotValidException, headers: HttpHeaders, status: HttpStatusCode, - request: WebRequest + request: WebRequest, ): ResponseEntity? { val badRequestStatus = HttpStatus.BAD_REQUEST val problemDetail = ProblemDetail.forStatus(badRequestStatus) diff --git a/common/src/main/kotlin/com/cosmotech/common/exceptions/CsmServerExceptions.kt b/common/src/main/kotlin/com/cosmotech/common/exceptions/CsmServerExceptions.kt index c7d56450b..d88851b6a 100644 --- a/common/src/main/kotlin/com/cosmotech/common/exceptions/CsmServerExceptions.kt +++ b/common/src/main/kotlin/com/cosmotech/common/exceptions/CsmServerExceptions.kt @@ -12,5 +12,5 @@ open class CsmServerException(override val message: String, override val cause: @ResponseStatus(HttpStatus.SERVICE_UNAVAILABLE) class CsmServiceUnavailableException( override val message: String, - override val cause: Throwable? = null + override val cause: Throwable? = null, ) : CsmServerException(message, cause) diff --git a/common/src/main/kotlin/com/cosmotech/common/home/HomeController.kt b/common/src/main/kotlin/com/cosmotech/common/home/HomeController.kt index 831c1a044..f9604ce48 100644 --- a/common/src/main/kotlin/com/cosmotech/common/home/HomeController.kt +++ b/common/src/main/kotlin/com/cosmotech/common/home/HomeController.kt @@ -25,7 +25,8 @@ internal class HomeController( [ "/", ], - produces = [MediaType.APPLICATION_JSON_VALUE]) + produces = [MediaType.APPLICATION_JSON_VALUE], + ) fun redirectHomeToOpenApi(httpServletResponse: HttpServletResponse) { redirectOpenApiJsonToOpenApi(httpServletResponse) } diff --git a/common/src/main/kotlin/com/cosmotech/common/id/CsmIdGenerator.kt b/common/src/main/kotlin/com/cosmotech/common/id/CsmIdGenerator.kt index c8e86dcd5..107b3ccaf 100644 --- a/common/src/main/kotlin/com/cosmotech/common/id/CsmIdGenerator.kt +++ b/common/src/main/kotlin/com/cosmotech/common/id/CsmIdGenerator.kt @@ -21,7 +21,8 @@ fun generateId(scope: String, prependPrefix: String? = null): String { Hashids("$scope-${UUID.randomUUID()}", MIN_HASH_LENGTH, ALPHABET) .encode( // PROD-8703: encodedElement might be higher than the maximum number supported - min(System.nanoTime(), MAX_NUMBER)) + min(System.nanoTime(), MAX_NUMBER) + ) return "${prependPrefix ?: "${scope[0].lowercaseChar()}-"}$id" } diff --git a/common/src/main/kotlin/com/cosmotech/common/metrics/MonitorServiceAspect.kt b/common/src/main/kotlin/com/cosmotech/common/metrics/MonitorServiceAspect.kt index 2dceba377..0e06b2e64 100644 --- a/common/src/main/kotlin/com/cosmotech/common/metrics/MonitorServiceAspect.kt +++ b/common/src/main/kotlin/com/cosmotech/common/metrics/MonitorServiceAspect.kt @@ -25,11 +25,14 @@ private const val SERVICE_NAME = "API" @Aspect @Component @ConditionalOnProperty( - name = ["csm.platform.metrics.enabled"], havingValue = "true", matchIfMissing = false) + name = ["csm.platform.metrics.enabled"], + havingValue = "true", + matchIfMissing = false, +) class MonitorServiceAspect( private var meterRegistry: MeterRegistry, private val eventPublisher: CsmEventPublisher, - private val csmPlatformProperties: CsmPlatformProperties + private val csmPlatformProperties: CsmPlatformProperties, ) { private val logger: Logger = LoggerFactory.getLogger(this::class.java) @@ -41,10 +44,12 @@ class MonitorServiceAspect( "runnerId", "runId", "datasetId", - "connectorId") + "connectorId", + ) @Pointcut( - "within(@org.springframework.web.bind.annotation.RestController *) && within(com.cosmotech..*Controller)") + "within(@org.springframework.web.bind.annotation.RestController *) && within(com.cosmotech..*Controller)" + ) @Suppress("EmptyFunctionBlock") fun cosmotechPointcut() {} diff --git a/common/src/main/kotlin/com/cosmotech/common/rbac/CsmRbac.kt b/common/src/main/kotlin/com/cosmotech/common/rbac/CsmRbac.kt index 107d5c18e..b70ab345a 100644 --- a/common/src/main/kotlin/com/cosmotech/common/rbac/CsmRbac.kt +++ b/common/src/main/kotlin/com/cosmotech/common/rbac/CsmRbac.kt @@ -18,7 +18,7 @@ import org.springframework.stereotype.Component @Component open class CsmRbac( protected val csmPlatformProperties: CsmPlatformProperties, - protected val csmAdmin: CsmAdmin + protected val csmAdmin: CsmAdmin, ) { private val logger: Logger = LoggerFactory.getLogger(this::class.java) @@ -31,7 +31,8 @@ open class CsmRbac( objectSecurity.accessControlList.forEach { if (accessControls.contains(it.id)) { throw IllegalArgumentException( - "Entity ${it.id} is referenced multiple times in the security") + "Entity ${it.id} is referenced multiple times in the security" + ) } accessControls.add(it.id) } @@ -53,17 +54,18 @@ open class CsmRbac( fun verify( rbacSecurity: RbacSecurity, permission: String, - rolesDefinition: RolesDefinition = getCommonRolesDefinition() + rolesDefinition: RolesDefinition = getCommonRolesDefinition(), ) { if (!this.check(rbacSecurity, permission, rolesDefinition)) throw CsmAccessForbiddenException( - "RBAC ${rbacSecurity.id} - User does not have permission $permission") + "RBAC ${rbacSecurity.id} - User does not have permission $permission" + ) } fun check( rbacSecurity: RbacSecurity, permission: String, - rolesDefinition: RolesDefinition = getCommonRolesDefinition() + rolesDefinition: RolesDefinition = getCommonRolesDefinition(), ): Boolean { logger.info("RBAC ${rbacSecurity.id} - Verifying permission $permission for entity") if (!this.csmPlatformProperties.rbac.enabled) { @@ -83,7 +85,7 @@ open class CsmRbac( fun setDefault( rbacSecurity: RbacSecurity, defaultRole: String, - rolesDefinition: RolesDefinition = getCommonRolesDefinition() + rolesDefinition: RolesDefinition = getCommonRolesDefinition(), ): RbacSecurity { logger.info("RBAC ${rbacSecurity.id} - Setting default security") if (defaultRole != ROLE_NONE) { @@ -98,14 +100,15 @@ open class CsmRbac( rbacSecurity: RbacSecurity, entityId: String, role: String, - rolesDefinition: RolesDefinition = getCommonRolesDefinition() + rolesDefinition: RolesDefinition = getCommonRolesDefinition(), ): RbacSecurity { if (!isAdmin(rbacSecurity, rolesDefinition)) { this.checkEntityExists( parentRbacSecurity, entityId, - "Entity $entityId not found in parent ${parentRbacSecurity.id} component") + "Entity $entityId not found in parent ${parentRbacSecurity.id} component", + ) } return setEntityRole(rbacSecurity, entityId, role, rolesDefinition) } @@ -114,7 +117,7 @@ open class CsmRbac( rbacSecurity: RbacSecurity, entityId: String, role: String, - rolesDefinition: RolesDefinition = getCommonRolesDefinition() + rolesDefinition: RolesDefinition = getCommonRolesDefinition(), ): RbacSecurity { logger.info("RBAC ${rbacSecurity.id} - Setting entity $entityId roles") this.verifyRoleOrThrow(rbacSecurity, role, rolesDefinition) @@ -123,11 +126,14 @@ open class CsmRbac( .firstOrNull { it.id.lowercase() == entityId.lowercase() } ?.role val adminRole = this.getAdminRole(rolesDefinition) - if (currentACLRole == adminRole && - role != adminRole && - this.getAdminCount(rbacSecurity, rolesDefinition) == 1) { + if ( + currentACLRole == adminRole && + role != adminRole && + this.getAdminCount(rbacSecurity, rolesDefinition) == 1 + ) { throw CsmAccessForbiddenException( - "RBAC ${rbacSecurity.id} - It is forbidden to unset the last administrator") + "RBAC ${rbacSecurity.id} - It is forbidden to unset the last administrator" + ) } val accessList = rbacSecurity.accessControlList val entityAccess = accessList.find { it.id == entityId } @@ -146,13 +152,14 @@ open class CsmRbac( fun getAccessControl(rbacSecurity: RbacSecurity, entityId: String): RbacAccessControl { return rbacSecurity.accessControlList.find { it.id == entityId } ?: throw CsmResourceNotFoundException( - "Entity $entityId not found in ${rbacSecurity.id} component") + "Entity $entityId not found in ${rbacSecurity.id} component" + ) } fun checkEntityExists( rbacSecurity: RbacSecurity, entityId: String, - exceptionEntityNotFoundMessage: String + exceptionEntityNotFoundMessage: String, ): RbacAccessControl { return rbacSecurity.accessControlList.find { it.id == entityId } ?: throw CsmResourceNotFoundException(exceptionEntityNotFoundMessage) @@ -161,15 +168,18 @@ open class CsmRbac( fun removeEntity( rbacSecurity: RbacSecurity, entityId: String, - rolesDefinition: RolesDefinition = getCommonRolesDefinition() + rolesDefinition: RolesDefinition = getCommonRolesDefinition(), ): RbacSecurity { logger.info("RBAC ${rbacSecurity.id} - Removing entity $entityId from security") checkEntityExists(rbacSecurity, entityId, "Entity $entityId not found") val role = this.getEntityRole(rbacSecurity, entityId) - if (role == (this.getAdminRole(rolesDefinition)) && - this.getAdminCount(rbacSecurity, rolesDefinition) == 1) { + if ( + role == (this.getAdminRole(rolesDefinition)) && + this.getAdminCount(rbacSecurity, rolesDefinition) == 1 + ) { throw CsmAccessForbiddenException( - "RBAC ${rbacSecurity.id} - It is forbidden to remove the last administrator") + "RBAC ${rbacSecurity.id} - It is forbidden to remove the last administrator" + ) } rbacSecurity.accessControlList.removeIf { it.id == entityId } return rbacSecurity @@ -189,7 +199,7 @@ open class CsmRbac( rbacSecurity: RbacSecurity, user: String, groups: List, - rolesDefinition: RolesDefinition + rolesDefinition: RolesDefinition, ): Boolean { logger.debug("RBAC ${rbacSecurity.id} - Verifying if $user has default admin rbac role") val isAdmin = @@ -209,7 +219,7 @@ open class CsmRbac( permission: String, rolesDefinition: RolesDefinition, user: String, - groups: List + groups: List, ): Boolean { logger.debug("RBAC ${rbacSecurity.id} - Verifying $user has permission in ACL: $permission") val isAuthorized = @@ -227,13 +237,14 @@ open class CsmRbac( internal fun verifyDefault( rbacSecurity: RbacSecurity, permission: String, - rolesDefinition: RolesDefinition + rolesDefinition: RolesDefinition, ): Boolean { logger.debug("RBAC ${rbacSecurity.id} - Verifying default roles for permission: $permission") val defaultRole = if (rbacSecurity.default == ROLE_NONE) null else rbacSecurity.default val isAuthorized = this.verifyPermissionFromRole(permission, defaultRole, rolesDefinition) logger.debug( - "RBAC ${rbacSecurity.id} - default roles for permission $permission: $isAuthorized") + "RBAC ${rbacSecurity.id} - default roles for permission $permission: $isAuthorized" + ) return isAuthorized } @@ -242,7 +253,7 @@ open class CsmRbac( permission: String, rolesDefinition: RolesDefinition, user: String, - groups: List + groups: List, ): Boolean { return (this.verifyDefault(rbacSecurity, permission, rolesDefinition) || this.verifyUser(rbacSecurity, permission, rolesDefinition, user, groups)) @@ -251,15 +262,17 @@ open class CsmRbac( internal fun verifyPermissionFromRole( permission: String, role: String?, - rolesDefinition: RolesDefinition + rolesDefinition: RolesDefinition, ): Boolean { return this.verifyPermission( - permission, this.getRolePermissions(role, rolesDefinition.permissions)) + permission, + this.getRolePermissions(role, rolesDefinition.permissions), + ) } internal fun getRolePermissions( role: String?, - rolesDefinition: MutableMap> + rolesDefinition: MutableMap>, ): List { return rolesDefinition[role] ?: listOf() } @@ -280,7 +293,7 @@ open class CsmRbac( internal fun verifyRoleOrThrow( rbacSecurity: RbacSecurity, role: String, - rolesDefinition: RolesDefinition + rolesDefinition: RolesDefinition, ) { if (!rolesDefinition.permissions.keys.contains(role)) throw CsmClientException("RBAC ${rbacSecurity.id} - Role $role does not exist") @@ -293,7 +306,7 @@ open class CsmRbac( internal fun verifyPermissionFromRoles( permission: String, roles: List, - rolesDefinition: RolesDefinition + rolesDefinition: RolesDefinition, ): Boolean { return roles.any { role -> this.verifyPermissionFromRole(permission, role, rolesDefinition) } } diff --git a/common/src/main/kotlin/com/cosmotech/common/rbac/RolesDefinition.kt b/common/src/main/kotlin/com/cosmotech/common/rbac/RolesDefinition.kt index 68cb1e2e8..da65eb93a 100644 --- a/common/src/main/kotlin/com/cosmotech/common/rbac/RolesDefinition.kt +++ b/common/src/main/kotlin/com/cosmotech/common/rbac/RolesDefinition.kt @@ -49,7 +49,8 @@ val RUNNER_ROLE_VALIDATOR_PERMISSIONS = PERMISSION_READ_SECURITY, PERMISSION_LAUNCH, PERMISSION_WRITE, - PERMISSION_VALIDATE) + PERMISSION_VALIDATE, + ) val RUNNER_ROLE_ADMIN_PERMISSIONS = listOf( PERMISSION_READ, @@ -64,7 +65,7 @@ val RUNNER_ROLE_ADMIN_PERMISSIONS = @Component data class RolesDefinition( val permissions: MutableMap> = mutableMapOf(), - val adminRole: String = ROLE_ADMIN + val adminRole: String = ROLE_ADMIN, ) fun getAllRolesDefinition(): Map>> { @@ -83,7 +84,8 @@ fun getAllRolesDefinition(): Map> getRunnerRolesDefinition() .permissions .mapValues { it.value.toMutableList() } - .toMutableMap()) + .toMutableMap(), + ) } fun getPermissions(role: String, rolesDefinition: RolesDefinition): List { @@ -100,7 +102,8 @@ fun getCommonRolesDefinition(): RolesDefinition { ROLE_EDITOR to COMMON_ROLE_EDITOR_PERMISSIONS, ROLE_ADMIN to COMMON_ROLE_ADMIN_PERMISSIONS, ), - adminRole = ROLE_ADMIN) + adminRole = ROLE_ADMIN, + ) } fun getRunnerRolesDefinition(): RolesDefinition { @@ -113,5 +116,6 @@ fun getRunnerRolesDefinition(): RolesDefinition { ROLE_VALIDATOR to RUNNER_ROLE_VALIDATOR_PERMISSIONS, ROLE_ADMIN to RUNNER_ROLE_ADMIN_PERMISSIONS, ), - adminRole = ROLE_ADMIN) + adminRole = ROLE_ADMIN, + ) } diff --git a/common/src/main/kotlin/com/cosmotech/common/rbac/model/RbacSecurity.kt b/common/src/main/kotlin/com/cosmotech/common/rbac/model/RbacSecurity.kt index cecce619e..68ae752f0 100644 --- a/common/src/main/kotlin/com/cosmotech/common/rbac/model/RbacSecurity.kt +++ b/common/src/main/kotlin/com/cosmotech/common/rbac/model/RbacSecurity.kt @@ -7,5 +7,5 @@ import com.cosmotech.common.rbac.ROLE_NONE data class RbacSecurity( var id: String?, var default: String = ROLE_NONE, - var accessControlList: kotlin.collections.MutableList = mutableListOf() + var accessControlList: kotlin.collections.MutableList = mutableListOf(), ) diff --git a/common/src/main/kotlin/com/cosmotech/common/redis/RedisAspect.kt b/common/src/main/kotlin/com/cosmotech/common/redis/RedisAspect.kt index a5af8219b..14efdf041 100644 --- a/common/src/main/kotlin/com/cosmotech/common/redis/RedisAspect.kt +++ b/common/src/main/kotlin/com/cosmotech/common/redis/RedisAspect.kt @@ -34,7 +34,7 @@ class RedisAspect { private inline fun applyAnnotation( methodSignature: MethodSignature, - applyLambda: (Int) -> Unit + applyLambda: (Int) -> Unit, ) { val parameterAnnotations = methodSignature.method.parameterAnnotations val annotatedParamIndexes = diff --git a/common/src/main/kotlin/com/cosmotech/common/security/AbstractSecurityConfiguration.kt b/common/src/main/kotlin/com/cosmotech/common/security/AbstractSecurityConfiguration.kt index 18f6ec860..0d6c32c74 100644 --- a/common/src/main/kotlin/com/cosmotech/common/security/AbstractSecurityConfiguration.kt +++ b/common/src/main/kotlin/com/cosmotech/common/security/AbstractSecurityConfiguration.kt @@ -11,7 +11,7 @@ import org.springframework.security.web.access.intercept.AuthorizationFilter import org.springframework.security.web.context.DelegatingSecurityContextRepository import org.springframework.security.web.context.HttpSessionSecurityContextRepository import org.springframework.security.web.context.RequestAttributeSecurityContextRepository -import org.springframework.security.web.util.matcher.AntPathRequestMatcher +import org.springframework.security.web.servlet.util.matcher.PathPatternRequestMatcher import org.springframework.security.web.util.matcher.RequestHeaderRequestMatcher import org.springframework.web.cors.CorsConfiguration @@ -64,7 +64,8 @@ val PATHS_ORGANIZATIONS = "/organizations/*/security/access", "/organizations/*/security/access/*", "/organizations/*/security/default", - "/organizations/*/security/users") + "/organizations/*/security/users", + ) // Path Runs val PATHS_RUNS = @@ -74,7 +75,8 @@ val PATHS_RUNS = "/organizations/*/workspaces/*/runners/*/runs/*/data/query", "/organizations/*/workspaces/*/runners/*/runs/*/data/send", "/organizations/*/workspaces/*/runners/*/runs/*/logs", - "/organizations/*/workspaces/*/runners/*/runs/*/status") + "/organizations/*/workspaces/*/runners/*/runs/*/status", + ) // Path Runners val PATHS_RUNNERS = @@ -88,7 +90,8 @@ val PATHS_RUNNERS = "/organizations/*/workspaces/*/runners/*/security/default", "/organizations/*/workspaces/*/runners/*/security/users", "/organizations/*/workspaces/*/runners/*/start", - "/organizations/*/workspaces/*/runners/*/stop") + "/organizations/*/workspaces/*/runners/*/stop", + ) // Path Solutions val PATHS_SOLUTIONS = @@ -113,7 +116,8 @@ val PATHS_WORKSPACES_FILES = listOf( "/organizations/*/workspaces/*/files", "/organizations/*/workspaces/*/files/delete", - "/organizations/*/workspaces/*/files/download") + "/organizations/*/workspaces/*/files/download", + ) // Path Workspaces val PATHS_WORKSPACES = @@ -147,7 +151,7 @@ val endpointSecurityPublic = internal fun endpointSecurityReaders( customOrganizationAdmin: String, customOrganizationUser: String, - customOrganizationViewer: String + customOrganizationViewer: String, ) = listOf( CsmSecurityEndpointsRolesReader( @@ -157,8 +161,10 @@ internal fun endpointSecurityReaders( ROLE_ORGANIZATION_USER, ROLE_ORGANIZATION_VIEWER, customOrganizationUser, - customOrganizationViewer), - customAdmin = customOrganizationAdmin), + customOrganizationViewer, + ), + customAdmin = customOrganizationAdmin, + ), CsmSecurityEndpointsRolesReader( paths = PATHS_DATASETS, roles = @@ -168,8 +174,10 @@ internal fun endpointSecurityReaders( SCOPE_DATASET_READ, SCOPE_DATASET_WRITE, customOrganizationUser, - customOrganizationViewer), - customAdmin = customOrganizationAdmin), + customOrganizationViewer, + ), + customAdmin = customOrganizationAdmin, + ), CsmSecurityEndpointsRolesReader( paths = PATHS_ORGANIZATIONS, roles = @@ -179,8 +187,10 @@ internal fun endpointSecurityReaders( SCOPE_ORGANIZATION_READ, SCOPE_ORGANIZATION_WRITE, customOrganizationUser, - customOrganizationViewer), - customAdmin = customOrganizationAdmin), + customOrganizationViewer, + ), + customAdmin = customOrganizationAdmin, + ), CsmSecurityEndpointsRolesReader( paths = PATHS_SOLUTIONS, roles = @@ -190,8 +200,10 @@ internal fun endpointSecurityReaders( SCOPE_SOLUTION_READ, SCOPE_SOLUTION_WRITE, customOrganizationUser, - customOrganizationViewer), - customAdmin = customOrganizationAdmin), + customOrganizationViewer, + ), + customAdmin = customOrganizationAdmin, + ), CsmSecurityEndpointsRolesReader( paths = PATHS_WORKSPACES, roles = @@ -201,8 +213,10 @@ internal fun endpointSecurityReaders( SCOPE_WORKSPACE_READ, SCOPE_WORKSPACE_WRITE, customOrganizationUser, - customOrganizationViewer), - customAdmin = customOrganizationAdmin), + customOrganizationViewer, + ), + customAdmin = customOrganizationAdmin, + ), CsmSecurityEndpointsRolesReader( paths = PATHS_RUNS, roles = @@ -212,8 +226,10 @@ internal fun endpointSecurityReaders( SCOPE_RUN_READ, SCOPE_RUN_WRITE, customOrganizationUser, - customOrganizationViewer), - customAdmin = customOrganizationAdmin), + customOrganizationViewer, + ), + customAdmin = customOrganizationAdmin, + ), CsmSecurityEndpointsRolesReader( paths = PATHS_RUNNERS, roles = @@ -223,43 +239,53 @@ internal fun endpointSecurityReaders( SCOPE_RUNNER_READ, SCOPE_RUNNER_WRITE, customOrganizationUser, - customOrganizationViewer), - customAdmin = customOrganizationAdmin)) + customOrganizationViewer, + ), + customAdmin = customOrganizationAdmin, + ), + ) @Suppress("LongMethod") internal fun endpointSecurityWriters( customOrganizationAdmin: String, - customOrganizationUser: String + customOrganizationUser: String, ) = listOf( CsmSecurityEndpointsRolesWriter( paths = PATHS_DATASETS, roles = arrayOf(ROLE_ORGANIZATION_USER, SCOPE_DATASET_WRITE, customOrganizationUser), - customAdmin = customOrganizationAdmin), + customAdmin = customOrganizationAdmin, + ), CsmSecurityEndpointsRolesWriter( paths = PATHS_ORGANIZATIONS, roles = arrayOf(SCOPE_ORGANIZATION_WRITE), - customAdmin = customOrganizationAdmin), + customAdmin = customOrganizationAdmin, + ), CsmSecurityEndpointsRolesWriter( paths = PATHS_SOLUTIONS, roles = arrayOf(ROLE_ORGANIZATION_USER, SCOPE_SOLUTION_WRITE, customOrganizationUser), - customAdmin = customOrganizationAdmin), + customAdmin = customOrganizationAdmin, + ), CsmSecurityEndpointsRolesWriter( paths = PATHS_WORKSPACES, roles = arrayOf(SCOPE_WORKSPACE_WRITE), - customAdmin = customOrganizationAdmin), + customAdmin = customOrganizationAdmin, + ), CsmSecurityEndpointsRolesWriter( paths = PATHS_RUNS, roles = arrayOf(ROLE_ORGANIZATION_USER, SCOPE_RUN_WRITE, customOrganizationUser), - customAdmin = customOrganizationAdmin), + customAdmin = customOrganizationAdmin, + ), CsmSecurityEndpointsRolesWriter( paths = PATHS_RUNNERS, roles = arrayOf(ROLE_ORGANIZATION_USER, SCOPE_RUNNER_WRITE, customOrganizationUser), - customAdmin = customOrganizationAdmin), + customAdmin = customOrganizationAdmin, + ), CsmSecurityEndpointsRolesWriter( paths = PATHS_WORKSPACES_FILES, roles = arrayOf(ROLE_ORGANIZATION_USER, SCOPE_WORKSPACE_WRITE, customOrganizationUser), - customAdmin = customOrganizationAdmin), + customAdmin = customOrganizationAdmin, + ), ) abstract class AbstractSecurityConfiguration { @@ -269,7 +295,7 @@ abstract class AbstractSecurityConfiguration { organizationAdminGroup: String, organizationUserGroup: String, organizationViewerGroup: String, - csmPlatformProperties: CsmPlatformProperties + csmPlatformProperties: CsmPlatformProperties, ): HttpSecurity { val corsHttpMethodsAllowed = @@ -286,30 +312,42 @@ abstract class AbstractSecurityConfiguration { .csrf { csrfConfigurer -> csmPlatformProperties.authorization.allowedApiKeyConsumers.forEach { apiKeyConsumer -> csrfConfigurer.ignoringRequestMatchers( - RequestHeaderRequestMatcher(apiKeyConsumer.apiKeyHeaderName)) + RequestHeaderRequestMatcher(apiKeyConsumer.apiKeyHeaderName) + ) } } .securityContext { it.securityContextRepository( DelegatingSecurityContextRepository( RequestAttributeSecurityContextRepository(), - HttpSessionSecurityContextRepository())) + HttpSessionSecurityContextRepository(), + ) + ) } .addFilterBefore( - ApiKeyAuthenticationFilter(csmPlatformProperties), AuthorizationFilter::class.java) + ApiKeyAuthenticationFilter(csmPlatformProperties), + AuthorizationFilter::class.java, + ) .authorizeHttpRequests { requests -> requests - .requestMatchers(AntPathRequestMatcher.antMatcher(HttpMethod.OPTIONS, "/**")) + .requestMatchers( + PathPatternRequestMatcher.withDefaults().matcher(HttpMethod.OPTIONS, "/**") + ) .permitAll() // Public paths endpointSecurityPublic.forEach { path -> requests - .requestMatchers(AntPathRequestMatcher.antMatcher(HttpMethod.GET, path)) + .requestMatchers( + PathPatternRequestMatcher.withDefaults().matcher(HttpMethod.GET, path) + ) .permitAll() } // Endpoint security for reader roles endpointSecurityReaders( - organizationAdminGroup, organizationUserGroup, organizationViewerGroup) + organizationAdminGroup, + organizationUserGroup, + organizationViewerGroup, + ) .forEach { endpointsRoles -> endpointsRoles.applyRoles(requests) } // Endpoint security for writer roles @@ -337,11 +375,13 @@ internal class CsmSecurityEndpointsRolesWriter( val authoritiesList = addAdminRolesIfNotAlreadyDefined(this.roles) this.paths.forEach { path -> requests - .requestMatchers(AntPathRequestMatcher.antMatcher(HttpMethod.POST, path)) + .requestMatchers(PathPatternRequestMatcher.withDefaults().matcher(HttpMethod.POST, path)) .hasAnyAuthority(*authoritiesList.toTypedArray()) - .requestMatchers(AntPathRequestMatcher.antMatcher(HttpMethod.PATCH, path)) + .requestMatchers(PathPatternRequestMatcher.withDefaults().matcher(HttpMethod.PATCH, path)) .hasAnyAuthority(*authoritiesList.toTypedArray()) - .requestMatchers(AntPathRequestMatcher.antMatcher(HttpMethod.DELETE, path)) + .requestMatchers( + PathPatternRequestMatcher.withDefaults().matcher(HttpMethod.DELETE, path) + ) .hasAnyAuthority(*authoritiesList.toTypedArray()) } } @@ -372,7 +412,7 @@ internal class CsmSecurityEndpointsRolesReader( val authoritiesList = addAdminRolesIfNotAlreadyDefined(this.roles) this.paths.forEach { path -> requests - .requestMatchers(AntPathRequestMatcher.antMatcher(HttpMethod.GET, path)) + .requestMatchers(PathPatternRequestMatcher.withDefaults().matcher(HttpMethod.GET, path)) .hasAnyAuthority(*authoritiesList.toTypedArray()) } } diff --git a/common/src/main/kotlin/com/cosmotech/common/security/filters/ApiKeyAuthenticationFilter.kt b/common/src/main/kotlin/com/cosmotech/common/security/filters/ApiKeyAuthenticationFilter.kt index e9c43ef3c..820fa2392 100644 --- a/common/src/main/kotlin/com/cosmotech/common/security/filters/ApiKeyAuthenticationFilter.kt +++ b/common/src/main/kotlin/com/cosmotech/common/security/filters/ApiKeyAuthenticationFilter.kt @@ -20,7 +20,7 @@ class ApiKeyAuthenticationFilter(val csmPlatformProperties: CsmPlatformPropertie override fun doFilterInternal( request: HttpServletRequest, response: HttpServletResponse, - chain: FilterChain + chain: FilterChain, ) { logger.debug("API-Key filter starts") val allowedApiKeyConsumers = csmPlatformProperties.authorization.allowedApiKeyConsumers @@ -67,7 +67,8 @@ class ApiKeyAuthenticationFilter(val csmPlatformProperties: CsmPlatformPropertie ApiKeyAuthentication( apiKeyValueConfigured, apiKeyHeaderName, - AuthorityUtils.createAuthorityList(associatedRole)) + AuthorityUtils.createAuthorityList(associatedRole), + ) HttpSessionSecurityContextRepository().saveContext(securityContext, request, response) } else { response.status = HttpStatus.FORBIDDEN.value() @@ -88,7 +89,7 @@ class ApiKeyAuthenticationFilter(val csmPlatformProperties: CsmPlatformPropertie private fun filterSecuredUriWithRequestUri( securedUriSplitted: List, requestUri: String, - securedUri: String + securedUri: String, ) = if (securedUriSplitted.size == 1 && securedUriSplitted[0] == "/") { true @@ -106,7 +107,7 @@ class ApiKeyAuthenticationFilter(val csmPlatformProperties: CsmPlatformPropertie class ApiKeyAuthentication( val apiKey: String, val apiKeyName: String, - authorities: MutableCollection + authorities: MutableCollection, ) : AbstractAuthenticationToken(authorities) { init { diff --git a/common/src/main/kotlin/com/cosmotech/common/security/keycloak/KeycloakSecurityConfiguration.kt b/common/src/main/kotlin/com/cosmotech/common/security/keycloak/KeycloakSecurityConfiguration.kt index a432a1ed4..a6373b98a 100644 --- a/common/src/main/kotlin/com/cosmotech/common/security/keycloak/KeycloakSecurityConfiguration.kt +++ b/common/src/main/kotlin/com/cosmotech/common/security/keycloak/KeycloakSecurityConfiguration.kt @@ -41,13 +41,16 @@ import org.springframework.util.StringUtils @Configuration @EnableWebSecurity(debug = true) @ConditionalOnProperty( - name = ["csm.platform.identityProvider.code"], havingValue = "keycloak", matchIfMissing = true) + name = ["csm.platform.identityProvider.code"], + havingValue = "keycloak", + matchIfMissing = true, +) @EnableMethodSecurity(securedEnabled = true, prePostEnabled = true, proxyTargetClass = true) internal open class KeycloakSecurityConfiguration( private val oAuth2ResourceServerProperties: OAuth2ResourceServerProperties, private val csmPlatformProperties: CsmPlatformProperties, private val sslBundles: SslBundles, - private val restTemplateBuilder: RestTemplateBuilder + private val restTemplateBuilder: RestTemplateBuilder, ) : AbstractSecurityConfiguration() { private val logger = LoggerFactory.getLogger(KeycloakSecurityConfiguration::class.java) @@ -69,13 +72,15 @@ internal open class KeycloakSecurityConfiguration( organizationAdminGroup, organizationUserGroup, organizationViewerGroup, - csmPlatformProperties) + csmPlatformProperties, + ) .oauth2ResourceServer { oauth2 -> oauth2.jwt { jwt -> run { jwt.decoder(keycloakJwtDecoder(oAuth2ResourceServerProperties, csmPlatformProperties)) jwt.jwtAuthenticationConverter( - KeycloakJwtAuthenticationConverter(csmPlatformProperties)) + KeycloakJwtAuthenticationConverter(csmPlatformProperties) + ) } } } @@ -86,7 +91,7 @@ internal open class KeycloakSecurityConfiguration( @Bean open fun keycloakJwtDecoder( oAuth2ResourceServerProperties: OAuth2ResourceServerProperties, - csmPlatformProperties: CsmPlatformProperties + csmPlatformProperties: CsmPlatformProperties, ): JwtDecoder { val jwtProperties = oAuth2ResourceServerProperties.jwt val nimbusJwtDecoderBuilder = @@ -98,7 +103,8 @@ internal open class KeycloakSecurityConfiguration( } if (tlsEnabled) { nimbusJwtDecoderBuilder.restOperations( - restTemplateBuilder.sslBundle(sslBundles.getBundle(tlsBundle)).build()) + restTemplateBuilder.sslBundle(sslBundles.getBundle(tlsBundle)).build() + ) } val nimbusJwtDecoder = nimbusJwtDecoderBuilder.build() @@ -121,7 +127,8 @@ internal open class KeycloakSecurityConfiguration( if ("*" in allowedTenants) { logger.info( "All tenants allowed to authenticate, since the following property contains a wildcard " + - "element: csm.platform.authorization.allowed-tenants") + "element: csm.platform.authorization.allowed-tenants" + ) } else { // Validate against the list of allowed tenants val tenantValidator = @@ -150,13 +157,14 @@ class KeycloakJwtGrantedAuthoritiesConverter( override fun convert(jwt: Jwt): Collection { val extractAuthorities = mutableListOf() extractAuthorities.addAll( - convertRolesToAuthorities(jwt.claims, csmPlatformProperties.authorization.rolesJwtClaim)) + convertRolesToAuthorities(jwt.claims, csmPlatformProperties.authorization.rolesJwtClaim) + ) return extractAuthorities } private fun convertRolesToAuthorities( attributes: Map, - claimKey: String + claimKey: String, ): MutableCollection { if (!CollectionUtils.isEmpty(attributes) && StringUtils.hasText(claimKey)) { val rawRoleClaim = attributes[claimKey] @@ -168,7 +176,9 @@ class KeycloakJwtGrantedAuthoritiesConverter( .collect(Collectors.toList()) } else if (rawRoleClaim != null) { logger.debug( - "Could not extract authorities from claim '{}', value was not a collection", claimKey) + "Could not extract authorities from claim '{}', value was not a collection", + claimKey, + ) } } return mutableSetOf() diff --git a/common/src/main/kotlin/com/cosmotech/common/tests/CsmTestBase.kt b/common/src/main/kotlin/com/cosmotech/common/tests/CsmTestBase.kt index 40154b256..5ae50c596 100644 --- a/common/src/main/kotlin/com/cosmotech/common/tests/CsmTestBase.kt +++ b/common/src/main/kotlin/com/cosmotech/common/tests/CsmTestBase.kt @@ -21,12 +21,14 @@ open class CsmTestBase : AbstractTestcontainersRedisTestBase() { companion object { private const val DEFAULT_REDIS_PORT = 6379 - private const val LOCALSTACK_FULL_IMAGE_NAME = "localstack/localstack:3.5.0" + private const val LOCALSTACK_FULL_IMAGE_NAME = "localstack/localstack:latest" var postgres: PostgreSQLContainer<*> = - PostgreSQLContainer("postgres:alpine3.19") + PostgreSQLContainer("postgres:latest") .withCopyFileToContainer( - MountableFile.forClasspathResource("init-db.sql"), "/docker-entrypoint-initdb.d/") + MountableFile.forClasspathResource("init-db.sql"), + "/docker-entrypoint-initdb.d/", + ) var redisStackServer = RedisStackContainer(RedisStackContainer.DEFAULT_IMAGE_NAME) diff --git a/common/src/main/kotlin/com/cosmotech/common/utils/AboutInfo.kt b/common/src/main/kotlin/com/cosmotech/common/utils/AboutInfo.kt index ddb67a484..bb4bcf608 100644 --- a/common/src/main/kotlin/com/cosmotech/common/utils/AboutInfo.kt +++ b/common/src/main/kotlin/com/cosmotech/common/utils/AboutInfo.kt @@ -10,7 +10,8 @@ fun getAboutInfo(): JSONObject { val aboutJsonInputStream = object {}::class.java.getResourceAsStream("/about.json") ?: throw IllegalStateException( - "Unable to read about info data from 'classpath:/about.json'") + "Unable to read about info data from 'classpath:/about.json'" + ) val aboutJsonContent = aboutJsonInputStream.use { it.bufferedReader().use(BufferedReader::readText) } diff --git a/common/src/main/kotlin/com/cosmotech/common/utils/AnyExtensions.kt b/common/src/main/kotlin/com/cosmotech/common/utils/AnyExtensions.kt index 737064a05..69c4bb066 100644 --- a/common/src/main/kotlin/com/cosmotech/common/utils/AnyExtensions.kt +++ b/common/src/main/kotlin/com/cosmotech/common/utils/AnyExtensions.kt @@ -51,7 +51,7 @@ fun T.convertToMap(): Map = inline fun T.compareToAndMutateIfNeeded( new: T, mutateIfChanged: Boolean = true, - excludedFields: Array = emptyArray() + excludedFields: Array = emptyArray(), ): Set { if (!T::class.isData) { throw UnsupportedOperationException("${T::class} is not a data class") @@ -85,7 +85,8 @@ inline fun T.compareToAndMutateIfNeeded( "this object because property ${member.name} " + "(on class ${T::class}) is not mutable. " + "Either exclude this field or call this function with " + - "mutateIfChanged=false to view the changes detected") + "mutateIfChanged=false to view the changes detected" + ) } member.setter.call(this, newValue) } diff --git a/common/src/main/kotlin/com/cosmotech/common/utils/RedisUtils.kt b/common/src/main/kotlin/com/cosmotech/common/utils/RedisUtils.kt index 5f285df5a..f9b822ce0 100644 --- a/common/src/main/kotlin/com/cosmotech/common/utils/RedisUtils.kt +++ b/common/src/main/kotlin/com/cosmotech/common/utils/RedisUtils.kt @@ -20,7 +20,7 @@ fun constructPageRequest(page: Int?, size: Int?, defaultPageSize: Int): PageRequ fun findAllPaginated( maxResult: Int, - findAllLambda: (pageRequest: PageRequest) -> MutableList + findAllLambda: (pageRequest: PageRequest) -> MutableList, ): MutableList { var pageRequest = PageRequest.ofSize(maxResult) var list = mutableListOf() diff --git a/common/src/main/kotlin/com/cosmotech/common/utils/ResourceScanner.kt b/common/src/main/kotlin/com/cosmotech/common/utils/ResourceScanner.kt index b53d18361..03aca3d3f 100644 --- a/common/src/main/kotlin/com/cosmotech/common/utils/ResourceScanner.kt +++ b/common/src/main/kotlin/com/cosmotech/common/utils/ResourceScanner.kt @@ -24,7 +24,7 @@ class ResourceScanner { fun scanMimeTypes( fileName: String = ENTRY_NAME_UNKNOWN, inputStream: InputStream, - authorizedMimeTypes: List + authorizedMimeTypes: List, ) { val tika = TikaConfig() this.scanStream(tika, inputStream, fileName, authorizedMimeTypes) @@ -34,7 +34,7 @@ class ResourceScanner { tika: TikaConfig, inputStream: InputStream, name: String, - authorizedMimeTypes: List + authorizedMimeTypes: List, ) { val metadata = Metadata() metadata.set(TikaCoreProperties.RESOURCE_NAME_KEY, name) @@ -51,14 +51,16 @@ class ResourceScanner { tika: TikaConfig, zipInputStream: ZipInputStream, fileName: String, - authorizedMimeTypes: List + authorizedMimeTypes: List, ) { this.logger.info("Scanning Zip file $fileName") var entry: ZipEntry? - while (run { - entry = zipInputStream.nextEntry - entry - } != null) { + while ( + run { + entry = zipInputStream.nextEntry + entry + } != null + ) { this.logger.debug("Zip entry ${entry?.name}") if (entry?.isDirectory == true) { this.logger.debug("Directory detected") @@ -76,7 +78,7 @@ class ResourceScanner { private fun validateMimeType( mimetype: String, fileName: String, - authorizedMimeTypes: List + authorizedMimeTypes: List, ) { if (!authorizedMimeTypes.contains(mimetype)) { throw CsmAccessForbiddenException("MIME type $mimetype for file $fileName is not authorized.") diff --git a/common/src/main/kotlin/com/cosmotech/common/utils/SecurityUtils.kt b/common/src/main/kotlin/com/cosmotech/common/utils/SecurityUtils.kt index 626d397bc..e97c11947 100644 --- a/common/src/main/kotlin/com/cosmotech/common/utils/SecurityUtils.kt +++ b/common/src/main/kotlin/com/cosmotech/common/utils/SecurityUtils.kt @@ -79,7 +79,7 @@ fun getCurrentAuthenticatedRoles(configuration: CsmPlatformProperties): List getValueFromAuthenticatedToken( configuration: CsmPlatformProperties, - actionLambda: (String) -> T + actionLambda: (String) -> T, ): T { if (getCurrentAuthentication() == null) { throw IllegalStateException("User Authentication not found in Security Context") @@ -103,7 +103,8 @@ fun getValueFromAuthenticatedToken( configuration.authorization.rolesJwtClaim, authentication.authorities .map { (it as SimpleGrantedAuthority).authority } - .toList()) + .toList(), + ) .build() } } diff --git a/common/src/main/kotlin/com/cosmotech/common/utils/ZipUtils.kt b/common/src/main/kotlin/com/cosmotech/common/utils/ZipUtils.kt index ddb3162b2..eb4a53759 100644 --- a/common/src/main/kotlin/com/cosmotech/common/utils/ZipUtils.kt +++ b/common/src/main/kotlin/com/cosmotech/common/utils/ZipUtils.kt @@ -25,7 +25,8 @@ fun unzip(file: InputStream, prefixNames: List, fileExtension: String): UnzippedFile( filename = it.name.extractFileNameFromPath(), prefix = prefixNames.first { prefix -> it.name.contains(prefix, true) }, - content = zipInputStream.readAllBytes()) + content = zipInputStream.readAllBytes(), + ) } .toList() } diff --git a/common/src/test/kotlin/com/cosmotech/common/containerregistry/ContainerRegistryServiceTest.kt b/common/src/test/kotlin/com/cosmotech/common/containerregistry/ContainerRegistryServiceTest.kt index 9f8fa5b72..5efa7bf35 100644 --- a/common/src/test/kotlin/com/cosmotech/common/containerregistry/ContainerRegistryServiceTest.kt +++ b/common/src/test/kotlin/com/cosmotech/common/containerregistry/ContainerRegistryServiceTest.kt @@ -161,7 +161,8 @@ class ContainerRegistryServiceTest { val response = ResponseEntity( MultiValueMap.fromSingleValue(mapOf(HttpHeaders.LOCATION to String())), - HttpStatus.TEMPORARY_REDIRECT) + HttpStatus.TEMPORARY_REDIRECT, + ) every { noRedirectClient .get() diff --git a/common/src/test/kotlin/com/cosmotech/common/rbac/CsmRbacTests.kt b/common/src/test/kotlin/com/cosmotech/common/rbac/CsmRbacTests.kt index e50268e89..68e12fa2b 100644 --- a/common/src/test/kotlin/com/cosmotech/common/rbac/CsmRbacTests.kt +++ b/common/src/test/kotlin/com/cosmotech/common/rbac/CsmRbacTests.kt @@ -96,7 +96,9 @@ class CsmRbacTests { CsmPlatformProperties.CsmIdentityProvider.CsmIdentity( tenantId = "my_tenant_id", clientId = "my_client_id", - clientSecret = "my_client_secret")) + clientSecret = "my_client_secret", + ), + ) @BeforeTest fun beforeEachTest() { @@ -116,7 +118,8 @@ class CsmRbacTests { ROLE_READER to ROLE_READER_PERMS, ROLE_WRITER to ROLE_WRITER_PERMS, ROLE_ADMIN to ROLE_ADMIN_PERMS, - )) + ), + ) parentRbacSecurity = RbacSecurity( @@ -129,7 +132,8 @@ class CsmRbacTests { RbacAccessControl(USER_NONE, USER_NONE_ROLE), RbacAccessControl(USER_ADMIN, USER_ADMIN_ROLE), RbacAccessControl(USER_MAIL_TOKEN, USER_READER_ROLE), - )) + ), + ) rbacSecurity = RbacSecurity( @@ -141,7 +145,9 @@ class CsmRbacTests { RbacAccessControl(USER_NONE, USER_NONE_ROLE), RbacAccessControl(USER_ADMIN, USER_ADMIN_ROLE), RbacAccessControl(USER_MAIL_TOKEN, USER_READER_ROLE), - RbacAccessControl(APP_REG_ID, ROLE_USER))) + RbacAccessControl(APP_REG_ID, ROLE_USER), + ), + ) admin = CsmAdmin(csmPlatformProperties) rbac = CsmRbac(csmPlatformProperties, admin) @@ -259,7 +265,11 @@ class CsmRbacTests { fun `verify permission writer from roles reader writer OK`() { assertTrue( rbac.verifyPermissionFromRoles( - PERM_READ, listOf(USER_WRITER_ROLE, USER_READER_ROLE), rolesDefinition)) + PERM_READ, + listOf(USER_WRITER_ROLE, USER_READER_ROLE), + rolesDefinition, + ) + ) } @Test @@ -280,7 +290,8 @@ class CsmRbacTests { @Test fun `verify permission write for user writer KO`() { assertFalse( - rbac.verifyUser(rbacSecurity, PERM_WRITE, rolesDefinition, USER_READER, emptyList())) + rbac.verifyUser(rbacSecurity, PERM_WRITE, rolesDefinition, USER_READER, emptyList()) + ) } @Test @@ -302,14 +313,16 @@ class CsmRbacTests { fun `add new reader user and verify read permission OK`() { rbac.setEntityRole(rbacSecurity, USER_NEW_READER, USER_READER_ROLE, rolesDefinition) assertTrue( - rbac.verifyUser(rbacSecurity, PERM_READ, rolesDefinition, USER_NEW_READER, emptyList())) + rbac.verifyUser(rbacSecurity, PERM_READ, rolesDefinition, USER_NEW_READER, emptyList()) + ) } @Test fun `add new reader user and verify write permission KO`() { rbac.setEntityRole(rbacSecurity, USER_NEW_READER, USER_READER_ROLE, rolesDefinition) assertFalse( - rbac.verifyUser(rbacSecurity, PERM_WRITE, rolesDefinition, USER_NEW_READER, emptyList())) + rbac.verifyUser(rbacSecurity, PERM_WRITE, rolesDefinition, USER_NEW_READER, emptyList()) + ) } @Test @@ -326,7 +339,12 @@ class CsmRbacTests { listOf(ROLE_ORGANIZATION_USER) assertThrows { rbac.addEntityRole( - parentRbacSecurity, rbacSecurity, USER_NOTIN, USER_READER_ROLE, rolesDefinition) + parentRbacSecurity, + rbacSecurity, + USER_NOTIN, + USER_READER_ROLE, + rolesDefinition, + ) } } @@ -337,9 +355,15 @@ class CsmRbacTests { listOf(ROLE_ORGANIZATION_USER) val rbacSecurity = rbac.addEntityRole( - parentRbacSecurity, rbacSecurity, USER_IN_PARENT, USER_READER_ROLE, rolesDefinition) + parentRbacSecurity, + rbacSecurity, + USER_IN_PARENT, + USER_READER_ROLE, + rolesDefinition, + ) assertTrue( - rbac.verifyUser(rbacSecurity, PERM_READ, rolesDefinition, USER_IN_PARENT, emptyList())) + rbac.verifyUser(rbacSecurity, PERM_READ, rolesDefinition, USER_IN_PARENT, emptyList()) + ) } @Test @@ -348,7 +372,12 @@ class CsmRbacTests { listOf(ROLE_PLATFORM_ADMIN) val rbacSecurity = rbac.addEntityRole( - parentRbacSecurity, rbacSecurity, USER_NOTIN, USER_READER_ROLE, rolesDefinition) + parentRbacSecurity, + rbacSecurity, + USER_NOTIN, + USER_READER_ROLE, + rolesDefinition, + ) assertTrue(rbac.verifyUser(rbacSecurity, PERM_READ, rolesDefinition, USER_NOTIN, emptyList())) } @@ -359,7 +388,8 @@ class CsmRbacTests { rbac.setEntityRole(rbacSecurity, USER_NEW_READER, USER_READER_ROLE, rolesDefinition) rbac.removeEntity(rbacSecurity, USER_NEW_READER, rolesDefinition) assertFalse( - rbac.verifyUser(rbacSecurity, PERM_READ, rolesDefinition, USER_NEW_READER, emptyList())) + rbac.verifyUser(rbacSecurity, PERM_READ, rolesDefinition, USER_NEW_READER, emptyList()) + ) } @Test @@ -369,7 +399,8 @@ class CsmRbacTests { rbac.setEntityRole(rbacSecurity, USER_NEW_READER, USER_READER_ROLE, rolesDefinition) rbac.removeEntity(rbacSecurity, USER_NEW_READER, rolesDefinition) assertTrue( - rbac.verifyUser(rbacSecurity, PERM_READ, rolesDefinition, USER_NEW_READER, emptyList())) + rbac.verifyUser(rbacSecurity, PERM_READ, rolesDefinition, USER_NEW_READER, emptyList()) + ) } @Test @@ -379,21 +410,24 @@ class CsmRbacTests { rbac.setEntityRole(rbacSecurity, USER_NEW_READER, USER_READER_ROLE, rolesDefinition) rbac.removeEntity(rbacSecurity, USER_NEW_READER, rolesDefinition) assertTrue( - rbac.verifyUser(rbacSecurity, PERM_ADMIN, rolesDefinition, USER_NEW_READER, emptyList())) + rbac.verifyUser(rbacSecurity, PERM_ADMIN, rolesDefinition, USER_NEW_READER, emptyList()) + ) } @Test fun `update existing new user and verify write permission OK`() { rbac.setEntityRole(rbacSecurity, USER_NEW_READER, USER_WRITER_ROLE, rolesDefinition) assertTrue( - rbac.verifyUser(rbacSecurity, PERM_WRITE, rolesDefinition, USER_NEW_READER, emptyList())) + rbac.verifyUser(rbacSecurity, PERM_WRITE, rolesDefinition, USER_NEW_READER, emptyList()) + ) } @Test fun `update existing new user and verify read permission OK`() { rbac.setEntityRole(rbacSecurity, USER_NEW_READER, USER_READER_ROLE, rolesDefinition) assertTrue( - rbac.verifyUser(rbacSecurity, PERM_READ, rolesDefinition, USER_NEW_READER, emptyList())) + rbac.verifyUser(rbacSecurity, PERM_READ, rolesDefinition, USER_NEW_READER, emptyList()) + ) } @Test @@ -625,7 +659,8 @@ class CsmRbacTests { fun `get user list`() { assertEquals( listOf(USER_WRITER, USER_READER, USER_NONE, USER_ADMIN, USER_MAIL_TOKEN, APP_REG_ID), - rbac.getEntities(rbacSecurity)) + rbac.getEntities(rbacSecurity), + ) } @Test @@ -634,7 +669,8 @@ class CsmRbacTests { assertTrue( resourceSecurity.accessControlList.any { it.id == USER_ADMIN && it.role == rolesDefinition.adminRole - }) + } + ) } @Test @@ -649,7 +685,8 @@ class CsmRbacTests { }) && (resourceSecurity.accessControlList.any { it.id == USER_ADMIN_2 && it.role == rolesDefinition.adminRole - })) + }) + ) } // Role definition tests @@ -720,21 +757,26 @@ class CsmRbacTests { fun `add ACL entry when default role is admin with only one admin defined`() = listOf(ROLE_VIEWER, ROLE_USER, ROLE_EDITOR, ROLE_ADMIN).map { role -> DynamicTest.dynamicTest( - "add ACL entry $role when default role is admin (with only one admin defined)") { - val rbacDefinition = - RbacSecurity( - id = "rbacOnlyOneAdminWithAdminDefaultRole", - default = ROLE_ADMIN, - accessControlList = - mutableListOf( - RbacAccessControl(id = "test.user@test.com", role = ROLE_ADMIN))) - val newUserId = "whatever.user@test.com" - rbac.setEntityRole(rbacDefinition, newUserId, role, getCommonRolesDefinition()) - assertTrue(rbacDefinition.accessControlList.size == 2) - assertTrue( - rbacDefinition.accessControlList.contains( - RbacAccessControl(id = newUserId, role = role))) - } + "add ACL entry $role when default role is admin (with only one admin defined)" + ) { + val rbacDefinition = + RbacSecurity( + id = "rbacOnlyOneAdminWithAdminDefaultRole", + default = ROLE_ADMIN, + accessControlList = + mutableListOf( + RbacAccessControl(id = "test.user@test.com", role = ROLE_ADMIN) + ), + ) + val newUserId = "whatever.user@test.com" + rbac.setEntityRole(rbacDefinition, newUserId, role, getCommonRolesDefinition()) + assertTrue(rbacDefinition.accessControlList.size == 2) + assertTrue( + rbacDefinition.accessControlList.contains( + RbacAccessControl(id = newUserId, role = role) + ) + ) + } } @TestFactory @@ -748,7 +790,8 @@ class CsmRbacTests { id = "rbacOnlyOneAdmin", default = ROLE_NONE, accessControlList = - mutableListOf(RbacAccessControl(id = userId, role = ROLE_ADMIN))) + mutableListOf(RbacAccessControl(id = userId, role = ROLE_ADMIN)), + ) if (shouldThrows) { val assertThrows = assertThrows { @@ -756,14 +799,17 @@ class CsmRbacTests { } assertEquals( "RBAC ${rbacDefinition.id} - It is forbidden to unset the last administrator", - assertThrows.message) + assertThrows.message, + ) } else { assertDoesNotThrow { rbac.setEntityRole(rbacDefinition, userId, role, getCommonRolesDefinition()) assertTrue(rbacDefinition.accessControlList.size == 1) assertTrue( rbacDefinition.accessControlList.contains( - RbacAccessControl(id = userId, role = role))) + RbacAccessControl(id = userId, role = role) + ) + ) } } } @@ -773,46 +819,54 @@ class CsmRbacTests { fun `remove ACL entry when default role is admin with only one admin defined`() = listOf(ROLE_VIEWER, ROLE_USER, ROLE_EDITOR, ROLE_ADMIN).map { role -> DynamicTest.dynamicTest( - "remove ACL entry $role when default role is admin (with only one admin defined)") { - val userId = "test.user@test.com" - val rbacDefinition = - RbacSecurity( - id = "rbacOnlyOneAdminWithAdminDefaultRole", - default = ROLE_ADMIN, - accessControlList = - mutableListOf(RbacAccessControl(id = userId, role = ROLE_ADMIN))) - val assertThrows = - assertThrows { - rbac.removeEntity(rbacDefinition, userId, getCommonRolesDefinition()) - } - assertEquals( - "RBAC ${rbacDefinition.id} - It is forbidden to remove the last administrator", - assertThrows.message) - } + "remove ACL entry $role when default role is admin (with only one admin defined)" + ) { + val userId = "test.user@test.com" + val rbacDefinition = + RbacSecurity( + id = "rbacOnlyOneAdminWithAdminDefaultRole", + default = ROLE_ADMIN, + accessControlList = + mutableListOf(RbacAccessControl(id = userId, role = ROLE_ADMIN)), + ) + val assertThrows = + assertThrows { + rbac.removeEntity(rbacDefinition, userId, getCommonRolesDefinition()) + } + assertEquals( + "RBAC ${rbacDefinition.id} - It is forbidden to remove the last administrator", + assertThrows.message, + ) + } } @TestFactory fun `remove ACL entry when default role is admin with an admin and another user defined`() = listOf(ROLE_VIEWER, ROLE_USER, ROLE_EDITOR, ROLE_ADMIN).map { role -> DynamicTest.dynamicTest( - "remove ACL entry $role when default role is admin (with only one admin defined)") { - val userId = "test.user@test.com" - val rbacDefinition = - RbacSecurity( - id = "rbacOnlyOneAdminWithAdminDefaultRole", - default = ROLE_ADMIN, - accessControlList = - mutableListOf( - RbacAccessControl(id = USER_ADMIN, role = ROLE_ADMIN), - RbacAccessControl(id = userId, role = role))) - assertDoesNotThrow { - rbac.removeEntity(rbacDefinition, userId, getCommonRolesDefinition()) - assertTrue(rbacDefinition.accessControlList.size == 1) - assertTrue( - rbacDefinition.accessControlList.contains( - RbacAccessControl(id = USER_ADMIN, role = ROLE_ADMIN))) - } - } + "remove ACL entry $role when default role is admin (with only one admin defined)" + ) { + val userId = "test.user@test.com" + val rbacDefinition = + RbacSecurity( + id = "rbacOnlyOneAdminWithAdminDefaultRole", + default = ROLE_ADMIN, + accessControlList = + mutableListOf( + RbacAccessControl(id = USER_ADMIN, role = ROLE_ADMIN), + RbacAccessControl(id = userId, role = role), + ), + ) + assertDoesNotThrow { + rbac.removeEntity(rbacDefinition, userId, getCommonRolesDefinition()) + assertTrue(rbacDefinition.accessControlList.size == 1) + assertTrue( + rbacDefinition.accessControlList.contains( + RbacAccessControl(id = USER_ADMIN, role = ROLE_ADMIN) + ) + ) + } + } } @Test @@ -825,7 +879,8 @@ class CsmRbacTests { ROLE_READER, mutableListOf( RbacAccessControl(USER_READER, ROLE_VIEWER), - )) + ), + ) every { getCurrentAuthenticatedRoles(csmPlatformProperties) } returns listOf(ROLE_ORGANIZATION_USER) every { getCurrentAccountIdentifier(csmPlatformProperties) } returns USER_READER @@ -842,7 +897,8 @@ class CsmRbacTests { ROLE_VIEWER, mutableListOf( RbacAccessControl(USER_WRITER, ROLE_EDITOR), - )) + ), + ) every { getCurrentAuthenticatedRoles(csmPlatformProperties) } returns listOf(ROLE_ORGANIZATION_USER) every { getCurrentAccountIdentifier(csmPlatformProperties) } returns USER_READER @@ -859,7 +915,8 @@ class CsmRbacTests { ROLE_VIEWER, mutableListOf( RbacAccessControl(USER_WRITER, ROLE_EDITOR), - )) + ), + ) every { getCurrentAuthenticatedRoles(csmPlatformProperties) } returns listOf(ROLE_ORGANIZATION_USER) every { getCurrentAccountIdentifier(csmPlatformProperties) } returns USER_READER @@ -876,8 +933,11 @@ class CsmRbacTests { ROLE_VIEWER, mutableListOf( RbacAccessControl( - getCurrentAccountIdentifier(csmPlatformProperties), definition.adminRole), - )) + getCurrentAccountIdentifier(csmPlatformProperties), + definition.adminRole, + ), + ), + ) every { getCurrentAuthenticatedRoles(csmPlatformProperties) } returns listOf(ROLE_ORGANIZATION_USER) every { getCurrentAccountIdentifier(csmPlatformProperties) } returns USER_MAIL_TOKEN @@ -894,7 +954,8 @@ class CsmRbacTests { ROLE_VIEWER, mutableListOf( RbacAccessControl(USER_WRITER, ROLE_EDITOR), - )) + ), + ) every { getCurrentAuthenticatedRoles(csmPlatformProperties) } returns listOf(ROLE_ORGANIZATION_USER) every { getCurrentAccountIdentifier(csmPlatformProperties) } returns USER_WRITER @@ -911,7 +972,8 @@ class CsmRbacTests { ROLE_VIEWER, mutableListOf( RbacAccessControl(USER_MAIL_TOKEN, ROLE_EDITOR), - )) + ), + ) every { getCurrentAuthenticatedRoles(csmPlatformProperties) } returns listOf(ROLE_ORGANIZATION_USER) every { getCurrentAccountIdentifier(csmPlatformProperties) } returns USER_MAIL_TOKEN @@ -928,7 +990,8 @@ class CsmRbacTests { ROLE_VIEWER, mutableListOf( RbacAccessControl(USER_WRITER, ROLE_EDITOR), - )) + ), + ) every { getCurrentAuthenticatedRoles(csmPlatformProperties) } returns listOf(ROLE_ORGANIZATION_USER) every { getCurrentAccountIdentifier(csmPlatformProperties) } returns USER_WRITER @@ -977,7 +1040,10 @@ class CsmRbacTests { every { getCurrentAccountIdentifier(csmPlatformProperties) } returns APP_REG_ID val emptyRbacSecuWithDefaultNone = RbacSecurity( - COMPONENT_ID, ROLE_NONE, mutableListOf(RbacAccessControl(APP_REG_ID, ROLE_ADMIN))) + COMPONENT_ID, + ROLE_NONE, + mutableListOf(RbacAccessControl(APP_REG_ID, ROLE_ADMIN)), + ) assertTrue(rbac.isAdmin(emptyRbacSecuWithDefaultNone, getCommonRolesDefinition())) } @@ -988,7 +1054,13 @@ class CsmRbacTests { every { getCurrentAccountIdentifier(csmPlatformProperties) } returns APP_REG_ID assertTrue( rbac.verifyRbac( - rbacSecurity, PERMISSION_READ, getCommonRolesDefinition(), APP_REG_ID, emptyList())) + rbacSecurity, + PERMISSION_READ, + getCommonRolesDefinition(), + APP_REG_ID, + emptyList(), + ) + ) } @Test @@ -997,8 +1069,10 @@ class CsmRbacTests { val security = rbac.initSecurity(inputSecurity) assertEquals( inputSecurity.copy( - accessControlList = mutableListOf(RbacAccessControl(USER_NOTIN, ROLE_ADMIN))), - security) + accessControlList = mutableListOf(RbacAccessControl(USER_NOTIN, ROLE_ADMIN)) + ), + security, + ) } @Test @@ -1010,7 +1084,10 @@ class CsmRbacTests { ROLE_NONE, mutableListOf( RbacAccessControl(USER_READER, ROLE_USER), - RbacAccessControl(USER_READER, ROLE_ADMIN)))) + RbacAccessControl(USER_READER, ROLE_ADMIN), + ), + ) + ) } } @@ -1018,27 +1095,38 @@ class CsmRbacTests { fun `initSecurity no admin in ACL without current user`() { val inputSecurity = RbacSecurity( - COMPONENT_ID, ROLE_NONE, mutableListOf(RbacAccessControl(USER_NOTIN, ROLE_USER))) + COMPONENT_ID, + ROLE_NONE, + mutableListOf(RbacAccessControl(USER_NOTIN, ROLE_USER)), + ) val security = rbac.initSecurity(inputSecurity) assertEquals( inputSecurity.copy( - accessControlList = mutableListOf(RbacAccessControl(USER_NOTIN, ROLE_ADMIN))), - security) + accessControlList = mutableListOf(RbacAccessControl(USER_NOTIN, ROLE_ADMIN)) + ), + security, + ) } @Test fun `initSecurity no admin in ACL with current user`() { val inputSecurity = RbacSecurity( - COMPONENT_ID, ROLE_NONE, mutableListOf(RbacAccessControl(USER_READER, ROLE_USER))) + COMPONENT_ID, + ROLE_NONE, + mutableListOf(RbacAccessControl(USER_READER, ROLE_USER)), + ) val security = rbac.initSecurity(inputSecurity) assertEquals( inputSecurity.copy( accessControlList = mutableListOf( RbacAccessControl(USER_READER, ROLE_USER), - RbacAccessControl(USER_NOTIN, ROLE_ADMIN))), - security) + RbacAccessControl(USER_NOTIN, ROLE_ADMIN), + ) + ), + security, + ) } @Test @@ -1053,7 +1141,9 @@ class CsmRbacTests { RbacAccessControl(GROUP_ADMIN, ROLE_ADMIN), RbacAccessControl(GROUP_EDITOR, ROLE_EDITOR), RbacAccessControl(GROUP_READER, ROLE_READER), - RbacAccessControl(GROUP_NONE, ROLE_NONE))) + RbacAccessControl(GROUP_NONE, ROLE_NONE), + ), + ) assertTrue(rbac.check(rbacSecurity, PERMISSION_WRITE_SECURITY, getCommonRolesDefinition())) } @@ -1067,7 +1157,9 @@ class CsmRbacTests { ROLE_NONE, mutableListOf( RbacAccessControl(GROUP_EDITOR, ROLE_EDITOR), - RbacAccessControl(USER_NOTIN, ROLE_NONE))) + RbacAccessControl(USER_NOTIN, ROLE_NONE), + ), + ) assertFalse(rbac.check(rbacSecurity, PERMISSION_READ, getCommonRolesDefinition())) } } diff --git a/common/src/test/kotlin/com/cosmotech/common/security/keycloak/KeycloakJwtAuthenticationConverterTests.kt b/common/src/test/kotlin/com/cosmotech/common/security/keycloak/KeycloakJwtAuthenticationConverterTests.kt index f53917139..20d6211d6 100644 --- a/common/src/test/kotlin/com/cosmotech/common/security/keycloak/KeycloakJwtAuthenticationConverterTests.kt +++ b/common/src/test/kotlin/com/cosmotech/common/security/keycloak/KeycloakJwtAuthenticationConverterTests.kt @@ -42,12 +42,14 @@ class KeycloakJwtAuthenticationConverterTests { "claimRoles" to listOf("role1", "role2", "role3"), "claimName" to "myClaimName", "sub" to "123-456-798", - principalClaimName to principalClaimValue) + principalClaimName to principalClaimValue, + ) val expectedSimpleGrantedAuthorities = listOf( SimpleGrantedAuthority("role1"), SimpleGrantedAuthority("role2"), - SimpleGrantedAuthority("role3")) + SimpleGrantedAuthority("role3"), + ) every { jwt.claims } returns claims every { csmPlatformProperties.authorization.rolesJwtClaim } returns "claimRoles" @@ -58,7 +60,8 @@ class KeycloakJwtAuthenticationConverterTests { assertEquals( JwtAuthenticationToken(jwt, expectedSimpleGrantedAuthorities, principalClaimName), - jwtConverted) + jwtConverted, + ) } @Test @@ -71,12 +74,14 @@ class KeycloakJwtAuthenticationConverterTests { "claim1" to "10", "claimRoles" to listOf("role1", "role2", "role3"), "claimName" to "myClaimName", - applicationIdClaimName to applicationIdClaimValue) + applicationIdClaimName to applicationIdClaimValue, + ) val expectedSimpleGrantedAuthorities = listOf( SimpleGrantedAuthority("role1"), SimpleGrantedAuthority("role2"), - SimpleGrantedAuthority("role3")) + SimpleGrantedAuthority("role3"), + ) every { jwt.claims } returns claims every { csmPlatformProperties.authorization.rolesJwtClaim } returns "claimRoles" @@ -90,7 +95,8 @@ class KeycloakJwtAuthenticationConverterTests { assertEquals( JwtAuthenticationToken(jwt, expectedSimpleGrantedAuthorities, applicationIdClaimValue), - jwtConverted) + jwtConverted, + ) } @Test @@ -103,7 +109,8 @@ class KeycloakJwtAuthenticationConverterTests { "claimRoles" to listOf("role1", "role2", "role3"), "claimName" to "myClaimName", "sub" to "123-456-798", - principalClaimName to principalClaimValue) + principalClaimName to principalClaimValue, + ) every { jwt.claims } returns claims every { csmPlatformProperties.authorization.rolesJwtClaim } returns "unexisting-role-claim" @@ -125,7 +132,8 @@ class KeycloakJwtAuthenticationConverterTests { "claim1" to "10", "claimRoles" to listOf("role1", "role2", "role3"), "claimName" to "myClaimName", - "sub" to "123-456-798") + "sub" to "123-456-798", + ) every { jwt.claims } returns claims every { csmPlatformProperties.authorization.rolesJwtClaim } returns "unexisting-role-claim" @@ -150,7 +158,8 @@ class KeycloakJwtAuthenticationConverterTests { "claimRoles" to emptyList(), "claimName" to "myClaimName", "sub" to "123-456-798", - principalClaimName to principalClaimValue) + principalClaimName to principalClaimValue, + ) every { jwt.claims } returns claims every { csmPlatformProperties.authorization.rolesJwtClaim } returns "claimRoles" @@ -172,7 +181,8 @@ class KeycloakJwtAuthenticationConverterTests { "claim1" to "10", "claimRoles" to emptyList(), "claimName" to "myClaimName", - "sub" to "123-456-798") + "sub" to "123-456-798", + ) every { jwt.claims } returns claims every { csmPlatformProperties.authorization.rolesJwtClaim } returns "claimRoles" diff --git a/common/src/test/kotlin/com/cosmotech/common/utils/AnyExtensionsTests.kt b/common/src/test/kotlin/com/cosmotech/common/utils/AnyExtensionsTests.kt index 86f85bbee..9893b446c 100644 --- a/common/src/test/kotlin/com/cosmotech/common/utils/AnyExtensionsTests.kt +++ b/common/src/test/kotlin/com/cosmotech/common/utils/AnyExtensionsTests.kt @@ -98,7 +98,9 @@ class AnyExtensionsTests { assertThrows { myDataClassObj.compareToAndMutateIfNeeded( - MyDataClass("new_attr", false), mutateIfChanged = true) + MyDataClass("new_attr", false), + mutateIfChanged = true, + ) } assertEquals("old_attr", myDataClassObj.attr) assertTrue { myDataClassObj.anotherAttr } @@ -111,7 +113,9 @@ class AnyExtensionsTests { val changes = myDataClassObj.compareToAndMutateIfNeeded( - MyDataClass("new_attr", false), mutateIfChanged = false) + MyDataClass("new_attr", false), + mutateIfChanged = false, + ) assertEquals(2, changes.size) assertTrue { "attr" in changes } assertTrue { "anotherAttr" in changes } @@ -152,7 +156,9 @@ class AnyExtensionsTests { val changes = myDataClassObj.compareToAndMutateIfNeeded( - MyDataClass("id2", "attr2", false), excludedFields = arrayOf("attr", "anotherAttr")) + MyDataClass("id2", "attr2", false), + excludedFields = arrayOf("attr", "anotherAttr"), + ) assertTrue(changes.isEmpty()) @@ -168,7 +174,8 @@ class AnyExtensionsTests { val changes = myDataClassObj.compareToAndMutateIfNeeded( - MyDataClass("id2", listOf("attr2", "attr3", "attr4"), false)) + MyDataClass("id2", listOf("attr2", "attr3", "attr4"), false) + ) assertEquals(2, changes.size) assertTrue("listAttr" in changes) @@ -187,7 +194,8 @@ class AnyExtensionsTests { val changes = myDataClassObj.compareToAndMutateIfNeeded( - MyDataClass("id2", listOf("attr2", "attr1"), false)) + MyDataClass("id2", listOf("attr2", "attr1"), false) + ) assertEquals(1, changes.size) assertTrue("anotherAttr" in changes) @@ -202,5 +210,5 @@ private data class TestDataClass(val id: String, val name: String) private data class TestDataClassWithCollections( val dataList: List = listOf(), - val dataMap: Map = mapOf() + val dataMap: Map = mapOf(), ) diff --git a/common/src/test/kotlin/com/cosmotech/common/utils/RedisUtilsTests.kt b/common/src/test/kotlin/com/cosmotech/common/utils/RedisUtilsTests.kt index 5c3511607..6e1b9a427 100644 --- a/common/src/test/kotlin/com/cosmotech/common/utils/RedisUtilsTests.kt +++ b/common/src/test/kotlin/com/cosmotech/common/utils/RedisUtilsTests.kt @@ -18,7 +18,8 @@ class RedisUtilsTests { Pair(1, 10) to PageRequest.of(1, 10), Pair(null, 10) to PageRequest.of(0, 10), Pair(1, null) to PageRequest.of(1, DEFAULT_MAX_PAGE_SIZE), - Pair(null, null) to null) + Pair(null, null) to null, + ) .forEach { (input, expected) -> val actual = constructPageRequest(input.first, input.second, DEFAULT_MAX_PAGE_SIZE) assertEquals(expected, actual) diff --git a/common/src/test/kotlin/com/cosmotech/common/utils/StringExtensionsTests.kt b/common/src/test/kotlin/com/cosmotech/common/utils/StringExtensionsTests.kt index b0b8397a7..3fb3d6a9a 100644 --- a/common/src/test/kotlin/com/cosmotech/common/utils/StringExtensionsTests.kt +++ b/common/src/test/kotlin/com/cosmotech/common/utils/StringExtensionsTests.kt @@ -48,7 +48,8 @@ class StringExtensionsTests { "name" to "Joe Doe", "id" to "100", "object" to "{id:\"id\"}", - "array" to "{id:['one', 'two']}") + "array" to "{id:['one', 'two']}", + ) val actual = "CREATE (:Person {name: \$name, id: \$id, object: \$object, array: \$array)" val expected = "CREATE (:Person {name: \"Joe Doe\", id: \"100\", object: \"{id:\\\"id\\\"}\", " + diff --git a/dataset/src/integrationTest/kotlin/com/cosmotech/dataset/service/DatasetServiceIntegrationTest.kt b/dataset/src/integrationTest/kotlin/com/cosmotech/dataset/service/DatasetServiceIntegrationTest.kt index 5986b93fd..23916a550 100644 --- a/dataset/src/integrationTest/kotlin/com/cosmotech/dataset/service/DatasetServiceIntegrationTest.kt +++ b/dataset/src/integrationTest/kotlin/com/cosmotech/dataset/service/DatasetServiceIntegrationTest.kt @@ -153,11 +153,18 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { val datasetTags = mutableListOf("dataset", "public", "customers") val datasetCreateRequest = DatasetCreateRequest( - name = datasetName, description = datasetDescription, tags = datasetTags) + name = datasetName, + description = datasetDescription, + tags = datasetTags, + ) val createdDataset = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, datasetCreateRequest, arrayOf()) + organizationSaved.id, + workspaceSaved.id, + datasetCreateRequest, + arrayOf(), + ) assertNotNull(createdDataset) assertEquals(datasetName, createdDataset.name) @@ -181,7 +188,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { description = datasetPartDescription, tags = datasetPartTags, additionalData = datasetPartAdditionalData, - type = DatasetPartTypeEnum.File) + type = DatasetPartTypeEnum.File, + ) val datasetName = "Customer Dataset" val datasetDescription = "Dataset for customers" @@ -194,7 +202,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { description = datasetDescription, tags = datasetTags, additionalData = datasetAdditionalData, - parts = mutableListOf(datasetPartCreateRequest)) + parts = mutableListOf(datasetPartCreateRequest), + ) val resourceTestFile = resourceLoader.getResource("classpath:/$CUSTOMER_SOURCE_FILE_NAME").file @@ -205,14 +214,16 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "files", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToSend)) + IOUtils.toByteArray(fileToSend), + ) val createdDataset = datasetApiService.createDataset( organizationSaved.id, workspaceSaved.id, datasetCreateRequest, - arrayOf(mockMultipartFile)) + arrayOf(mockMultipartFile), + ) val datasetPartFilePath = constructFilePathForDatasetPart(createdDataset, 0) assertTrue(s3Template.objectExists(csmPlatformProperties.s3.bucketName, datasetPartFilePath)) @@ -248,14 +259,16 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { sourceName = UNALLOWED_MIME_TYPE_SOURCE_FILE_NAME, description = "List of customers", tags = mutableListOf("part", "public", "customers"), - type = DatasetPartTypeEnum.File) + type = DatasetPartTypeEnum.File, + ) val datasetCreateRequest = DatasetCreateRequest( name = "Customer Dataset", description = "Dataset for customers", tags = mutableListOf("dataset", "public", "customers"), - parts = mutableListOf(datasetPartCreateRequest)) + parts = mutableListOf(datasetPartCreateRequest), + ) val resourceTestFile = resourceLoader.getResource("classpath:/$UNALLOWED_MIME_TYPE_SOURCE_FILE_NAME").file @@ -267,7 +280,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "files", UNALLOWED_MIME_TYPE_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToSend)) + IOUtils.toByteArray(fileToSend), + ) val exception = assertThrows { @@ -275,12 +289,14 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { organizationSaved.id, workspaceSaved.id, datasetCreateRequest, - arrayOf(mockMultipartFile)) + arrayOf(mockMultipartFile), + ) } assertEquals( "MIME type text/x-yaml for file $UNALLOWED_MIME_TYPE_SOURCE_FILE_NAME is not authorized.", - exception.message) + exception.message, + ) } @Test @@ -292,21 +308,24 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { sourceName = WRONG_ORIGINAL_FILE_NAME, description = "List of customers", tags = mutableListOf("part", "public", "customers"), - type = DatasetPartTypeEnum.File) + type = DatasetPartTypeEnum.File, + ) val datasetCreateRequest = DatasetCreateRequest( name = "Customer Dataset", description = "Dataset for customers", tags = mutableListOf("dataset", "public", "customers"), - parts = mutableListOf(datasetPartCreateRequest)) + parts = mutableListOf(datasetPartCreateRequest), + ) val mockMultipartFile = MockMultipartFile( "files", WRONG_ORIGINAL_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - InputStream.nullInputStream()) + InputStream.nullInputStream(), + ) val exception = assertThrows { @@ -314,12 +333,14 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { organizationSaved.id, workspaceSaved.id, datasetCreateRequest, - arrayOf(mockMultipartFile)) + arrayOf(mockMultipartFile), + ) } assertEquals( "Invalid filename: '$WRONG_ORIGINAL_FILE_NAME'. File name should neither contains '..' nor starts by '/'.", - exception.message) + exception.message, + ) } @Test @@ -334,7 +355,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { sourceName = CUSTOMER_SOURCE_FILE_NAME, description = customerPartDescription, tags = customerPartTags, - type = DatasetPartTypeEnum.File) + type = DatasetPartTypeEnum.File, + ) val inventoryPartName = "Product list" val inventoryPartDescription = "List of Product" @@ -345,7 +367,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { sourceName = INVENTORY_SOURCE_FILE_NAME, description = inventoryPartDescription, tags = inventoryPartTags, - type = DatasetPartTypeEnum.File) + type = DatasetPartTypeEnum.File, + ) val datasetName = "Shop Dataset" val datasetDescription = "Dataset for shop" @@ -355,7 +378,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { name = datasetName, description = datasetDescription, tags = datasetTags, - parts = mutableListOf(customerPartCreateRequest, inventoryPartCreateRequest)) + parts = mutableListOf(customerPartCreateRequest, inventoryPartCreateRequest), + ) val customerTestFile = resourceLoader.getResource("classpath:/$CUSTOMER_SOURCE_FILE_NAME").file val inventoryTestFile = @@ -369,21 +393,24 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "files", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(customerFileToSend)) + IOUtils.toByteArray(customerFileToSend), + ) val inventoryMockMultipartFile = MockMultipartFile( "files", INVENTORY_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(inventoryFileToSend)) + IOUtils.toByteArray(inventoryFileToSend), + ) val createdDataset = datasetApiService.createDataset( organizationSaved.id, workspaceSaved.id, datasetCreateRequest, - arrayOf(customerMockMultipartFile, inventoryMockMultipartFile)) + arrayOf(customerMockMultipartFile, inventoryMockMultipartFile), + ) val customerPartFilePath = constructFilePathForDatasetPart(createdDataset, 0) val inventoryPartFilePath = constructFilePathForDatasetPart(createdDataset, 1) @@ -442,7 +469,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { sourceName = CUSTOMER_SOURCE_FILE_NAME, description = customerPartDescription, tags = customerPartTags, - type = DatasetPartTypeEnum.File) + type = DatasetPartTypeEnum.File, + ) val datasetName = "Shop Dataset" val datasetDescription = "Dataset for shop" @@ -456,7 +484,11 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { mutableListOf( customerPartCreateRequest, DatasetPartCreateRequest( - name = "Part create request 2", sourceName = "anotherFile.txt"))) + name = "Part create request 2", + sourceName = "anotherFile.txt", + ), + ), + ) val customerTestFile = resourceLoader.getResource("classpath:/$CUSTOMER_SOURCE_FILE_NAME").file @@ -467,14 +499,16 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "files", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(customerFileToSend)) + IOUtils.toByteArray(customerFileToSend), + ) val customerMockMultipartFile2 = MockMultipartFile( "files", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - InputStream.nullInputStream()) + InputStream.nullInputStream(), + ) val exception = assertThrows { @@ -482,13 +516,15 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { organizationSaved.id, workspaceSaved.id, datasetCreateRequest, - arrayOf(customerMockMultipartFile, customerMockMultipartFile2)) + arrayOf(customerMockMultipartFile, customerMockMultipartFile2), + ) } assertEquals( "Part File names should be unique during dataset creation. " + "Multipart file names: [$CUSTOMER_SOURCE_FILE_NAME, $CUSTOMER_SOURCE_FILE_NAME]. " + "Dataset parts source names: [$CUSTOMER_SOURCE_FILE_NAME, anotherFile.txt].", - exception.message) + exception.message, + ) } @Test @@ -498,7 +534,11 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { val datasetCreated = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, datasetCreateRequest, arrayOf()) + organizationSaved.id, + workspaceSaved.id, + datasetCreateRequest, + arrayOf(), + ) assertNotNull(datasetCreated) } @@ -517,7 +557,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "files", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToSend)) + IOUtils.toByteArray(fileToSend), + ) val exception = assertThrows { @@ -525,7 +566,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { organizationSaved.id, workspaceSaved.id, datasetCreateRequest, - arrayOf(mockMultipartFile)) + arrayOf(mockMultipartFile), + ) } assertEquals("Dataset name must not be blank", exception.message) } @@ -539,16 +581,22 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { parts = mutableListOf( DatasetPartCreateRequest(name = "part1", sourceName = "filepart1.csv"), - )) + ), + ) val exception = assertThrows { datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, datasetCreateRequest, arrayOf()) + organizationSaved.id, + workspaceSaved.id, + datasetCreateRequest, + arrayOf(), + ) } assertEquals( "Number of files must be equal to the number of parts if specified. 0 != 1", - exception.message) + exception.message, + ) } @Test @@ -565,7 +613,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "files", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToSend)) + IOUtils.toByteArray(fileToSend), + ) val exception = assertThrows { @@ -573,11 +622,13 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { organizationSaved.id, workspaceSaved.id, datasetCreateRequest, - arrayOf(mockMultipartFile)) + arrayOf(mockMultipartFile), + ) } assertEquals( "Number of files must be equal to the number of parts if specified. 1 != 0", - exception.message) + exception.message, + ) } @Test @@ -588,7 +639,9 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { name = "Dataset Test", parts = mutableListOf( - DatasetPartCreateRequest(name = "part1", sourceName = "wrongname.csv"))) + DatasetPartCreateRequest(name = "part1", sourceName = "wrongname.csv") + ), + ) val resourceTestFile = resourceLoader.getResource("classpath:/$CUSTOMER_SOURCE_FILE_NAME").file @@ -599,7 +652,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "files", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToSend)) + IOUtils.toByteArray(fileToSend), + ) val exception = assertThrows { @@ -607,13 +661,15 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { organizationSaved.id, workspaceSaved.id, datasetCreateRequest, - arrayOf(mockMultipartFile)) + arrayOf(mockMultipartFile), + ) } assertEquals( "All files must have the same name as corresponding sourceName in a Dataset Part. " + "Multipart file names: [customers.csv]. " + "Dataset parts source names: [wrongname.csv].", - exception.message) + exception.message, + ) } @Test @@ -623,7 +679,11 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { val createDataset = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, datasetCreateRequest, arrayOf()) + organizationSaved.id, + workspaceSaved.id, + datasetCreateRequest, + arrayOf(), + ) val datasetId = createDataset.id datasetApiService.deleteDataset(organizationSaved.id, workspaceSaved.id, datasetId) @@ -637,7 +697,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "Dataset $datasetId not found " + "in organization ${organizationSaved.id} " + "and workspace ${workspaceSaved.id}", - exception.message) + exception.message, + ) } @Test @@ -652,7 +713,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { sourceName = CUSTOMER_SOURCE_FILE_NAME, description = datasetPartDescription, tags = datasetPartTags, - type = DatasetPartTypeEnum.File) + type = DatasetPartTypeEnum.File, + ) val datasetName = "Customer Dataset" val datasetDescription = "Dataset for customers" @@ -662,7 +724,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { name = datasetName, description = datasetDescription, tags = datasetTags, - parts = mutableListOf(datasetPartCreateRequest)) + parts = mutableListOf(datasetPartCreateRequest), + ) val resourceTestFile = resourceLoader.getResource("classpath:/$CUSTOMER_SOURCE_FILE_NAME").file @@ -673,14 +736,16 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "files", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToSend)) + IOUtils.toByteArray(fileToSend), + ) val createdDataset = datasetApiService.createDataset( organizationSaved.id, workspaceSaved.id, datasetCreateRequest, - arrayOf(mockMultipartFile)) + arrayOf(mockMultipartFile), + ) val fileKeyPath = constructFilePathForDatasetPart(createdDataset, 0) @@ -698,7 +763,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "Dataset $datasetId not found " + "in organization ${organizationSaved.id} " + "and workspace ${workspaceSaved.id}", - exception.message) + exception.message, + ) assertFalse(s3Template.objectExists(csmPlatformProperties.s3.bucketName, fileKeyPath)) } @@ -715,7 +781,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { sourceName = CUSTOMER_SOURCE_FILE_NAME, description = datasetPartDescription, tags = datasetPartTags, - type = DatasetPartTypeEnum.File) + type = DatasetPartTypeEnum.File, + ) val datasetName = "Customer Dataset" val datasetDescription = "Dataset for customers" @@ -725,7 +792,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { name = datasetName, description = datasetDescription, tags = datasetTags, - parts = mutableListOf(datasetPartCreateRequest)) + parts = mutableListOf(datasetPartCreateRequest), + ) val resourceTestFile = resourceLoader.getResource("classpath:/$CUSTOMER_SOURCE_FILE_NAME").file @@ -736,7 +804,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "files", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToSend)) + IOUtils.toByteArray(fileToSend), + ) val datasetId = datasetApiService @@ -744,7 +813,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { organizationSaved.id, workspaceSaved.id, datasetCreateRequest, - arrayOf(mockMultipartFile)) + arrayOf(mockMultipartFile), + ) .id val fakeRunnerId = "r-XXXXXX" @@ -760,7 +830,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { assertEquals( "Dataset $datasetId is defined as a runner dataset ($fakeRunnerId). It cannot be deleted", - exception.message) + exception.message, + ) } @Test @@ -770,7 +841,11 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { val createDataset = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, datasetCreateRequest, arrayOf()) + organizationSaved.id, + workspaceSaved.id, + datasetCreateRequest, + arrayOf(), + ) val retrievedDataset = datasetApiService.getDataset(organizationSaved.id, workspaceSaved.id, createDataset.id) @@ -791,7 +866,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { sourceName = CUSTOMER_SOURCE_FILE_NAME, description = datasetPartDescription, tags = datasetPartTags, - type = DatasetPartTypeEnum.File) + type = DatasetPartTypeEnum.File, + ) val datasetName = "Customer Dataset" val datasetDescription = "Dataset for customers" @@ -801,7 +877,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { name = datasetName, description = datasetDescription, tags = datasetTags, - parts = mutableListOf(datasetPartCreateRequest)) + parts = mutableListOf(datasetPartCreateRequest), + ) val resourceTestFile = resourceLoader.getResource("classpath:/$CUSTOMER_SOURCE_FILE_NAME").file @@ -812,14 +889,16 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "files", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToSend)) + IOUtils.toByteArray(fileToSend), + ) val createdDataset = datasetApiService.createDataset( organizationSaved.id, workspaceSaved.id, datasetCreateRequest, - arrayOf(mockMultipartFile)) + arrayOf(mockMultipartFile), + ) val retrievedDataset = datasetApiService.getDataset(organizationSaved.id, workspaceSaved.id, createdDataset.id) @@ -835,11 +914,19 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { val createDataset = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, datasetCreateRequest, arrayOf()) + organizationSaved.id, + workspaceSaved.id, + datasetCreateRequest, + arrayOf(), + ) val retrievedDatasetAccessControl = datasetApiService.getDatasetAccessControl( - organizationSaved.id, workspaceSaved.id, createDataset.id, CONNECTED_ADMIN_USER) + organizationSaved.id, + workspaceSaved.id, + createDataset.id, + CONNECTED_ADMIN_USER, + ) assertNotNull(retrievedDatasetAccessControl) assertEquals(CONNECTED_ADMIN_USER, retrievedDatasetAccessControl.id) @@ -853,11 +940,18 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { val createDataset = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, datasetCreateRequest, arrayOf()) + organizationSaved.id, + workspaceSaved.id, + datasetCreateRequest, + arrayOf(), + ) val retrievedDatasetListUsers = datasetApiService.listDatasetSecurityUsers( - organizationSaved.id, workspaceSaved.id, createDataset.id) + organizationSaved.id, + workspaceSaved.id, + createDataset.id, + ) assertNotNull(retrievedDatasetListUsers) assertTrue(retrievedDatasetListUsers.size == 1) @@ -871,13 +965,21 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { val createDataset = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, datasetCreateRequest, arrayOf()) + organizationSaved.id, + workspaceSaved.id, + datasetCreateRequest, + arrayOf(), + ) val datasetCreateRequest2 = DatasetCreateRequest(name = "Dataset Test 2") val createDataset2 = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, datasetCreateRequest2, arrayOf()) + organizationSaved.id, + workspaceSaved.id, + datasetCreateRequest2, + arrayOf(), + ) var retrievedDatasetList = datasetApiService.listDatasets(organizationSaved.id, workspaceSaved.id, null, null) @@ -911,18 +1013,33 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { accessControlList = mutableListOf( DatasetAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), - DatasetAccessControl(CONNECTED_DEFAULT_USER, ROLE_EDITOR)))) + DatasetAccessControl(CONNECTED_DEFAULT_USER, ROLE_EDITOR), + ), + ), + ) val createDataset = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, datasetCreateRequest, arrayOf()) + organizationSaved.id, + workspaceSaved.id, + datasetCreateRequest, + arrayOf(), + ) datasetApiService.deleteDatasetAccessControl( - organizationSaved.id, workspaceSaved.id, createDataset.id, CONNECTED_DEFAULT_USER) + organizationSaved.id, + workspaceSaved.id, + createDataset.id, + CONNECTED_DEFAULT_USER, + ) val retrievedDatasetAccessControl = datasetApiService.getDatasetAccessControl( - organizationSaved.id, workspaceSaved.id, createDataset.id, CONNECTED_ADMIN_USER) + organizationSaved.id, + workspaceSaved.id, + createDataset.id, + CONNECTED_ADMIN_USER, + ) assertNotNull(retrievedDatasetAccessControl) assertEquals(CONNECTED_ADMIN_USER, retrievedDatasetAccessControl.id) @@ -941,18 +1058,26 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { accessControlList = mutableListOf( DatasetAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), - DatasetAccessControl(CONNECTED_DEFAULT_USER, ROLE_EDITOR)))) + DatasetAccessControl(CONNECTED_DEFAULT_USER, ROLE_EDITOR), + ), + ), + ) val createDataset = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, datasetCreateRequest, arrayOf()) + organizationSaved.id, + workspaceSaved.id, + datasetCreateRequest, + arrayOf(), + ) val newDatasetSecurity = datasetApiService.updateDatasetDefaultSecurity( organizationSaved.id, workspaceSaved.id, createDataset.id, - DatasetRole(role = ROLE_EDITOR)) + DatasetRole(role = ROLE_EDITOR), + ) assertNotNull(newDatasetSecurity) assertEquals(ROLE_EDITOR, newDatasetSecurity.default) val accessControlList = newDatasetSecurity.accessControlList @@ -975,11 +1100,18 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { accessControlList = mutableListOf( DatasetAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), - DatasetAccessControl(CONNECTED_DEFAULT_USER, ROLE_EDITOR)))) + DatasetAccessControl(CONNECTED_DEFAULT_USER, ROLE_EDITOR), + ), + ), + ) val createDataset = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, datasetCreateRequest, arrayOf()) + organizationSaved.id, + workspaceSaved.id, + datasetCreateRequest, + arrayOf(), + ) val newDatasetAccessControl = datasetApiService.updateDatasetAccessControl( @@ -987,7 +1119,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { workspaceSaved.id, createDataset.id, CONNECTED_DEFAULT_USER, - DatasetRole(role = ROLE_ADMIN)) + DatasetRole(role = ROLE_ADMIN), + ) assertNotNull(newDatasetAccessControl) assertEquals(ROLE_ADMIN, newDatasetAccessControl.role) assertEquals(CONNECTED_DEFAULT_USER, newDatasetAccessControl.id) @@ -1001,10 +1134,17 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { val datasetTags = mutableListOf("dataset", "public", "customers") val datasetCreateRequest = DatasetCreateRequest( - name = datasetName, description = datasetDescription, tags = datasetTags) + name = datasetName, + description = datasetDescription, + tags = datasetTags, + ) datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, datasetCreateRequest, arrayOf()) + organizationSaved.id, + workspaceSaved.id, + datasetCreateRequest, + arrayOf(), + ) datasetApiService.createDataset( organizationSaved.id, @@ -1012,12 +1152,19 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { DatasetCreateRequest( name = "Other Dataset", description = "Other Dataset ", - tags = mutableListOf("dataset", "public", "other")), - arrayOf()) + tags = mutableListOf("dataset", "public", "other"), + ), + arrayOf(), + ) val foundDatasets = datasetApiService.searchDatasets( - organizationSaved.id, workspaceSaved.id, listOf("customers"), null, null) + organizationSaved.id, + workspaceSaved.id, + listOf("customers"), + null, + null, + ) assertTrue(foundDatasets.size == 1) assertEquals(datasetName, foundDatasets[0].name) @@ -1034,10 +1181,17 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { val datasetTags = mutableListOf("dataset", "public", "customers", "!") val datasetCreateRequest = DatasetCreateRequest( - name = datasetName, description = datasetDescription, tags = datasetTags) + name = datasetName, + description = datasetDescription, + tags = datasetTags, + ) datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, datasetCreateRequest, arrayOf()) + organizationSaved.id, + workspaceSaved.id, + datasetCreateRequest, + arrayOf(), + ) datasetApiService.createDataset( organizationSaved.id, @@ -1045,8 +1199,10 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { DatasetCreateRequest( name = "Other Dataset", description = "Other Dataset ", - tags = mutableListOf("dataset", "public", "other")), - arrayOf()) + tags = mutableListOf("dataset", "public", "other"), + ), + arrayOf(), + ) datasetApiService.createDataset( organizationSaved.id, @@ -1054,8 +1210,10 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { DatasetCreateRequest( name = "Another Dataset", description = "Another Dataset ", - tags = mutableListOf("dataset", "public", "other with blankspace 12 34")), - arrayOf()) + tags = mutableListOf("dataset", "public", "other with blankspace 12 34"), + ), + arrayOf(), + ) val foundDatasets = datasetApiService.searchDatasets( @@ -1093,9 +1251,11 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { ")", "`", "~", - "\$fofo"), + "\$fofo", + ), + null, null, - null) + ) assertEquals(2, foundDatasets.size) } @@ -1108,10 +1268,17 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { val datasetTags = mutableListOf("dataset", "public", "customers", "!") val datasetCreateRequest = DatasetCreateRequest( - name = datasetName, description = datasetDescription, tags = datasetTags) + name = datasetName, + description = datasetDescription, + tags = datasetTags, + ) datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, datasetCreateRequest, arrayOf()) + organizationSaved.id, + workspaceSaved.id, + datasetCreateRequest, + arrayOf(), + ) datasetApiService.createDataset( organizationSaved.id, @@ -1119,8 +1286,10 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { DatasetCreateRequest( name = "Other Dataset", description = "Other Dataset ", - tags = mutableListOf("dataset", "public", "other")), - arrayOf()) + tags = mutableListOf("dataset", "public", "other"), + ), + arrayOf(), + ) val foundDatasets = datasetApiService.searchDatasets( @@ -1128,7 +1297,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { workspaceSaved.id, listOf("other", ",./;'[]-=<>?:\"{}|_+!@#%^&*()`~$"), null, - null) + null, + ) assertEquals(1, foundDatasets.size) } @@ -1140,7 +1310,11 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { val createDataset = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, datasetCreateRequest, arrayOf()) + organizationSaved.id, + workspaceSaved.id, + datasetCreateRequest, + arrayOf(), + ) assertTrue(createDataset.parts.isEmpty()) @@ -1153,7 +1327,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "file", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToSend)) + IOUtils.toByteArray(fileToSend), + ) val datasetPartName = "Customer list" val datasetPartDescription = "List of customers" @@ -1173,7 +1348,9 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { description = datasetPartDescription, tags = datasetPartTags, additionalData = datasetPartAdditionalData, - type = DatasetPartTypeEnum.File)) + type = DatasetPartTypeEnum.File, + ), + ) assertNotNull(createDatasetPart) assertEquals(datasetPartName, createDatasetPart.name) @@ -1205,13 +1382,21 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { fun `test createDatasetPart type DB`() { testCreateDatasetPartWithSimpleFile(CUSTOMER_SOURCE_FILE_NAME, CUSTOMER_SOURCE_FILE_NAME) testCreateDatasetPartWithSimpleFile( - CUSTOMERS_1000_SOURCE_FILE_NAME, CUSTOMERS_1000_SOURCE_FILE_NAME) + CUSTOMERS_1000_SOURCE_FILE_NAME, + CUSTOMERS_1000_SOURCE_FILE_NAME, + ) testCreateDatasetPartWithSimpleFile( - CUSTOMERS_10000_SOURCE_FILE_NAME, CUSTOMERS_10000_SOURCE_FILE_NAME) + CUSTOMERS_10000_SOURCE_FILE_NAME, + CUSTOMERS_10000_SOURCE_FILE_NAME, + ) testCreateDatasetPartWithSimpleFile( - CUSTOMERS_WITH_QUOTES_SOURCE_FILE_NAME, CUSTOMERS_WITH_QUOTES_SOURCE_FILE_NAME) + CUSTOMERS_WITH_QUOTES_SOURCE_FILE_NAME, + CUSTOMERS_WITH_QUOTES_SOURCE_FILE_NAME, + ) testCreateDatasetPartWithSimpleFile( - CUSTOMERS_WITH_DOUBLE_QUOTES_SOURCE_FILE_NAME, CUSTOMER_SOURCE_FILE_NAME) + CUSTOMERS_WITH_DOUBLE_QUOTES_SOURCE_FILE_NAME, + CUSTOMER_SOURCE_FILE_NAME, + ) } @Test @@ -1227,7 +1412,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "file", CUSTOMERS_1000_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(customers1000FileToSend)) + IOUtils.toByteArray(customers1000FileToSend), + ) val customers10000File = resourceLoader.getResource("classpath:/$CUSTOMERS_10000_SOURCE_FILE_NAME").file @@ -1239,7 +1425,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "file", CUSTOMERS_10000_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(customers10000FileToSend)) + IOUtils.toByteArray(customers10000FileToSend), + ) val datasetCreateRequest = DatasetCreateRequest( @@ -1249,18 +1436,23 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { DatasetPartCreateRequest( name = "File part", sourceName = CUSTOMERS_1000_SOURCE_FILE_NAME, - type = DatasetPartTypeEnum.File), + type = DatasetPartTypeEnum.File, + ), DatasetPartCreateRequest( name = "DB part", sourceName = CUSTOMERS_10000_SOURCE_FILE_NAME, - type = DatasetPartTypeEnum.DB))) + type = DatasetPartTypeEnum.DB, + ), + ), + ) val createdDataset = datasetApiService.createDataset( organizationSaved.id, workspaceSaved.id, datasetCreateRequest, - arrayOf(customers1000MultipartFile, customers10000MultipartFile)) + arrayOf(customers1000MultipartFile, customers10000MultipartFile), + ) val fileDatasetPartId = createdDataset.parts.first { it.type == DatasetPartTypeEnum.File }.id val dBDatasetPartId = createdDataset.parts.first { it.type == DatasetPartTypeEnum.DB }.id @@ -1274,14 +1466,22 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { val datasetPartFile = datasetApiService.downloadDatasetPart( - organizationSaved.id, workspaceSaved.id, createdDataset.id, fileDatasetPartId) + organizationSaved.id, + workspaceSaved.id, + createdDataset.id, + fileDatasetPartId, + ) var expectedText = FileInputStream(customers1000File).bufferedReader().use { it.readText() } var retrievedText = datasetPartFile.inputStream.bufferedReader().use { it.readText() } assertEquals(expectedText, retrievedText) val datasetPartDB = datasetApiService.downloadDatasetPart( - organizationSaved.id, workspaceSaved.id, createdDataset.id, dBDatasetPartId) + organizationSaved.id, + workspaceSaved.id, + createdDataset.id, + dBDatasetPartId, + ) expectedText = FileInputStream(customers10000File).bufferedReader().use { it.readText() } retrievedText = datasetPartDB.inputStream.bufferedReader().use { it.readText() } assertEquals(expectedText, retrievedText) @@ -1300,7 +1500,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "file", CUSTOMERS_10000_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(customers10000FileToSend)) + IOUtils.toByteArray(customers10000FileToSend), + ) val datasetCreateRequest = DatasetCreateRequest( @@ -1310,21 +1511,29 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { DatasetPartCreateRequest( name = "DB part", sourceName = CUSTOMERS_10000_SOURCE_FILE_NAME, - type = DatasetPartTypeEnum.DB))) + type = DatasetPartTypeEnum.DB, + ) + ), + ) val createdDataset = datasetApiService.createDataset( organizationSaved.id, workspaceSaved.id, datasetCreateRequest, - arrayOf(customers10000MultipartFile)) + arrayOf(customers10000MultipartFile), + ) val dBDatasetPartId = createdDataset.parts.first { it.type == DatasetPartTypeEnum.DB }.id assertTrue(writerJdbcTemplate.existTable(dBDatasetPartId.replace('-', '_'))) datasetApiService.deleteDatasetPart( - organizationSaved.id, workspaceSaved.id, createdDataset.id, dBDatasetPartId) + organizationSaved.id, + workspaceSaved.id, + createdDataset.id, + dBDatasetPartId, + ) assertFalse(writerJdbcTemplate.existTable(dBDatasetPartId.replace('-', '_'))) } @@ -1342,7 +1551,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "file", CUSTOMERS_10000_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(customers10000FileToSend)) + IOUtils.toByteArray(customers10000FileToSend), + ) val datasetCreateRequest = DatasetCreateRequest( @@ -1352,14 +1562,18 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { DatasetPartCreateRequest( name = "DB part", sourceName = CUSTOMERS_10000_SOURCE_FILE_NAME, - type = DatasetPartTypeEnum.DB))) + type = DatasetPartTypeEnum.DB, + ) + ), + ) val createdDataset = datasetApiService.createDataset( organizationSaved.id, workspaceSaved.id, datasetCreateRequest, - arrayOf(customers10000MultipartFile)) + arrayOf(customers10000MultipartFile), + ) val firstDBDatasetPartId = createdDataset.parts.first { it.type == DatasetPartTypeEnum.DB }.id @@ -1367,7 +1581,11 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { var datasetPartDB = datasetApiService.downloadDatasetPart( - organizationSaved.id, workspaceSaved.id, createdDataset.id, firstDBDatasetPartId) + organizationSaved.id, + workspaceSaved.id, + createdDataset.id, + firstDBDatasetPartId, + ) var expectedText = FileInputStream(customers10000File).bufferedReader().use { it.readText() } var retrievedText = datasetPartDB.inputStream.bufferedReader().use { it.readText() } assertEquals(expectedText, retrievedText) @@ -1382,7 +1600,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "file", CUSTOMERS_1000_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(customers1000FileToSend)) + IOUtils.toByteArray(customers1000FileToSend), + ) val updatedDataset = datasetApiService.updateDataset( @@ -1395,8 +1614,12 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { DatasetPartCreateRequest( name = "New part DB", sourceName = CUSTOMERS_1000_SOURCE_FILE_NAME, - type = DatasetPartTypeEnum.DB))), - arrayOf(customers1000MultipartFile)) + type = DatasetPartTypeEnum.DB, + ) + ) + ), + arrayOf(customers1000MultipartFile), + ) assertFalse(writerJdbcTemplate.existTable(firstDBDatasetPartId.replace('-', '_'))) @@ -1406,7 +1629,11 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { datasetPartDB = datasetApiService.downloadDatasetPart( - organizationSaved.id, workspaceSaved.id, createdDataset.id, updatedDBDatasetPartId) + organizationSaved.id, + workspaceSaved.id, + createdDataset.id, + updatedDBDatasetPartId, + ) expectedText = FileInputStream(customers1000File).bufferedReader().use { it.readText() } retrievedText = datasetPartDB.inputStream.bufferedReader().use { it.readText() } assertEquals(expectedText, retrievedText) @@ -1425,7 +1652,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "file", UNALLOWED_CHAR_HEADERS_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(unallowedCharInHeaderFileToSend)) + IOUtils.toByteArray(unallowedCharInHeaderFileToSend), + ) val datasetCreateRequest = DatasetCreateRequest( @@ -1435,7 +1663,10 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { DatasetPartCreateRequest( name = "DB part", sourceName = UNALLOWED_CHAR_HEADERS_FILE_NAME, - type = DatasetPartTypeEnum.DB))) + type = DatasetPartTypeEnum.DB, + ) + ), + ) val exception = assertThrows { @@ -1443,13 +1674,15 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { organizationSaved.id, workspaceSaved.id, datasetCreateRequest, - arrayOf(unallowedCharInHeaderMultipartFile)) + arrayOf(unallowedCharInHeaderMultipartFile), + ) } assertEquals( "Invalid header name found in dataset part file: " + "header name must match [a-zA-Z0-9_\"' ]+ (found: [\"%1325 \\ sr\", \"-#()char'\\`\\\"\"])", - exception.message) + exception.message, + ) } @Test @@ -1465,7 +1698,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "file", EMPTY_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(unallowedCharInHeaderFileToSend)) + IOUtils.toByteArray(unallowedCharInHeaderFileToSend), + ) val datasetCreateRequest = DatasetCreateRequest( @@ -1475,7 +1709,10 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { DatasetPartCreateRequest( name = "DB part", sourceName = EMPTY_SOURCE_FILE_NAME, - type = DatasetPartTypeEnum.DB))) + type = DatasetPartTypeEnum.DB, + ) + ), + ) val exception = assertThrows { @@ -1483,7 +1720,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { organizationSaved.id, workspaceSaved.id, datasetCreateRequest, - arrayOf(unallowedCharInHeaderMultipartFile)) + arrayOf(unallowedCharInHeaderMultipartFile), + ) } assertEquals("No headers found in dataset part file", exception.message) @@ -1502,7 +1740,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "file", SAME_HEADERS_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(unallowedCharInHeaderFileToSend)) + IOUtils.toByteArray(unallowedCharInHeaderFileToSend), + ) val datasetCreateRequest = DatasetCreateRequest( @@ -1512,7 +1751,10 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { DatasetPartCreateRequest( name = "DB part", sourceName = SAME_HEADERS_FILE_NAME, - type = DatasetPartTypeEnum.DB))) + type = DatasetPartTypeEnum.DB, + ) + ), + ) val exception = assertThrows { @@ -1520,7 +1762,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { organizationSaved.id, workspaceSaved.id, datasetCreateRequest, - arrayOf(unallowedCharInHeaderMultipartFile)) + arrayOf(unallowedCharInHeaderMultipartFile), + ) } assertEquals("Duplicate headers found in dataset part file", exception.message) @@ -1533,7 +1776,11 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { val createDataset = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, datasetCreateRequest, arrayOf()) + organizationSaved.id, + workspaceSaved.id, + datasetCreateRequest, + arrayOf(), + ) assertTrue(createDataset.parts.isEmpty()) @@ -1547,7 +1794,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "file", UNALLOWED_MIME_TYPE_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToSend)) + IOUtils.toByteArray(fileToSend), + ) val exception = assertThrows { @@ -1561,11 +1809,14 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { sourceName = UNALLOWED_MIME_TYPE_SOURCE_FILE_NAME, description = "List of customers", tags = mutableListOf("part", "public", "customers"), - type = DatasetPartTypeEnum.File)) + type = DatasetPartTypeEnum.File, + ), + ) } assertEquals( "MIME type text/x-yaml for file $UNALLOWED_MIME_TYPE_SOURCE_FILE_NAME is not authorized.", - exception.message) + exception.message, + ) } @Test @@ -1575,7 +1826,11 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { val createDataset = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, datasetCreateRequest, arrayOf()) + organizationSaved.id, + workspaceSaved.id, + datasetCreateRequest, + arrayOf(), + ) assertTrue(createDataset.parts.isEmpty()) @@ -1589,7 +1844,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "file", CUSTOMER_ZIPPED_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToSend)) + IOUtils.toByteArray(fileToSend), + ) val exception = assertThrows { @@ -1603,11 +1859,14 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { sourceName = CUSTOMER_ZIPPED_SOURCE_FILE_NAME, description = "List of customers", tags = mutableListOf("part", "public", "customers"), - type = DatasetPartTypeEnum.File)) + type = DatasetPartTypeEnum.File, + ), + ) } assertEquals( "MIME type application/zip for file $CUSTOMER_ZIPPED_SOURCE_FILE_NAME is not authorized.", - exception.message) + exception.message, + ) } @Test @@ -1617,7 +1876,11 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { val createDataset = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, datasetCreateRequest, arrayOf()) + organizationSaved.id, + workspaceSaved.id, + datasetCreateRequest, + arrayOf(), + ) assertTrue(createDataset.parts.isEmpty()) @@ -1626,7 +1889,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "file", WRONG_ORIGINAL_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - InputStream.nullInputStream()) + InputStream.nullInputStream(), + ) val exception = assertThrows { @@ -1640,11 +1904,14 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { sourceName = WRONG_ORIGINAL_FILE_NAME, description = "List of customers", tags = mutableListOf("part", "public", "customers"), - type = DatasetPartTypeEnum.File)) + type = DatasetPartTypeEnum.File, + ), + ) } assertEquals( "Invalid filename: '$WRONG_ORIGINAL_FILE_NAME'. File name should neither contains '..' nor starts by '/'.", - exception.message) + exception.message, + ) } @Test @@ -1654,7 +1921,11 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { val createDataset = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, datasetCreateRequest, arrayOf()) + organizationSaved.id, + workspaceSaved.id, + datasetCreateRequest, + arrayOf(), + ) assertTrue(createDataset.parts.isEmpty()) @@ -1663,7 +1934,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "file", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - InputStream.nullInputStream()) + InputStream.nullInputStream(), + ) val exception = assertThrows { @@ -1675,7 +1947,9 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { DatasetPartCreateRequest( name = "", sourceName = CUSTOMER_SOURCE_FILE_NAME, - type = DatasetPartTypeEnum.File)) + type = DatasetPartTypeEnum.File, + ), + ) } assertEquals("Dataset Part name must not be blank", exception.message) } @@ -1687,7 +1961,11 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { val createDataset = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, datasetCreateRequest, arrayOf()) + organizationSaved.id, + workspaceSaved.id, + datasetCreateRequest, + arrayOf(), + ) assertTrue(createDataset.parts.isEmpty()) @@ -1696,7 +1974,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "file", "wrongFileName.csv", MediaType.MULTIPART_FORM_DATA_VALUE, - InputStream.nullInputStream()) + InputStream.nullInputStream(), + ) val exception = assertThrows { @@ -1708,12 +1987,15 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { DatasetPartCreateRequest( name = "Dataset Part Name", sourceName = CUSTOMER_SOURCE_FILE_NAME, - type = DatasetPartTypeEnum.File)) + type = DatasetPartTypeEnum.File, + ), + ) } assertEquals( "You must upload a file with the same name as the Dataset Part sourceName. " + "You provided $CUSTOMER_SOURCE_FILE_NAME and wrongFileName.csv instead.", - exception.message) + exception.message, + ) } @Test @@ -1723,7 +2005,11 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { val createDataset = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, datasetCreateRequest, arrayOf()) + organizationSaved.id, + workspaceSaved.id, + datasetCreateRequest, + arrayOf(), + ) assertTrue(createDataset.parts.isEmpty()) @@ -1736,7 +2022,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "file", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToSend)) + IOUtils.toByteArray(fileToSend), + ) val datasetPartName = "Customer list" val datasetPartDescription = "List of customers" @@ -1753,11 +2040,17 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { sourceName = CUSTOMER_SOURCE_FILE_NAME, description = datasetPartDescription, tags = datasetPartTags, - type = DatasetPartTypeEnum.File)) + type = DatasetPartTypeEnum.File, + ), + ) assertNotNull(createDatasetPart) datasetApiService.deleteDatasetPart( - organizationSaved.id, workspaceSaved.id, createDataset.id, createDatasetPart.id) + organizationSaved.id, + workspaceSaved.id, + createDataset.id, + createDatasetPart.id, + ) val retrievedDataset = datasetApiService.getDataset(organizationSaved.id, workspaceSaved.id, createDataset.id) @@ -1781,7 +2074,11 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { val createDataset = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, datasetCreateRequest, arrayOf()) + organizationSaved.id, + workspaceSaved.id, + datasetCreateRequest, + arrayOf(), + ) assertTrue(createDataset.parts.isEmpty()) @@ -1794,7 +2091,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "file", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToSend)) + IOUtils.toByteArray(fileToSend), + ) val datasetPartName = "Customer list" val datasetPartDescription = "List of customers" @@ -1811,11 +2109,17 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { sourceName = CUSTOMER_SOURCE_FILE_NAME, description = datasetPartDescription, tags = datasetPartTags, - type = DatasetPartTypeEnum.DB)) + type = DatasetPartTypeEnum.DB, + ), + ) assertNotNull(createDatasetPart) datasetApiService.deleteDatasetPart( - organizationSaved.id, workspaceSaved.id, createDataset.id, createDatasetPart.id) + organizationSaved.id, + workspaceSaved.id, + createDataset.id, + createDatasetPart.id, + ) val retrievedDataset = datasetApiService.getDataset(organizationSaved.id, workspaceSaved.id, createDataset.id) @@ -1832,7 +2136,11 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { val createDataset = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, datasetCreateRequest, arrayOf()) + organizationSaved.id, + workspaceSaved.id, + datasetCreateRequest, + arrayOf(), + ) assertTrue(createDataset.parts.isEmpty()) @@ -1845,7 +2153,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "file", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToSend)) + IOUtils.toByteArray(fileToSend), + ) val datasetPartName = "Customer list" val datasetPartDescription = "List of customers" @@ -1862,11 +2171,17 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { sourceName = CUSTOMER_SOURCE_FILE_NAME, description = datasetPartDescription, tags = datasetPartTags, - type = DatasetPartTypeEnum.File)) + type = DatasetPartTypeEnum.File, + ), + ) val retrievedDatasetPart = datasetApiService.getDatasetPart( - organizationSaved.id, workspaceSaved.id, createDataset.id, createDatasetPart.id) + organizationSaved.id, + workspaceSaved.id, + createDataset.id, + createDatasetPart.id, + ) assertEquals(createDatasetPart, retrievedDatasetPart) } @@ -1878,7 +2193,11 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { val createDataset = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, datasetCreateRequest, arrayOf()) + organizationSaved.id, + workspaceSaved.id, + datasetCreateRequest, + arrayOf(), + ) assertTrue(createDataset.parts.isEmpty()) @@ -1891,7 +2210,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "file", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToSend)) + IOUtils.toByteArray(fileToSend), + ) val datasetPartName = "Customer list" val datasetPartDescription = "List of customers" @@ -1908,7 +2228,9 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { sourceName = CUSTOMER_SOURCE_FILE_NAME, description = datasetPartDescription, tags = datasetPartTags, - type = DatasetPartTypeEnum.File)) + type = DatasetPartTypeEnum.File, + ), + ) val foundDatasetParts = datasetApiService.searchDatasetParts( @@ -1917,7 +2239,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { createDataset.id, listOf("customers"), null, - null) + null, + ) assertTrue(foundDatasetParts.size == 1) assertEquals(createDatasetPart.id, foundDatasetParts[0].id) @@ -1935,7 +2258,11 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { val createDataset = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, datasetCreateRequest, arrayOf()) + organizationSaved.id, + workspaceSaved.id, + datasetCreateRequest, + arrayOf(), + ) assertTrue(createDataset.parts.isEmpty()) @@ -1948,7 +2275,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "file", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToSend)) + IOUtils.toByteArray(fileToSend), + ) val datasetPartName = "Customer list" val datasetPartDescription = "List of customers" @@ -1964,7 +2292,9 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { sourceName = CUSTOMER_SOURCE_FILE_NAME, description = datasetPartDescription, tags = datasetPartTags, - type = DatasetPartTypeEnum.File)) + type = DatasetPartTypeEnum.File, + ), + ) val foundDatasetParts = datasetApiService.searchDatasetParts( @@ -2003,9 +2333,11 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { ")", "`", "~", - "\$fofo"), + "\$fofo", + ), + null, null, - null) + ) assertEquals(1, foundDatasetParts.size) } @@ -2017,7 +2349,11 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { val createDataset = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, datasetCreateRequest, arrayOf()) + organizationSaved.id, + workspaceSaved.id, + datasetCreateRequest, + arrayOf(), + ) assertTrue(createDataset.parts.isEmpty()) @@ -2030,7 +2366,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "file", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToSend)) + IOUtils.toByteArray(fileToSend), + ) val datasetPartName = "Customer list" val datasetPartDescription = "List of customers" @@ -2046,7 +2383,9 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { sourceName = CUSTOMER_SOURCE_FILE_NAME, description = datasetPartDescription, tags = datasetPartTags, - type = DatasetPartTypeEnum.File)) + type = DatasetPartTypeEnum.File, + ), + ) val foundDatasetParts = datasetApiService.searchDatasetParts( @@ -2055,7 +2394,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { createDataset.id, listOf("test", ",./;'[]-=<>?:\"{}|_+!@#%^&*()`~$"), null, - null) + null, + ) assertTrue(foundDatasetParts.isEmpty()) } @@ -2067,7 +2407,11 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { val createDataset = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, datasetCreateRequest, arrayOf()) + organizationSaved.id, + workspaceSaved.id, + datasetCreateRequest, + arrayOf(), + ) assertTrue(createDataset.parts.isEmpty()) @@ -2080,7 +2424,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "file", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToSend)) + IOUtils.toByteArray(fileToSend), + ) val datasetPartName = "Customer list" val datasetPartDescription = "List of customers" @@ -2096,7 +2441,9 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { sourceName = CUSTOMER_SOURCE_FILE_NAME, description = datasetPartDescription, tags = datasetPartTags, - type = DatasetPartTypeEnum.File)) + type = DatasetPartTypeEnum.File, + ), + ) val foundDatasetParts = datasetApiService.searchDatasetParts( @@ -2105,7 +2452,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { createDataset.id, listOf("part", ",./;'[]-=<>?:\"{}|_+!@#%^&*()`~$"), null, - null) + null, + ) assertEquals(1, foundDatasetParts.size) } @@ -2117,20 +2465,29 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { val createDataset = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, datasetCreateRequest, arrayOf()) + organizationSaved.id, + workspaceSaved.id, + datasetCreateRequest, + arrayOf(), + ) assertTrue(createDataset.parts.isEmpty()) val exception = assertThrows { datasetApiService.getDatasetPart( - organizationSaved.id, workspaceSaved.id, createDataset.id, "wrongDatasetPartId") + organizationSaved.id, + workspaceSaved.id, + createDataset.id, + "wrongDatasetPartId", + ) } assertEquals( "Dataset Part wrongDatasetPartId not found in organization ${organizationSaved.id}, " + "workspace ${workspaceSaved.id} and dataset ${createDataset.id}", - exception.message) + exception.message, + ) } @Test @@ -2145,7 +2502,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { sourceName = CUSTOMER_SOURCE_FILE_NAME, description = customerPartDescription, tags = customerPartTags, - type = DatasetPartTypeEnum.File) + type = DatasetPartTypeEnum.File, + ) val inventoryPartName = "Product list" val inventoryPartDescription = "List of Product" @@ -2156,7 +2514,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { sourceName = INVENTORY_SOURCE_FILE_NAME, description = inventoryPartDescription, tags = inventoryPartTags, - type = DatasetPartTypeEnum.File) + type = DatasetPartTypeEnum.File, + ) val datasetName = "Shop Dataset" val datasetDescription = "Dataset for shop" @@ -2166,32 +2525,41 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { name = datasetName, description = datasetDescription, tags = datasetTags, - parts = mutableListOf(customerPartCreateRequest, inventoryPartCreateRequest)) + parts = mutableListOf(customerPartCreateRequest, inventoryPartCreateRequest), + ) val emptyCustomerMockMultipartFile = MockMultipartFile( "files", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - InputStream.nullInputStream()) + " ".toByteArray(), + ) val emptyInventoryMockMultipartFile = MockMultipartFile( "files", INVENTORY_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - InputStream.nullInputStream()) + " ".toByteArray(), + ) val createdDataset = datasetApiService.createDataset( organizationSaved.id, workspaceSaved.id, datasetCreateRequest, - arrayOf(emptyCustomerMockMultipartFile, emptyInventoryMockMultipartFile)) + arrayOf(emptyCustomerMockMultipartFile, emptyInventoryMockMultipartFile), + ) var listDatasetParts = datasetApiService.listDatasetParts( - organizationSaved.id, workspaceSaved.id, createdDataset.id, null, null) + organizationSaved.id, + workspaceSaved.id, + createdDataset.id, + null, + null, + ) assertNotNull(listDatasetParts) assertEquals(2, listDatasetParts.size) @@ -2210,7 +2578,12 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { listDatasetParts = datasetApiService.listDatasetParts( - organizationSaved.id, workspaceSaved.id, createdDataset.id, 0, 1) + organizationSaved.id, + workspaceSaved.id, + createdDataset.id, + 0, + 1, + ) assertNotNull(listDatasetParts) assertEquals(1, listDatasetParts.size) @@ -2223,7 +2596,12 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { listDatasetParts = datasetApiService.listDatasetParts( - organizationSaved.id, workspaceSaved.id, createdDataset.id, 1, 5) + organizationSaved.id, + workspaceSaved.id, + createdDataset.id, + 1, + 5, + ) assertNotNull(listDatasetParts) assertTrue(listDatasetParts.isEmpty()) } @@ -2240,7 +2618,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { sourceName = CUSTOMER_SOURCE_FILE_NAME, description = datasetPartDescription, tags = datasetPartTags, - type = DatasetPartTypeEnum.File) + type = DatasetPartTypeEnum.File, + ) val datasetName = "Customer Dataset" val datasetDescription = "Dataset for customers" @@ -2250,7 +2629,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { name = datasetName, description = datasetDescription, tags = datasetTags, - parts = mutableListOf(datasetPartCreateRequest)) + parts = mutableListOf(datasetPartCreateRequest), + ) val resourceTestFile = resourceLoader.getResource("classpath:/$CUSTOMER_SOURCE_FILE_NAME").file @@ -2261,18 +2641,24 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "files", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToSend)) + IOUtils.toByteArray(fileToSend), + ) val createdDataset = datasetApiService.createDataset( organizationSaved.id, workspaceSaved.id, datasetCreateRequest, - arrayOf(mockMultipartFile)) + arrayOf(mockMultipartFile), + ) val downloadFile = datasetApiService.downloadDatasetPart( - organizationSaved.id, workspaceSaved.id, createdDataset.id, createdDataset.parts[0].id) + organizationSaved.id, + workspaceSaved.id, + createdDataset.id, + createdDataset.parts[0].id, + ) val expectedText = FileInputStream(resourceTestFile).bufferedReader().use { it.readText() } val retrievedText = @@ -2297,7 +2683,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { description = datasetPartDescription, tags = datasetPartTags, additionalData = datasetPartAdditionalData, - type = DatasetPartTypeEnum.File) + type = DatasetPartTypeEnum.File, + ) val datasetName = "Customer Dataset" val datasetDescription = "Dataset for customers" @@ -2311,7 +2698,9 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { accessControlList = mutableListOf( DatasetAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), - DatasetAccessControl(CONNECTED_DEFAULT_USER, ROLE_EDITOR))) + DatasetAccessControl(CONNECTED_DEFAULT_USER, ROLE_EDITOR), + ), + ) val datasetCreateRequest = DatasetCreateRequest( name = datasetName, @@ -2319,7 +2708,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { tags = datasetTags, additionalData = datasetAdditionalData, parts = mutableListOf(datasetPartCreateRequest), - security = datasetSecurity) + security = datasetSecurity, + ) val resourceTestFile = resourceLoader.getResource("classpath:/$CUSTOMER_SOURCE_FILE_NAME").file @@ -2330,14 +2720,16 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "files", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToSend)) + IOUtils.toByteArray(fileToSend), + ) val createdDataset = datasetApiService.createDataset( organizationSaved.id, workspaceSaved.id, datasetCreateRequest, - arrayOf(mockMultipartFile)) + arrayOf(mockMultipartFile), + ) // Create a DatasetUpdateRequest with new dataset part val newDatasetPartName = "Product list" @@ -2351,7 +2743,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { description = newDatasetPartDescription, tags = newDatasetPartTags, additionalData = newDatasetPartAdditionalData, - type = DatasetPartTypeEnum.File) + type = DatasetPartTypeEnum.File, + ) val newDatasetName = "Shop Dataset" val newDatasetDescription = "Dataset for shop" @@ -2363,7 +2756,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { description = newDatasetDescription, tags = newDatasetTags, additionalData = newDatasetAdditionalData, - parts = mutableListOf(newDatasetPartCreateRequest)) + parts = mutableListOf(newDatasetPartCreateRequest), + ) val newDatasetPartTestFile = resourceLoader.getResource("classpath:/$INVENTORY_SOURCE_FILE_NAME").file @@ -2375,7 +2769,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "files", INVENTORY_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(newDatasetPartFileToSend)) + IOUtils.toByteArray(newDatasetPartFileToSend), + ) // Update dataset with all new information + new part instead of the previous one val updatedDataset = @@ -2384,7 +2779,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { workspaceSaved.id, createdDataset.id, datasetUpdateRequest, - arrayOf(newDatasetPartMockMultipartFile)) + arrayOf(newDatasetPartMockMultipartFile), + ) // check new Dataset simple data assertEquals(newDatasetName, updatedDataset.name) @@ -2398,7 +2794,11 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { // check the new Dataset part is created and corresponding to data specified during update val newDatasetPart = datasetApiService.getDatasetPart( - organizationSaved.id, workspaceSaved.id, updatedDataset.id, updatedDataset.parts[0].id) + organizationSaved.id, + workspaceSaved.id, + updatedDataset.id, + updatedDataset.parts[0].id, + ) assertTrue(updatedDataset.parts.size == 1) assertEquals(newDatasetPart, updatedDataset.parts[0]) @@ -2409,25 +2809,31 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { organizationSaved.id, workspaceSaved.id, createdDataset.id, - createdDataset.parts[0].id) + createdDataset.parts[0].id, + ) } assertEquals( "Dataset Part ${createdDataset.parts[0].id} not found " + "in organization ${organizationSaved.id}, " + "workspace ${workspaceSaved.id} and dataset ${createdDataset.id}", - oldDatasetPartShouldNotExistInDB.message) + oldDatasetPartShouldNotExistInDB.message, + ) // check the old Dataset part is not in s3 storage anymore assertFalse( s3Template.objectExists( csmPlatformProperties.s3.bucketName, - constructFilePathForDatasetPart(createdDataset, 0))) + constructFilePathForDatasetPart(createdDataset, 0), + ) + ) // check the new Dataset part is in s3 storage now assertTrue( s3Template.objectExists( csmPlatformProperties.s3.bucketName, - constructFilePathForDatasetPart(updatedDataset, 0))) + constructFilePathForDatasetPart(updatedDataset, 0), + ) + ) } @Test @@ -2446,7 +2852,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { description = datasetPartDescription, tags = datasetPartTags, additionalData = datasetPartAdditionalData, - type = DatasetPartTypeEnum.File) + type = DatasetPartTypeEnum.File, + ) val datasetName = "Customer Dataset" val datasetDescription = "Dataset for customers" @@ -2459,7 +2866,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { description = datasetDescription, tags = datasetTags, additionalData = datasetAdditionalData, - parts = mutableListOf(datasetPartCreateRequest)) + parts = mutableListOf(datasetPartCreateRequest), + ) val resourceTestFile = resourceLoader.getResource("classpath:/$CUSTOMER_SOURCE_FILE_NAME").file @@ -2470,14 +2878,16 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "files", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToSend)) + IOUtils.toByteArray(fileToSend), + ) val createdDataset = datasetApiService.createDataset( organizationSaved.id, workspaceSaved.id, datasetCreateRequest, - arrayOf(mockMultipartFile)) + arrayOf(mockMultipartFile), + ) // Create a DatasetUpdateRequest with new dataset part val newDatasetPartName = "Product list" @@ -2491,26 +2901,21 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { description = newDatasetPartDescription, tags = newDatasetPartTags, additionalData = newDatasetPartAdditionalData, - type = DatasetPartTypeEnum.DB) + type = DatasetPartTypeEnum.DB, + ) val newDatasetName = "Shop Dataset" val newDatasetDescription = "Dataset for shop" val newDatasetTags = mutableListOf("dataset", "public", "shop") val newDatasetAdditionalData = mutableMapOf("dataset" to "new data") - val newDatasetSecurity = - DatasetSecurity( - default = ROLE_NONE, - accessControlList = - mutableListOf( - DatasetAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), - DatasetAccessControl(CONNECTED_DEFAULT_USER, ROLE_EDITOR))) val datasetUpdateRequest = DatasetUpdateRequest( name = newDatasetName, description = newDatasetDescription, tags = newDatasetTags, additionalData = newDatasetAdditionalData, - parts = mutableListOf(newDatasetPartCreateRequest)) + parts = mutableListOf(newDatasetPartCreateRequest), + ) val newDatasetPartTestFile = resourceLoader.getResource("classpath:/$CUSTOMER_ZIPPED_SOURCE_FILE_NAME").file @@ -2522,7 +2927,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "files", CUSTOMER_ZIPPED_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(newDatasetPartFileToSend)) + IOUtils.toByteArray(newDatasetPartFileToSend), + ) val exception = assertThrows { @@ -2531,12 +2937,14 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { workspaceSaved.id, createdDataset.id, datasetUpdateRequest, - arrayOf(newDatasetPartMockMultipartFile)) + arrayOf(newDatasetPartMockMultipartFile), + ) } assertEquals( "MIME type application/zip for file $CUSTOMER_ZIPPED_SOURCE_FILE_NAME is not authorized.", - exception.message) + exception.message, + ) } @Test @@ -2555,7 +2963,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { description = datasetPartDescription, tags = datasetPartTags, additionalData = datasetPartAdditionalData, - type = DatasetPartTypeEnum.File) + type = DatasetPartTypeEnum.File, + ) val datasetName = "Customer Dataset" val datasetDescription = "Dataset for customers" @@ -2568,7 +2977,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { description = datasetDescription, tags = datasetTags, additionalData = datasetAdditionalData, - parts = mutableListOf(datasetPartCreateRequest)) + parts = mutableListOf(datasetPartCreateRequest), + ) val resourceTestFile = resourceLoader.getResource("classpath:/$CUSTOMER_SOURCE_FILE_NAME").file @@ -2579,14 +2989,16 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "files", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToSend)) + IOUtils.toByteArray(fileToSend), + ) val createdDataset = datasetApiService.createDataset( organizationSaved.id, workspaceSaved.id, datasetCreateRequest, - arrayOf(mockMultipartFile)) + arrayOf(mockMultipartFile), + ) // Update dataset with an empty body val updatedDataset = @@ -2595,7 +3007,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { workspaceSaved.id, createdDataset.id, DatasetUpdateRequest(), - arrayOf()) + arrayOf(), + ) // check Dataset file data after update val datasetPartFilePath = constructFilePathForDatasetPart(createdDataset, 0) @@ -2635,7 +3048,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { organizationSaved.id, workspaceSaved.id, DatasetCreateRequest(name = "Dataset without parts"), - emptyArray()) + emptyArray(), + ) val customerPartName = "Customers list" val customerPartDescription = "List of customers" @@ -2646,7 +3060,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { sourceName = CUSTOMER_SOURCE_FILE_NAME, description = customerPartDescription, tags = customerPartTags, - type = DatasetPartTypeEnum.File) + type = DatasetPartTypeEnum.File, + ) val datasetName = "Shop Dataset" val datasetDescription = "Dataset for shop" @@ -2660,7 +3075,11 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { mutableListOf( customerPartCreateRequest, DatasetPartCreateRequest( - name = "Part create request 2", sourceName = "anotherFile.txt"))) + name = "Part create request 2", + sourceName = "anotherFile.txt", + ), + ), + ) val customerTestFile = resourceLoader.getResource("classpath:/$CUSTOMER_SOURCE_FILE_NAME").file @@ -2671,14 +3090,16 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "files", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(customerFileToSend)) + IOUtils.toByteArray(customerFileToSend), + ) val customerMockMultipartFile2 = MockMultipartFile( "files", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - InputStream.nullInputStream()) + InputStream.nullInputStream(), + ) val exception = assertThrows { @@ -2687,13 +3108,15 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { workspaceSaved.id, initialDataset.id, datasetUpdateRequest, - arrayOf(customerMockMultipartFile, customerMockMultipartFile2)) + arrayOf(customerMockMultipartFile, customerMockMultipartFile2), + ) } assertEquals( "Multipart file names should be unique during dataset update. " + "Multipart file names: [$CUSTOMER_SOURCE_FILE_NAME, $CUSTOMER_SOURCE_FILE_NAME]. " + "Dataset parts source names: [$CUSTOMER_SOURCE_FILE_NAME, anotherFile.txt].", - exception.message) + exception.message, + ) } @Test @@ -2706,7 +3129,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { sourceName = CUSTOMER_SOURCE_FILE_NAME, description = "List of customers", tags = mutableListOf("part", "public", "customers"), - type = DatasetPartTypeEnum.File) + type = DatasetPartTypeEnum.File, + ) val datasetSecurity = DatasetSecurity( @@ -2714,7 +3138,9 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { accessControlList = mutableListOf( DatasetAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), - DatasetAccessControl(CONNECTED_DEFAULT_USER, ROLE_EDITOR))) + DatasetAccessControl(CONNECTED_DEFAULT_USER, ROLE_EDITOR), + ), + ) val datasetCreateRequest = DatasetCreateRequest( @@ -2722,7 +3148,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { description = "Dataset for customers", tags = mutableListOf("dataset", "public", "customers"), parts = mutableListOf(datasetPartCreateRequest), - security = datasetSecurity) + security = datasetSecurity, + ) val resourceTestFile = resourceLoader.getResource("classpath:/$CUSTOMER_SOURCE_FILE_NAME").file @@ -2733,14 +3160,16 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "files", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToSend)) + IOUtils.toByteArray(fileToSend), + ) val createdDataset = datasetApiService.createDataset( organizationSaved.id, workspaceSaved.id, datasetCreateRequest, - arrayOf(mockMultipartFile)) + arrayOf(mockMultipartFile), + ) // Create a DatasetUpdateRequest with new dataset part val newDatasetPartCreateRequest = @@ -2749,14 +3178,16 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { sourceName = UNALLOWED_MIME_TYPE_SOURCE_FILE_NAME, description = "List of Product", tags = mutableListOf("part", "public", "product"), - type = DatasetPartTypeEnum.File) + type = DatasetPartTypeEnum.File, + ) val datasetUpdateRequest = DatasetUpdateRequest( name = "Shop Dataset", description = "Dataset for shop", tags = mutableListOf("dataset", "public", "shop"), - parts = mutableListOf(newDatasetPartCreateRequest)) + parts = mutableListOf(newDatasetPartCreateRequest), + ) val wrongTypeTestFile = resourceLoader.getResource("classpath:/$UNALLOWED_MIME_TYPE_SOURCE_FILE_NAME").file @@ -2768,7 +3199,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "files", UNALLOWED_MIME_TYPE_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(wrongTypeFileToSend)) + IOUtils.toByteArray(wrongTypeFileToSend), + ) val exception = assertThrows { @@ -2777,11 +3209,13 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { workspaceSaved.id, createdDataset.id, datasetUpdateRequest, - arrayOf(wrongTypeMockMultipartFile)) + arrayOf(wrongTypeMockMultipartFile), + ) } assertEquals( "MIME type text/x-yaml for file $UNALLOWED_MIME_TYPE_SOURCE_FILE_NAME is not authorized.", - exception.message) + exception.message, + ) } @Test @@ -2794,7 +3228,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { sourceName = CUSTOMER_SOURCE_FILE_NAME, description = "List of customers", tags = mutableListOf("part", "public", "customers"), - type = DatasetPartTypeEnum.File) + type = DatasetPartTypeEnum.File, + ) val datasetCreateRequest = DatasetCreateRequest( @@ -2808,7 +3243,10 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { accessControlList = mutableListOf( DatasetAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), - DatasetAccessControl(CONNECTED_DEFAULT_USER, ROLE_EDITOR)))) + DatasetAccessControl(CONNECTED_DEFAULT_USER, ROLE_EDITOR), + ), + ), + ) val resourceTestFile = resourceLoader.getResource("classpath:/$CUSTOMER_SOURCE_FILE_NAME").file @@ -2819,14 +3257,16 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "files", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToSend)) + IOUtils.toByteArray(fileToSend), + ) val createdDataset = datasetApiService.createDataset( organizationSaved.id, workspaceSaved.id, datasetCreateRequest, - arrayOf(mockMultipartFile)) + arrayOf(mockMultipartFile), + ) // Create a DatasetUpdateRequest with new dataset part val newDatasetPartCreateRequest = @@ -2835,21 +3275,24 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { sourceName = WRONG_ORIGINAL_FILE_NAME, description = "List of Product", tags = mutableListOf("part", "public", "product"), - type = DatasetPartTypeEnum.File) + type = DatasetPartTypeEnum.File, + ) val datasetUpdateRequest = DatasetUpdateRequest( name = "Shop Dataset", description = "Dataset for shop", tags = mutableListOf("dataset", "public", "shop"), - parts = mutableListOf(newDatasetPartCreateRequest)) + parts = mutableListOf(newDatasetPartCreateRequest), + ) val wrongTypeMockMultipartFile = MockMultipartFile( "files", WRONG_ORIGINAL_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - InputStream.nullInputStream()) + InputStream.nullInputStream(), + ) val exception = assertThrows { @@ -2858,11 +3301,13 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { workspaceSaved.id, createdDataset.id, datasetUpdateRequest, - arrayOf(wrongTypeMockMultipartFile)) + arrayOf(wrongTypeMockMultipartFile), + ) } assertEquals( "Invalid filename: '$WRONG_ORIGINAL_FILE_NAME'. File name should neither contains '..' nor starts by '/'.", - exception.message) + exception.message, + ) } @Test @@ -2881,7 +3326,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { description = customerPartDescription, tags = customerPartTags, additionalData = customerPartAdditionalData, - type = DatasetPartTypeEnum.File) + type = DatasetPartTypeEnum.File, + ) val datasetName = "Shop Dataset" val datasetDescription = "Dataset for shop" @@ -2891,7 +3337,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { name = datasetName, description = datasetDescription, tags = datasetTags, - parts = mutableListOf(customerPartCreateRequest)) + parts = mutableListOf(customerPartCreateRequest), + ) val customerTestFile = resourceLoader.getResource("classpath:/$CUSTOMER_SOURCE_FILE_NAME").file val customerFileToSend = FileInputStream(customerTestFile) @@ -2901,14 +3348,16 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "files", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(customerFileToSend)) + IOUtils.toByteArray(customerFileToSend), + ) val createdDataset = datasetApiService.createDataset( organizationSaved.id, workspaceSaved.id, datasetCreateRequest, - arrayOf(customerMockMultipartFile)) + arrayOf(customerMockMultipartFile), + ) val customerPartFilePath = constructFilePathForDatasetPart(createdDataset, 0) assertTrue(s3Template.objectExists(csmPlatformProperties.s3.bucketName, customerPartFilePath)) @@ -2957,7 +3406,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { workspaceSaved.id, createdDataset.id, datasetPartToReplace.id, - datasetPartUpdateRequest) + datasetPartUpdateRequest, + ) val datasetWithReplacedPart = datasetApiService.getDataset(organizationSaved.id, workspaceSaved.id, createdDataset.id) @@ -3000,7 +3450,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { sourceName = CUSTOMER_SOURCE_FILE_NAME, description = customerPartDescription, tags = customerPartTags, - type = DatasetPartTypeEnum.File) + type = DatasetPartTypeEnum.File, + ) val datasetName = "Shop Dataset" val datasetDescription = "Dataset for shop" @@ -3010,7 +3461,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { name = datasetName, description = datasetDescription, tags = datasetTags, - parts = mutableListOf(customerPartCreateRequest)) + parts = mutableListOf(customerPartCreateRequest), + ) val customerTestFile = resourceLoader.getResource("classpath:/$CUSTOMER_SOURCE_FILE_NAME").file val customerFileToSend = FileInputStream(customerTestFile) @@ -3020,14 +3472,16 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "files", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(customerFileToSend)) + IOUtils.toByteArray(customerFileToSend), + ) val createdDataset = datasetApiService.createDataset( organizationSaved.id, workspaceSaved.id, datasetCreateRequest, - arrayOf(customerMockMultipartFile)) + arrayOf(customerMockMultipartFile), + ) val customerPartFilePath = constructFilePathForDatasetPart(createdDataset, 0) assertTrue(s3Template.objectExists(csmPlatformProperties.s3.bucketName, customerPartFilePath)) @@ -3076,7 +3530,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "files", INVENTORY_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(newDatasetPartFileToSend)) + IOUtils.toByteArray(newDatasetPartFileToSend), + ) val replacedDatasetPart = datasetApiService.replaceDatasetPart( @@ -3085,7 +3540,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { createdDataset.id, datasetPartToReplace.id, newDatasetPartMockMultipartFile, - datasetPartUpdateRequest) + datasetPartUpdateRequest, + ) val datasetWithReplacedPart = datasetApiService.getDataset(organizationSaved.id, workspaceSaved.id, createdDataset.id) @@ -3127,14 +3583,16 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { sourceName = CUSTOMER_SOURCE_FILE_NAME, description = "List of customers", tags = mutableListOf("part", "public", "customers"), - type = DatasetPartTypeEnum.File) + type = DatasetPartTypeEnum.File, + ) val datasetCreateRequest = DatasetCreateRequest( name = "Customer Dataset", description = "Dataset for customers", tags = mutableListOf("dataset", "public", "customers"), - parts = mutableListOf(datasetPartCreateRequest)) + parts = mutableListOf(datasetPartCreateRequest), + ) val resourceTestFile = resourceLoader.getResource("classpath:/$CUSTOMER_SOURCE_FILE_NAME").file @@ -3145,21 +3603,24 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "files", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToSend)) + IOUtils.toByteArray(fileToSend), + ) val createdDataset = datasetApiService.createDataset( organizationSaved.id, workspaceSaved.id, datasetCreateRequest, - arrayOf(mockMultipartFile)) + arrayOf(mockMultipartFile), + ) // Create a DatasetUpdateRequest with new dataset part val datasetPartUpdateRequest = DatasetPartUpdateRequest( sourceName = "updatedResourceFile.csv", description = "Dataset for shop", - tags = mutableListOf("dataset", "public", "shop")) + tags = mutableListOf("dataset", "public", "shop"), + ) val wrongTypeTestFile = resourceLoader.getResource("classpath:/$UNALLOWED_MIME_TYPE_SOURCE_FILE_NAME").file @@ -3171,7 +3632,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "files", UNALLOWED_MIME_TYPE_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(wrongTypeFileToSend)) + IOUtils.toByteArray(wrongTypeFileToSend), + ) val exception = assertThrows { @@ -3181,11 +3643,13 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { createdDataset.id, createdDataset.parts[0].id, wrongTypeMockMultipartFile, - datasetPartUpdateRequest) + datasetPartUpdateRequest, + ) } assertEquals( "MIME type text/x-yaml for file $UNALLOWED_MIME_TYPE_SOURCE_FILE_NAME is not authorized.", - exception.message) + exception.message, + ) } @Test @@ -3198,14 +3662,16 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { sourceName = CUSTOMER_SOURCE_FILE_NAME, description = "List of customers", tags = mutableListOf("part", "public", "customers"), - type = DatasetPartTypeEnum.DB) + type = DatasetPartTypeEnum.DB, + ) val datasetCreateRequest = DatasetCreateRequest( name = "Customer Dataset", description = "Dataset for customers", tags = mutableListOf("dataset", "public", "customers"), - parts = mutableListOf(datasetPartCreateRequest)) + parts = mutableListOf(datasetPartCreateRequest), + ) val resourceTestFile = resourceLoader.getResource("classpath:/$CUSTOMER_SOURCE_FILE_NAME").file @@ -3216,21 +3682,24 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "files", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToSend)) + IOUtils.toByteArray(fileToSend), + ) val createdDataset = datasetApiService.createDataset( organizationSaved.id, workspaceSaved.id, datasetCreateRequest, - arrayOf(mockMultipartFile)) + arrayOf(mockMultipartFile), + ) // Create a DatasetUpdateRequest with new dataset part val datasetPartUpdateRequest = DatasetPartUpdateRequest( sourceName = CUSTOMER_ZIPPED_SOURCE_FILE_NAME, description = "Dataset for shop", - tags = mutableListOf("dataset", "public", "shop")) + tags = mutableListOf("dataset", "public", "shop"), + ) val wrongTypeTestFile = resourceLoader.getResource("classpath:/$CUSTOMER_ZIPPED_SOURCE_FILE_NAME").file @@ -3242,7 +3711,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "files", CUSTOMER_ZIPPED_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(wrongTypeFileToSend)) + IOUtils.toByteArray(wrongTypeFileToSend), + ) val exception = assertThrows { @@ -3252,11 +3722,13 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { createdDataset.id, createdDataset.parts[0].id, wrongTypeMockMultipartFile, - datasetPartUpdateRequest) + datasetPartUpdateRequest, + ) } assertEquals( "MIME type application/zip for file $CUSTOMER_ZIPPED_SOURCE_FILE_NAME is not authorized.", - exception.message) + exception.message, + ) } @Test @@ -3269,14 +3741,16 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { sourceName = CUSTOMER_SOURCE_FILE_NAME, description = "List of customers", tags = mutableListOf("part", "public", "customers"), - type = DatasetPartTypeEnum.File) + type = DatasetPartTypeEnum.File, + ) val datasetCreateRequest = DatasetCreateRequest( name = "Customer Dataset", description = "Dataset for customers", tags = mutableListOf("dataset", "public", "customers"), - parts = mutableListOf(datasetPartCreateRequest)) + parts = mutableListOf(datasetPartCreateRequest), + ) val resourceTestFile = resourceLoader.getResource("classpath:/$CUSTOMER_SOURCE_FILE_NAME").file @@ -3287,14 +3761,16 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "files", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToSend)) + IOUtils.toByteArray(fileToSend), + ) val createdDataset = datasetApiService.createDataset( organizationSaved.id, workspaceSaved.id, datasetCreateRequest, - arrayOf(mockMultipartFile)) + arrayOf(mockMultipartFile), + ) // Create a DatasetUpdateRequest with new dataset part @@ -3302,14 +3778,16 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { DatasetPartUpdateRequest( sourceName = "updatedResourceFile.csv", description = "Dataset for shop", - tags = mutableListOf("dataset", "public", "shop")) + tags = mutableListOf("dataset", "public", "shop"), + ) val wrongTypeMockMultipartFile = MockMultipartFile( "files", WRONG_ORIGINAL_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - InputStream.nullInputStream()) + InputStream.nullInputStream(), + ) val exception = assertThrows { @@ -3319,11 +3797,13 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { createdDataset.id, createdDataset.parts[0].id, wrongTypeMockMultipartFile, - datasetPartUpdateRequest) + datasetPartUpdateRequest, + ) } assertEquals( "Invalid filename: '$WRONG_ORIGINAL_FILE_NAME'. File name should neither contains '..' nor starts by '/'.", - exception.message) + exception.message, + ) } @Test @@ -3778,7 +4258,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { null, null, null, - mutableListOf("age")) + mutableListOf("age"), + ) val expectedTestFile = resourceLoader.getResource("classpath:/query/customers_customerID_orderby_age_asc.csv").file @@ -4016,7 +4497,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { sourceName = CUSTOMER_SOURCE_FILE_NAME, description = datasetPartDescription, tags = datasetPartTags, - type = DatasetPartTypeEnum.DB) + type = DatasetPartTypeEnum.DB, + ) val datasetName = "Customer Dataset" val datasetDescription = "Dataset for customers" @@ -4026,7 +4508,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { name = datasetName, description = datasetDescription, tags = datasetTags, - parts = mutableListOf(datasetPartCreateRequest)) + parts = mutableListOf(datasetPartCreateRequest), + ) val fileToSend = FileInputStream(resourceTestFile) @@ -4035,10 +4518,15 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { "files", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToSend)) + IOUtils.toByteArray(fileToSend), + ) return datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, datasetCreateRequest, arrayOf(mockMultipartFile)) + organizationSaved.id, + workspaceSaved.id, + datasetCreateRequest, + arrayOf(mockMultipartFile), + ) } private fun testCreateDatasetPartWithSimpleFile(fileName: String, expectedFileName: String) { @@ -4046,7 +4534,11 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { val createDataset = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, datasetCreateRequest, arrayOf()) + organizationSaved.id, + workspaceSaved.id, + datasetCreateRequest, + arrayOf(), + ) assertTrue(createDataset.parts.isEmpty()) @@ -4056,7 +4548,11 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { val mockMultipartFile = MockMultipartFile( - "file", fileName, MediaType.MULTIPART_FORM_DATA_VALUE, IOUtils.toByteArray(fileToSend)) + "file", + fileName, + MediaType.MULTIPART_FORM_DATA_VALUE, + IOUtils.toByteArray(fileToSend), + ) val datasetPartName = "Customer list" val datasetPartDescription = "List of customers" @@ -4073,7 +4569,9 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { sourceName = fileName, description = datasetPartDescription, tags = datasetPartTags, - type = DatasetPartTypeEnum.DB)) + type = DatasetPartTypeEnum.DB, + ), + ) assertNotNull(createDatasetPart) assertEquals(datasetPartName, createDatasetPart.name) @@ -4092,7 +4590,11 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { val datasetPartFile = datasetApiService.downloadDatasetPart( - organizationSaved.id, workspaceSaved.id, createDataset.id, createDatasetPart.id) + organizationSaved.id, + workspaceSaved.id, + createDataset.id, + createDatasetPart.id, + ) val expectedTestFile = resourceLoader.getResource("classpath:/$expectedFileName").file val expectedText = FileInputStream(expectedTestFile).bufferedReader().use { it.readText() } @@ -4106,7 +4608,7 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { fun makeOrganizationCreateRequest( name: String = "Organization Name", userName: String = CONNECTED_ADMIN_USER, - role: String = ROLE_ADMIN + role: String = ROLE_ADMIN, ) = OrganizationCreateRequest( name = name, @@ -4116,7 +4618,10 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { accessControlList = mutableListOf( OrganizationAccessControl(id = userName, role = role), - OrganizationAccessControl("userLambda", "viewer")))) + OrganizationAccessControl("userLambda", "viewer"), + ), + ), + ) fun makeSolution(userName: String = CONNECTED_DEFAULT_USER, role: String = ROLE_USER) = SolutionCreateRequest( @@ -4133,13 +4638,16 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { accessControlList = mutableListOf( SolutionAccessControl(id = CONNECTED_ADMIN_USER, role = ROLE_ADMIN), - SolutionAccessControl(id = userName, role = role)))) + SolutionAccessControl(id = userName, role = role), + ), + ), + ) fun makeWorkspaceCreateRequest( solutionId: String = solutionSaved.id, name: String = "name", userName: String = CONNECTED_ADMIN_USER, - role: String = ROLE_ADMIN + role: String = ROLE_ADMIN, ) = WorkspaceCreateRequest( key = UUID.randomUUID().toString(), @@ -4154,5 +4662,8 @@ class DatasetServiceIntegrationTest() : CsmTestBase() { accessControlList = mutableListOf( WorkspaceAccessControl(id = userName, role = role), - WorkspaceAccessControl(CONNECTED_DEFAULT_USER, "viewer")))) + WorkspaceAccessControl(CONNECTED_DEFAULT_USER, "viewer"), + ), + ), + ) } diff --git a/dataset/src/integrationTest/kotlin/com/cosmotech/dataset/service/DatasetServiceRBACTest.kt b/dataset/src/integrationTest/kotlin/com/cosmotech/dataset/service/DatasetServiceRBACTest.kt index 3252f3725..0eca8f306 100644 --- a/dataset/src/integrationTest/kotlin/com/cosmotech/dataset/service/DatasetServiceRBACTest.kt +++ b/dataset/src/integrationTest/kotlin/com/cosmotech/dataset/service/DatasetServiceRBACTest.kt @@ -125,7 +125,9 @@ class DatasetServiceRBACTest : CsmTestBase() { "files", CUSTOMER_SOURCE_FILE_NAME, MediaType.MULTIPART_FORM_DATA_VALUE, - IOUtils.toByteArray(fileToSend))) + IOUtils.toByteArray(fileToSend), + ) + ) rediSearchIndexer.createIndexFor(Organization::class.java) rediSearchIndexer.createIndexFor(Workspace::class.java) @@ -145,7 +147,11 @@ class DatasetServiceRBACTest : CsmTestBase() { dataset = makeDatasetCreateRequest() datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, mockMultipartFiles) + organizationSaved.id, + workspaceSaved.id, + dataset, + mockMultipartFiles, + ) } @TestFactory @@ -172,22 +178,35 @@ class DatasetServiceRBACTest : CsmTestBase() { mutableListOf( DatasetAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), DatasetAccessControl( - id = CONNECTED_DEFAULT_USER, role = role)))), - mockMultipartFiles) + id = CONNECTED_DEFAULT_USER, + role = role, + ), + ), + ) + ), + mockMultipartFiles, + ) if (shouldThrow) { val exception = assertThrows { datasetApiService.getDataset( - organizationSaved.id, workspaceSaved.id, datasetCreated.id) + organizationSaved.id, + workspaceSaved.id, + datasetCreated.id, + ) } assertEquals( "RBAC ${datasetCreated.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { datasetApiService.getDataset( - organizationSaved.id, workspaceSaved.id, datasetCreated.id) + organizationSaved.id, + workspaceSaved.id, + datasetCreated.id, + ) } } } @@ -215,10 +234,19 @@ class DatasetServiceRBACTest : CsmTestBase() { mutableListOf( DatasetAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), DatasetAccessControl( - id = CONNECTED_DEFAULT_USER, role = role)))) + id = CONNECTED_DEFAULT_USER, + role = role, + ), + ), + ) + ) datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, mockMultipartFiles) + organizationSaved.id, + workspaceSaved.id, + dataset, + mockMultipartFiles, + ) if (shouldThrow) { val exception = @@ -227,18 +255,21 @@ class DatasetServiceRBACTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, datasetSaved.id, - DatasetAccessControl("NewUser", role)) + DatasetAccessControl("NewUser", role), + ) } assertEquals( "RBAC ${datasetSaved.id} - User does not have permission $PERMISSION_WRITE_SECURITY", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { datasetApiService.createDatasetAccessControl( organizationSaved.id, workspaceSaved.id, datasetSaved.id, - DatasetAccessControl("NewUser", role)) + DatasetAccessControl("NewUser", role), + ) } } } @@ -271,15 +302,26 @@ class DatasetServiceRBACTest : CsmTestBase() { val exception = assertThrows { datasetApiService.searchDatasets( - organizationSaved.id, workspaceSaved.id, listOf(), null, null) + organizationSaved.id, + workspaceSaved.id, + listOf(), + null, + null, + ) } assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { datasetApiService.searchDatasets( - organizationSaved.id, workspaceSaved.id, listOf(), null, null) + organizationSaved.id, + workspaceSaved.id, + listOf(), + null, + null, + ) } } } @@ -307,24 +349,40 @@ class DatasetServiceRBACTest : CsmTestBase() { mutableListOf( DatasetAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), DatasetAccessControl( - id = CONNECTED_DEFAULT_USER, role = role)))) + id = CONNECTED_DEFAULT_USER, + role = role, + ), + ), + ) + ) datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, mockMultipartFiles) + organizationSaved.id, + workspaceSaved.id, + dataset, + mockMultipartFiles, + ) if (shouldThrow) { val exception = assertThrows { datasetApiService.deleteDataset( - organizationSaved.id, workspaceSaved.id, datasetSaved.id) + organizationSaved.id, + workspaceSaved.id, + datasetSaved.id, + ) } assertEquals( "RBAC ${datasetSaved.id} - User does not have permission $PERMISSION_DELETE", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { datasetApiService.deleteDataset( - organizationSaved.id, workspaceSaved.id, datasetSaved.id) + organizationSaved.id, + workspaceSaved.id, + datasetSaved.id, + ) } } } @@ -352,10 +410,19 @@ class DatasetServiceRBACTest : CsmTestBase() { mutableListOf( DatasetAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), DatasetAccessControl( - id = CONNECTED_DEFAULT_USER, role = role)))) + id = CONNECTED_DEFAULT_USER, + role = role, + ), + ), + ) + ) datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, mockMultipartFiles) + organizationSaved.id, + workspaceSaved.id, + dataset, + mockMultipartFiles, + ) if (shouldThrow) { val exception = @@ -364,18 +431,21 @@ class DatasetServiceRBACTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, datasetSaved.id, - CONNECTED_DEFAULT_USER) + CONNECTED_DEFAULT_USER, + ) } assertEquals( "RBAC ${datasetSaved.id} - User does not have permission $PERMISSION_WRITE_SECURITY", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { datasetApiService.deleteDatasetAccessControl( organizationSaved.id, workspaceSaved.id, datasetSaved.id, - CONNECTED_DEFAULT_USER) + CONNECTED_DEFAULT_USER, + ) } } } @@ -398,7 +468,8 @@ class DatasetServiceRBACTest : CsmTestBase() { makeOrganizationCreateRequest( name = "Organization test", userName = CONNECTED_DEFAULT_USER, - role = ROLE_USER) + role = ROLE_USER, + ) organizationSaved = organizationApiService.createOrganization(organization) solution = makeSolution() @@ -416,23 +487,37 @@ class DatasetServiceRBACTest : CsmTestBase() { mutableListOf( DatasetAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), DatasetAccessControl( - id = CONNECTED_DEFAULT_USER, role = role)))) + id = CONNECTED_DEFAULT_USER, + role = role, + ), + ), + ) + ) if (shouldThrow) { val exception = assertThrows { datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, mockMultipartFiles) + organizationSaved.id, + workspaceSaved.id, + dataset, + mockMultipartFiles, + ) } assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_CREATE_CHILDREN", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, mockMultipartFiles) + organizationSaved.id, + workspaceSaved.id, + dataset, + mockMultipartFiles, + ) } } } @@ -460,10 +545,19 @@ class DatasetServiceRBACTest : CsmTestBase() { mutableListOf( DatasetAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), DatasetAccessControl( - id = CONNECTED_DEFAULT_USER, role = role)))) + id = CONNECTED_DEFAULT_USER, + role = role, + ), + ), + ) + ) datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, mockMultipartFiles) + organizationSaved.id, + workspaceSaved.id, + dataset, + mockMultipartFiles, + ) if (shouldThrow) { val exception = @@ -472,18 +566,21 @@ class DatasetServiceRBACTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, datasetSaved.id, - CONNECTED_DEFAULT_USER) + CONNECTED_DEFAULT_USER, + ) } assertEquals( "RBAC ${datasetSaved.id} - User does not have permission $PERMISSION_READ_SECURITY", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { datasetApiService.getDatasetAccessControl( organizationSaved.id, workspaceSaved.id, datasetSaved.id, - CONNECTED_DEFAULT_USER) + CONNECTED_DEFAULT_USER, + ) } } } @@ -511,24 +608,40 @@ class DatasetServiceRBACTest : CsmTestBase() { mutableListOf( DatasetAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), DatasetAccessControl( - id = CONNECTED_DEFAULT_USER, role = role)))) + id = CONNECTED_DEFAULT_USER, + role = role, + ), + ), + ) + ) datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, mockMultipartFiles) + organizationSaved.id, + workspaceSaved.id, + dataset, + mockMultipartFiles, + ) if (shouldThrow) { val exception = assertThrows { datasetApiService.listDatasetSecurityUsers( - organizationSaved.id, workspaceSaved.id, datasetSaved.id) + organizationSaved.id, + workspaceSaved.id, + datasetSaved.id, + ) } assertEquals( "RBAC ${datasetSaved.id} - User does not have permission $PERMISSION_READ_SECURITY", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { datasetApiService.listDatasetSecurityUsers( - organizationSaved.id, workspaceSaved.id, datasetSaved.id) + organizationSaved.id, + workspaceSaved.id, + datasetSaved.id, + ) } } } @@ -551,7 +664,8 @@ class DatasetServiceRBACTest : CsmTestBase() { makeOrganizationCreateRequest( name = "Organization test", userName = CONNECTED_DEFAULT_USER, - role = ROLE_USER) + role = ROLE_USER, + ) organizationSaved = organizationApiService.createOrganization(organization) solution = makeSolution() @@ -564,15 +678,24 @@ class DatasetServiceRBACTest : CsmTestBase() { val exception = assertThrows { datasetApiService.listDatasets( - organizationSaved.id, workspaceSaved.id, null, null) + organizationSaved.id, + workspaceSaved.id, + null, + null, + ) } assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { datasetApiService.listDatasets( - organizationSaved.id, workspaceSaved.id, null, null) + organizationSaved.id, + workspaceSaved.id, + null, + null, + ) } } } @@ -595,7 +718,8 @@ class DatasetServiceRBACTest : CsmTestBase() { makeOrganizationCreateRequest( name = "Organization test", userName = CONNECTED_DEFAULT_USER, - role = ROLE_USER) + role = ROLE_USER, + ) organizationSaved = organizationApiService.createOrganization(organization) solution = makeSolution() @@ -613,12 +737,21 @@ class DatasetServiceRBACTest : CsmTestBase() { mutableListOf( DatasetAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), DatasetAccessControl( - id = CONNECTED_DEFAULT_USER, role = role)))) + id = CONNECTED_DEFAULT_USER, + role = role, + ), + ), + ) + ) every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, mockMultipartFiles) + organizationSaved.id, + workspaceSaved.id, + dataset, + mockMultipartFiles, + ) every { getCurrentAccountIdentifier(any()) } returns CONNECTED_DEFAULT_USER @@ -630,11 +763,13 @@ class DatasetServiceRBACTest : CsmTestBase() { workspaceSaved.id, datasetSaved.id, DatasetUpdateRequest(), - arrayOf()) + arrayOf(), + ) } assertEquals( "RBAC ${datasetSaved.id} - User does not have permission $PERMISSION_WRITE", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { datasetApiService.updateDataset( @@ -642,7 +777,8 @@ class DatasetServiceRBACTest : CsmTestBase() { workspaceSaved.id, datasetSaved.id, DatasetUpdateRequest(), - arrayOf()) + arrayOf(), + ) } } } @@ -670,10 +806,19 @@ class DatasetServiceRBACTest : CsmTestBase() { mutableListOf( DatasetAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), DatasetAccessControl( - id = CONNECTED_DEFAULT_USER, role = role)))) + id = CONNECTED_DEFAULT_USER, + role = role, + ), + ), + ) + ) datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, mockMultipartFiles) + organizationSaved.id, + workspaceSaved.id, + dataset, + mockMultipartFiles, + ) if (shouldThrow) { val exception = @@ -684,11 +829,13 @@ class DatasetServiceRBACTest : CsmTestBase() { datasetSaved.id, listOf(), null, - null) + null, + ) } assertEquals( "RBAC ${datasetSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { datasetApiService.searchDatasetParts( @@ -697,7 +844,8 @@ class DatasetServiceRBACTest : CsmTestBase() { datasetSaved.id, listOf(), null, - null) + null, + ) } } } @@ -725,10 +873,19 @@ class DatasetServiceRBACTest : CsmTestBase() { mutableListOf( DatasetAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), DatasetAccessControl( - id = CONNECTED_DEFAULT_USER, role = role)))) + id = CONNECTED_DEFAULT_USER, + role = role, + ), + ), + ) + ) datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, mockMultipartFiles) + organizationSaved.id, + workspaceSaved.id, + dataset, + mockMultipartFiles, + ) if (shouldThrow) { val exception = @@ -738,11 +895,13 @@ class DatasetServiceRBACTest : CsmTestBase() { workspaceSaved.id, datasetSaved.id, CONNECTED_DEFAULT_USER, - DatasetRole(role)) + DatasetRole(role), + ) } assertEquals( "RBAC ${datasetSaved.id} - User does not have permission $PERMISSION_WRITE_SECURITY", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { datasetApiService.updateDatasetAccessControl( @@ -750,7 +909,8 @@ class DatasetServiceRBACTest : CsmTestBase() { workspaceSaved.id, datasetSaved.id, CONNECTED_DEFAULT_USER, - DatasetRole(role)) + DatasetRole(role), + ) } } } @@ -778,10 +938,19 @@ class DatasetServiceRBACTest : CsmTestBase() { mutableListOf( DatasetAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), DatasetAccessControl( - id = CONNECTED_DEFAULT_USER, role = role)))) + id = CONNECTED_DEFAULT_USER, + role = role, + ), + ), + ) + ) datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, mockMultipartFiles) + organizationSaved.id, + workspaceSaved.id, + dataset, + mockMultipartFiles, + ) if (shouldThrow) { val exception = @@ -790,15 +959,21 @@ class DatasetServiceRBACTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, datasetSaved.id, - DatasetRole(role)) + DatasetRole(role), + ) } assertEquals( "RBAC ${datasetSaved.id} - User does not have permission $PERMISSION_WRITE_SECURITY", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { datasetApiService.updateDatasetDefaultSecurity( - organizationSaved.id, workspaceSaved.id, datasetSaved.id, DatasetRole(role)) + organizationSaved.id, + workspaceSaved.id, + datasetSaved.id, + DatasetRole(role), + ) } } } @@ -819,7 +994,8 @@ class DatasetServiceRBACTest : CsmTestBase() { makeOrganizationCreateRequest( name = "Organization test", userName = CONNECTED_DEFAULT_USER, - role = ROLE_USER) + role = ROLE_USER, + ) organizationSaved = organizationApiService.createOrganization(organization) solution = makeSolution() @@ -838,11 +1014,20 @@ class DatasetServiceRBACTest : CsmTestBase() { mutableListOf( DatasetAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), DatasetAccessControl( - id = CONNECTED_DEFAULT_USER, role = role)))) + id = CONNECTED_DEFAULT_USER, + role = role, + ), + ), + ) + ) datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, mockMultipartFiles) + organizationSaved.id, + workspaceSaved.id, + dataset, + mockMultipartFiles, + ) every { getCurrentAccountIdentifier(any()) } returns CONNECTED_DEFAULT_USER @@ -854,11 +1039,13 @@ class DatasetServiceRBACTest : CsmTestBase() { workspaceSaved.id, datasetSaved.id, mockMultipartFiles[0], - makeDatasetPartCreateRequest()) + makeDatasetPartCreateRequest(), + ) } assertEquals( "RBAC ${datasetSaved.id} - User does not have permission $PERMISSION_WRITE", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { datasetApiService.createDatasetPart( @@ -866,7 +1053,8 @@ class DatasetServiceRBACTest : CsmTestBase() { workspaceSaved.id, datasetSaved.id, mockMultipartFiles[0], - makeDatasetPartCreateRequest()) + makeDatasetPartCreateRequest(), + ) } } } @@ -887,7 +1075,8 @@ class DatasetServiceRBACTest : CsmTestBase() { makeOrganizationCreateRequest( name = "Organization test", userName = CONNECTED_DEFAULT_USER, - role = ROLE_USER) + role = ROLE_USER, + ) organizationSaved = organizationApiService.createOrganization(organization) solution = makeSolution() @@ -906,11 +1095,20 @@ class DatasetServiceRBACTest : CsmTestBase() { mutableListOf( DatasetAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), DatasetAccessControl( - id = CONNECTED_DEFAULT_USER, role = role)))) + id = CONNECTED_DEFAULT_USER, + role = role, + ), + ), + ) + ) datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, mockMultipartFiles) + organizationSaved.id, + workspaceSaved.id, + dataset, + mockMultipartFiles, + ) every { getCurrentAccountIdentifier(any()) } returns CONNECTED_DEFAULT_USER @@ -921,18 +1119,21 @@ class DatasetServiceRBACTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, datasetSaved.id, - datasetSaved.parts[0].id) + datasetSaved.parts[0].id, + ) } assertEquals( "RBAC ${datasetSaved.id} - User does not have permission $PERMISSION_WRITE", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { datasetApiService.deleteDatasetPart( organizationSaved.id, workspaceSaved.id, datasetSaved.id, - datasetSaved.parts[0].id) + datasetSaved.parts[0].id, + ) } } } @@ -953,7 +1154,8 @@ class DatasetServiceRBACTest : CsmTestBase() { makeOrganizationCreateRequest( name = "Organization test", userName = CONNECTED_DEFAULT_USER, - role = ROLE_USER) + role = ROLE_USER, + ) organizationSaved = organizationApiService.createOrganization(organization) solution = makeSolution() @@ -972,11 +1174,20 @@ class DatasetServiceRBACTest : CsmTestBase() { mutableListOf( DatasetAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), DatasetAccessControl( - id = CONNECTED_DEFAULT_USER, role = role)))) + id = CONNECTED_DEFAULT_USER, + role = role, + ), + ), + ) + ) datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, mockMultipartFiles) + organizationSaved.id, + workspaceSaved.id, + dataset, + mockMultipartFiles, + ) every { getCurrentAccountIdentifier(any()) } returns CONNECTED_DEFAULT_USER @@ -987,18 +1198,21 @@ class DatasetServiceRBACTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, datasetSaved.id, - datasetSaved.parts[0].id) + datasetSaved.parts[0].id, + ) } assertEquals( "RBAC ${datasetSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { datasetApiService.downloadDatasetPart( organizationSaved.id, workspaceSaved.id, datasetSaved.id, - datasetSaved.parts[0].id) + datasetSaved.parts[0].id, + ) } } } @@ -1019,7 +1233,8 @@ class DatasetServiceRBACTest : CsmTestBase() { makeOrganizationCreateRequest( name = "Organization test", userName = CONNECTED_DEFAULT_USER, - role = ROLE_USER) + role = ROLE_USER, + ) organizationSaved = organizationApiService.createOrganization(organization) solution = makeSolution() @@ -1038,11 +1253,20 @@ class DatasetServiceRBACTest : CsmTestBase() { mutableListOf( DatasetAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), DatasetAccessControl( - id = CONNECTED_DEFAULT_USER, role = role)))) + id = CONNECTED_DEFAULT_USER, + role = role, + ), + ), + ) + ) datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, mockMultipartFiles) + organizationSaved.id, + workspaceSaved.id, + dataset, + mockMultipartFiles, + ) every { getCurrentAccountIdentifier(any()) } returns CONNECTED_DEFAULT_USER @@ -1053,18 +1277,21 @@ class DatasetServiceRBACTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, datasetSaved.id, - datasetSaved.parts[0].id) + datasetSaved.parts[0].id, + ) } assertEquals( "RBAC ${datasetSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { datasetApiService.getDatasetPart( organizationSaved.id, workspaceSaved.id, datasetSaved.id, - datasetSaved.parts[0].id) + datasetSaved.parts[0].id, + ) } } } @@ -1085,7 +1312,8 @@ class DatasetServiceRBACTest : CsmTestBase() { makeOrganizationCreateRequest( name = "Organization test", userName = CONNECTED_DEFAULT_USER, - role = ROLE_USER) + role = ROLE_USER, + ) organizationSaved = organizationApiService.createOrganization(organization) solution = makeSolution() @@ -1104,11 +1332,20 @@ class DatasetServiceRBACTest : CsmTestBase() { mutableListOf( DatasetAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), DatasetAccessControl( - id = CONNECTED_DEFAULT_USER, role = role)))) + id = CONNECTED_DEFAULT_USER, + role = role, + ), + ), + ) + ) datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, mockMultipartFiles) + organizationSaved.id, + workspaceSaved.id, + dataset, + mockMultipartFiles, + ) every { getCurrentAccountIdentifier(any()) } returns CONNECTED_DEFAULT_USER @@ -1116,15 +1353,26 @@ class DatasetServiceRBACTest : CsmTestBase() { val exception = assertThrows { datasetApiService.listDatasetParts( - organizationSaved.id, workspaceSaved.id, datasetSaved.id, null, null) + organizationSaved.id, + workspaceSaved.id, + datasetSaved.id, + null, + null, + ) } assertEquals( "RBAC ${datasetSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { datasetApiService.listDatasetParts( - organizationSaved.id, workspaceSaved.id, datasetSaved.id, null, null) + organizationSaved.id, + workspaceSaved.id, + datasetSaved.id, + null, + null, + ) } } } @@ -1145,7 +1393,8 @@ class DatasetServiceRBACTest : CsmTestBase() { makeOrganizationCreateRequest( name = "Organization test", userName = CONNECTED_DEFAULT_USER, - role = ROLE_USER) + role = ROLE_USER, + ) organizationSaved = organizationApiService.createOrganization(organization) solution = makeSolution() @@ -1164,11 +1413,20 @@ class DatasetServiceRBACTest : CsmTestBase() { mutableListOf( DatasetAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), DatasetAccessControl( - id = CONNECTED_DEFAULT_USER, role = role)))) + id = CONNECTED_DEFAULT_USER, + role = role, + ), + ), + ) + ) datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, mockMultipartFiles) + organizationSaved.id, + workspaceSaved.id, + dataset, + mockMultipartFiles, + ) every { getCurrentAccountIdentifier(any()) } returns CONNECTED_DEFAULT_USER @@ -1181,11 +1439,13 @@ class DatasetServiceRBACTest : CsmTestBase() { datasetSaved.id, datasetSaved.parts[0].id, mockMultipartFiles[0], - makeDatasetPartUpdateRequest()) + makeDatasetPartUpdateRequest(), + ) } assertEquals( "RBAC ${datasetSaved.id} - User does not have permission $PERMISSION_WRITE", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { datasetApiService.replaceDatasetPart( @@ -1194,7 +1454,8 @@ class DatasetServiceRBACTest : CsmTestBase() { datasetSaved.id, datasetSaved.parts[0].id, mockMultipartFiles[0], - makeDatasetPartUpdateRequest()) + makeDatasetPartUpdateRequest(), + ) } } } @@ -1215,7 +1476,8 @@ class DatasetServiceRBACTest : CsmTestBase() { makeOrganizationCreateRequest( name = "Organization test", userName = CONNECTED_DEFAULT_USER, - role = ROLE_USER) + role = ROLE_USER, + ) organizationSaved = organizationApiService.createOrganization(organization) solution = makeSolution() @@ -1234,11 +1496,20 @@ class DatasetServiceRBACTest : CsmTestBase() { mutableListOf( DatasetAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), DatasetAccessControl( - id = CONNECTED_DEFAULT_USER, role = role)))) + id = CONNECTED_DEFAULT_USER, + role = role, + ), + ), + ) + ) datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, mockMultipartFiles) + organizationSaved.id, + workspaceSaved.id, + dataset, + mockMultipartFiles, + ) every { getCurrentAccountIdentifier(any()) } returns CONNECTED_DEFAULT_USER @@ -1250,11 +1521,13 @@ class DatasetServiceRBACTest : CsmTestBase() { workspaceSaved.id, datasetSaved.id, datasetSaved.parts[0].id, - makeDatasetPartUpdateRequest()) + makeDatasetPartUpdateRequest(), + ) } assertEquals( "RBAC ${datasetSaved.id} - User does not have permission $PERMISSION_WRITE", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { datasetApiService.updateDatasetPart( @@ -1262,7 +1535,8 @@ class DatasetServiceRBACTest : CsmTestBase() { workspaceSaved.id, datasetSaved.id, datasetSaved.parts[0].id, - makeDatasetPartUpdateRequest()) + makeDatasetPartUpdateRequest(), + ) } } } @@ -1288,14 +1562,15 @@ class DatasetServiceRBACTest : CsmTestBase() { datasetPartDescription: String = "Test dataset part description", datasetPartTags: MutableList = mutableListOf("part", "public", "test"), datasetPartSourceName: String = CUSTOMER_SOURCE_FILE_NAME, - datasetPartType: DatasetPartTypeEnum = DatasetPartTypeEnum.File + datasetPartType: DatasetPartTypeEnum = DatasetPartTypeEnum.File, ): DatasetPartCreateRequest { return DatasetPartCreateRequest( name = datasetPartName, sourceName = datasetPartSourceName, description = datasetPartDescription, tags = datasetPartTags, - type = datasetPartType) + type = datasetPartType, + ) } fun makeDatasetCreateRequest( @@ -1307,7 +1582,7 @@ class DatasetServiceRBACTest : CsmTestBase() { datasetPartDescription: String = "Test dataset part description", datasetPartTags: MutableList = mutableListOf("part", "public", "test"), datasetPartSourceName: String = CUSTOMER_SOURCE_FILE_NAME, - datasetPartType: DatasetPartTypeEnum = DatasetPartTypeEnum.File + datasetPartType: DatasetPartTypeEnum = DatasetPartTypeEnum.File, ): DatasetCreateRequest { val datasetPartCreateRequest = DatasetPartCreateRequest( @@ -1315,20 +1590,22 @@ class DatasetServiceRBACTest : CsmTestBase() { sourceName = datasetPartSourceName, description = datasetPartDescription, tags = datasetPartTags, - type = datasetPartType) + type = datasetPartType, + ) return DatasetCreateRequest( name = datasetName, description = datasetDescription, tags = datasetTags, parts = mutableListOf(datasetPartCreateRequest), - security = datasetSecurity) + security = datasetSecurity, + ) } fun makeOrganizationCreateRequest( name: String = "Organization Name", userName: String = CONNECTED_DEFAULT_USER, - role: String = ROLE_VIEWER + role: String = ROLE_VIEWER, ) = OrganizationCreateRequest( name = name, @@ -1338,7 +1615,10 @@ class DatasetServiceRBACTest : CsmTestBase() { accessControlList = mutableListOf( OrganizationAccessControl(id = CONNECTED_ADMIN_USER, role = ROLE_ADMIN), - OrganizationAccessControl(userName, role)))) + OrganizationAccessControl(userName, role), + ), + ), + ) fun makeSolution(userName: String = CONNECTED_DEFAULT_USER, role: String = ROLE_USER) = SolutionCreateRequest( @@ -1355,13 +1635,16 @@ class DatasetServiceRBACTest : CsmTestBase() { accessControlList = mutableListOf( SolutionAccessControl(id = CONNECTED_ADMIN_USER, role = ROLE_ADMIN), - SolutionAccessControl(id = userName, role = role)))) + SolutionAccessControl(id = userName, role = role), + ), + ), + ) fun makeWorkspaceCreateRequest( solutionId: String = solutionSaved.id, name: String = "name", userName: String = CONNECTED_DEFAULT_USER, - role: String = ROLE_USER + role: String = ROLE_USER, ) = WorkspaceCreateRequest( key = UUID.randomUUID().toString(), @@ -1376,5 +1659,8 @@ class DatasetServiceRBACTest : CsmTestBase() { accessControlList = mutableListOf( WorkspaceAccessControl(id = userName, role = role), - WorkspaceAccessControl(id = CONNECTED_ADMIN_USER, role = ROLE_ADMIN)))) + WorkspaceAccessControl(id = CONNECTED_ADMIN_USER, role = ROLE_ADMIN), + ), + ), + ) } diff --git a/dataset/src/main/kotlin/com/cosmotech/dataset/DatasetApiServiceInterface.kt b/dataset/src/main/kotlin/com/cosmotech/dataset/DatasetApiServiceInterface.kt index 75cc71fee..3f03aad22 100644 --- a/dataset/src/main/kotlin/com/cosmotech/dataset/DatasetApiServiceInterface.kt +++ b/dataset/src/main/kotlin/com/cosmotech/dataset/DatasetApiServiceInterface.kt @@ -25,7 +25,7 @@ interface DatasetApiServiceInterface : DatasetApiService { organizationId: String, workspaceId: String, datasetId: String, - requiredPermission: String = PERMISSION_READ + requiredPermission: String = PERMISSION_READ, ): Dataset /** @@ -40,7 +40,7 @@ interface DatasetApiServiceInterface : DatasetApiService { fun findByOrganizationIdWorkspaceIdAndDatasetId( organizationId: String, workspaceId: String, - datasetId: String + datasetId: String, ): Dataset? /** @@ -73,7 +73,7 @@ interface DatasetApiServiceInterface : DatasetApiService { organizationId: String, workspaceId: String, datasetId: String, - datasetPartCreateRequest: DatasetPartCreateRequest + datasetPartCreateRequest: DatasetPartCreateRequest, ): DatasetPart /** @@ -94,6 +94,6 @@ interface DatasetApiServiceInterface : DatasetApiService { workspaceId: kotlin.String, datasetId: kotlin.String, file: Resource, - datasetPartCreateRequest: DatasetPartCreateRequest + datasetPartCreateRequest: DatasetPartCreateRequest, ): DatasetPart } diff --git a/dataset/src/main/kotlin/com/cosmotech/dataset/part/factories/DatasetPartManagementFactory.kt b/dataset/src/main/kotlin/com/cosmotech/dataset/part/factories/DatasetPartManagementFactory.kt index 27e2a8ac2..eb73efa57 100644 --- a/dataset/src/main/kotlin/com/cosmotech/dataset/part/factories/DatasetPartManagementFactory.kt +++ b/dataset/src/main/kotlin/com/cosmotech/dataset/part/factories/DatasetPartManagementFactory.kt @@ -35,7 +35,8 @@ class DatasetPartManagementFactory( fun getDatasetPartManagementService(implementation: String): DatasetPartManagementService = datasetPartManagementServices[implementation] ?: throw IllegalStateException( - "No implementation found for DatasetPartManagementService with name '$implementation'") + "No implementation found for DatasetPartManagementService with name '$implementation'" + ) fun storeData(datasetPart: DatasetPart, file: MultipartFile, overwrite: Boolean = false) { val datasetPartManagementService = getDatasetPartManagementService(datasetPart.type.value) diff --git a/dataset/src/main/kotlin/com/cosmotech/dataset/part/services/FileDatasetPartManagementService.kt b/dataset/src/main/kotlin/com/cosmotech/dataset/part/services/FileDatasetPartManagementService.kt index e2b88ebab..01b3b6cb9 100644 --- a/dataset/src/main/kotlin/com/cosmotech/dataset/part/services/FileDatasetPartManagementService.kt +++ b/dataset/src/main/kotlin/com/cosmotech/dataset/part/services/FileDatasetPartManagementService.kt @@ -20,7 +20,7 @@ import org.springframework.web.multipart.MultipartFile @Service("File") class FileDatasetPartManagementService( private val csmPlatformProperties: CsmPlatformProperties, - private val s3Template: S3Template + private val s3Template: S3Template, ) : DatasetPartManagementService { private val logger = LoggerFactory.getLogger(FileDatasetPartManagementService::class.java) @@ -49,9 +49,13 @@ class FileDatasetPartManagementService( datasetPart.organizationId, datasetPart.workspaceId, datasetPart.datasetId, - datasetPart.id) + datasetPart.id, + ) logger.debug( - "Downloading file resource for dataset part #{} from path {}", datasetPart.id, filePath) + "Downloading file resource for dataset part #{} from path {}", + datasetPart.id, + filePath, + ) return s3Template.download(csmPlatformProperties.s3.bucketName, filePath) } @@ -61,7 +65,8 @@ class FileDatasetPartManagementService( datasetPart.organizationId, datasetPart.workspaceId, datasetPart.datasetId, - datasetPart.id) + datasetPart.id, + ) logger.debug("Deleting file resource from workspace #{} from path {}", datasetPart.id, filePath) s3Template.deleteObject(csmPlatformProperties.s3.bucketName, filePath) @@ -71,7 +76,7 @@ class FileDatasetPartManagementService( organizationId: String, workspaceId: String, datasetId: String, - datasetPartId: String + datasetPartId: String, ) = "$organizationId/$workspaceId/$datasetId/$datasetPartId" private fun uploadFile( @@ -79,7 +84,7 @@ class FileDatasetPartManagementService( overwrite: Boolean, fileName: String, fileSize: Long, - file: InputStream + file: InputStream, ) { val fileAlreadyExists = s3Template.objectExists(csmPlatformProperties.s3.bucketName, filePath) diff --git a/dataset/src/main/kotlin/com/cosmotech/dataset/part/services/RelationalDatasetPartManagementService.kt b/dataset/src/main/kotlin/com/cosmotech/dataset/part/services/RelationalDatasetPartManagementService.kt index cbedbc6a9..f37da5a8d 100644 --- a/dataset/src/main/kotlin/com/cosmotech/dataset/part/services/RelationalDatasetPartManagementService.kt +++ b/dataset/src/main/kotlin/com/cosmotech/dataset/part/services/RelationalDatasetPartManagementService.kt @@ -32,7 +32,7 @@ import org.springframework.web.multipart.MultipartFile class RelationalDatasetPartManagementService( val writerJdbcTemplate: JdbcTemplate, val readerJdbcTemplate: JdbcTemplate, - val csmPlatformProperties: CsmPlatformProperties + val csmPlatformProperties: CsmPlatformProperties, ) : DatasetPartManagementService { private val logger = LoggerFactory.getLogger(RelationalDatasetPartManagementService::class.java) @@ -52,7 +52,8 @@ class RelationalDatasetPartManagementService( if (tableExists && !overwrite) { throw IllegalArgumentException( - "Table ${datasetPart.id} already exists and overwrite is set to false.") + "Table ${datasetPart.id} already exists and overwrite is set to false." + ) } inputStream.bufferedReader().use { reader -> @@ -71,7 +72,8 @@ class RelationalDatasetPartManagementService( val prepareStatement = connection.prepareStatement( "CREATE TABLE IF NOT EXISTS $tableName ${constructSQLColumnsValues(headers)};" + - "GRANT SELECT ON $tableName to \"$readerUserName\";") + "GRANT SELECT ON $tableName to \"$readerUserName\";" + ) prepareStatement.execute() } val insertedRows = diff --git a/dataset/src/main/kotlin/com/cosmotech/dataset/repositories/DatasetPartRepository.kt b/dataset/src/main/kotlin/com/cosmotech/dataset/repositories/DatasetPartRepository.kt index 74e5a203f..e99b54dbe 100644 --- a/dataset/src/main/kotlin/com/cosmotech/dataset/repositories/DatasetPartRepository.kt +++ b/dataset/src/main/kotlin/com/cosmotech/dataset/repositories/DatasetPartRepository.kt @@ -16,43 +16,47 @@ interface DatasetPartRepository : RedisDocumentRepository { @Query( "@organizationId:{\$organizationId} @workspaceId:{\$workspaceId} " + - "@datasetId:{\$datasetId} @id:{\$datasetPartId}") + "@datasetId:{\$datasetId} @id:{\$datasetPartId}" + ) fun findBy( @Sanitize @Param("organizationId") organizationId: String, @Sanitize @Param("workspaceId") workspaceId: String, @Sanitize @Param("datasetId") datasetId: String, - @Sanitize @Param("datasetPartId") datasetPartId: String + @Sanitize @Param("datasetPartId") datasetPartId: String, ): Optional @Query( "(@organizationId:{\$organizationId} @workspaceId:{\$workspaceId} " + - "@datasetId:{\$datasetId}) \$securityConstraint") + "@datasetId:{\$datasetId}) \$securityConstraint" + ) fun findByOrganizationIdAndWorkspaceIdAndDatasetId( @Sanitize @Param("organizationId") organizationId: String, @Sanitize @Param("workspaceId") workspaceId: String, @Sanitize @Param("datasetId") datasetId: String, @SecurityConstraint @Param("securityConstraint") securityConstraint: String, - pageRequest: PageRequest + pageRequest: PageRequest, ): Page @Query( "(@organizationId:{\$organizationId} @workspaceId:{\$workspaceId} " + - "@datasetId:{\$datasetId})") + "@datasetId:{\$datasetId})" + ) fun findByOrganizationIdAndWorkspaceIdAndDatasetIdNoSecurity( @Sanitize @Param("organizationId") organizationId: String, @Sanitize @Param("workspaceId") workspaceId: String, @Sanitize @Param("datasetId") datasetId: String, - pageRequest: PageRequest + pageRequest: PageRequest, ): Page @Query( "@organizationId:{\$organizationId} @workspaceId:{\$workspaceId} " + - "@datasetId:{\$datasetId} @tags:{\$tags}") + "@datasetId:{\$datasetId} @tags:{\$tags}" + ) fun findDatasetPartByTags( @Sanitize @Param("organizationId") organizationId: String, @Sanitize @Param("workspaceId") workspaceId: String, @Sanitize @Param("datasetId") datasetId: String, @Param("tags") tags: List, - pageRequest: PageRequest + pageRequest: PageRequest, ): Page } diff --git a/dataset/src/main/kotlin/com/cosmotech/dataset/repositories/DatasetRepository.kt b/dataset/src/main/kotlin/com/cosmotech/dataset/repositories/DatasetRepository.kt index 4770c5ec3..0c863658e 100644 --- a/dataset/src/main/kotlin/com/cosmotech/dataset/repositories/DatasetRepository.kt +++ b/dataset/src/main/kotlin/com/cosmotech/dataset/repositories/DatasetRepository.kt @@ -18,7 +18,7 @@ interface DatasetRepository : RedisDocumentRepository { fun findBy( @Sanitize @Param("organizationId") organizationId: String, @Sanitize @Param("workspaceId") workspaceId: String, - @Sanitize @Param("datasetId") datasetId: String + @Sanitize @Param("datasetId") datasetId: String, ): Optional @Query("(@organizationId:{\$organizationId} @workspaceId:{\$workspaceId}) \$securityConstraint") @@ -26,14 +26,14 @@ interface DatasetRepository : RedisDocumentRepository { @Sanitize @Param("organizationId") organizationId: String, @Sanitize @Param("workspaceId") workspaceId: String, @SecurityConstraint @Param("securityConstraint") securityConstraint: String, - pageRequest: PageRequest + pageRequest: PageRequest, ): Page @Query("(@organizationId:{\$organizationId} @workspaceId:{\$workspaceId})") fun findByOrganizationIdAndWorkspaceIdNoSecurity( @Sanitize @Param("organizationId") organizationId: String, @Sanitize @Param("workspaceId") workspaceId: String, - pageRequest: PageRequest + pageRequest: PageRequest, ): Page @Query("@organizationId:{\$organizationId} @workspaceId:{\$workspaceId} @tags:{\$tags}") @@ -41,6 +41,6 @@ interface DatasetRepository : RedisDocumentRepository { @Sanitize @Param("organizationId") organizationId: String, @Sanitize @Param("workspaceId") workspaceId: String, @Param("tags") tags: List, - pageRequest: PageRequest + pageRequest: PageRequest, ): Page } diff --git a/dataset/src/main/kotlin/com/cosmotech/dataset/service/DatasetServiceImpl.kt b/dataset/src/main/kotlin/com/cosmotech/dataset/service/DatasetServiceImpl.kt index fba255a18..7fc8bd9e2 100644 --- a/dataset/src/main/kotlin/com/cosmotech/dataset/service/DatasetServiceImpl.kt +++ b/dataset/src/main/kotlin/com/cosmotech/dataset/service/DatasetServiceImpl.kt @@ -70,20 +70,21 @@ class DatasetServiceImpl( private val csmRbac: CsmRbac, private val datasetPartManagementFactory: DatasetPartManagementFactory, private val resourceScanner: ResourceScanner, - private val readerJdbcTemplate: JdbcTemplate + private val readerJdbcTemplate: JdbcTemplate, ) : CsmPhoenixService(), DatasetApiServiceInterface { override fun getVerifiedDataset( organizationId: String, workspaceId: String, datasetId: String, - requiredPermission: String + requiredPermission: String, ): Dataset { workspaceService.getVerifiedWorkspace(organizationId, workspaceId) val dataset = datasetRepository.findBy(organizationId, workspaceId, datasetId).orElseThrow { CsmResourceNotFoundException( - "Dataset $datasetId not found in organization $organizationId and workspace $workspaceId") + "Dataset $datasetId not found in organization $organizationId and workspace $workspaceId" + ) } csmRbac.verify(dataset.security.toGenericSecurity(datasetId), requiredPermission) return dataset @@ -92,12 +93,13 @@ class DatasetServiceImpl( override fun findByOrganizationIdWorkspaceIdAndDatasetId( organizationId: String, workspaceId: String, - datasetId: String + datasetId: String, ): Dataset { workspaceService.getVerifiedWorkspace(organizationId, workspaceId) return datasetRepository.findBy(organizationId, workspaceId, datasetId).orElseThrow { CsmResourceNotFoundException( - "Dataset $datasetId not found in organization $organizationId and workspace $workspaceId") + "Dataset $datasetId not found in organization $organizationId and workspace $workspaceId" + ) } } @@ -116,7 +118,7 @@ class DatasetServiceImpl( organizationId: String, workspaceId: String, datasetId: String, - datasetAccessControl: DatasetAccessControl + datasetAccessControl: DatasetAccessControl, ): DatasetAccessControl { val dataset = getVerifiedDataset(organizationId, workspaceId, datasetId, PERMISSION_WRITE_SECURITY) @@ -127,13 +129,16 @@ class DatasetServiceImpl( csmRbac.setEntityRole( dataset.security.toGenericSecurity(datasetId), datasetAccessControl.id, - datasetAccessControl.role) + datasetAccessControl.role, + ) dataset.security = rbacSecurity.toResourceSecurity() save(dataset) val rbacAccessControl = csmRbac.getAccessControl( - dataset.security.toGenericSecurity(datasetId), datasetAccessControl.id) + dataset.security.toGenericSecurity(datasetId), + datasetAccessControl.id, + ) return DatasetAccessControl(id = rbacAccessControl.id, role = rbacAccessControl.role) } @@ -141,7 +146,7 @@ class DatasetServiceImpl( organizationId: String, workspaceId: String, datasetCreateRequest: DatasetCreateRequest, - files: Array? + files: Array?, ): Dataset { val filesUploaded = files ?: emptyArray() workspaceService.getVerifiedWorkspace(organizationId, workspaceId, PERMISSION_CREATE_CHILDREN) @@ -165,7 +170,8 @@ class DatasetServiceImpl( constructDatasetPart(organizationId, workspaceId, datasetId, part) datasetPartManagementFactory.storeData( constructDatasetPart, - filesUploaded.first { it.originalFilename == part.sourceName }) + filesUploaded.first { it.originalFilename == part.sourceName }, + ) constructDatasetPart } ?.toMutableList() @@ -186,7 +192,8 @@ class DatasetServiceImpl( parts = datasetParts ?: mutableListOf(), createInfo = createInfo, updateInfo = editInfo, - security = security) + security = security, + ) logger.debug("Registering Dataset: {}", createdDataset) return datasetRepository.save(createdDataset) @@ -214,14 +221,15 @@ class DatasetServiceImpl( override fun getDataset(organizationId: String, workspaceId: String, datasetId: String): Dataset { return updateSecurityVisibility( - getVerifiedDataset(organizationId, workspaceId, datasetId, PERMISSION_READ)) + getVerifiedDataset(organizationId, workspaceId, datasetId, PERMISSION_READ) + ) } override fun getDatasetAccessControl( organizationId: String, workspaceId: String, datasetId: String, - identityId: String + identityId: String, ): DatasetAccessControl { val dataset = getVerifiedDataset(organizationId, workspaceId, datasetId, PERMISSION_READ_SECURITY) @@ -233,7 +241,7 @@ class DatasetServiceImpl( override fun listDatasetSecurityUsers( organizationId: String, workspaceId: String, - datasetId: String + datasetId: String, ): List { val dataset = @@ -246,14 +254,16 @@ class DatasetServiceImpl( organizationId: String, workspaceId: String, page: Int?, - size: Int? + size: Int?, ): List { val workspace = workspaceService.getVerifiedWorkspace(organizationId, workspaceId) val defaultPageSize = csmPlatformProperties.databases.resources.dataset.defaultPageSize val pageable = constructPageRequest(page, size, defaultPageSize) val isAdmin = csmRbac.isAdmin( - workspace.security.toGenericSecurity(workspaceId), getCommonRolesDefinition()) + workspace.security.toGenericSecurity(workspaceId), + getCommonRolesDefinition(), + ) val result: MutableList val rbacEnabled = !isAdmin && this.csmPlatformProperties.rbac.enabled if (pageable == null) { @@ -276,7 +286,11 @@ class DatasetServiceImpl( val currentUser = getCurrentAccountIdentifier(this.csmPlatformProperties) datasetRepository .findByOrganizationIdAndWorkspaceId( - organizationId, workspaceId, currentUser, pageable) + organizationId, + workspaceId, + currentUser, + pageable, + ) .toList() } else { datasetRepository @@ -292,7 +306,7 @@ class DatasetServiceImpl( organizationId: String, workspaceId: String, datasetId: String, - identityId: String + identityId: String, ) { val dataset = @@ -307,7 +321,7 @@ class DatasetServiceImpl( organizationId: String, workspaceId: String, datasetId: String, - datasetRole: DatasetRole + datasetRole: DatasetRole, ): DatasetSecurity { val dataset = @@ -324,7 +338,7 @@ class DatasetServiceImpl( workspaceId: String, datasetId: String, datasetUpdateRequest: DatasetUpdateRequest, - files: Array? + files: Array?, ): Dataset { logger.debug("Updating Dataset: {}", datasetUpdateRequest) val filesUploaded = files ?: emptyArray() @@ -337,7 +351,9 @@ class DatasetServiceImpl( val constructDatasetPart = constructDatasetPart(organizationId, workspaceId, datasetId, part) datasetPartManagementFactory.storeData( - constructDatasetPart, filesUploaded.first { it.originalFilename == part.sourceName }) + constructDatasetPart, + filesUploaded.first { it.originalFilename == part.sourceName }, + ) constructDatasetPart } @@ -356,8 +372,10 @@ class DatasetServiceImpl( updateInfo = DatasetEditInfo( timestamp = Instant.now().toEpochMilli(), - userId = getCurrentAccountIdentifier(csmPlatformProperties)), - security = previousDataset.security) + userId = getCurrentAccountIdentifier(csmPlatformProperties), + ), + security = previousDataset.security, + ) logger.debug("New Dataset info to register: {}", updatedDataset) @@ -378,7 +396,7 @@ class DatasetServiceImpl( workspaceId: String, datasetId: String, identityId: String, - datasetRole: DatasetRole + datasetRole: DatasetRole, ): DatasetAccessControl { val dataset = @@ -386,10 +404,14 @@ class DatasetServiceImpl( csmRbac.checkEntityExists( dataset.security.toGenericSecurity(datasetId), identityId, - "User '$identityId' not found in dataset $datasetId") + "User '$identityId' not found in dataset $datasetId", + ) val rbacSecurity = csmRbac.setEntityRole( - dataset.security.toGenericSecurity(datasetId), identityId, datasetRole.role) + dataset.security.toGenericSecurity(datasetId), + identityId, + datasetRole.role, + ) dataset.security = rbacSecurity.toResourceSecurity() save(dataset) val rbacAccessControl = @@ -398,9 +420,11 @@ class DatasetServiceImpl( } fun updateSecurityVisibility(dataset: Dataset): Dataset { - if (csmRbac - .check(dataset.security.toGenericSecurity(dataset.id), PERMISSION_READ_SECURITY) - .not()) { + if ( + csmRbac + .check(dataset.security.toGenericSecurity(dataset.id), PERMISSION_READ_SECURITY) + .not() + ) { val username = getCurrentAccountIdentifier(csmPlatformProperties) val retrievedAC = dataset.security.accessControlList.firstOrNull { it.id == username } @@ -413,7 +437,10 @@ class DatasetServiceImpl( return dataset.copy( security = DatasetSecurity( - default = dataset.security.default, accessControlList = accessControlList)) + default = dataset.security.default, + accessControlList = accessControlList, + ) + ) } return dataset } @@ -422,7 +449,8 @@ class DatasetServiceImpl( dataset.updateInfo = DatasetEditInfo( timestamp = Instant.now().toEpochMilli(), - userId = getCurrentAccountIdentifier(csmPlatformProperties)) + userId = getCurrentAccountIdentifier(csmPlatformProperties), + ) return datasetRepository.save(dataset) } @@ -431,7 +459,7 @@ class DatasetServiceImpl( workspaceId: String, datasetId: String, file: MultipartFile, - datasetPartCreateRequest: DatasetPartCreateRequest + datasetPartCreateRequest: DatasetPartCreateRequest, ): DatasetPart { val dataset = getVerifiedDataset(organizationId, workspaceId, datasetId, PERMISSION_WRITE) validDatasetPartCreateRequest(datasetPartCreateRequest, file) @@ -448,7 +476,7 @@ class DatasetServiceImpl( workspaceId: String, datasetId: String, file: Resource, - datasetPartCreateRequest: DatasetPartCreateRequest + datasetPartCreateRequest: DatasetPartCreateRequest, ): DatasetPart { val dataset = getVerifiedDataset(organizationId, workspaceId, datasetId, PERMISSION_WRITE) val createdDatasetPart = @@ -462,7 +490,7 @@ class DatasetServiceImpl( organizationId: String, workspaceId: String, datasetId: String, - datasetPartCreateRequest: DatasetPartCreateRequest + datasetPartCreateRequest: DatasetPartCreateRequest, ): DatasetPart { logger.debug("Registering DatasetPart: {}", datasetPartCreateRequest) val now = Instant.now().toEpochMilli() @@ -482,7 +510,8 @@ class DatasetServiceImpl( workspaceId = workspaceId, createInfo = editInfo, updateInfo = editInfo, - sourceName = datasetPartCreateRequest.sourceName) + sourceName = datasetPartCreateRequest.sourceName, + ) logger.debug("Registering DatasetPart: {}", createdDatasetPart) return createdDatasetPart } @@ -491,7 +520,7 @@ class DatasetServiceImpl( organizationId: String, workspaceId: String, datasetId: String, - datasetPartId: String + datasetPartId: String, ) { val dataset = getVerifiedDataset(organizationId, workspaceId, datasetId, PERMISSION_WRITE) @@ -501,7 +530,8 @@ class DatasetServiceImpl( .orElseThrow { CsmResourceNotFoundException( "Dataset Part $datasetPartId not found in organization $organizationId, " + - "workspace $workspaceId and dataset $datasetId") + "workspace $workspaceId and dataset $datasetId" + ) } removeDatasetPartFromDataset(dataset, datasetPartId) @@ -513,7 +543,7 @@ class DatasetServiceImpl( organizationId: String, workspaceId: String, datasetId: String, - datasetPartId: String + datasetPartId: String, ): Resource { val datasetPart = getDatasetPart(organizationId, workspaceId, datasetId, datasetPartId) return datasetPartManagementFactory.getData(datasetPart) @@ -523,7 +553,7 @@ class DatasetServiceImpl( organizationId: String, workspaceId: String, datasetId: String, - datasetPartId: String + datasetPartId: String, ): DatasetPart { getVerifiedDataset(organizationId, workspaceId, datasetId, PERMISSION_READ) @@ -532,7 +562,8 @@ class DatasetServiceImpl( .orElseThrow { CsmResourceNotFoundException( "Dataset Part $datasetPartId not found in organization $organizationId, " + - "workspace $workspaceId and dataset $datasetId") + "workspace $workspaceId and dataset $datasetId" + ) } } @@ -541,7 +572,7 @@ class DatasetServiceImpl( workspaceId: String, datasetId: String, page: Int?, - size: Int? + size: Int?, ): List { val dataset = getVerifiedDataset(organizationId, workspaceId, datasetId, PERMISSION_READ) @@ -559,12 +590,21 @@ class DatasetServiceImpl( val currentUser = getCurrentAccountIdentifier(this.csmPlatformProperties) datasetPartRepository .findByOrganizationIdAndWorkspaceIdAndDatasetId( - organizationId, workspaceId, datasetId, currentUser, it) + organizationId, + workspaceId, + datasetId, + currentUser, + it, + ) .toList() } else { datasetPartRepository .findByOrganizationIdAndWorkspaceIdAndDatasetIdNoSecurity( - organizationId, workspaceId, datasetId, it) + organizationId, + workspaceId, + datasetId, + it, + ) .toList() } } @@ -574,12 +614,21 @@ class DatasetServiceImpl( val currentUser = getCurrentAccountIdentifier(this.csmPlatformProperties) datasetPartRepository .findByOrganizationIdAndWorkspaceIdAndDatasetId( - organizationId, workspaceId, datasetId, currentUser, pageable) + organizationId, + workspaceId, + datasetId, + currentUser, + pageable, + ) .toList() } else { datasetPartRepository .findByOrganizationIdAndWorkspaceIdAndDatasetIdNoSecurity( - organizationId, workspaceId, datasetId, pageable) + organizationId, + workspaceId, + datasetId, + pageable, + ) .toList() } } @@ -601,7 +650,7 @@ class DatasetServiceImpl( offset: Int?, limit: Int?, groupBys: List?, - orderBys: List? + orderBys: List?, ): Resource { val datasetPart = getDatasetPart(organizationId, workspaceId, datasetId, datasetPartId) require(datasetPart.type != DatasetPartTypeEnum.File) { @@ -616,7 +665,9 @@ class DatasetServiceImpl( "mins" to mins, "maxs" to maxs, "groupBys" to groupBys, - "orderBys" to orderBys)) + "orderBys" to orderBys, + ) + ) val query = constructQuery( datasetPartId, @@ -629,7 +680,8 @@ class DatasetServiceImpl( offset, limit, groupBys, - orderBys) + orderBys, + ) val outputStream = ByteArrayOutputStream() try { @@ -639,7 +691,9 @@ class DatasetServiceImpl( } } catch (e: PSQLException) { throw IllegalArgumentException( - "Error while querying Dataset Part $datasetPartId: ($query)", e) + "Error while querying Dataset Part $datasetPartId: ($query)", + e, + ) } return ByteArrayResource(outputStream.toByteArray()) @@ -673,7 +727,7 @@ class DatasetServiceImpl( offset: Int?, limit: Int?, groupBys: List?, - orderBys: List? + orderBys: List?, ): String { val tableName = "${DATASET_INPUTS_SCHEMA}.${datasetPartId.sanitizeDatasetPartId()}" @@ -721,7 +775,7 @@ class DatasetServiceImpl( columnNames: List?, aggregationFunction: AggregationType?, castType: String?, - orderable: Boolean = false + orderable: Boolean = false, ): String { return columnNames?.joinToString(separator = ",") { columnName -> if (aggregationFunction != null) { @@ -751,19 +805,21 @@ class DatasetServiceImpl( private fun getDistinctData(columnSpec: String) = Pair( columnSpec.endsWith(DISTINCT_COLUMN_CHAR), - columnSpec.substringBeforeLast(DISTINCT_COLUMN_CHAR)) + columnSpec.substringBeforeLast(DISTINCT_COLUMN_CHAR), + ) private fun createDistinctClause(isDistinct: Boolean, columnName: String): String { return "%s %s" .format( if (isDistinct) COLUMN_DISTINCT_KEYWORD.uppercase() else "", - StringUtils.wrapIfMissing(columnName, "\"")) + StringUtils.wrapIfMissing(columnName, "\""), + ) } private fun createAggregationClause( aggFunction: String, columnName: String, - castType: String? + castType: String?, ): String { val queryPart = StringBuilder(aggFunction) val (isMarkedAsDistinct, actualColumnName) = getDistinctData(columnName) @@ -776,7 +832,7 @@ class DatasetServiceImpl( private fun StringBuilder.addAggregatedColumn( isDistinct: Boolean, - columnName: String + columnName: String, ): StringBuilder = apply { this.append("(%s".format(createDistinctClause(isDistinct, columnName))) } @@ -788,12 +844,16 @@ class DatasetServiceImpl( private fun StringBuilder.addRenameClause( isDistinct: Boolean, columnName: String, - aggFunction: String + aggFunction: String, ): StringBuilder = apply { this.append( "as \"%s%s%s\"" .format( - aggFunction, if (isDistinct) "_${COLUMN_DISTINCT_KEYWORD}_" else "_", columnName)) + aggFunction, + if (isDistinct) "_${COLUMN_DISTINCT_KEYWORD}_" else "_", + columnName, + ) + ) } override fun updateDatasetPart( @@ -801,7 +861,7 @@ class DatasetServiceImpl( workspaceId: String, datasetId: String, datasetPartId: String, - datasetPartUpdateRequest: DatasetPartUpdateRequest + datasetPartUpdateRequest: DatasetPartUpdateRequest, ): DatasetPart { val dataset = getVerifiedDataset(organizationId, workspaceId, datasetId, PERMISSION_WRITE) val datasetPart = @@ -810,7 +870,8 @@ class DatasetServiceImpl( .orElseThrow { CsmResourceNotFoundException( "Dataset Part $datasetPartId not found in organization $organizationId, " + - "workspace $workspaceId and dataset $datasetId") + "workspace $workspaceId and dataset $datasetId" + ) } val now = Instant.now().toEpochMilli() val userId = getCurrentAccountIdentifier(csmPlatformProperties) @@ -844,7 +905,7 @@ class DatasetServiceImpl( datasetId: String, datasetPartId: String, file: MultipartFile, - datasetPartUpdateRequest: DatasetPartUpdateRequest? + datasetPartUpdateRequest: DatasetPartUpdateRequest?, ): DatasetPart { val dataset = getVerifiedDataset(organizationId, workspaceId, datasetId, PERMISSION_WRITE) val datasetPart = @@ -853,7 +914,8 @@ class DatasetServiceImpl( .orElseThrow { CsmResourceNotFoundException( "Dataset Part $datasetPartId not found in organization $organizationId, " + - "workspace $workspaceId and dataset $datasetId") + "workspace $workspaceId and dataset $datasetId" + ) } validateFile(datasetPart.type == DatasetPartTypeEnum.DB, file) @@ -889,7 +951,7 @@ class DatasetServiceImpl( datasetId: String, requestBody: List, page: Int?, - size: Int? + size: Int?, ): List { if (requestBody.isEmpty()) { return listDatasetParts(organizationId, workspaceId, datasetId, page, size) @@ -904,7 +966,12 @@ class DatasetServiceImpl( if (pageable != null) { datasetPartRepository .findDatasetPartByTags( - organizationId, workspaceId, datasetId, tagsSanitized, pageable) + organizationId, + workspaceId, + datasetId, + tagsSanitized, + pageable, + ) .toList() } else { findAllPaginated(defaultPageSize) { @@ -922,7 +989,7 @@ class DatasetServiceImpl( workspaceId: String, requestBody: List, page: Int?, - size: Int? + size: Int?, ): List { if (requestBody.isEmpty()) { return listDatasets(organizationId, workspaceId, page, size) @@ -958,7 +1025,8 @@ class DatasetServiceImpl( val dataset = datasetRepository.findBy(organizationId, workspaceId, datasetParameterId).orElseThrow { CsmResourceNotFoundException( - "Dataset $datasetParameterId not found in organization $organizationId and workspace $workspaceId") + "Dataset $datasetParameterId not found in organization $organizationId and workspace $workspaceId" + ) } datasetRepository.delete(dataset) @@ -970,7 +1038,7 @@ class DatasetServiceImpl( private fun validDatasetPartCreateRequest( datasetPartCreateRequest: DatasetPartCreateRequest, - file: MultipartFile + file: MultipartFile, ) { require(datasetPartCreateRequest.name.isNotBlank()) { "Dataset Part name must not be blank" } require(datasetPartCreateRequest.sourceName == file.originalFilename) { @@ -994,13 +1062,14 @@ class DatasetServiceImpl( resourceScanner.scanMimeTypes( originalFilename, file.inputStream, - csmPlatformProperties.upload.authorizedMimeTypes.datasets) + csmPlatformProperties.upload.authorizedMimeTypes.datasets, + ) } } private fun validDatasetCreateRequest( datasetCreateRequest: DatasetCreateRequest, - files: Array + files: Array, ) { require(datasetCreateRequest.name.isNotBlank()) { "Dataset name must not be blank" } require(files.size == datasetCreateRequest.parts?.size) { @@ -1008,18 +1077,20 @@ class DatasetServiceImpl( "${files.size} != ${datasetCreateRequest.parts?.size}" } require( - files.groupingBy { it.originalFilename }.eachCount().filter { it.value > 1 }.isEmpty()) { - "Part File names should be unique during dataset creation. " + - "Multipart file names: ${files.map { it.originalFilename }}. " + - "Dataset parts source names: ${datasetCreateRequest.parts?.map { it.sourceName }}." - } + files.groupingBy { it.originalFilename }.eachCount().filter { it.value > 1 }.isEmpty() + ) { + "Part File names should be unique during dataset creation. " + + "Multipart file names: ${files.map { it.originalFilename }}. " + + "Dataset parts source names: ${datasetCreateRequest.parts?.map { it.sourceName }}." + } require( files.mapNotNull { it.originalFilename }.toSortedSet(naturalOrder()) == - datasetCreateRequest.parts?.map { it.sourceName }?.toSortedSet(naturalOrder())) { - "All files must have the same name as corresponding sourceName in a Dataset Part. " + - "Multipart file names: ${files.map { it.originalFilename }}. " + - "Dataset parts source names: ${datasetCreateRequest.parts?.map { it.sourceName }}." - } + datasetCreateRequest.parts?.map { it.sourceName }?.toSortedSet(naturalOrder()) + ) { + "All files must have the same name as corresponding sourceName in a Dataset Part. " + + "Multipart file names: ${files.map { it.originalFilename }}. " + + "Dataset parts source names: ${datasetCreateRequest.parts?.map { it.sourceName }}." + } val parts = datasetCreateRequest.parts files.forEach { file -> val isDBFile = @@ -1030,31 +1101,34 @@ class DatasetServiceImpl( private fun validDatasetUpdateRequest( datasetUpdateRequest: DatasetUpdateRequest, - files: Array + files: Array, ) { require( datasetUpdateRequest.name == null || - (datasetUpdateRequest.name != null && datasetUpdateRequest.name!!.isNotBlank())) { - "Dataset name must not be blank" - } + (datasetUpdateRequest.name != null && datasetUpdateRequest.name!!.isNotBlank()) + ) { + "Dataset name must not be blank" + } require(files.size == (datasetUpdateRequest.parts?.size ?: 0)) { "Number of files must be equal to the number of parts if specified. " + "${files.size} != ${datasetUpdateRequest.parts?.size}" } require( - files.groupingBy { it.originalFilename }.eachCount().filter { it.value > 1 }.isEmpty()) { - "Multipart file names should be unique during dataset update. " + - "Multipart file names: ${files.map { it.originalFilename }}. " + - "Dataset parts source names: ${datasetUpdateRequest.parts?.map { it.sourceName }}." - } + files.groupingBy { it.originalFilename }.eachCount().filter { it.value > 1 }.isEmpty() + ) { + "Multipart file names should be unique during dataset update. " + + "Multipart file names: ${files.map { it.originalFilename }}. " + + "Dataset parts source names: ${datasetUpdateRequest.parts?.map { it.sourceName }}." + } require( files.mapNotNull { it.originalFilename }.toSortedSet(naturalOrder()) == (datasetUpdateRequest.parts?.map { it.sourceName }?.toSortedSet(naturalOrder()) - ?: emptySet())) { - "All files must have the same name as corresponding sourceName in a Dataset Part. " + - "Multipart file names: ${files.map { it.originalFilename }}. " + - "Dataset parts source names: ${datasetUpdateRequest.parts?.map { it.sourceName } ?: emptyList()}." - } + ?: emptySet()) + ) { + "All files must have the same name as corresponding sourceName in a Dataset Part. " + + "Multipart file names: ${files.map { it.originalFilename }}. " + + "Dataset parts source names: ${datasetUpdateRequest.parts?.map { it.sourceName } ?: emptyList()}." + } val parts = datasetUpdateRequest.parts files.forEach { file -> @@ -1070,7 +1144,7 @@ enum class AggregationType { Avg, Count, Min, - Max + Max, } fun DatasetSecurity?.toGenericSecurity(id: String) = @@ -1078,9 +1152,11 @@ fun DatasetSecurity?.toGenericSecurity(id: String) = id, this?.default ?: ROLE_NONE, this?.accessControlList?.map { RbacAccessControl(it.id, it.role) }?.toMutableList() - ?: mutableListOf()) + ?: mutableListOf(), + ) fun RbacSecurity.toResourceSecurity() = DatasetSecurity( this.default, - this.accessControlList.map { DatasetAccessControl(it.id, it.role) }.toMutableList()) + this.accessControlList.map { DatasetAccessControl(it.id, it.role) }.toMutableList(), + ) diff --git a/meta/src/main/kotlin/com/cosmotech/meta/service/MetaServiceImpl.kt b/meta/src/main/kotlin/com/cosmotech/meta/service/MetaServiceImpl.kt index 5e81b0463..2bc54f488 100644 --- a/meta/src/main/kotlin/com/cosmotech/meta/service/MetaServiceImpl.kt +++ b/meta/src/main/kotlin/com/cosmotech/meta/service/MetaServiceImpl.kt @@ -29,6 +29,7 @@ class MetaServiceImpl : CsmPhoenixService(), MetaApiServiceInterface { patch = numbers[2].toInt(), label = numbersAndLabel.getOrElse(1, { "" }), build = aboutVersion.getString("build"), - )) + ) + ) } } diff --git a/meta/src/test/kotlin/com/cosmotech/meta/service/MetaServiceImplTests.kt b/meta/src/test/kotlin/com/cosmotech/meta/service/MetaServiceImplTests.kt index 126668855..aaf476f88 100644 --- a/meta/src/test/kotlin/com/cosmotech/meta/service/MetaServiceImplTests.kt +++ b/meta/src/test/kotlin/com/cosmotech/meta/service/MetaServiceImplTests.kt @@ -25,6 +25,7 @@ class MetaServiceImplTests { mockkStatic("com.cosmotech.common.utils.AboutInfoKt") } + @Suppress("LongMethod") @TestFactory fun `about version info`() = mapOf( @@ -36,7 +37,8 @@ class MetaServiceImplTests { label = "", build = "abcdef12", release = "", - full = ""), + full = "", + ), "Release, no label, no build" to AboutInfoVersion( major = 1, @@ -45,7 +47,8 @@ class MetaServiceImplTests { label = "", build = "", release = "", - full = ""), + full = "", + ), "SNAPSHOT label" to AboutInfoVersion( major = 1, @@ -54,7 +57,8 @@ class MetaServiceImplTests { label = "SNAPSHOT", build = "abcdef12", release = "", - full = ""), + full = "", + ), "'-' in label" to AboutInfoVersion( major = 1, @@ -63,7 +67,8 @@ class MetaServiceImplTests { label = "my-branch-SNAPSHOT", build = "abcdef12", release = "", - full = ""), + full = "", + ), ) .map { (name, data) -> DynamicTest.dynamicTest("about version info: $name") { @@ -80,7 +85,10 @@ class MetaServiceImplTests { mapOf( "full" to data.full, "release" to data.release, - "build" to data.build))) + "build" to data.build, + ) + ) + ) assertEquals(data, metaApiService.about().version) } diff --git a/metrics/src/main/kotlin/com/cosmotech/metrics/MetricsServiceImpl.kt b/metrics/src/main/kotlin/com/cosmotech/metrics/MetricsServiceImpl.kt index 6e957bb99..57b6ac625 100644 --- a/metrics/src/main/kotlin/com/cosmotech/metrics/MetricsServiceImpl.kt +++ b/metrics/src/main/kotlin/com/cosmotech/metrics/MetricsServiceImpl.kt @@ -18,6 +18,7 @@ private const val MILLISECONDS_IN_DAY = 86400000 private const val KEY_PREFIX = "ts2" @Service +@Suppress("TooManyFunctions") class MetricsServiceImpl( private val unifiedJedis: UnifiedJedis, private val csmPlatformProperties: CsmPlatformProperties, @@ -50,63 +51,97 @@ class MetricsServiceImpl( logger.debug("Testing Redis TS exist: $key") val exist = unifiedJedis.exists(key) logger.debug("Redis TS exist: $key:$exist") - val metricRetention = getMetricRetention(metric) - val commonLabels = getCommonLabels(metric) if (!exist) { - val metricLabels = getMetricLabels(commonLabels) + createTimeSeries(commonLabels, key, metricRetention, metric) + } else { + alterTimeSeries(key, metricRetention, commonLabels) + } + } + + private fun alterTimeSeries( + key: String, + metricRetention: Long, + commonLabels: Map, + ) { + val timeSeriesRetention = unifiedJedis.tsInfo(key).getProperty("retentionTime") + + if (timeSeriesRetention != metricRetention) { logger.debug( - "Creating Redis TS: $key with retention: $metricRetention and ${metricLabels.count()} labels") - unifiedJedis.tsCreate( + "Redis TS retention changed: {} from {} to {}." + + "Redis TS library cannot get current labels so it is not possible to check if labels changed", + key, + timeSeriesRetention, + metricRetention, + ) + val metricLabels = getMetricLabels(commonLabels) + unifiedJedis.tsAlter( key, - TSCreateParams() + TSAlterParams() .retention(metricRetention) .labels(metricLabels) - .duplicatePolicy(DuplicatePolicy.MAX)) - if (metric.downSampling || csmPlatformProperties.metrics.downSamplingDefaultEnabled) { - val downSamplingKey = getDownSamplingKey(metric) - val downSamplingMetricLabels = getDownSamplingMetricLabels(commonLabels) - val downSamplingRetention = getDownSamplingRetention(metric) - val downSamplingBucketDuration = getDownSamplingBucketDuration(metric) - logger.debug( - "Creating Redis DownSampling TS: $downSamplingKey with retention: $metricRetention " + - "and ${downSamplingMetricLabels.count()} labels") - unifiedJedis.tsCreate( - downSamplingKey, - TSCreateParams() - .retention(downSamplingRetention) - .labels(downSamplingMetricLabels) - .duplicatePolicy(DuplicatePolicy.MAX)) - logger.debug( - "Creating Redis DownSampling TS rule: from $key to $downSamplingKey, " + - "aggregation: ${metric.downSamplingAggregation.value}, bucketDuration: $downSamplingBucketDuration") - unifiedJedis.tsCreateRule( - key, - downSamplingKey, - metric.downSamplingAggregation.toRedisAggregation(), - downSamplingBucketDuration, - 0) - } - } else { - val timeSeriesRetention = unifiedJedis.tsInfo(key).getProperty("retentionTime") - - if (timeSeriesRetention != metricRetention) { - logger.debug( - "Redis TS retention changed: $key from $timeSeriesRetention to $metricRetention") - logger.debug( - "Redis TS library cannot get current labels so it is not possible to check if labels changed") - val metricLabels = getMetricLabels(commonLabels) - unifiedJedis.tsAlter( - key, - TSAlterParams() - .retention(metricRetention) - .labels(metricLabels) - .duplicatePolicy(DuplicatePolicy.MAX)) - } + .duplicatePolicy(DuplicatePolicy.MAX), + ) } } + private fun createTimeSeries( + commonLabels: Map, + key: String, + metricRetention: Long, + metric: PersistentMetric, + ) { + val metricLabels = getMetricLabels(commonLabels) + logger.debug( + "Creating Redis TS: $key with retention: $metricRetention and ${metricLabels.count()} labels" + ) + unifiedJedis.tsCreate( + key, + TSCreateParams() + .retention(metricRetention) + .labels(metricLabels) + .duplicatePolicy(DuplicatePolicy.MAX), + ) + if (metric.downSampling || csmPlatformProperties.metrics.downSamplingDefaultEnabled) { + handleDownSampling(metric, commonLabels, metricRetention, key) + } + } + + private fun handleDownSampling( + metric: PersistentMetric, + commonLabels: Map, + metricRetention: Long, + key: String, + ) { + val downSamplingKey = getDownSamplingKey(metric) + val downSamplingMetricLabels = getDownSamplingMetricLabels(commonLabels) + val downSamplingRetention = getDownSamplingRetention(metric) + val downSamplingBucketDuration = getDownSamplingBucketDuration(metric) + logger.debug( + "Creating Redis DownSampling TS: $downSamplingKey with retention: $metricRetention " + + "and ${downSamplingMetricLabels.count()} labels" + ) + unifiedJedis.tsCreate( + downSamplingKey, + TSCreateParams() + .retention(downSamplingRetention) + .labels(downSamplingMetricLabels) + .duplicatePolicy(DuplicatePolicy.MAX), + ) + logger.debug( + "Creating Redis DownSampling TS rule: from $key to $downSamplingKey, " + + "aggregation: ${metric.downSamplingAggregation.value}, bucketDuration: $downSamplingBucketDuration" + ) + unifiedJedis.tsCreateRule( + key, + downSamplingKey, + metric.downSamplingAggregation.toRedisAggregation(), + downSamplingBucketDuration, + 0, + ) + } + private fun getDownSamplingBucketDuration(metric: PersistentMetric): Long = when (metric.downSamplingBucketDuration) { 0L -> csmPlatformProperties.metrics.downSamplingBucketDurationMs.toLong() diff --git a/organization/src/integrationTest/kotlin/com/cosmotech/organization/service/OrganizationServiceIntegrationTest.kt b/organization/src/integrationTest/kotlin/com/cosmotech/organization/service/OrganizationServiceIntegrationTest.kt index e021c7e97..9ee3df71c 100644 --- a/organization/src/integrationTest/kotlin/com/cosmotech/organization/service/OrganizationServiceIntegrationTest.kt +++ b/organization/src/integrationTest/kotlin/com/cosmotech/organization/service/OrganizationServiceIntegrationTest.kt @@ -162,7 +162,8 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { fun `getOrganization as resource admin`() { val organizationRegistered = organizationApiService.createOrganization( - makeSimpleOrganizationCreateRequest("o-connector-test-1")) + makeSimpleOrganizationCreateRequest("o-connector-test-1") + ) assertNotNull(organizationApiService.getOrganization(organizationRegistered.id)) } @@ -202,8 +203,10 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { assertEquals( OrganizationSecurity( default = ROLE_NONE, - mutableListOf(OrganizationAccessControl(id = TEST_USER_ID, role = ROLE_ADMIN))), - organizationRegistered.security) + mutableListOf(OrganizationAccessControl(id = TEST_USER_ID, role = ROLE_ADMIN)), + ), + organizationRegistered.security, + ) assertEquals(name, organizationRegistered.name) assertTrue(organizationRegistered.id.startsWith("o-")) } @@ -222,7 +225,11 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val name = "o-connector-test-1" val organizationToRegister = makeOrganizationCreateRequestWithSimpleSecurity( - name, OTHER_TEST_USER_ID, ROLE_USER, ROLE_NONE) + name, + OTHER_TEST_USER_ID, + ROLE_USER, + ROLE_NONE, + ) val organizationRegistered = organizationApiService.createOrganization(organizationToRegister) assertEquals( @@ -230,8 +237,11 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { default = ROLE_USER, mutableListOf( OrganizationAccessControl(id = OTHER_TEST_USER_ID, role = ROLE_NONE), - OrganizationAccessControl(id = TEST_USER_ID, role = ROLE_ADMIN))), - organizationRegistered.security) + OrganizationAccessControl(id = TEST_USER_ID, role = ROLE_ADMIN), + ), + ), + organizationRegistered.security, + ) assertEquals(name, organizationRegistered.name) assertTrue(organizationRegistered.id.startsWith("o-")) } @@ -261,7 +271,11 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val name = "o-connector-test-1" val organizationToRegister = makeOrganizationCreateRequestWithSimpleSecurity( - name, OTHER_TEST_USER_ID, ROLE_USER, ROLE_ADMIN) + name, + OTHER_TEST_USER_ID, + ROLE_USER, + ROLE_ADMIN, + ) val organizationRegistered = organizationApiService.createOrganization(organizationToRegister) organizationApiService.deleteOrganization(organizationRegistered.id) @@ -275,7 +289,11 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { runAsDifferentOrganizationUser() val organizationToRegister = makeOrganizationCreateRequestWithSimpleSecurity( - name, TEST_USER_ID, ROLE_NONE, ROLE_ADMIN) + name, + TEST_USER_ID, + ROLE_NONE, + ROLE_ADMIN, + ) val organizationRegistered = organizationApiService.createOrganization(organizationToRegister) runAsOrganizationUser() @@ -292,19 +310,25 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val newName = "my-new-name" val organizationUpdated = organizationApiService.updateOrganization( - organizationRegistered.id, OrganizationUpdateRequest(newName)) + organizationRegistered.id, + OrganizationUpdateRequest(newName), + ) assertEquals(newName, organizationApiService.getOrganization(organizationUpdated.id).name) // Update organization with empty body organizationApiService.updateOrganization( - organizationUpdated.id, OrganizationUpdateRequest()) + organizationUpdated.id, + OrganizationUpdateRequest(), + ) assertEquals(newName, organizationApiService.getOrganization(organizationUpdated.id).name) // Update organization with null value as name organizationApiService.updateOrganization( - organizationUpdated.id, OrganizationUpdateRequest(null)) + organizationUpdated.id, + OrganizationUpdateRequest(null), + ) assertEquals(newName, organizationApiService.getOrganization(organizationUpdated.id).name) } @@ -318,26 +342,37 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val organizationRegistered = organizationApiService.createOrganization( makeOrganizationCreateRequestWithSimpleSecurity( - name, TEST_USER_ID, ROLE_NONE, ROLE_EDITOR)) + name, + TEST_USER_ID, + ROLE_NONE, + ROLE_EDITOR, + ) + ) runAsOrganizationUser() val newName = "my-new-name" val organizationUpdated = organizationApiService.updateOrganization( - organizationRegistered.id, OrganizationUpdateRequest(newName)) + organizationRegistered.id, + OrganizationUpdateRequest(newName), + ) assertEquals(newName, organizationApiService.getOrganization(organizationUpdated.id).name) // Update organization with empty body organizationApiService.updateOrganization( - organizationUpdated.id, OrganizationUpdateRequest()) + organizationUpdated.id, + OrganizationUpdateRequest(), + ) assertEquals(newName, organizationApiService.getOrganization(organizationUpdated.id).name) // Update organization with null value as name organizationApiService.updateOrganization( - organizationUpdated.id, OrganizationUpdateRequest(null)) + organizationUpdated.id, + OrganizationUpdateRequest(null), + ) assertEquals(newName, organizationApiService.getOrganization(organizationUpdated.id).name) } @@ -352,7 +387,9 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { organizationApiService.createOrganization(makeSimpleOrganizationCreateRequest(name)) runAsOrganizationUser() organizationApiService.updateOrganization( - organizationRegistered.id, OrganizationUpdateRequest("name")) + organizationRegistered.id, + OrganizationUpdateRequest("name"), + ) } } @@ -370,13 +407,15 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { mutableListOf( PERMISSION_READ, PERMISSION_READ_SECURITY, - PERMISSION_CREATE_CHILDREN), + PERMISSION_CREATE_CHILDREN, + ), ROLE_EDITOR to mutableListOf( PERMISSION_READ, PERMISSION_READ_SECURITY, PERMISSION_CREATE_CHILDREN, - PERMISSION_WRITE), + PERMISSION_WRITE, + ), ROLE_ADMIN to mutableListOf( PERMISSION_READ, @@ -384,8 +423,10 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { PERMISSION_CREATE_CHILDREN, PERMISSION_WRITE, PERMISSION_WRITE_SECURITY, - PERMISSION_DELETE), - )), + PERMISSION_DELETE, + ), + ), + ), ComponentRolePermissions( component = "workspace", roles = @@ -396,13 +437,15 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { mutableListOf( PERMISSION_READ, PERMISSION_READ_SECURITY, - PERMISSION_CREATE_CHILDREN), + PERMISSION_CREATE_CHILDREN, + ), ROLE_EDITOR to mutableListOf( PERMISSION_READ, PERMISSION_READ_SECURITY, PERMISSION_CREATE_CHILDREN, - PERMISSION_WRITE), + PERMISSION_WRITE, + ), ROLE_ADMIN to mutableListOf( PERMISSION_READ, @@ -410,8 +453,10 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { PERMISSION_CREATE_CHILDREN, PERMISSION_WRITE, PERMISSION_WRITE_SECURITY, - PERMISSION_DELETE), - )), + PERMISSION_DELETE, + ), + ), + ), ComponentRolePermissions( component = "runner", roles = @@ -423,14 +468,16 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { PERMISSION_READ, PERMISSION_READ_SECURITY, PERMISSION_LAUNCH, - PERMISSION_WRITE), + PERMISSION_WRITE, + ), ROLE_VALIDATOR to mutableListOf( PERMISSION_READ, PERMISSION_READ_SECURITY, PERMISSION_LAUNCH, PERMISSION_WRITE, - PERMISSION_VALIDATE), + PERMISSION_VALIDATE, + ), ROLE_ADMIN to mutableListOf( PERMISSION_READ, @@ -439,8 +486,11 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { PERMISSION_WRITE, PERMISSION_VALIDATE, PERMISSION_WRITE_SECURITY, - PERMISSION_DELETE), - ))) + PERMISSION_DELETE, + ), + ), + ), + ) assertEquals(mapAllPermissions, organizationApiService.listPermissions()) } @@ -452,23 +502,30 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { organizationApiService.createOrganization(makeSimpleOrganizationCreateRequest(name)) var organizationUserPermissions = organizationApiService.getOrganizationPermissions( - organizationRegistered.id, ROLE_VIEWER) + organizationRegistered.id, + ROLE_VIEWER, + ) assertEquals(mutableListOf(PERMISSION_READ), organizationUserPermissions) organizationUserPermissions = organizationApiService.getOrganizationPermissions(organizationRegistered.id, ROLE_USER) assertEquals( mutableListOf(PERMISSION_READ, PERMISSION_READ_SECURITY, PERMISSION_CREATE_CHILDREN), - organizationUserPermissions) + organizationUserPermissions, + ) organizationUserPermissions = organizationApiService.getOrganizationPermissions( - organizationRegistered.id, ROLE_EDITOR) + organizationRegistered.id, + ROLE_EDITOR, + ) assertEquals( mutableListOf( PERMISSION_READ, PERMISSION_READ_SECURITY, PERMISSION_CREATE_CHILDREN, - PERMISSION_WRITE), - organizationUserPermissions) + PERMISSION_WRITE, + ), + organizationUserPermissions, + ) organizationUserPermissions = organizationApiService.getOrganizationPermissions(organizationRegistered.id, ROLE_ADMIN) assertEquals( @@ -478,11 +535,15 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { PERMISSION_CREATE_CHILDREN, PERMISSION_WRITE, PERMISSION_WRITE_SECURITY, - PERMISSION_DELETE), - organizationUserPermissions) + PERMISSION_DELETE, + ), + organizationUserPermissions, + ) organizationUserPermissions = organizationApiService.getOrganizationPermissions( - organizationRegistered.id, UNKNOWN_IDENTIFIER) + organizationRegistered.id, + UNKNOWN_IDENTIFIER, + ) assertEquals(emptyList(), organizationUserPermissions) } } @@ -495,27 +556,39 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val organizationRegistered = organizationApiService.createOrganization( makeOrganizationCreateRequestWithSimpleSecurity( - name, TEST_USER_ID, ROLE_NONE, ROLE_USER)) + name, + TEST_USER_ID, + ROLE_NONE, + ROLE_USER, + ) + ) runAsOrganizationUser() var organizationUserPermissions = organizationApiService.getOrganizationPermissions( - organizationRegistered.id, ROLE_VIEWER) + organizationRegistered.id, + ROLE_VIEWER, + ) assertEquals(mutableListOf(PERMISSION_READ), organizationUserPermissions) organizationUserPermissions = organizationApiService.getOrganizationPermissions(organizationRegistered.id, ROLE_USER) assertEquals( mutableListOf(PERMISSION_READ, PERMISSION_READ_SECURITY, PERMISSION_CREATE_CHILDREN), - organizationUserPermissions) + organizationUserPermissions, + ) organizationUserPermissions = organizationApiService.getOrganizationPermissions( - organizationRegistered.id, ROLE_EDITOR) + organizationRegistered.id, + ROLE_EDITOR, + ) assertEquals( mutableListOf( PERMISSION_READ, PERMISSION_READ_SECURITY, PERMISSION_CREATE_CHILDREN, - PERMISSION_WRITE), - organizationUserPermissions) + PERMISSION_WRITE, + ), + organizationUserPermissions, + ) organizationUserPermissions = organizationApiService.getOrganizationPermissions(organizationRegistered.id, ROLE_ADMIN) assertEquals( @@ -525,11 +598,15 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { PERMISSION_CREATE_CHILDREN, PERMISSION_WRITE, PERMISSION_WRITE_SECURITY, - PERMISSION_DELETE), - organizationUserPermissions) + PERMISSION_DELETE, + ), + organizationUserPermissions, + ) organizationUserPermissions = organizationApiService.getOrganizationPermissions( - organizationRegistered.id, UNKNOWN_IDENTIFIER) + organizationRegistered.id, + UNKNOWN_IDENTIFIER, + ) assertEquals(emptyList(), organizationUserPermissions) } } @@ -571,7 +648,12 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val organizationRegistered = organizationApiService.createOrganization( makeOrganizationCreateRequestWithSimpleSecurity( - name, TEST_USER_ID, ROLE_NONE, ROLE_USER)) + name, + TEST_USER_ID, + ROLE_NONE, + ROLE_USER, + ) + ) runAsOrganizationUser() assertNotNull(organizationApiService.getOrganizationSecurity(organizationRegistered.id)) } @@ -585,7 +667,12 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val organizationRegistered = organizationApiService.createOrganization( makeOrganizationCreateRequestWithSimpleSecurity( - name, TEST_USER_ID, ROLE_NONE, ROLE_NONE)) + name, + TEST_USER_ID, + ROLE_NONE, + ROLE_NONE, + ) + ) runAsOrganizationUser() organizationApiService.getOrganizationSecurity(organizationRegistered.id) } @@ -600,7 +687,10 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val defaultRoleCreated = organizationRegistered.security.default assertNotNull( organizationApiService.updateOrganizationDefaultSecurity( - organizationRegistered.id, OrganizationRole(ROLE_ADMIN))) + organizationRegistered.id, + OrganizationRole(ROLE_ADMIN), + ) + ) val defaultRoleUpdated = organizationApiService.getOrganizationSecurity(organizationRegistered.id).default assertNotEquals(defaultRoleCreated, defaultRoleUpdated) @@ -614,7 +704,9 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val organizationRegistered = organizationApiService.createOrganization(makeSimpleOrganizationCreateRequest(name)) organizationApiService.updateOrganizationDefaultSecurity( - organizationRegistered.id, OrganizationRole(UNKNOWN_IDENTIFIER)) + organizationRegistered.id, + OrganizationRole(UNKNOWN_IDENTIFIER), + ) } } @@ -626,12 +718,20 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val organizationRegistered = organizationApiService.createOrganization( makeOrganizationCreateRequestWithSimpleSecurity( - name, TEST_USER_ID, ROLE_NONE, ROLE_ADMIN)) + name, + TEST_USER_ID, + ROLE_NONE, + ROLE_ADMIN, + ) + ) val defaultRoleCreated = organizationRegistered.security.default runAsOrganizationUser() assertNotNull( organizationApiService.updateOrganizationDefaultSecurity( - organizationRegistered.id, OrganizationRole(ROLE_ADMIN))) + organizationRegistered.id, + OrganizationRole(ROLE_ADMIN), + ) + ) val defaultRoleUpdated = organizationApiService.getOrganizationSecurity(organizationRegistered.id).default assertNotEquals(defaultRoleCreated, defaultRoleUpdated) @@ -646,10 +746,17 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val organizationRegistered = organizationApiService.createOrganization( makeOrganizationCreateRequestWithSimpleSecurity( - name, TEST_USER_ID, ROLE_NONE, ROLE_USER)) + name, + TEST_USER_ID, + ROLE_NONE, + ROLE_USER, + ) + ) runAsOrganizationUser() organizationApiService.updateOrganizationDefaultSecurity( - organizationRegistered.id, OrganizationRole(ROLE_ADMIN)) + organizationRegistered.id, + OrganizationRole(ROLE_ADMIN), + ) } } @@ -661,7 +768,9 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { organizationApiService.createOrganization(makeSimpleOrganizationCreateRequest(name)) val organizationRole = organizationApiService.getOrganizationAccessControl( - organizationRegistered.id, TEST_USER_ID) + organizationRegistered.id, + TEST_USER_ID, + ) assertNotNull(organizationRole) assertEquals(ROLE_ADMIN, organizationRole.role) assertEquals(TEST_USER_ID, organizationRole.id) @@ -686,11 +795,18 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val organizationRegistered = organizationApiService.createOrganization( makeOrganizationCreateRequestWithSimpleSecurity( - name, TEST_USER_ID, ROLE_NONE, ROLE_USER)) + name, + TEST_USER_ID, + ROLE_NONE, + ROLE_USER, + ) + ) runAsOrganizationUser() val organizationRole = organizationApiService.getOrganizationAccessControl( - organizationRegistered.id, TEST_USER_ID) + organizationRegistered.id, + TEST_USER_ID, + ) assertNotNull(organizationRole) assertEquals(ROLE_USER, organizationRole.role) assertEquals(TEST_USER_ID, organizationRole.id) @@ -705,10 +821,17 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val organizationRegistered = organizationApiService.createOrganization( makeOrganizationCreateRequestWithSimpleSecurity( - name, TEST_USER_ID, ROLE_NONE, ROLE_USER)) + name, + TEST_USER_ID, + ROLE_NONE, + ROLE_USER, + ) + ) runAsOrganizationUser() organizationApiService.getOrganizationAccessControl( - organizationRegistered.id, UNKNOWN_IDENTIFIER) + organizationRegistered.id, + UNKNOWN_IDENTIFIER, + ) } } @@ -720,10 +843,17 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val organizationRegistered = organizationApiService.createOrganization( makeOrganizationCreateRequestWithSimpleSecurity( - name, TEST_USER_ID, ROLE_NONE, ROLE_NONE)) + name, + TEST_USER_ID, + ROLE_NONE, + ROLE_NONE, + ) + ) runAsOrganizationUser() organizationApiService.getOrganizationAccessControl( - organizationRegistered.id, UNKNOWN_IDENTIFIER) + organizationRegistered.id, + UNKNOWN_IDENTIFIER, + ) } } @@ -735,18 +865,27 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { organizationApiService.createOrganization(makeSimpleOrganizationCreateRequest(name)) assertThrows { organizationApiService.getOrganizationAccessControl( - organizationRegistered.id, OTHER_TEST_USER_ID) + organizationRegistered.id, + OTHER_TEST_USER_ID, + ) } val otherUserACL = OrganizationAccessControl(id = OTHER_TEST_USER_ID, role = ROLE_VIEWER) assertNotNull( organizationApiService.createOrganizationAccessControl( - organizationRegistered.id, otherUserACL)) + organizationRegistered.id, + otherUserACL, + ) + ) val otherUserACLRetrieved = organizationApiService.getOrganizationAccessControl( - organizationRegistered.id, OTHER_TEST_USER_ID) + organizationRegistered.id, + OTHER_TEST_USER_ID, + ) assertEquals( - OrganizationAccessControl(id = OTHER_TEST_USER_ID, ROLE_VIEWER), otherUserACLRetrieved) + OrganizationAccessControl(id = OTHER_TEST_USER_ID, ROLE_VIEWER), + otherUserACLRetrieved, + ) } } @@ -758,22 +897,36 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val organizationRegistered = organizationApiService.createOrganization( makeOrganizationCreateRequestWithSimpleSecurity( - name, TEST_USER_ID, ROLE_NONE, ROLE_ADMIN)) + name, + TEST_USER_ID, + ROLE_NONE, + ROLE_ADMIN, + ) + ) runAsOrganizationUser() assertThrows { organizationApiService.getOrganizationAccessControl( - organizationRegistered.id, TEST_ADMIN_USER_ID) + organizationRegistered.id, + TEST_ADMIN_USER_ID, + ) } val otherUserACL = OrganizationAccessControl(id = TEST_ADMIN_USER_ID, role = ROLE_VIEWER) assertNotNull( organizationApiService.createOrganizationAccessControl( - organizationRegistered.id, otherUserACL)) + organizationRegistered.id, + otherUserACL, + ) + ) val otherUserACLRetrieved = organizationApiService.getOrganizationAccessControl( - organizationRegistered.id, TEST_ADMIN_USER_ID) + organizationRegistered.id, + TEST_ADMIN_USER_ID, + ) assertEquals( - OrganizationAccessControl(TEST_ADMIN_USER_ID, ROLE_VIEWER), otherUserACLRetrieved) + OrganizationAccessControl(TEST_ADMIN_USER_ID, ROLE_VIEWER), + otherUserACLRetrieved, + ) } } @@ -785,15 +938,24 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val organizationRegistered = organizationApiService.createOrganization( makeOrganizationCreateRequestWithSimpleSecurity( - name, TEST_USER_ID, ROLE_NONE, ROLE_USER)) + name, + TEST_USER_ID, + ROLE_NONE, + ROLE_USER, + ) + ) runAsOrganizationUser() assertThrows { organizationApiService.getOrganizationAccessControl( - organizationRegistered.id, TEST_ADMIN_USER_ID) + organizationRegistered.id, + TEST_ADMIN_USER_ID, + ) } val otherUserACL = OrganizationAccessControl(id = TEST_ADMIN_USER_ID, role = ROLE_VIEWER) organizationApiService.createOrganizationAccessControl( - organizationRegistered.id, otherUserACL) + organizationRegistered.id, + otherUserACL, + ) } } @@ -804,7 +966,10 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val organizationRegistered = organizationApiService.createOrganization(makeSimpleOrganizationCreateRequest(name)) organizationApiService.updateOrganizationAccessControl( - organizationRegistered.id, TEST_USER_ID, OrganizationRole(role = ROLE_VIEWER)) + organizationRegistered.id, + TEST_USER_ID, + OrganizationRole(role = ROLE_VIEWER), + ) } } @@ -817,17 +982,22 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { organizationApiService.createOrganizationAccessControl( organizationRegistered.id, - OrganizationAccessControl(id = OTHER_TEST_USER_ID, role = ROLE_VIEWER)) + OrganizationAccessControl(id = OTHER_TEST_USER_ID, role = ROLE_VIEWER), + ) assertNotNull( organizationApiService.updateOrganizationAccessControl( organizationRegistered.id, OTHER_TEST_USER_ID, - OrganizationRole(role = ROLE_EDITOR))) + OrganizationRole(role = ROLE_EDITOR), + ) + ) val userACLRetrieved = organizationApiService.getOrganizationAccessControl( - organizationRegistered.id, OTHER_TEST_USER_ID) + organizationRegistered.id, + OTHER_TEST_USER_ID, + ) assertNotEquals(ROLE_VIEWER, userACLRetrieved.role) assertEquals(ROLE_EDITOR, userACLRetrieved.role) } @@ -841,7 +1011,10 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { organizationApiService.createOrganization(makeSimpleOrganizationCreateRequest(name)) organizationApiService.updateOrganizationAccessControl( - organizationRegistered.id, TEST_USER_ID, OrganizationRole(role = ROLE_NONE)) + organizationRegistered.id, + TEST_USER_ID, + OrganizationRole(role = ROLE_NONE), + ) } } @@ -853,7 +1026,10 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { organizationApiService.createOrganization(makeSimpleOrganizationCreateRequest(name)) organizationApiService.updateOrganizationAccessControl( - organizationRegistered.id, UNKNOWN_IDENTIFIER, OrganizationRole(role = ROLE_EDITOR)) + organizationRegistered.id, + UNKNOWN_IDENTIFIER, + OrganizationRole(role = ROLE_EDITOR), + ) } } @@ -865,7 +1041,10 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { organizationApiService.createOrganization(makeSimpleOrganizationCreateRequest(name)) organizationApiService.updateOrganizationAccessControl( - organizationRegistered.id, TEST_USER_ID, OrganizationRole(role = UNKNOWN_IDENTIFIER)) + organizationRegistered.id, + TEST_USER_ID, + OrganizationRole(role = UNKNOWN_IDENTIFIER), + ) } } @@ -879,7 +1058,8 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { organizationApiService.createOrganizationAccessControl( organizationRegistered.id, - OrganizationAccessControl(id = TEST_USER_ID, role = ROLE_ADMIN)) + OrganizationAccessControl(id = TEST_USER_ID, role = ROLE_ADMIN), + ) runAsOrganizationUser() @@ -887,11 +1067,15 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { organizationApiService.updateOrganizationAccessControl( organizationRegistered.id, OTHER_TEST_USER_ID, - OrganizationRole(role = ROLE_EDITOR))) + OrganizationRole(role = ROLE_EDITOR), + ) + ) val userACLRetrieved = organizationApiService.getOrganizationAccessControl( - organizationRegistered.id, OTHER_TEST_USER_ID) + organizationRegistered.id, + OTHER_TEST_USER_ID, + ) assertEquals(ROLE_EDITOR, userACLRetrieved.role) } } @@ -906,12 +1090,16 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { organizationApiService.createOrganizationAccessControl( organizationRegistered.id, - OrganizationAccessControl(id = TEST_USER_ID, role = ROLE_VIEWER)) + OrganizationAccessControl(id = TEST_USER_ID, role = ROLE_VIEWER), + ) runAsOrganizationUser() organizationApiService.updateOrganizationAccessControl( - organizationRegistered.id, OTHER_TEST_USER_ID, OrganizationRole(role = ROLE_EDITOR)) + organizationRegistered.id, + OTHER_TEST_USER_ID, + OrganizationRole(role = ROLE_EDITOR), + ) } } @@ -925,12 +1113,16 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { organizationApiService.createOrganizationAccessControl( organizationRegistered.id, - OrganizationAccessControl(id = TEST_USER_ID, role = ROLE_VIEWER)) + OrganizationAccessControl(id = TEST_USER_ID, role = ROLE_VIEWER), + ) runAsOrganizationUser() organizationApiService.updateOrganizationAccessControl( - organizationRegistered.id, OTHER_TEST_USER_ID, OrganizationRole(role = ROLE_NONE)) + organizationRegistered.id, + OTHER_TEST_USER_ID, + OrganizationRole(role = ROLE_NONE), + ) } } @@ -942,13 +1134,19 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val otherUserACL = OrganizationAccessControl(id = OTHER_TEST_USER_ID, role = ROLE_VIEWER) organizationApiService.createOrganizationAccessControl( - organizationRegistered.id, otherUserACL) + organizationRegistered.id, + otherUserACL, + ) organizationApiService.deleteOrganizationAccessControl( - organizationRegistered.id, OTHER_TEST_USER_ID) + organizationRegistered.id, + OTHER_TEST_USER_ID, + ) assertThrows { organizationApiService.getOrganizationAccessControl( - organizationRegistered.id, OTHER_TEST_USER_ID) + organizationRegistered.id, + OTHER_TEST_USER_ID, + ) } } @@ -961,14 +1159,20 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val otherUserACL = OrganizationAccessControl(id = TEST_USER_ID, role = ROLE_ADMIN) organizationApiService.createOrganizationAccessControl( - organizationRegistered.id, otherUserACL) + organizationRegistered.id, + otherUserACL, + ) runAsOrganizationUser() organizationApiService.deleteOrganizationAccessControl( - organizationRegistered.id, OTHER_TEST_USER_ID) + organizationRegistered.id, + OTHER_TEST_USER_ID, + ) assertThrows { organizationApiService.getOrganizationAccessControl( - organizationRegistered.id, OTHER_TEST_USER_ID) + organizationRegistered.id, + OTHER_TEST_USER_ID, + ) } } @@ -981,12 +1185,16 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val otherUserACL = OrganizationAccessControl(id = TEST_USER_ID, role = ROLE_VIEWER) organizationApiService.createOrganizationAccessControl( - organizationRegistered.id, otherUserACL) + organizationRegistered.id, + otherUserACL, + ) runAsOrganizationUser() assertThrows { organizationApiService.deleteOrganizationAccessControl( - organizationRegistered.id, OTHER_TEST_USER_ID) + organizationRegistered.id, + OTHER_TEST_USER_ID, + ) } } @@ -1008,7 +1216,12 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val organizationRegistered = organizationApiService.createOrganization( makeOrganizationCreateRequestWithSimpleSecurity( - name, TEST_USER_ID, ROLE_NONE, ROLE_USER)) + name, + TEST_USER_ID, + ROLE_NONE, + ROLE_USER, + ) + ) runAsOrganizationUser() val orgaUsers = organizationApiService.listOrganizationSecurityUsers(organizationRegistered.id) @@ -1022,7 +1235,12 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val organizationRegistered = organizationApiService.createOrganization( makeOrganizationCreateRequestWithSimpleSecurity( - name, TEST_USER_ID, ROLE_NONE, ROLE_NONE)) + name, + TEST_USER_ID, + ROLE_NONE, + ROLE_NONE, + ) + ) runAsOrganizationUser() assertThrows { organizationApiService.listOrganizationSecurityUsers(organizationRegistered.id) @@ -1048,7 +1266,12 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val organizationRegistered = organizationApiService.createOrganization( makeOrganizationCreateRequestWithSimpleSecurity( - name, TEST_USER_ID, ROLE_NONE, ROLE_NONE)) + name, + TEST_USER_ID, + ROLE_NONE, + ROLE_NONE, + ) + ) runAsOrganizationUser() assertThrows { organizationApiService.getVerifiedOrganization(organizationRegistered.id) @@ -1071,8 +1294,10 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { assertEquals( OrganizationSecurity( default = ROLE_NONE, - mutableListOf(OrganizationAccessControl(TEST_USER_ID, ROLE_VIEWER))), - organizationSaved.security) + mutableListOf(OrganizationAccessControl(TEST_USER_ID, ROLE_VIEWER)), + ), + organizationSaved.security, + ) assertEquals(1, organizationSaved.security.accessControlList.size) } @@ -1086,8 +1311,10 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { assertEquals( OrganizationSecurity( default = ROLE_NONE, - mutableListOf(OrganizationAccessControl(TEST_USER_ID, ROLE_VIEWER))), - it.security) + mutableListOf(OrganizationAccessControl(TEST_USER_ID, ROLE_VIEWER)), + ), + it.security, + ) assertEquals(1, it.security.accessControlList.size) } } @@ -1143,7 +1370,8 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { fun `getOrganization as resource admin`() { val organizationRegistered = organizationApiService.createOrganization( - makeSimpleOrganizationCreateRequest("o-connector-test-1")) + makeSimpleOrganizationCreateRequest("o-connector-test-1") + ) assertNotNull(organizationApiService.getOrganization(organizationRegistered.id)) } @@ -1163,8 +1391,11 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { OrganizationSecurity( default = ROLE_NONE, mutableListOf( - OrganizationAccessControl(id = TEST_ADMIN_USER_ID, role = ROLE_ADMIN))), - organizationRegistered.security) + OrganizationAccessControl(id = TEST_ADMIN_USER_ID, role = ROLE_ADMIN) + ), + ), + organizationRegistered.security, + ) assertEquals(name, organizationRegistered.name) assertTrue(organizationRegistered.id.startsWith("o-")) } @@ -1184,15 +1415,22 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val name = "o-connector-test-1" val organizationToRegister = makeOrganizationCreateRequestWithSimpleSecurity( - name, OTHER_TEST_USER_ID, ROLE_USER, ROLE_NONE) + name, + OTHER_TEST_USER_ID, + ROLE_USER, + ROLE_NONE, + ) val organizationRegistered = organizationApiService.createOrganization(organizationToRegister) assertEquals( OrganizationSecurity( default = ROLE_USER, mutableListOf( OrganizationAccessControl(id = OTHER_TEST_USER_ID, role = ROLE_NONE), - OrganizationAccessControl(id = defaultName, role = ROLE_ADMIN))), - organizationRegistered.security) + OrganizationAccessControl(id = defaultName, role = ROLE_ADMIN), + ), + ), + organizationRegistered.security, + ) assertEquals(name, organizationRegistered.name) assertTrue(organizationRegistered.id.startsWith("o-")) } @@ -1233,11 +1471,14 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { assertDoesNotThrow { val organizationRegistered = organizationApiService.createOrganization( - makeSimpleOrganizationCreateRequest("o-connector-test-1")) + makeSimpleOrganizationCreateRequest("o-connector-test-1") + ) val newName = "my-new-name" val organizationUpdated = organizationApiService.updateOrganization( - organizationRegistered.id, OrganizationUpdateRequest(newName)) + organizationRegistered.id, + OrganizationUpdateRequest(newName), + ) assertEquals(newName, organizationApiService.getOrganization(organizationUpdated.id).name) @@ -1248,7 +1489,9 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { // Update organization with null value as name organizationApiService.updateOrganization( - organizationUpdated.id, OrganizationUpdateRequest(null)) + organizationUpdated.id, + OrganizationUpdateRequest(null), + ) assertEquals(newName, organizationApiService.getOrganization(organizationUpdated.id).name) } @@ -1262,14 +1505,21 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val organizationRegistered = organizationApiService.createOrganization( makeOrganizationCreateRequestWithSimpleSecurity( - name, TEST_ADMIN_USER_ID, ROLE_NONE, ROLE_EDITOR)) + name, + TEST_ADMIN_USER_ID, + ROLE_NONE, + ROLE_EDITOR, + ) + ) runAsPlatformAdmin() val newName = "my-new-name" val organizationUpdated = organizationApiService.updateOrganization( - organizationRegistered.id, OrganizationUpdateRequest(newName)) + organizationRegistered.id, + OrganizationUpdateRequest(newName), + ) assertEquals(newName, organizationApiService.getOrganization(organizationUpdated.id).name) @@ -1280,7 +1530,9 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { // Update organization with null value as name organizationApiService.updateOrganization( - organizationUpdated.id, OrganizationUpdateRequest(null)) + organizationUpdated.id, + OrganizationUpdateRequest(null), + ) assertEquals(newName, organizationApiService.getOrganization(organizationUpdated.id).name) } @@ -1297,7 +1549,9 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val newName = "my-new-name" val organizationUpdated = organizationApiService.updateOrganization( - organizationRegistered.id, OrganizationUpdateRequest(newName)) + organizationRegistered.id, + OrganizationUpdateRequest(newName), + ) assertEquals(newName, organizationApiService.getOrganization(organizationUpdated.id).name) @@ -1308,7 +1562,9 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { // Update organization with null value as name organizationApiService.updateOrganization( - organizationUpdated.id, OrganizationUpdateRequest(null)) + organizationUpdated.id, + OrganizationUpdateRequest(null), + ) assertEquals(newName, organizationApiService.getOrganization(organizationUpdated.id).name) } @@ -1328,13 +1584,15 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { mutableListOf( PERMISSION_READ, PERMISSION_READ_SECURITY, - PERMISSION_CREATE_CHILDREN), + PERMISSION_CREATE_CHILDREN, + ), ROLE_EDITOR to mutableListOf( PERMISSION_READ, PERMISSION_READ_SECURITY, PERMISSION_CREATE_CHILDREN, - PERMISSION_WRITE), + PERMISSION_WRITE, + ), ROLE_ADMIN to mutableListOf( PERMISSION_READ, @@ -1342,8 +1600,10 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { PERMISSION_CREATE_CHILDREN, PERMISSION_WRITE, PERMISSION_WRITE_SECURITY, - PERMISSION_DELETE), - )), + PERMISSION_DELETE, + ), + ), + ), ComponentRolePermissions( component = "workspace", roles = @@ -1354,13 +1614,15 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { mutableListOf( PERMISSION_READ, PERMISSION_READ_SECURITY, - PERMISSION_CREATE_CHILDREN), + PERMISSION_CREATE_CHILDREN, + ), ROLE_EDITOR to mutableListOf( PERMISSION_READ, PERMISSION_READ_SECURITY, PERMISSION_CREATE_CHILDREN, - PERMISSION_WRITE), + PERMISSION_WRITE, + ), ROLE_ADMIN to mutableListOf( PERMISSION_READ, @@ -1368,8 +1630,10 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { PERMISSION_CREATE_CHILDREN, PERMISSION_WRITE, PERMISSION_WRITE_SECURITY, - PERMISSION_DELETE), - )), + PERMISSION_DELETE, + ), + ), + ), ComponentRolePermissions( component = "runner", roles = @@ -1381,14 +1645,16 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { PERMISSION_READ, PERMISSION_READ_SECURITY, PERMISSION_LAUNCH, - PERMISSION_WRITE), + PERMISSION_WRITE, + ), ROLE_VALIDATOR to mutableListOf( PERMISSION_READ, PERMISSION_READ_SECURITY, PERMISSION_LAUNCH, PERMISSION_WRITE, - PERMISSION_VALIDATE), + PERMISSION_VALIDATE, + ), ROLE_ADMIN to mutableListOf( PERMISSION_READ, @@ -1397,8 +1663,11 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { PERMISSION_WRITE, PERMISSION_VALIDATE, PERMISSION_WRITE_SECURITY, - PERMISSION_DELETE), - ))) + PERMISSION_DELETE, + ), + ), + ), + ) assertEquals(mapAllPermissions, organizationApiService.listPermissions()) } @@ -1415,7 +1684,8 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { organizationApiService.getOrganizationPermissions(organizationRegistered.id, ROLE_USER) assertEquals( mutableListOf(PERMISSION_READ, PERMISSION_READ_SECURITY, PERMISSION_CREATE_CHILDREN), - organizationUserPermissions) + organizationUserPermissions, + ) organizationUserPermissions = organizationApiService.getOrganizationPermissions(organizationRegistered.id, ROLE_EDITOR) assertEquals( @@ -1423,8 +1693,10 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { PERMISSION_READ, PERMISSION_READ_SECURITY, PERMISSION_CREATE_CHILDREN, - PERMISSION_WRITE), - organizationUserPermissions) + PERMISSION_WRITE, + ), + organizationUserPermissions, + ) organizationUserPermissions = organizationApiService.getOrganizationPermissions(organizationRegistered.id, ROLE_ADMIN) assertEquals( @@ -1434,11 +1706,15 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { PERMISSION_CREATE_CHILDREN, PERMISSION_WRITE, PERMISSION_WRITE_SECURITY, - PERMISSION_DELETE), - organizationUserPermissions) + PERMISSION_DELETE, + ), + organizationUserPermissions, + ) organizationUserPermissions = organizationApiService.getOrganizationPermissions( - organizationRegistered.id, UNKNOWN_IDENTIFIER) + organizationRegistered.id, + UNKNOWN_IDENTIFIER, + ) assertEquals(emptyList(), organizationUserPermissions) } } @@ -1451,7 +1727,12 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val organizationRegistered = organizationApiService.createOrganization( makeOrganizationCreateRequestWithSimpleSecurity( - name, TEST_USER_ID, ROLE_NONE, ROLE_VIEWER)) + name, + TEST_USER_ID, + ROLE_NONE, + ROLE_VIEWER, + ) + ) runAsPlatformAdmin() var organizationUserPermissions = organizationApiService.getOrganizationPermissions(organizationRegistered.id, ROLE_VIEWER) @@ -1460,7 +1741,8 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { organizationApiService.getOrganizationPermissions(organizationRegistered.id, ROLE_USER) assertEquals( mutableListOf(PERMISSION_READ, PERMISSION_READ_SECURITY, PERMISSION_CREATE_CHILDREN), - organizationUserPermissions) + organizationUserPermissions, + ) organizationUserPermissions = organizationApiService.getOrganizationPermissions(organizationRegistered.id, ROLE_EDITOR) assertEquals( @@ -1468,8 +1750,10 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { PERMISSION_READ, PERMISSION_READ_SECURITY, PERMISSION_CREATE_CHILDREN, - PERMISSION_WRITE), - organizationUserPermissions) + PERMISSION_WRITE, + ), + organizationUserPermissions, + ) organizationUserPermissions = organizationApiService.getOrganizationPermissions(organizationRegistered.id, ROLE_ADMIN) assertEquals( @@ -1479,11 +1763,15 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { PERMISSION_CREATE_CHILDREN, PERMISSION_WRITE, PERMISSION_WRITE_SECURITY, - PERMISSION_DELETE), - organizationUserPermissions) + PERMISSION_DELETE, + ), + organizationUserPermissions, + ) organizationUserPermissions = organizationApiService.getOrganizationPermissions( - organizationRegistered.id, UNKNOWN_IDENTIFIER) + organizationRegistered.id, + UNKNOWN_IDENTIFIER, + ) assertEquals(emptyList(), organizationUserPermissions) } } @@ -1496,7 +1784,12 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val organizationRegistered = organizationApiService.createOrganization( makeOrganizationCreateRequestWithSimpleSecurity( - name, TEST_USER_ID, ROLE_NONE, ROLE_VIEWER)) + name, + TEST_USER_ID, + ROLE_NONE, + ROLE_VIEWER, + ) + ) runAsPlatformAdmin() var organizationUserPermissions = organizationApiService.getOrganizationPermissions(organizationRegistered.id, ROLE_VIEWER) @@ -1505,7 +1798,8 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { organizationApiService.getOrganizationPermissions(organizationRegistered.id, ROLE_USER) assertEquals( mutableListOf(PERMISSION_READ, PERMISSION_READ_SECURITY, PERMISSION_CREATE_CHILDREN), - organizationUserPermissions) + organizationUserPermissions, + ) organizationUserPermissions = organizationApiService.getOrganizationPermissions(organizationRegistered.id, ROLE_EDITOR) assertEquals( @@ -1513,8 +1807,10 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { PERMISSION_READ, PERMISSION_READ_SECURITY, PERMISSION_CREATE_CHILDREN, - PERMISSION_WRITE), - organizationUserPermissions) + PERMISSION_WRITE, + ), + organizationUserPermissions, + ) organizationUserPermissions = organizationApiService.getOrganizationPermissions(organizationRegistered.id, ROLE_ADMIN) assertEquals( @@ -1524,11 +1820,15 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { PERMISSION_CREATE_CHILDREN, PERMISSION_WRITE, PERMISSION_WRITE_SECURITY, - PERMISSION_DELETE), - organizationUserPermissions) + PERMISSION_DELETE, + ), + organizationUserPermissions, + ) organizationUserPermissions = organizationApiService.getOrganizationPermissions( - organizationRegistered.id, UNKNOWN_IDENTIFIER) + organizationRegistered.id, + UNKNOWN_IDENTIFIER, + ) assertEquals(emptyList(), organizationUserPermissions) } } @@ -1566,7 +1866,12 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val organizationRegistered = organizationApiService.createOrganization( makeOrganizationCreateRequestWithSimpleSecurity( - name, TEST_USER_ID, ROLE_NONE, ROLE_VIEWER)) + name, + TEST_USER_ID, + ROLE_NONE, + ROLE_VIEWER, + ) + ) runAsPlatformAdmin() assertNotNull(organizationApiService.getOrganizationSecurity(organizationRegistered.id)) } @@ -1580,7 +1885,12 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val organizationRegistered = organizationApiService.createOrganization( makeOrganizationCreateRequestWithSimpleSecurity( - name, defaultName, ROLE_NONE, ROLE_NONE)) + name, + defaultName, + ROLE_NONE, + ROLE_NONE, + ) + ) runAsPlatformAdmin() assertNotNull(organizationApiService.getOrganizationSecurity(organizationRegistered.id)) } @@ -1595,7 +1905,10 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val defaultRoleCreated = organizationRegistered.security.default assertNotNull( organizationApiService.updateOrganizationDefaultSecurity( - organizationRegistered.id, OrganizationRole(ROLE_ADMIN))) + organizationRegistered.id, + OrganizationRole(ROLE_ADMIN), + ) + ) val defaultRoleUpdated = organizationApiService.getOrganizationSecurity(organizationRegistered.id).default assertNotEquals(defaultRoleCreated, defaultRoleUpdated) @@ -1609,7 +1922,9 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val organizationRegistered = organizationApiService.createOrganization(makeSimpleOrganizationCreateRequest(name)) organizationApiService.updateOrganizationDefaultSecurity( - organizationRegistered.id, OrganizationRole(UNKNOWN_IDENTIFIER)) + organizationRegistered.id, + OrganizationRole(UNKNOWN_IDENTIFIER), + ) } } @@ -1624,7 +1939,10 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { runAsPlatformAdmin() assertNotNull( organizationApiService.updateOrganizationDefaultSecurity( - organizationRegistered.id, OrganizationRole(ROLE_ADMIN))) + organizationRegistered.id, + OrganizationRole(ROLE_ADMIN), + ) + ) val defaultRoleUpdated = organizationApiService.getOrganizationSecurity(organizationRegistered.id).default assertNotEquals(defaultRoleCreated, defaultRoleUpdated) @@ -1639,12 +1957,20 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val organizationRegistered = organizationApiService.createOrganization( makeOrganizationCreateRequestWithSimpleSecurity( - name, TEST_ADMIN_USER_ID, ROLE_NONE, ROLE_NONE)) + name, + TEST_ADMIN_USER_ID, + ROLE_NONE, + ROLE_NONE, + ) + ) val defaultRoleCreated = organizationRegistered.security.default runAsPlatformAdmin() assertNotNull( organizationApiService.updateOrganizationDefaultSecurity( - organizationRegistered.id, OrganizationRole(ROLE_ADMIN))) + organizationRegistered.id, + OrganizationRole(ROLE_ADMIN), + ) + ) val defaultRoleUpdated = organizationApiService.getOrganizationSecurity(organizationRegistered.id).default assertNotEquals(defaultRoleCreated, defaultRoleUpdated) @@ -1659,7 +1985,9 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { organizationApiService.createOrganization(makeSimpleOrganizationCreateRequest(name)) val organizationRole = organizationApiService.getOrganizationAccessControl( - organizationRegistered.id, defaultName) + organizationRegistered.id, + defaultName, + ) assertNotNull(organizationRole) assertEquals(ROLE_ADMIN, organizationRole.role) assertEquals(defaultName, organizationRole.id) @@ -1684,11 +2012,18 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val organizationRegistered = organizationApiService.createOrganization( makeOrganizationCreateRequestWithSimpleSecurity( - name, TEST_USER_ID, ROLE_NONE, ROLE_VIEWER)) + name, + TEST_USER_ID, + ROLE_NONE, + ROLE_VIEWER, + ) + ) runAsPlatformAdmin() val organizationRole = organizationApiService.getOrganizationAccessControl( - organizationRegistered.id, TEST_USER_ID) + organizationRegistered.id, + TEST_USER_ID, + ) assertNotNull(organizationRole) assertEquals(ROLE_VIEWER, organizationRole.role) assertEquals(TEST_USER_ID, organizationRole.id) @@ -1703,10 +2038,17 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val organizationRegistered = organizationApiService.createOrganization( makeOrganizationCreateRequestWithSimpleSecurity( - name, TEST_USER_ID, ROLE_NONE, ROLE_VIEWER)) + name, + TEST_USER_ID, + ROLE_NONE, + ROLE_VIEWER, + ) + ) runAsPlatformAdmin() organizationApiService.getOrganizationAccessControl( - organizationRegistered.id, UNKNOWN_IDENTIFIER) + organizationRegistered.id, + UNKNOWN_IDENTIFIER, + ) } } @@ -1718,10 +2060,17 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val organizationRegistered = organizationApiService.createOrganization( makeOrganizationCreateRequestWithSimpleSecurity( - name, TEST_ADMIN_USER_ID, ROLE_NONE, ROLE_NONE)) + name, + TEST_ADMIN_USER_ID, + ROLE_NONE, + ROLE_NONE, + ) + ) runAsPlatformAdmin() organizationApiService.getOrganizationAccessControl( - organizationRegistered.id, UNKNOWN_IDENTIFIER) + organizationRegistered.id, + UNKNOWN_IDENTIFIER, + ) } } @@ -1733,11 +2082,18 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val organizationRegistered = organizationApiService.createOrganization( makeOrganizationCreateRequestWithSimpleSecurity( - name, TEST_USER_ID, ROLE_NONE, ROLE_NONE)) + name, + TEST_USER_ID, + ROLE_NONE, + ROLE_NONE, + ) + ) runAsPlatformAdmin() val organizationAccessControl = organizationApiService.getOrganizationAccessControl( - organizationRegistered.id, TEST_USER_ID) + organizationRegistered.id, + TEST_USER_ID, + ) assertNotNull(organizationAccessControl) assertEquals(TEST_USER_ID, organizationAccessControl.id) assertEquals(ROLE_NONE, organizationAccessControl.role) @@ -1752,18 +2108,27 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { organizationApiService.createOrganization(makeSimpleOrganizationCreateRequest(name)) assertThrows { organizationApiService.getOrganizationAccessControl( - organizationRegistered.id, OTHER_TEST_USER_ID) + organizationRegistered.id, + OTHER_TEST_USER_ID, + ) } val otherUserACL = OrganizationAccessControl(id = OTHER_TEST_USER_ID, role = ROLE_VIEWER) assertNotNull( organizationApiService.createOrganizationAccessControl( - organizationRegistered.id, otherUserACL)) + organizationRegistered.id, + otherUserACL, + ) + ) val otherUserACLRetrieved = organizationApiService.getOrganizationAccessControl( - organizationRegistered.id, OTHER_TEST_USER_ID) + organizationRegistered.id, + OTHER_TEST_USER_ID, + ) assertEquals( - OrganizationAccessControl(OTHER_TEST_USER_ID, ROLE_VIEWER), otherUserACLRetrieved) + OrganizationAccessControl(OTHER_TEST_USER_ID, ROLE_VIEWER), + otherUserACLRetrieved, + ) } } @@ -1775,7 +2140,12 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val organizationRegistered = organizationApiService.createOrganization( makeOrganizationCreateRequestWithSimpleSecurity( - name, TEST_ADMIN_USER_ID, ROLE_NONE, ROLE_ADMIN)) + name, + TEST_ADMIN_USER_ID, + ROLE_NONE, + ROLE_ADMIN, + ) + ) runAsPlatformAdmin() assertThrows { organizationApiService.getOrganizationAccessControl(organizationRegistered.id, TEST_USER_ID) @@ -1783,11 +2153,16 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val otherUserACL = OrganizationAccessControl(id = TEST_USER_ID, role = ROLE_VIEWER) assertNotNull( organizationApiService.createOrganizationAccessControl( - organizationRegistered.id, otherUserACL)) + organizationRegistered.id, + otherUserACL, + ) + ) val otherUserACLRetrieved = organizationApiService.getOrganizationAccessControl( - organizationRegistered.id, TEST_USER_ID) + organizationRegistered.id, + TEST_USER_ID, + ) assertEquals(otherUserACL, otherUserACLRetrieved) } } @@ -1800,7 +2175,12 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val organizationRegistered = organizationApiService.createOrganization( makeOrganizationCreateRequestWithSimpleSecurity( - name, defaultName, ROLE_NONE, ROLE_NONE)) + name, + defaultName, + ROLE_NONE, + ROLE_NONE, + ) + ) runAsPlatformAdmin() assertThrows { organizationApiService.getOrganizationAccessControl(organizationRegistered.id, TEST_USER_ID) @@ -1808,11 +2188,16 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val otherUserACL = OrganizationAccessControl(id = TEST_USER_ID, role = ROLE_VIEWER) assertNotNull( organizationApiService.createOrganizationAccessControl( - organizationRegistered.id, otherUserACL)) + organizationRegistered.id, + otherUserACL, + ) + ) val otherUserACLRetrieved = organizationApiService.getOrganizationAccessControl( - organizationRegistered.id, TEST_USER_ID) + organizationRegistered.id, + TEST_USER_ID, + ) assertEquals(otherUserACL, otherUserACLRetrieved) } } @@ -1824,7 +2209,10 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val organizationRegistered = organizationApiService.createOrganization(makeSimpleOrganizationCreateRequest(name)) organizationApiService.updateOrganizationAccessControl( - organizationRegistered.id, defaultName, OrganizationRole(role = ROLE_VIEWER)) + organizationRegistered.id, + defaultName, + OrganizationRole(role = ROLE_VIEWER), + ) } } @@ -1837,15 +2225,22 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { organizationApiService.createOrganizationAccessControl( organizationRegistered.id, - OrganizationAccessControl(id = OTHER_TEST_USER_ID, role = ROLE_VIEWER)) + OrganizationAccessControl(id = OTHER_TEST_USER_ID, role = ROLE_VIEWER), + ) assertNotNull( organizationApiService.updateOrganizationAccessControl( - organizationRegistered.id, OTHER_TEST_USER_ID, OrganizationRole(role = ROLE_EDITOR))) + organizationRegistered.id, + OTHER_TEST_USER_ID, + OrganizationRole(role = ROLE_EDITOR), + ) + ) val userACLRetrieved = organizationApiService.getOrganizationAccessControl( - organizationRegistered.id, OTHER_TEST_USER_ID) + organizationRegistered.id, + OTHER_TEST_USER_ID, + ) assertNotEquals(ROLE_VIEWER, userACLRetrieved.role) assertEquals(ROLE_EDITOR, userACLRetrieved.role) } @@ -1859,7 +2254,10 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { organizationApiService.createOrganization(makeSimpleOrganizationCreateRequest(name)) organizationApiService.updateOrganizationAccessControl( - organizationRegistered.id, TEST_USER_ID, OrganizationRole(role = ROLE_NONE)) + organizationRegistered.id, + TEST_USER_ID, + OrganizationRole(role = ROLE_NONE), + ) } } @@ -1871,7 +2269,10 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { organizationApiService.createOrganization(makeSimpleOrganizationCreateRequest(name)) organizationApiService.updateOrganizationAccessControl( - organizationRegistered.id, UNKNOWN_IDENTIFIER, OrganizationRole(role = ROLE_EDITOR)) + organizationRegistered.id, + UNKNOWN_IDENTIFIER, + OrganizationRole(role = ROLE_EDITOR), + ) } } @@ -1883,7 +2284,10 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { organizationApiService.createOrganization(makeSimpleOrganizationCreateRequest(name)) organizationApiService.updateOrganizationAccessControl( - organizationRegistered.id, TEST_USER_ID, OrganizationRole(role = UNKNOWN_IDENTIFIER)) + organizationRegistered.id, + TEST_USER_ID, + OrganizationRole(role = UNKNOWN_IDENTIFIER), + ) } } @@ -1897,17 +2301,24 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { organizationApiService.createOrganizationAccessControl( organizationRegistered.id, - OrganizationAccessControl(id = TEST_ADMIN_USER_ID, role = ROLE_ADMIN)) + OrganizationAccessControl(id = TEST_ADMIN_USER_ID, role = ROLE_ADMIN), + ) runAsPlatformAdmin() assertNotNull( organizationApiService.updateOrganizationAccessControl( - organizationRegistered.id, OTHER_TEST_USER_ID, OrganizationRole(role = ROLE_EDITOR))) + organizationRegistered.id, + OTHER_TEST_USER_ID, + OrganizationRole(role = ROLE_EDITOR), + ) + ) val userACLRetrieved = organizationApiService.getOrganizationAccessControl( - organizationRegistered.id, OTHER_TEST_USER_ID) + organizationRegistered.id, + OTHER_TEST_USER_ID, + ) assertEquals(ROLE_EDITOR, userACLRetrieved.role) } } @@ -1922,17 +2333,24 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { organizationApiService.createOrganizationAccessControl( organizationRegistered.id, - OrganizationAccessControl(id = TEST_ADMIN_USER_ID, role = ROLE_VIEWER)) + OrganizationAccessControl(id = TEST_ADMIN_USER_ID, role = ROLE_VIEWER), + ) runAsPlatformAdmin() assertNotNull( organizationApiService.updateOrganizationAccessControl( - organizationRegistered.id, TEST_ADMIN_USER_ID, OrganizationRole(role = ROLE_EDITOR))) + organizationRegistered.id, + TEST_ADMIN_USER_ID, + OrganizationRole(role = ROLE_EDITOR), + ) + ) val userACLRetrieved = organizationApiService.getOrganizationAccessControl( - organizationRegistered.id, TEST_ADMIN_USER_ID) + organizationRegistered.id, + TEST_ADMIN_USER_ID, + ) assertEquals(ROLE_EDITOR, userACLRetrieved.role) } } @@ -1947,12 +2365,16 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { organizationApiService.createOrganizationAccessControl( organizationRegistered.id, - OrganizationAccessControl(id = TEST_USER_ID, role = ROLE_VIEWER)) + OrganizationAccessControl(id = TEST_USER_ID, role = ROLE_VIEWER), + ) runAsPlatformAdmin() organizationApiService.updateOrganizationAccessControl( - organizationRegistered.id, OTHER_TEST_USER_ID, OrganizationRole(role = ROLE_NONE)) + organizationRegistered.id, + OTHER_TEST_USER_ID, + OrganizationRole(role = ROLE_NONE), + ) } } @@ -1966,10 +2388,14 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { organizationApiService.createOrganizationAccessControl(organizationRegistered.id, otherUserACL) organizationApiService.deleteOrganizationAccessControl( - organizationRegistered.id, OTHER_TEST_USER_ID) + organizationRegistered.id, + OTHER_TEST_USER_ID, + ) assertThrows { organizationApiService.getOrganizationAccessControl( - organizationRegistered.id, OTHER_TEST_USER_ID) + organizationRegistered.id, + OTHER_TEST_USER_ID, + ) } } @@ -1985,10 +2411,14 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { runAsPlatformAdmin() organizationApiService.deleteOrganizationAccessControl( - organizationRegistered.id, OTHER_TEST_USER_ID) + organizationRegistered.id, + OTHER_TEST_USER_ID, + ) assertThrows { organizationApiService.getOrganizationAccessControl( - organizationRegistered.id, OTHER_TEST_USER_ID) + organizationRegistered.id, + OTHER_TEST_USER_ID, + ) } } @@ -2004,10 +2434,14 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { runAsPlatformAdmin() organizationApiService.deleteOrganizationAccessControl( - organizationRegistered.id, OTHER_TEST_USER_ID) + organizationRegistered.id, + OTHER_TEST_USER_ID, + ) assertThrows { organizationApiService.getOrganizationAccessControl( - organizationRegistered.id, OTHER_TEST_USER_ID) + organizationRegistered.id, + OTHER_TEST_USER_ID, + ) } } @@ -2028,7 +2462,12 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val organizationRegistered = organizationApiService.createOrganization( makeOrganizationCreateRequestWithSimpleSecurity( - name, TEST_USER_ID, ROLE_NONE, ROLE_VIEWER)) + name, + TEST_USER_ID, + ROLE_NONE, + ROLE_VIEWER, + ) + ) runAsPlatformAdmin() val orgaUsers = organizationApiService.listOrganizationSecurityUsers(organizationRegistered.id) assertEquals(listOf(TEST_USER_ID, OTHER_TEST_USER_ID), orgaUsers) @@ -2041,7 +2480,12 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val organizationRegistered = organizationApiService.createOrganization( makeOrganizationCreateRequestWithSimpleSecurity( - name, TEST_USER_ID, ROLE_NONE, ROLE_NONE)) + name, + TEST_USER_ID, + ROLE_NONE, + ROLE_NONE, + ) + ) runAsPlatformAdmin() val orgaUsers = organizationApiService.listOrganizationSecurityUsers(organizationRegistered.id) assertEquals(listOf(TEST_USER_ID, OTHER_TEST_USER_ID), orgaUsers) @@ -2058,7 +2502,10 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { accessControlList = mutableListOf( OrganizationAccessControl(TEST_USER_ID, ROLE_ADMIN), - OrganizationAccessControl(TEST_USER_ID, ROLE_EDITOR)))) + OrganizationAccessControl(TEST_USER_ID, ROLE_EDITOR), + ), + ), + ) assertThrows { organizationApiService.createOrganization(brokenOrganization) } @@ -2073,12 +2520,16 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { OrganizationSecurity( default = ROLE_NONE, accessControlList = - mutableListOf(OrganizationAccessControl(defaultName, ROLE_ADMIN)))) + mutableListOf(OrganizationAccessControl(defaultName, ROLE_ADMIN)), + ), + ) val organizationSaved = organizationApiService.createOrganization(workingOrganization) assertThrows { organizationApiService.createOrganizationAccessControl( - organizationSaved.id, OrganizationAccessControl(defaultName, ROLE_EDITOR)) + organizationSaved.id, + OrganizationAccessControl(defaultName, ROLE_EDITOR), + ) } } @@ -2101,7 +2552,12 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { val organizationRegistered = organizationApiService.createOrganization( makeOrganizationCreateRequestWithSimpleSecurity( - name, TEST_USER_ID, ROLE_NONE, ROLE_NONE)) + name, + TEST_USER_ID, + ROLE_NONE, + ROLE_NONE, + ) + ) runAsPlatformAdmin() assertDoesNotThrow { val organizationVerified = @@ -2121,14 +2577,17 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { fun `assert timestamps are functional for base CRUD`() { val organizationSaved = organizationApiService.createOrganization( - makeSimpleOrganizationCreateRequest("organization")) + makeSimpleOrganizationCreateRequest("organization") + ) assertTrue(organizationSaved.createInfo.timestamp >= startTime) assertEquals(organizationSaved.createInfo, organizationSaved.updateInfo) val updateTime = Instant.now().toEpochMilli() val organizationUpdated = organizationApiService.updateOrganization( - organizationSaved.id, OrganizationUpdateRequest("organizationUpdated")) + organizationSaved.id, + OrganizationUpdateRequest("organizationUpdated"), + ) assertTrue { updateTime < organizationUpdated.updateInfo.timestamp } assertEquals(organizationSaved.createInfo, organizationUpdated.createInfo) @@ -2145,9 +2604,12 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { fun `assert timestamps are functional for RBAC CRUD`() { val organizationSaved = organizationApiService.createOrganization( - makeSimpleOrganizationCreateRequest("organization")) + makeSimpleOrganizationCreateRequest("organization") + ) organizationApiService.createOrganizationAccessControl( - organizationSaved.id, OrganizationAccessControl("newUser", ROLE_USER)) + organizationSaved.id, + OrganizationAccessControl("newUser", ROLE_USER), + ) val rbacAdded = organizationApiService.getOrganization(organizationSaved.id) @@ -2155,7 +2617,10 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { assertTrue { organizationSaved.updateInfo.timestamp < rbacAdded.updateInfo.timestamp } organizationApiService.updateOrganizationAccessControl( - organizationSaved.id, "newUser", OrganizationRole(ROLE_VIEWER)) + organizationSaved.id, + "newUser", + OrganizationRole(ROLE_VIEWER), + ) val rbacUpdated = organizationApiService.getOrganization(organizationSaved.id) assertEquals(rbacAdded.createInfo, rbacUpdated.createInfo) @@ -2176,7 +2641,7 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { private fun testFindAllWithRBAC( numberOfOrganizationCreated: Int, - numberOfOrganizationReachableByTestUser: Int + numberOfOrganizationReachableByTestUser: Int, ) { val defaultPageSize = csmPlatformProperties.databases.resources.organization.defaultPageSize @@ -2204,14 +2669,18 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { defaultRole: String?, userRole: String?, throwException: Boolean, - rungetOrganizationAs: () -> Unit + rungetOrganizationAs: () -> Unit, ) { runAsDifferentOrganizationUser() val organizationId = "o-connector-test-1" val organization = if (hasUserSecurity) { makeOrganizationCreateRequestWithSimpleSecurity( - organizationId, userId!!, defaultRole!!, userRole!!) + organizationId, + userId!!, + defaultRole!!, + userRole!!, + ) } else { makeSimpleOrganizationCreateRequest(organizationId) } @@ -2283,7 +2752,8 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { "Organization with $defaultSecurity as default and $userId as $securityRole", userId, defaultSecurity, - securityRole) + securityRole, + ) organizationApiService.createOrganization(organization) numberOfOrganizationCreated++ } @@ -2309,13 +2779,15 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { OrganizationSecurity( default = defaultSecurity, accessControlList = - mutableListOf(OrganizationAccessControl(id = userName, role = role)))) + mutableListOf(OrganizationAccessControl(id = userName, role = role)), + ), + ) } fun makeOrganizationCreateRequest( id: String = "organization_id", userName: String = TEST_USER_ID, - role: String = ROLE_ADMIN + role: String = ROLE_ADMIN, ): OrganizationCreateRequest { return OrganizationCreateRequest( name = "Organization Name", @@ -2325,7 +2797,10 @@ class OrganizationServiceIntegrationTest : CsmTestBase() { accessControlList = mutableListOf( OrganizationAccessControl(id = TEST_ADMIN_USER_ID, role = "admin"), - OrganizationAccessControl(id = userName, role = role)))) + OrganizationAccessControl(id = userName, role = role), + ), + ), + ) } internal fun testlistOrganizations(page: Int?, size: Int?, expectedResultSize: Int) { diff --git a/organization/src/integrationTest/kotlin/com/cosmotech/organization/service/OrganizationServiceRBACTest.kt b/organization/src/integrationTest/kotlin/com/cosmotech/organization/service/OrganizationServiceRBACTest.kt index 7924b6462..87d6807bb 100644 --- a/organization/src/integrationTest/kotlin/com/cosmotech/organization/service/OrganizationServiceRBACTest.kt +++ b/organization/src/integrationTest/kotlin/com/cosmotech/organization/service/OrganizationServiceRBACTest.kt @@ -89,7 +89,8 @@ class OrganizationServiceRBACTest : CsmTestBase() { .map { (role, shouldThrow) -> DynamicTest.dynamicTest("Test RBAC listOrganizations : $role") { organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role) + ) val organizations = organizationApiService.listOrganizations(null, null) assertEquals(shouldThrow, organizations.size) @@ -111,7 +112,8 @@ class OrganizationServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL val organization = organizationApiService.createOrganization( - makeOrganizationCreateRequest(TEST_USER_MAIL, role)) + makeOrganizationCreateRequest(TEST_USER_MAIL, role) + ) if (shouldThrow) { val exception = @@ -120,7 +122,8 @@ class OrganizationServiceRBACTest : CsmTestBase() { } assertEquals( "RBAC ${organization.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { organizationApiService.getOrganization(organization.id) } } @@ -141,7 +144,8 @@ class OrganizationServiceRBACTest : CsmTestBase() { DynamicTest.dynamicTest("Test RBAC deleteOrganization : $role") { val organization = organizationApiService.createOrganization( - makeOrganizationCreateRequest(TEST_USER_MAIL, role)) + makeOrganizationCreateRequest(TEST_USER_MAIL, role) + ) if (shouldThrow) { val exception = @@ -150,7 +154,8 @@ class OrganizationServiceRBACTest : CsmTestBase() { } assertEquals( "RBAC ${organization.id} - User does not have permission $PERMISSION_DELETE", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { organizationApiService.deleteOrganization(organization.id) } } @@ -171,21 +176,27 @@ class OrganizationServiceRBACTest : CsmTestBase() { DynamicTest.dynamicTest("Test RBAC updateOrganization : $role") { val organization = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role) + ) if (shouldThrow) { val exception = assertThrows { organizationApiService.updateOrganization( - organization.id, OrganizationUpdateRequest("name")) + organization.id, + OrganizationUpdateRequest("name"), + ) } assertEquals( "RBAC ${organization.id} - User does not have permission $PERMISSION_WRITE", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { organizationApiService.updateOrganization( - organization.id, OrganizationUpdateRequest("name")) + organization.id, + OrganizationUpdateRequest("name"), + ) } } } @@ -205,7 +216,8 @@ class OrganizationServiceRBACTest : CsmTestBase() { DynamicTest.dynamicTest("Test RBAC getOrganizationPermissions : $role") { val organization = organizationApiService.createOrganization( - makeOrganizationCreateRequest(TEST_USER_MAIL, role)) + makeOrganizationCreateRequest(TEST_USER_MAIL, role) + ) if (shouldThrow) { val exception = @@ -214,7 +226,8 @@ class OrganizationServiceRBACTest : CsmTestBase() { } assertEquals( "RBAC ${organization.id} - User does not have permission $PERMISSION_READ_SECURITY", - exception.message) + exception.message, + ) } else assertDoesNotThrow { organizationApiService.getOrganizationPermissions(organization.id, role) @@ -236,7 +249,8 @@ class OrganizationServiceRBACTest : CsmTestBase() { DynamicTest.dynamicTest("Test RBAC getOrganizationSecurity : $role") { val organization = organizationApiService.createOrganization( - makeOrganizationCreateRequest(TEST_USER_MAIL, role)) + makeOrganizationCreateRequest(TEST_USER_MAIL, role) + ) if (shouldThrow) { val exception = @@ -245,7 +259,8 @@ class OrganizationServiceRBACTest : CsmTestBase() { } assertEquals( "RBAC ${organization.id} - User does not have permission $PERMISSION_READ_SECURITY", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { organizationApiService.getOrganizationSecurity(organization.id) @@ -268,21 +283,27 @@ class OrganizationServiceRBACTest : CsmTestBase() { DynamicTest.dynamicTest("Test RBAC updateOrganizationDefaultSecurity : $role") { val organization = organizationApiService.createOrganization( - makeOrganizationCreateRequest(TEST_USER_MAIL, role)) + makeOrganizationCreateRequest(TEST_USER_MAIL, role) + ) if (shouldThrow) { val exception = assertThrows { organizationApiService.updateOrganizationDefaultSecurity( - organization.id, OrganizationRole(role)) + organization.id, + OrganizationRole(role), + ) } assertEquals( "RBAC ${organization.id} - User does not have permission $PERMISSION_WRITE_SECURITY", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { organizationApiService.updateOrganizationDefaultSecurity( - organization.id, OrganizationRole(role)) + organization.id, + OrganizationRole(role), + ) } } } @@ -302,21 +323,27 @@ class OrganizationServiceRBACTest : CsmTestBase() { DynamicTest.dynamicTest("Test RBAC createOrganizationAccessControl : $role") { val organization = organizationApiService.createOrganization( - makeOrganizationCreateRequest(TEST_USER_MAIL, role)) + makeOrganizationCreateRequest(TEST_USER_MAIL, role) + ) if (shouldThrow) { val exception = assertThrows { organizationApiService.createOrganizationAccessControl( - organization.id, OrganizationAccessControl("id", role)) + organization.id, + OrganizationAccessControl("id", role), + ) } assertEquals( "RBAC ${organization.id} - User does not have permission $PERMISSION_WRITE_SECURITY", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { organizationApiService.createOrganizationAccessControl( - organization.id, OrganizationAccessControl("id", role)) + organization.id, + OrganizationAccessControl("id", role), + ) } } } @@ -336,21 +363,27 @@ class OrganizationServiceRBACTest : CsmTestBase() { DynamicTest.dynamicTest("Test RBAC getOrganizationAccessControl : $role") { val organization = organizationApiService.createOrganization( - makeOrganizationCreateRequest(TEST_USER_MAIL, role)) + makeOrganizationCreateRequest(TEST_USER_MAIL, role) + ) if (shouldThrow) { val exception = assertThrows { organizationApiService.getOrganizationAccessControl( - organization.id, TEST_USER_MAIL) + organization.id, + TEST_USER_MAIL, + ) } assertEquals( "RBAC ${organization.id} - User does not have permission $PERMISSION_READ_SECURITY", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { organizationApiService.getOrganizationAccessControl( - organization.id, TEST_USER_MAIL) + organization.id, + TEST_USER_MAIL, + ) } } } @@ -370,21 +403,27 @@ class OrganizationServiceRBACTest : CsmTestBase() { DynamicTest.dynamicTest("Test RBAC deleteOrganizationAccessControl : $role") { val organization = organizationApiService.createOrganization( - makeOrganizationCreateRequest(TEST_USER_MAIL, role)) + makeOrganizationCreateRequest(TEST_USER_MAIL, role) + ) if (shouldThrow) { val exception = assertThrows { organizationApiService.deleteOrganizationAccessControl( - organization.id, TEST_USER_MAIL) + organization.id, + TEST_USER_MAIL, + ) } assertEquals( "RBAC ${organization.id} - User does not have permission $PERMISSION_WRITE_SECURITY", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { organizationApiService.deleteOrganizationAccessControl( - organization.id, TEST_USER_MAIL) + organization.id, + TEST_USER_MAIL, + ) } } } @@ -404,21 +443,29 @@ class OrganizationServiceRBACTest : CsmTestBase() { DynamicTest.dynamicTest("Test RBAC updateOrganizationAccessControl : $role") { val organization = organizationApiService.createOrganization( - makeOrganizationCreateRequest(TEST_USER_MAIL, role)) + makeOrganizationCreateRequest(TEST_USER_MAIL, role) + ) if (shouldThrow) { val exception = assertThrows { organizationApiService.updateOrganizationAccessControl( - organization.id, TEST_USER_MAIL, OrganizationRole(role)) + organization.id, + TEST_USER_MAIL, + OrganizationRole(role), + ) } assertEquals( "RBAC ${organization.id} - User does not have permission $PERMISSION_WRITE_SECURITY", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { organizationApiService.updateOrganizationAccessControl( - organization.id, TEST_USER_MAIL, OrganizationRole(role)) + organization.id, + TEST_USER_MAIL, + OrganizationRole(role), + ) } } } @@ -438,7 +485,8 @@ class OrganizationServiceRBACTest : CsmTestBase() { DynamicTest.dynamicTest("Test RBAC listOrganizationSecurityUsers : $role") { val organization = organizationApiService.createOrganization( - makeOrganizationCreateRequest(TEST_USER_MAIL, role)) + makeOrganizationCreateRequest(TEST_USER_MAIL, role) + ) if (shouldThrow) { val exception = @@ -447,7 +495,8 @@ class OrganizationServiceRBACTest : CsmTestBase() { } assertEquals( "RBAC ${organization.id} - User does not have permission $PERMISSION_READ_SECURITY", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { organizationApiService.listOrganizationSecurityUsers(organization.id) @@ -465,6 +514,9 @@ class OrganizationServiceRBACTest : CsmTestBase() { accessControlList = mutableListOf( OrganizationAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), - OrganizationAccessControl(id = id, role = role)))) + OrganizationAccessControl(id = id, role = role), + ), + ), + ) } } diff --git a/organization/src/main/kotlin/com/cosmotech/organization/OrganizationApiServiceInterface.kt b/organization/src/main/kotlin/com/cosmotech/organization/OrganizationApiServiceInterface.kt index 9da2d8185..f3cea4814 100644 --- a/organization/src/main/kotlin/com/cosmotech/organization/OrganizationApiServiceInterface.kt +++ b/organization/src/main/kotlin/com/cosmotech/organization/OrganizationApiServiceInterface.kt @@ -10,11 +10,11 @@ interface OrganizationApiServiceInterface : OrganizationApiService { fun getVerifiedOrganization( organizationId: String, - requiredPermission: String = PERMISSION_READ + requiredPermission: String = PERMISSION_READ, ): Organization fun getVerifiedOrganization( organizationId: String, - requiredPermissions: List + requiredPermissions: List, ): Organization } diff --git a/organization/src/main/kotlin/com/cosmotech/organization/repository/OrganizationRepository.kt b/organization/src/main/kotlin/com/cosmotech/organization/repository/OrganizationRepository.kt index b4f2fec6f..0b0bf3434 100644 --- a/organization/src/main/kotlin/com/cosmotech/organization/repository/OrganizationRepository.kt +++ b/organization/src/main/kotlin/com/cosmotech/organization/repository/OrganizationRepository.kt @@ -14,6 +14,6 @@ interface OrganizationRepository : RedisDocumentRepository @Query("\$securityConstraint") fun findOrganizationsBySecurity( @SecurityConstraint @Param("securityConstraint") securityConstraint: String, - pageable: Pageable + pageable: Pageable, ): Page } diff --git a/organization/src/main/kotlin/com/cosmotech/organization/service/OrganizationServiceImpl.kt b/organization/src/main/kotlin/com/cosmotech/organization/service/OrganizationServiceImpl.kt index 55cef6800..703b7f0ee 100644 --- a/organization/src/main/kotlin/com/cosmotech/organization/service/OrganizationServiceImpl.kt +++ b/organization/src/main/kotlin/com/cosmotech/organization/service/OrganizationServiceImpl.kt @@ -40,7 +40,7 @@ import org.springframework.stereotype.Service class OrganizationServiceImpl( private val csmRbac: CsmRbac, private val csmAdmin: CsmAdmin, - private val organizationRepository: OrganizationRepository + private val organizationRepository: OrganizationRepository, ) : CsmPhoenixService(), OrganizationApiServiceInterface { override fun listOrganizations(page: Int?, size: Int?): List { @@ -99,11 +99,16 @@ class OrganizationServiceImpl( name = organizationCreateRequest.name, createInfo = OrganizationEditInfo( - timestamp = now, userId = getCurrentAccountIdentifier(csmPlatformProperties)), + timestamp = now, + userId = getCurrentAccountIdentifier(csmPlatformProperties), + ), updateInfo = OrganizationEditInfo( - timestamp = now, userId = getCurrentAccountIdentifier(csmPlatformProperties)), - security = security) + timestamp = now, + userId = getCurrentAccountIdentifier(csmPlatformProperties), + ), + security = security, + ) return organizationRepository.save(createdOrganization) } @@ -116,13 +121,15 @@ class OrganizationServiceImpl( override fun updateOrganization( organizationId: String, - organizationUpdateRequest: OrganizationUpdateRequest + organizationUpdateRequest: OrganizationUpdateRequest, ): Organization { val existingOrganization = getVerifiedOrganization(organizationId, PERMISSION_WRITE) var hasChanged = false - if (organizationUpdateRequest.name != null && - organizationUpdateRequest.name != existingOrganization.name) { + if ( + organizationUpdateRequest.name != null && + organizationUpdateRequest.name != existingOrganization.name + ) { existingOrganization.name = organizationUpdateRequest.name!! hasChanged = true } @@ -150,12 +157,14 @@ class OrganizationServiceImpl( override fun updateOrganizationDefaultSecurity( organizationId: String, - organizationRole: OrganizationRole + organizationRole: OrganizationRole, ): OrganizationSecurity { val organization = getVerifiedOrganization(organizationId, PERMISSION_WRITE_SECURITY) val rbacSecurity = csmRbac.setDefault( - organization.security.toGenericSecurity(organizationId), organizationRole.role) + organization.security.toGenericSecurity(organizationId), + organizationRole.role, + ) organization.security = rbacSecurity.toResourceSecurity() save(organization) return organization.security @@ -163,18 +172,20 @@ class OrganizationServiceImpl( override fun getOrganizationAccessControl( organizationId: String, - identityId: String + identityId: String, ): OrganizationAccessControl { val organization = getVerifiedOrganization(organizationId, PERMISSION_READ_SECURITY) val rbacAccessControl = csmRbac.getAccessControl( - organization.security.toGenericSecurity(organizationId), identityId) + organization.security.toGenericSecurity(organizationId), + identityId, + ) return OrganizationAccessControl(id = rbacAccessControl.id, role = rbacAccessControl.role) } override fun createOrganizationAccessControl( organizationId: String, - organizationAccessControl: OrganizationAccessControl + organizationAccessControl: OrganizationAccessControl, ): OrganizationAccessControl { val organization = getVerifiedOrganization(organizationId, PERMISSION_WRITE_SECURITY) @@ -187,35 +198,42 @@ class OrganizationServiceImpl( csmRbac.setEntityRole( organization.security.toGenericSecurity(organizationId), organizationAccessControl.id, - organizationAccessControl.role) + organizationAccessControl.role, + ) organization.security = rbacSecurity.toResourceSecurity() save(organization) val rbacAccessControl = csmRbac.getAccessControl( - organization.security.toGenericSecurity(organizationId), organizationAccessControl.id) + organization.security.toGenericSecurity(organizationId), + organizationAccessControl.id, + ) return OrganizationAccessControl(id = rbacAccessControl.id, role = rbacAccessControl.role) } override fun updateOrganizationAccessControl( organizationId: String, identityId: String, - organizationRole: OrganizationRole + organizationRole: OrganizationRole, ): OrganizationAccessControl { val organization = getVerifiedOrganization(organizationId, PERMISSION_WRITE_SECURITY) csmRbac.checkEntityExists( organization.security.toGenericSecurity(organizationId), identityId, - "User '$identityId' not found in organization $organizationId") + "User '$identityId' not found in organization $organizationId", + ) val rbacSecurity = csmRbac.setEntityRole( organization.security.toGenericSecurity(organizationId), identityId, - organizationRole.role) + organizationRole.role, + ) organization.security = rbacSecurity.toResourceSecurity() save(organization) val rbacAccessControl = csmRbac.getAccessControl( - organization.security.toGenericSecurity(organizationId), identityId) + organization.security.toGenericSecurity(organizationId), + identityId, + ) return OrganizationAccessControl(id = rbacAccessControl.id, role = rbacAccessControl.role) } @@ -234,7 +252,7 @@ class OrganizationServiceImpl( override fun getVerifiedOrganization( organizationId: String, - requiredPermission: String + requiredPermission: String, ): Organization { val organization = organizationRepository.findByIdOrNull(organizationId) @@ -245,7 +263,7 @@ class OrganizationServiceImpl( override fun getVerifiedOrganization( organizationId: String, - requiredPermissions: List + requiredPermissions: List, ): Organization { val organization = getVerifiedOrganization(organizationId) requiredPermissions.forEach { @@ -255,9 +273,14 @@ class OrganizationServiceImpl( } fun updateSecurityVisibility(organization: Organization): Organization { - if (csmRbac - .check(organization.security.toGenericSecurity(organization.id), PERMISSION_READ_SECURITY) - .not()) { + if ( + csmRbac + .check( + organization.security.toGenericSecurity(organization.id), + PERMISSION_READ_SECURITY, + ) + .not() + ) { val username = getCurrentAccountIdentifier(csmPlatformProperties) val retrievedAC = organization.security.accessControlList.firstOrNull { it.id == username } @@ -270,7 +293,10 @@ class OrganizationServiceImpl( return organization.copy( security = OrganizationSecurity( - default = organization.security.default, accessControlList = accessControlList)) + default = organization.security.default, + accessControlList = accessControlList, + ) + ) } return organization } @@ -279,7 +305,8 @@ class OrganizationServiceImpl( organization.updateInfo = OrganizationEditInfo( timestamp = Instant.now().toEpochMilli(), - userId = getCurrentAccountIdentifier(csmPlatformProperties)) + userId = getCurrentAccountIdentifier(csmPlatformProperties), + ) return organizationRepository.save(organization) } } @@ -289,9 +316,11 @@ fun OrganizationSecurity?.toGenericSecurity(organizationId: String) = organizationId, this?.default ?: ROLE_NONE, this?.accessControlList?.map { RbacAccessControl(it.id, it.role) }?.toMutableList() - ?: mutableListOf()) + ?: mutableListOf(), + ) fun RbacSecurity.toResourceSecurity() = OrganizationSecurity( this.default, - this.accessControlList.map { OrganizationAccessControl(it.id, it.role) }.toMutableList()) + this.accessControlList.map { OrganizationAccessControl(it.id, it.role) }.toMutableList(), + ) diff --git a/organization/src/test/kotlin/com/cosmotech/organization/service/OrganizationServiceImplTests.kt b/organization/src/test/kotlin/com/cosmotech/organization/service/OrganizationServiceImplTests.kt index 152d8a497..b540556d7 100644 --- a/organization/src/test/kotlin/com/cosmotech/organization/service/OrganizationServiceImplTests.kt +++ b/organization/src/test/kotlin/com/cosmotech/organization/service/OrganizationServiceImplTests.kt @@ -83,7 +83,8 @@ class OrganizationServiceImplTests { RbacSecurity( organization.id, organization.security.default, - mutableListOf(RbacAccessControl("ID", ROLE_VIEWER))) + mutableListOf(RbacAccessControl("ID", ROLE_VIEWER)), + ) val rbacAccessControl = RbacAccessControl(USER_ID, ROLE_ADMIN) every { organizationRepository.findByIdOrNull(any()) } returns organization every { csmRbac.verify(any(), any()) } returns Unit @@ -92,15 +93,22 @@ class OrganizationServiceImplTests { assertEquals(organization.security.default, rbacSecurity.default) assertEquals( - organization.security.accessControlList[0].id, rbacSecurity.accessControlList[0].id) + organization.security.accessControlList[0].id, + rbacSecurity.accessControlList[0].id, + ) assertEquals( - organization.security.accessControlList[0].role, rbacSecurity.accessControlList[0].role) + organization.security.accessControlList[0].role, + rbacSecurity.accessControlList[0].role, + ) every { organizationRepository.save(any()) } returns organization every { csmRbac.getAccessControl(any(), any()) } returns rbacAccessControl val organizationAccessControl = organizationApiService.updateOrganizationAccessControl( - ORGANIZATION_ID, USER_ID, organizationRole) + ORGANIZATION_ID, + USER_ID, + organizationRole, + ) assertEquals(organizationAccessControl.id, rbacAccessControl.id) assertEquals(organizationAccessControl.role, rbacAccessControl.role) } @@ -115,7 +123,10 @@ class OrganizationServiceImplTests { val organizationRole = OrganizationRole(role = ROLE_VIEWER) assertThrows { organizationApiService.updateOrganizationAccessControl( - ORGANIZATION_ID, USER_ID, organizationRole) + ORGANIZATION_ID, + USER_ID, + organizationRole, + ) } } @@ -127,7 +138,8 @@ class OrganizationServiceImplTests { RbacSecurity( id = organization.id, default = ROLE_VIEWER, - accessControlList = mutableListOf(RbacAccessControl(id = "ID", role = ROLE_VIEWER))) + accessControlList = mutableListOf(RbacAccessControl(id = "ID", role = ROLE_VIEWER)), + ) assertEquals(expectedRbac, rbacExtension) } @@ -138,13 +150,16 @@ class OrganizationServiceImplTests { RbacSecurity( id = organization.id, default = ROLE_VIEWER, - accessControlList = mutableListOf(RbacAccessControl(id = "ID2", role = ROLE_ADMIN))) + accessControlList = mutableListOf(RbacAccessControl(id = "ID2", role = ROLE_ADMIN)), + ) organization.security = newRbacSecurity.toResourceSecurity() assertEquals(newRbacSecurity, organization.security.toGenericSecurity(organization.id)) val expectedOrganizationSecurity = OrganizationSecurity( - ROLE_VIEWER, mutableListOf(OrganizationAccessControl("ID2", ROLE_ADMIN))) + ROLE_VIEWER, + mutableListOf(OrganizationAccessControl("ID2", ROLE_ADMIN)), + ) assertEquals(expectedOrganizationSecurity, organization.security) } @@ -157,7 +172,8 @@ class OrganizationServiceImplTests { ROLE_ADMIN to false, ROLE_VALIDATOR to true, ROLE_USER to false, - ROLE_NONE to true) + ROLE_NONE to true, + ) .map { (role, shouldThrow) -> rbacTest("Test RBAC read: $role", role, shouldThrow) { every { organizationRepository.findByIdOrNull(any()) } returns it @@ -173,7 +189,8 @@ class OrganizationServiceImplTests { ROLE_ADMIN to false, ROLE_VALIDATOR to true, ROLE_USER to true, - ROLE_NONE to true) + ROLE_NONE to true, + ) .map { (role, shouldThrow) -> rbacTest("Test RBAC unregister : $role", role, shouldThrow) { every { organizationRepository.findByIdOrNull(any()) } returns it @@ -190,7 +207,8 @@ class OrganizationServiceImplTests { ROLE_ADMIN to false, ROLE_VALIDATOR to true, ROLE_USER to true, - ROLE_NONE to true) + ROLE_NONE to true, + ) .map { (role, shouldThrow) -> rbacTest("Test RBAC update : $role", role, shouldThrow) { every { organizationRepository.findByIdOrNull(any()) } returns it @@ -207,7 +225,8 @@ class OrganizationServiceImplTests { ROLE_ADMIN to false, ROLE_VALIDATOR to true, ROLE_USER to false, - ROLE_NONE to true) + ROLE_NONE to true, + ) .map { (role, shouldThrow) -> rbacTest("Test RBAC getOrganizationSecurity : $role", role, shouldThrow) { every { organizationRepository.findByIdOrNull(any()) } returns it @@ -223,13 +242,16 @@ class OrganizationServiceImplTests { ROLE_ADMIN to false, ROLE_VALIDATOR to true, ROLE_USER to true, - ROLE_NONE to true) + ROLE_NONE to true, + ) .map { (role, shouldThrow) -> rbacTest("Test RBAC setOrganizationDefaultSecurity : $role", role, shouldThrow) { every { organizationRepository.findByIdOrNull(any()) } returns it every { organizationRepository.save(any()) } returns it organizationApiService.updateOrganizationDefaultSecurity( - it.id, OrganizationRole(role)) + it.id, + OrganizationRole(role), + ) } } @@ -241,7 +263,8 @@ class OrganizationServiceImplTests { ROLE_ADMIN to false, ROLE_VALIDATOR to true, ROLE_USER to false, - ROLE_NONE to true) + ROLE_NONE to true, + ) .map { (role, shouldThrow) -> rbacTest("Test RBAC getOrganizationAccessControl : $role", role, shouldThrow) { every { organizationRepository.findByIdOrNull(any()) } returns it @@ -257,13 +280,16 @@ class OrganizationServiceImplTests { ROLE_ADMIN to false, ROLE_VALIDATOR to true, ROLE_USER to true, - ROLE_NONE to true) + ROLE_NONE to true, + ) .map { (role, shouldThrow) -> rbacTest("Test RBAC addOrganizationAccessControl : $role", role, shouldThrow) { every { organizationRepository.findByIdOrNull(any()) } returns it every { organizationRepository.save(any()) } returns it organizationApiService.createOrganizationAccessControl( - it.id, OrganizationAccessControl("id", "viewer")) + it.id, + OrganizationAccessControl("id", "viewer"), + ) } } @@ -275,13 +301,17 @@ class OrganizationServiceImplTests { ROLE_ADMIN to false, ROLE_VALIDATOR to true, ROLE_USER to true, - ROLE_NONE to true) + ROLE_NONE to true, + ) .map { (role, shouldThrow) -> rbacTest("Test RBAC updateOrganizationAccessControl : $role", role, shouldThrow) { every { organizationRepository.findByIdOrNull(any()) } returns it every { organizationRepository.save(any()) } returns it organizationApiService.updateOrganizationAccessControl( - it.id, "2$USER_ID", OrganizationRole("user")) + it.id, + "2$USER_ID", + OrganizationRole("user"), + ) } } @@ -293,7 +323,8 @@ class OrganizationServiceImplTests { ROLE_ADMIN to false, ROLE_VALIDATOR to true, ROLE_USER to true, - ROLE_NONE to true) + ROLE_NONE to true, + ) .map { (role, shouldThrow) -> rbacTest("Test RBAC removeOrganizationAccessControl : $role", role, shouldThrow) { every { organizationRepository.findByIdOrNull(any()) } returns it @@ -310,7 +341,8 @@ class OrganizationServiceImplTests { ROLE_ADMIN to false, ROLE_VALIDATOR to true, ROLE_USER to false, - ROLE_NONE to true) + ROLE_NONE to true, + ) .map { (role, shouldThrow) -> rbacTest("Test RBAC get users with role : $role", role, shouldThrow) { every { organizationRepository.findByIdOrNull(any()) } returns it @@ -322,7 +354,7 @@ class OrganizationServiceImplTests { name: String, role: String, shouldThrow: Boolean, - testLambda: (organization: Organization) -> Unit + testLambda: (organization: Organization) -> Unit, ): DynamicTest? { val organization = makeOrganizationRequestWithRole(USER_ID, role) return DynamicTest.dynamicTest(name) { @@ -347,20 +379,26 @@ class OrganizationServiceImplTests { mutableListOf( OrganizationAccessControl(name, role), OrganizationAccessControl("2$name", "viewer"), - OrganizationAccessControl("admin", ROLE_ADMIN)))) + OrganizationAccessControl("admin", ROLE_ADMIN), + ), + ), + ) } fun getMockOrganization(): Organization { val security = OrganizationSecurity( - ROLE_VIEWER, mutableListOf(OrganizationAccessControl("ID", ROLE_VIEWER))) + ROLE_VIEWER, + mutableListOf(OrganizationAccessControl("ID", ROLE_VIEWER)), + ) val organization = Organization( id = ORGANIZATION_ID, name = "name", createInfo = OrganizationEditInfo(0, ""), updateInfo = OrganizationEditInfo(0, ""), - security = security) + security = security, + ) return organization } } diff --git a/run/build.gradle.kts b/run/build.gradle.kts index e319304c8..46d7e79a2 100644 --- a/run/build.gradle.kts +++ b/run/build.gradle.kts @@ -4,8 +4,8 @@ import org.openapitools.generator.gradle.plugin.tasks.GenerateTask plugins { id("org.jetbrains.kotlinx.kover") } -val argoClientJavaVersion = "v3.5.11" -val retroFitVersion = "2.11.0" +val argoClientJavaVersion = "v3.6.13" +val retroFitVersion = "3.0.0" val okHttpBom = "4.12.0" dependencies { diff --git a/run/src/integrationTest/kotlin/com/cosmotech/run/service/RunServiceIntegrationTest.kt b/run/src/integrationTest/kotlin/com/cosmotech/run/service/RunServiceIntegrationTest.kt index 7771a5639..beb175df0 100644 --- a/run/src/integrationTest/kotlin/com/cosmotech/run/service/RunServiceIntegrationTest.kt +++ b/run/src/integrationTest/kotlin/com/cosmotech/run/service/RunServiceIntegrationTest.kt @@ -142,14 +142,19 @@ class RunServiceIntegrationTest : CsmTestBase() { datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) runner = makeRunnerCreateRequest( solutionSaved.id, solutionSaved.runTemplates[0].id, "Runner", - mutableListOf(datasetSaved.id)) + mutableListOf(datasetSaved.id), + ) runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { workflowService.launchRun(any(), any(), any(), any()) } returns @@ -167,7 +172,9 @@ class RunServiceIntegrationTest : CsmTestBase() { RunTemplateCreateRequest( id = UUID.randomUUID().toString(), name = "RunTemplate1", - description = "RunTemplate1 description")), + description = "RunTemplate1 description", + ) + ), parameters = mutableListOf(RunTemplateParameterCreateRequest("parameter", "string")), version = "1.0.0", repository = "repository", @@ -178,7 +185,10 @@ class RunServiceIntegrationTest : CsmTestBase() { accessControlList = mutableListOf( SolutionAccessControl(id = CONNECTED_ADMIN_USER, role = ROLE_ADMIN), - SolutionAccessControl(id = CONNECTED_READER_USER, role = ROLE_ADMIN)))) + SolutionAccessControl(id = CONNECTED_READER_USER, role = ROLE_ADMIN), + ), + ), + ) fun makeOrganizationCreateRequest() = OrganizationCreateRequest( @@ -189,11 +199,14 @@ class RunServiceIntegrationTest : CsmTestBase() { accessControlList = mutableListOf( OrganizationAccessControl(id = CONNECTED_READER_USER, role = "reader"), - OrganizationAccessControl(id = CONNECTED_ADMIN_USER, role = "admin")))) + OrganizationAccessControl(id = CONNECTED_ADMIN_USER, role = "admin"), + ), + ), + ) fun makeWorkspaceCreateRequest( solutionId: String = solutionSaved.id, - name: String = "workspace" + name: String = "workspace", ) = WorkspaceCreateRequest( key = UUID.randomUUID().toString(), @@ -205,13 +218,15 @@ class RunServiceIntegrationTest : CsmTestBase() { security = WorkspaceSecurity( ROLE_NONE, - mutableListOf(WorkspaceAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN)))) + mutableListOf(WorkspaceAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN)), + ), + ) fun makeRunnerCreateRequest( solutionId: String = solutionSaved.id, runTemplateId: String = solutionSaved.runTemplates[0].id, name: String = "runner", - datasetList: MutableList = mutableListOf(datasetSaved.id) + datasetList: MutableList = mutableListOf(datasetSaved.id), ) = RunnerCreateRequest( name = name, @@ -220,13 +235,16 @@ class RunServiceIntegrationTest : CsmTestBase() { datasetList = datasetList, security = RunnerSecurity( - ROLE_NONE, mutableListOf(RunnerAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN)))) + ROLE_NONE, + mutableListOf(RunnerAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN)), + ), + ) fun mockStartRun( organizationId: String, workspaceId: String, runnerId: String, - solutionId: String + solutionId: String, ): String { val runner = Runner( @@ -238,18 +256,21 @@ class RunServiceIntegrationTest : CsmTestBase() { createInfo = RunnerEditInfo( timestamp = Instant.now().toEpochMilli(), - userId = getCurrentAccountIdentifier(csmPlatformProperties)), + userId = getCurrentAccountIdentifier(csmPlatformProperties), + ), updateInfo = RunnerEditInfo( timestamp = Instant.now().toEpochMilli(), - userId = getCurrentAccountIdentifier(csmPlatformProperties)), + userId = getCurrentAccountIdentifier(csmPlatformProperties), + ), datasets = RunnerDatasets(bases = mutableListOf(), parameter = ""), workspaceId = workspaceId, validationStatus = RunnerValidationStatus.Draft, parametersValues = mutableListOf(), lastRunInfo = LastRunInfo(lastRunId = null, lastRunStatus = LastRunStatus.NotStarted), security = - RunnerSecurity(ROLE_ADMIN, mutableListOf(RunnerAccessControl("user", ROLE_ADMIN)))) + RunnerSecurity(ROLE_ADMIN, mutableListOf(RunnerAccessControl("user", ROLE_ADMIN))), + ) val runStart = RunStart(this, runner) eventPublisher.publishEvent(runStart) return runStart.response!! @@ -263,7 +284,8 @@ class RunServiceIntegrationTest : CsmTestBase() { createInfo = RunEditInfo( timestamp = Instant.now().toEpochMilli(), - userId = getCurrentAccountIdentifier(csmPlatformProperties)), + userId = getCurrentAccountIdentifier(csmPlatformProperties), + ), ) } @@ -320,7 +342,12 @@ class RunServiceIntegrationTest : CsmTestBase() { logger.info("should find all Runs and assert there are $numberOfRuns") var runs = runApiService.listRuns( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, null, numberOfRuns * 2) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + null, + numberOfRuns * 2, + ) assertEquals(numberOfRuns, runs.size) logger.info("should find all Runs and assert it equals defaultPageSize: $defaultPageSize") @@ -330,13 +357,23 @@ class RunServiceIntegrationTest : CsmTestBase() { logger.info("should find all Runs and assert there are expected size: $expectedSize") runs = runApiService.listRuns( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, 0, expectedSize) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + 0, + expectedSize, + ) assertEquals(expectedSize, runs.size) logger.info("should find all Runs and assert it returns the second / last page") runs = runApiService.listRuns( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, 1, expectedSize) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + 1, + expectedSize, + ) assertEquals(numberOfRuns - expectedSize, runs.size) } @@ -374,7 +411,12 @@ class RunServiceIntegrationTest : CsmTestBase() { assertEquals( "first line of result" + "|second line of result" + "|third line of result", runApiService.getRunLogs( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, runSavedId)) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + runSavedId, + ), + ) } @Test @@ -394,7 +436,12 @@ class RunServiceIntegrationTest : CsmTestBase() { assertEquals( "first line of result" + "|second line of result" + "|third line of result", runApiService.getRunLogs( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, runSavedId)) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + runSavedId, + ), + ) } @Test @@ -417,7 +464,12 @@ class RunServiceIntegrationTest : CsmTestBase() { assertEquals( "first line of result" + "|second line of result" + "|third line of result", runApiService.getRunLogs( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, runSavedId)) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + runSavedId, + ), + ) } @Test diff --git a/run/src/main/kotlin/com/cosmotech/run/RunContainerFactory.kt b/run/src/main/kotlin/com/cosmotech/run/RunContainerFactory.kt index 8194e1c37..aa18b5015 100644 --- a/run/src/main/kotlin/com/cosmotech/run/RunContainerFactory.kt +++ b/run/src/main/kotlin/com/cosmotech/run/RunContainerFactory.kt @@ -81,7 +81,7 @@ class RunContainerFactory( private val workspaceService: WorkspaceApiService, private val solutionService: SolutionApiService, private val organizationService: OrganizationApiService, - private val containerRegistryService: ContainerRegistryService + private val containerRegistryService: ContainerRegistryService, ) { fun getStartInfo( @@ -89,7 +89,7 @@ class RunContainerFactory( workspaceId: String, runnerId: String, workflowType: String, - runId: String + runId: String, ): StartInfo { val organization = organizationService.getOrganization(organizationId) val workspace = workspaceService.getWorkspace(organizationId, workspaceId) @@ -161,11 +161,20 @@ class RunContainerFactory( val imageName = getImageName( - csmPlatformProperties.containerRegistry.host, solution.repository, solution.version) + csmPlatformProperties.containerRegistry.host, + solution.repository, + solution.version, + ) val envVars = getCommonEnvVars( - csmPlatformProperties, csmSimulationId, organization.id, workspace.id, runner.id, runId) + csmPlatformProperties, + csmSimulationId, + organization.id, + workspace.id, + runner.id, + runId, + ) envVars[RUN_TEMPLATE_ID_VAR] = runTemplateId @@ -180,7 +189,9 @@ class RunContainerFactory( entrypoint = ENTRYPOINT_NAME, solutionContainer = true, nodeLabel = nodeLabel, - runSizing = customSizing.toContainerResourceSizing())) + runSizing = customSizing.toContainerResourceSizing(), + ) + ) val generateName = "${runId}$GENERATE_NAME_SUFFIX".sanitizeForKubernetes() @@ -196,7 +207,8 @@ class RunContainerFactory( ORGANIZATION_ID_LABEL to organization.id, WORKSPACE_ID_LABEL to workspace.id, RUNNER_ID_LABEL to runner.id, - )) + ), + ) } internal fun buildSingleContainerStart( @@ -207,7 +219,7 @@ class RunContainerFactory( imageVersion: String = "latest", containerEnvVars: Map, workflowType: String, - nodeLabel: String = NODE_LABEL_DEFAULT + nodeLabel: String = NODE_LABEL_DEFAULT, ): RunStartContainers { var defaultSizing = BASIC_SIZING @@ -224,7 +236,8 @@ class RunContainerFactory( defaultSizing, containerName, containerEnvVars, - nodeLabel) + nodeLabel, + ) val generateName = "${jobId}$GENERATE_NAME_SUFFIX".sanitizeForKubernetes() @@ -240,7 +253,8 @@ class RunContainerFactory( ORGANIZATION_ID_LABEL to "none", WORKSPACE_ID_LABEL to "none", RUNNER_ID_LABEL to "none", - )) + ), + ) } internal fun buildSimpleContainer( @@ -250,7 +264,7 @@ class RunContainerFactory( nodeSizing: Sizing, containerName: String, containerEnvVars: Map, - nodeLabel: String + nodeLabel: String, ): RunContainer { val envVars = getMinimalCommonEnvVars(csmPlatformProperties).toMutableMap() @@ -262,13 +276,15 @@ class RunContainerFactory( dependencies = listOf(CSM_DAG_ROOT), envVars = envVars, nodeLabel = nodeLabel, - runSizing = nodeSizing.toContainerResourceSizing()) + runSizing = nodeSizing.toContainerResourceSizing(), + ) } private fun getRunTemplate(solution: Solution, runTemplateId: String): RunTemplate { return solution.runTemplates.find { runTemplate -> runTemplate.id == runTemplateId } ?: throw IllegalStateException( - "runTemplateId $runTemplateId not found in Solution ${solution.id}") + "runTemplateId $runTemplateId not found in Solution ${solution.id}" + ) } private fun getImageName(registry: String, repository: String, version: String? = null): String { @@ -300,7 +316,8 @@ internal fun getMinimalCommonEnvVars( TWIN_CACHE_PORT to (twinCacheInfo.port), TWIN_CACHE_PASSWORD to (twinCacheInfo.password), TWIN_CACHE_USERNAME to (twinCacheInfo.username), - )) + ) + ) val containerScopes = getContainerScopes(csmPlatformProperties) val commonEnvVars = mapOf( @@ -324,7 +341,7 @@ internal fun getCommonEnvVars( organizationId: String, workspaceId: String, runnerId: String, - runId: String + runId: String, ): MutableMap { val minimalEnvVars = getMinimalCommonEnvVars(csmPlatformProperties) @@ -335,6 +352,7 @@ internal fun getCommonEnvVars( PARAMETERS_ORGANIZATION_VAR to organizationId, PARAMETERS_WORKSPACE_VAR to workspaceId, PARAMETERS_RUNNER_VAR to runnerId, - PARAMETERS_RUN_VAR to runId) + PARAMETERS_RUN_VAR to runId, + ) return (minimalEnvVars + commonEnvVars).toMutableMap() } diff --git a/run/src/main/kotlin/com/cosmotech/run/container/StartInfo.kt b/run/src/main/kotlin/com/cosmotech/run/container/StartInfo.kt index 596a468a6..76bbd3918 100644 --- a/run/src/main/kotlin/com/cosmotech/run/container/StartInfo.kt +++ b/run/src/main/kotlin/com/cosmotech/run/container/StartInfo.kt @@ -29,34 +29,40 @@ data class Sizing(val requests: SizingInfo, val limits: SizingInfo) fun Sizing.toContainerResourceSizing(): ContainerResourceSizing { return ContainerResourceSizing( requests = ContainerResourceSizeInfo(cpu = this.requests.cpu, memory = this.requests.memory), - limits = ContainerResourceSizeInfo(cpu = this.limits.cpu, memory = this.limits.memory)) + limits = ContainerResourceSizeInfo(cpu = this.limits.cpu, memory = this.limits.memory), + ) } internal val BASIC_SIZING = Sizing( requests = SizingInfo(cpu = "3", memory = "4Gi"), - limits = SizingInfo(cpu = "3", memory = "4Gi")) + limits = SizingInfo(cpu = "3", memory = "4Gi"), + ) internal val HIGH_MEMORY_SIZING = Sizing( requests = SizingInfo(cpu = "7", memory = "57Gi"), - limits = SizingInfo(cpu = "7", memory = "57Gi")) + limits = SizingInfo(cpu = "7", memory = "57Gi"), + ) internal val HIGH_CPU_SIZING = Sizing( requests = SizingInfo(cpu = "70", memory = "130Gi"), - limits = SizingInfo(cpu = "70", memory = "130Gi")) + limits = SizingInfo(cpu = "70", memory = "130Gi"), + ) fun RunnerResourceSizing.toSizing(): Sizing { return Sizing( requests = SizingInfo(cpu = this.requests.cpu, memory = this.requests.memory), - limits = SizingInfo(cpu = this.limits.cpu, memory = this.limits.memory)) + limits = SizingInfo(cpu = this.limits.cpu, memory = this.limits.memory), + ) } fun RunTemplateResourceSizing.toSizing(): Sizing { return Sizing( requests = SizingInfo(cpu = this.requests.cpu, memory = this.requests.memory), - limits = SizingInfo(cpu = this.limits.cpu, memory = this.limits.memory)) + limits = SizingInfo(cpu = this.limits.cpu, memory = this.limits.memory), + ) } fun ContainerResourceSizing.getRequestsMap(): Map { diff --git a/run/src/main/kotlin/com/cosmotech/run/metrics/RunMetrics.kt b/run/src/main/kotlin/com/cosmotech/run/metrics/RunMetrics.kt index bae976745..051dbe666 100644 --- a/run/src/main/kotlin/com/cosmotech/run/metrics/RunMetrics.kt +++ b/run/src/main/kotlin/com/cosmotech/run/metrics/RunMetrics.kt @@ -23,7 +23,10 @@ private const val TS_RUN_WORKFLOW_NAME = "run" @Service @ConditionalOnProperty( - name = ["csm.platform.metrics.enabled"], havingValue = "true", matchIfMissing = false) + name = ["csm.platform.metrics.enabled"], + havingValue = "true", + matchIfMissing = false, +) internal class RunMetrics( private val eventPublisher: CsmEventPublisher, private val csmPlatformProperties: CsmPlatformProperties, diff --git a/run/src/main/kotlin/com/cosmotech/run/repository/RunRepository.kt b/run/src/main/kotlin/com/cosmotech/run/repository/RunRepository.kt index a6ac408bb..bd6049992 100644 --- a/run/src/main/kotlin/com/cosmotech/run/repository/RunRepository.kt +++ b/run/src/main/kotlin/com/cosmotech/run/repository/RunRepository.kt @@ -16,12 +16,13 @@ import org.springframework.stereotype.Repository interface RunRepository : RedisDocumentRepository { @Query( - "@organizationId:{\$organizationId} @workspaceId:{\$workspaceId} @runnerId:{\$runnerId} @id:{\$runId}") + "@organizationId:{\$organizationId} @workspaceId:{\$workspaceId} @runnerId:{\$runnerId} @id:{\$runId}" + ) fun findBy( @Sanitize @Param("organizationId") organizationId: String, @Sanitize @Param("workspaceId") workspaceId: String, @Sanitize @Param("runnerId") runnerId: String, - @Sanitize @Param("runId") runId: String + @Sanitize @Param("runId") runId: String, ): Optional @Query("@organizationId:{\$organizationId} @workspaceId:{\$workspaceId} @runnerId:{\$runnerId}") @@ -29,6 +30,6 @@ interface RunRepository : RedisDocumentRepository { @Sanitize @Param("organizationId") organizationId: String, @Sanitize @Param("workspaceId") workspaceId: String, @Sanitize @Param("runnerId") runnerId: String, - pageable: Pageable + pageable: Pageable, ): Page } diff --git a/run/src/main/kotlin/com/cosmotech/run/service/RunServiceImpl.kt b/run/src/main/kotlin/com/cosmotech/run/service/RunServiceImpl.kt index 009711592..ad6608d21 100644 --- a/run/src/main/kotlin/com/cosmotech/run/service/RunServiceImpl.kt +++ b/run/src/main/kotlin/com/cosmotech/run/service/RunServiceImpl.kt @@ -48,7 +48,7 @@ class RunServiceImpl( private val workflowService: WorkflowService, private val runnerApiService: RunnerApiServiceInterface, private val runRepository: RunRepository, - private val csmRbac: CsmRbac + private val csmRbac: CsmRbac, ) : CsmPhoenixService(), RunApiServiceInterface { override fun listRuns( @@ -56,7 +56,7 @@ class RunServiceImpl( workspaceId: String, runnerId: String, page: Int?, - size: Int? + size: Int?, ): List { // This call verify the user read authorization in the Runner runnerApiService.getRunner(organizationId, workspaceId, runnerId) @@ -74,7 +74,7 @@ class RunServiceImpl( override fun listAllRuns( organizationId: String, workspaceId: String, - runnerId: String + runnerId: String, ): List { // This call verify the user read authorization in the Runner runnerApiService.getRunner(organizationId, workspaceId, runnerId) @@ -111,7 +111,8 @@ class RunServiceImpl( fun getRunStatus(run: Run): RunStatus { val runStatus = this.workflowService.getRunStatus(run) return runStatus.copy( - state = mapWorkflowPhaseToRunStatus(phase = runStatus.phase, runId = run.id)) + state = mapWorkflowPhaseToRunStatus(phase = runStatus.phase, runId = run.id) + ) } private fun mapWorkflowPhaseToRunStatus(phase: String?, runId: String?): RunState { @@ -134,7 +135,7 @@ class RunServiceImpl( organizationId: String, workspaceId: String, runnerId: String, - runId: String + runId: String, ): Run { runnerApiService.getRunner(organizationId, workspaceId, runnerId) val run = @@ -142,7 +143,8 @@ class RunServiceImpl( .findBy(organizationId, workspaceId, runnerId, runId) .orElseThrow { throw IllegalArgumentException( - "Run #$runId not found in #$runnerId. In #$workspaceId, #$organizationId.") + "Run #$runId not found in #$runnerId. In #$workspaceId, #$organizationId." + ) } .withStateInformation() .withoutSensitiveData() @@ -155,7 +157,7 @@ class RunServiceImpl( organizationId: String, workspaceId: String, runnerId: String, - runId: String + runId: String, ) { val run = this.getRun(organizationId, workspaceId, runnerId, runId) run.hasPermission(PERMISSION_DELETE) @@ -188,7 +190,11 @@ class RunServiceImpl( runRepository.delete(run) } catch (exception: IllegalStateException) { logger.debug( - "An error occurred while deleting Run {}: {}", run.id, exception.message, exception) + "An error occurred while deleting Run {}: {}", + run.id, + exception.message, + exception, + ) } } @@ -196,7 +202,7 @@ class RunServiceImpl( organizationId: String, workspaceId: String, runnerId: String, - runId: String + runId: String, ): String { val run = getRun(organizationId, workspaceId, runnerId, runId) val status = getRunStatus(run) @@ -214,7 +220,7 @@ class RunServiceImpl( organizationId: String, workspaceId: String, runnerId: String, - runId: String + runId: String, ): RunStatus { return getRunStatus(this.getRun(organizationId, workspaceId, runnerId, runId)) } @@ -226,14 +232,20 @@ class RunServiceImpl( val startInfo = containerFactory.getStartInfo( - runner.organizationId, runner.workspaceId, runner.id, WORKFLOW_TYPE_RUN, runId) + runner.organizationId, + runner.workspaceId, + runner.id, + WORKFLOW_TYPE_RUN, + runId, + ) val runRequest = workflowService.launchRun( runner.organizationId, runner.workspaceId, startInfo.startContainers, startInfo.runTemplate.executionTimeout, - startInfo.solution.alwaysPull ?: false) + startInfo.solution.alwaysPull ?: false, + ) val run = this.dbCreateRun(runId, runner, startInfo, runRequest) runStartRequest.response = run.id } @@ -242,7 +254,7 @@ class RunServiceImpl( runId: String, runner: Runner, startInfo: StartInfo, - runRequest: Run + runRequest: Run, ): Run { val now = Instant.now().toEpochMilli() val run = @@ -258,11 +270,16 @@ class RunServiceImpl( datasetList = runner.datasets.bases + runner.datasets.parameter, createInfo = RunEditInfo( - timestamp = now, userId = getCurrentAccountIdentifier(csmPlatformProperties)), + timestamp = now, + userId = getCurrentAccountIdentifier(csmPlatformProperties), + ), parametersValues = (runner.parametersValues.map { RunTemplateParameterValue( - parameterId = it.parameterId, varType = it.varType, value = it.value) + parameterId = it.parameterId, + varType = it.varType, + value = it.value, + ) }) .toList(), nodeLabel = startInfo.startContainers.nodeLabel, @@ -273,7 +290,8 @@ class RunServiceImpl( "[workspaceId=${run.workspaceId}]" + "[runnerId=${run.runnerId}]" + "[runId=${run.id}] has been launched by " + - "[ownerId=${run.createInfo.userId}]") + "[ownerId=${run.createInfo.userId}]" + ) return runRepository.save(run) } @@ -289,7 +307,8 @@ class RunServiceImpl( .findBy(organizationId, workspaceId, runnerId, runId) .orElseThrow { throw IllegalArgumentException( - "Run #$runId not found in #$runnerId. In #$workspaceId, #$organizationId.") + "Run #$runId not found in #$runnerId. In #$workspaceId, #$organizationId." + ) } .withStateInformation() .withoutSensitiveData() diff --git a/run/src/main/kotlin/com/cosmotech/run/workflow/WorkflowService.kt b/run/src/main/kotlin/com/cosmotech/run/workflow/WorkflowService.kt index b17f57eec..11bbbfafb 100644 --- a/run/src/main/kotlin/com/cosmotech/run/workflow/WorkflowService.kt +++ b/run/src/main/kotlin/com/cosmotech/run/workflow/WorkflowService.kt @@ -12,7 +12,7 @@ data class RunStartContainers( val csmSimulationId: String, val nodeLabel: String? = null, val labels: Map? = null, - val containers: List + val containers: List, ) interface WorkflowService : HealthIndicator { @@ -30,7 +30,7 @@ interface WorkflowService : HealthIndicator { workspaceId: String?, runStartContainers: RunStartContainers, executionTimeout: Int?, - alwaysPull: Boolean = false + alwaysPull: Boolean = false, ): Run /** @@ -83,5 +83,5 @@ data class WorkflowContextData( data class WorkflowStatus( val workflowId: String, val status: String? = null, - val contextData: WorkflowContextData? = null + val contextData: WorkflowContextData? = null, ) diff --git a/run/src/main/kotlin/com/cosmotech/run/workflow/argo/RunArgoWorkflowService.kt b/run/src/main/kotlin/com/cosmotech/run/workflow/argo/RunArgoWorkflowService.kt index 14f634b51..632dec2be 100644 --- a/run/src/main/kotlin/com/cosmotech/run/workflow/argo/RunArgoWorkflowService.kt +++ b/run/src/main/kotlin/com/cosmotech/run/workflow/argo/RunArgoWorkflowService.kt @@ -112,7 +112,11 @@ internal class RunArgoWorkflowService( workflow = newServiceApiInstance(this.apiClient) .workflowServiceGetWorkflow( - csmPlatformProperties.argo.workflows.namespace, workflowName, "", "") + csmPlatformProperties.argo.workflows.namespace, + workflowName, + "", + "", + ) } catch (e: ApiException) { logger.warn( """ @@ -120,7 +124,8 @@ internal class RunArgoWorkflowService( Status code: ${e.code} Reason: ${e.responseBody} """ - .trimIndent()) + .trimIndent() + ) logger.debug("Response headers: " + e.getResponseHeaders()) } @@ -132,7 +137,7 @@ internal class RunArgoWorkflowService( workspaceId: String?, runStartContainers: RunStartContainers, executionTimeout: Int?, - alwaysPull: Boolean + alwaysPull: Boolean, ): Run { val body = IoArgoprojWorkflowV1alpha1WorkflowCreateRequest() @@ -143,7 +148,9 @@ internal class RunArgoWorkflowService( csmPlatformProperties, runStartContainers, executionTimeout, - alwaysPull)) + alwaysPull, + ) + ) logger.debug("Workflow: {}", body.workflow) @@ -160,7 +167,8 @@ internal class RunArgoWorkflowService( createInfo = RunEditInfo( timestamp = Instant.now().toEpochMilli(), - userId = getCurrentAccountIdentifier(csmPlatformProperties)), + userId = getCurrentAccountIdentifier(csmPlatformProperties), + ), workflowId = workflow.metadata.uid, workflowName = workflow.metadata.name, nodeLabel = runStartContainers.nodeLabel, @@ -173,7 +181,8 @@ internal class RunArgoWorkflowService( Status code: ${e.code} Reason: ${e.responseBody} """ - .trimIndent()) + .trimIndent() + ) logger.debug("Response headers: {}", e.responseHeaders) throw IllegalStateException(e) } @@ -193,7 +202,8 @@ internal class RunArgoWorkflowService( WorkflowStatus( workflowId = workflowId, status = status, - contextData = WorkflowContextData(organizationId, workspaceId, runnerId)) + contextData = WorkflowContextData(organizationId, workspaceId, runnerId), + ) } } @@ -213,7 +223,10 @@ internal class RunArgoWorkflowService( null, null, null, - null) + null, + null, + null, + ) .items } @@ -223,7 +236,8 @@ internal class RunArgoWorkflowService( val workflowName = run.workflowName ?: throw IllegalStateException( - "Run $runId for Organization $organizationId contains a null workflowName") + "Run $runId for Organization $organizationId contains a null workflowName" + ) val workflowStatus = getWorkflowStatus(workflowName) return buildRunStatusFromWorkflowStatus(run, workflowStatus) } @@ -246,7 +260,8 @@ internal class RunArgoWorkflowService( .get() .uri( "/api/v1/workflows/${csmPlatformProperties.argo.workflows.namespace}" + - "/$workflowName/log?podName=${podName}&logOptions.container=main") + "/$workflowName/log?podName=${podName}&logOptions.container=main" + ) .retrieve() .body(String::class.java) lines?.split("\n")?.forEach { @@ -301,7 +316,8 @@ internal class RunArgoWorkflowService( .workflowServiceStopWorkflow( csmPlatformProperties.argo.workflows.namespace, run.workflowName, - IoArgoprojWorkflowV1alpha1WorkflowStopRequest()) + IoArgoprojWorkflowV1alpha1WorkflowStopRequest(), + ) } catch (e: ApiException) { logger.warn( """ @@ -309,7 +325,8 @@ internal class RunArgoWorkflowService( Status code: ${e.code} Reason: ${e.responseBody} """ - .trimIndent()) + .trimIndent() + ) logger.debug("Response headers: " + e.responseHeaders) } @@ -318,7 +335,7 @@ internal class RunArgoWorkflowService( private fun buildRunStatusFromWorkflowStatus( run: Run, - workflowStatus: IoArgoprojWorkflowV1alpha1WorkflowStatus? + workflowStatus: IoArgoprojWorkflowV1alpha1WorkflowStatus?, ): RunStatus { return RunStatus( id = run.id, @@ -344,7 +361,8 @@ internal class RunArgoWorkflowService( resourcesDuration = RunResourceRequested( nodeStatus.resourcesDuration?.get("cpu"), - nodeStatus.resourcesDuration?.get("memory")), + nodeStatus.resourcesDuration?.get("memory"), + ), outboundNodes = nodeStatus.outboundNodes, hostNodeName = nodeStatus.hostNodeName, message = nodeStatus.message, @@ -353,7 +371,8 @@ internal class RunArgoWorkflowService( startTime = nodeStatus.startedAt?.toString(), endTime = nodeStatus.finishedAt?.toString(), ) - }) + }, + ) } // Should be handled synchronously diff --git a/run/src/main/kotlin/com/cosmotech/run/workflow/argo/WorkflowBuilders.kt b/run/src/main/kotlin/com/cosmotech/run/workflow/argo/WorkflowBuilders.kt index ea2016627..42fbb5b98 100644 --- a/run/src/main/kotlin/com/cosmotech/run/workflow/argo/WorkflowBuilders.kt +++ b/run/src/main/kotlin/com/cosmotech/run/workflow/argo/WorkflowBuilders.kt @@ -56,7 +56,7 @@ internal fun buildTemplate( workspaceId: String?, runContainer: RunContainer, csmPlatformProperties: CsmPlatformProperties, - alwaysPull: Boolean = false + alwaysPull: Boolean = false, ): IoArgoprojWorkflowV1alpha1Template { var envVars: MutableList? = null if (runContainer.envVars != null) { @@ -88,7 +88,8 @@ internal fun buildTemplate( V1VolumeMount() .name(VOLUME_CLAIM) .mountPath(VOLUME_TEMP_PATH) - .subPath(VOLUME_CLAIM_TEMP_SUBPATH)) + .subPath(VOLUME_CLAIM_TEMP_SUBPATH), + ) val volumeMounts = normalVolumeMount + secretVolumeMount @@ -105,7 +106,8 @@ internal fun buildTemplate( volumeMounts, sizingInfo, organizationId, - workspaceId) + workspaceId, + ) if (runContainer.entrypoint != null) { container.command(listOf(runContainer.entrypoint)) @@ -131,7 +133,7 @@ private fun buildContainer( volumeMounts: List, sizingInfo: ContainerResourceSizing, organizationId: String, - workspaceId: String? + workspaceId: String?, ): V1Container { val container = @@ -144,7 +146,8 @@ private fun buildContainer( .resources( V1ResourceRequirements() .requests(sizingInfo.getRequestsMap()) - .limits(sizingInfo.getLimitsMap())) + .limits(sizingInfo.getLimitsMap()) + ) if (workspaceId.isNullOrBlank()) return container @@ -154,7 +157,10 @@ private fun buildContainer( .secretRef( V1SecretEnvSource() .name("$organizationId-$workspaceId".lowercase()) - .optional(true)))) + .optional(true) + ) + ) + ) } internal fun buildWorkflowSpec( @@ -163,7 +169,7 @@ internal fun buildWorkflowSpec( csmPlatformProperties: CsmPlatformProperties, startContainers: RunStartContainers, executionTimeout: Int?, - alwaysPull: Boolean = false + alwaysPull: Boolean = false, ): IoArgoprojWorkflowV1alpha1WorkflowSpec { val templates = startContainers.containers @@ -180,7 +186,8 @@ internal fun buildWorkflowSpec( csmPlatformProperties.argo.imagePullSecrets ?.filterNot(String::isBlank) ?.map(V1LocalObjectReference()::name) - ?.ifEmpty { null }) + ?.ifEmpty { null } + ) .tolerations(listOf(V1Toleration().key("vendor").value("cosmotech").effect("NoSchedule"))) .serviceAccountName(csmPlatformProperties.argo.workflows.serviceAccountName) .entrypoint(CSM_DAG_ENTRYPOINT) @@ -200,14 +207,18 @@ internal fun buildWorkflowSpec( .items( secret.keyPath.map { secretKeyPath -> V1KeyToPath().key(secretKeyPath.key).path(secretKeyPath.path) - })) - }) + } + ) + ) + } + ) } if (csmPlatformProperties.argo.workflows.ignoreNodeSelector == false) { workflowSpec = workflowSpec.nodeSelector( - mutableMapOf("kubernetes.io/os" to "linux", "cosmotech.com/tier" to "compute")) + mutableMapOf("kubernetes.io/os" to "linux", "cosmotech.com/tier" to "compute") + ) } workflowSpec.activeDeadlineSeconds = executionTimeout ?: CSM_ARGO_WORKFLOWS_TIMEOUT @@ -221,13 +232,14 @@ internal fun buildWorkflow( csmPlatformProperties: CsmPlatformProperties, startContainers: RunStartContainers, executionTimeout: Int?, - alwaysPull: Boolean = false + alwaysPull: Boolean = false, ) = IoArgoprojWorkflowV1alpha1Workflow() .metadata( V1ObjectMeta() .generateName(startContainers.generateName ?: CSM_DEFAULT_WORKFLOW_NAME) - .labels(startContainers.labels)) + .labels(startContainers.labels) + ) .spec( buildWorkflowSpec( organizationId, @@ -235,7 +247,9 @@ internal fun buildWorkflow( csmPlatformProperties, startContainers, executionTimeout, - alwaysPull)) + alwaysPull, + ) + ) private fun buildEntrypointTemplate( startContainers: RunStartContainers @@ -280,9 +294,12 @@ private fun buildVolumeClaims( .accessModes(workflowsConfig.accessModes) .storageClassName( if (workflowsConfig.storageClass.isNullOrBlank()) null - else workflowsConfig.storageClass) + else workflowsConfig.storageClass + ) .resources( V1VolumeResourceRequirements() - .requests(workflowsConfig.requests.mapValues { Quantity(it.value) }))) + .requests(workflowsConfig.requests.mapValues { Quantity(it.value) }) + ) + ) return listOf(dataDir) } diff --git a/run/src/test/kotlin/com/cosmotech/run/ContainerFactoryTests.kt b/run/src/test/kotlin/com/cosmotech/run/ContainerFactoryTests.kt index aa162ff39..a6ded928a 100644 --- a/run/src/test/kotlin/com/cosmotech/run/ContainerFactoryTests.kt +++ b/run/src/test/kotlin/com/cosmotech/run/ContainerFactoryTests.kt @@ -86,7 +86,9 @@ class ContainerFactoryTests { CsmPlatformProperties.CsmIdentityProvider.CsmIdentity( tenantId = "my_tenant_id", clientId = "my_client_id", - clientSecret = "my_client_secret")) + clientSecret = "my_client_secret", + ), + ) every { csmPlatformProperties.databases.resources } returns CsmPlatformProperties.CsmDatabasesProperties.CsmResourcesProperties( host = "this_is_a_host", @@ -99,7 +101,8 @@ class ContainerFactoryTests { host = "twinengines.azurecr.io", checkSolutionImage = true, password = "password", - username = "username") + username = "username", + ) every { csmPlatformProperties.databases.data } returns CsmPlatformProperties.CsmDatabasesProperties.CsmDataIOProperties( @@ -108,10 +111,15 @@ class ContainerFactoryTests { database = "cosmotech", reader = CsmPlatformProperties.CsmDatabasesProperties.CsmDataIOProperties.CsmStorageUser( - username = "username", password = "password"), + username = "username", + password = "password", + ), writer = CsmPlatformProperties.CsmDatabasesProperties.CsmDataIOProperties.CsmStorageUser( - username = "username", password = "password")) + username = "username", + password = "password", + ), + ) factory = RunContainerFactory( @@ -120,7 +128,8 @@ class ContainerFactoryTests { workspaceService, solutionService, organizationService, - containerRegistryService) + containerRegistryService, + ) } @Test @@ -139,7 +148,8 @@ class ContainerFactoryTests { solution = getSolution(), runId = CSM_SIMULATION_ID, csmSimulationId = CSM_SIMULATION_ID, - workflowType = WORKFLOW_TYPE_RUN) + workflowType = WORKFLOW_TYPE_RUN, + ) val run_container = getRunContainer(solution, organization, workspace, runner, runTemplate, CSM_SIMULATION_ID) @@ -155,7 +165,7 @@ class ContainerFactoryTests { workspace: Workspace, runner: Runner, runTemplate: RunTemplate, - runId: String + runId: String, ): RunContainer { return RunContainer( @@ -182,14 +192,17 @@ class ContainerFactoryTests { "CSM_WORKSPACE_ID" to workspace.id, "CSM_RUNNER_ID" to runner.id, "CSM_RUN_ID" to runId, - "CSM_RUN_TEMPLATE_ID" to CSM_RUN_TEMPLATE_ID), + "CSM_RUN_TEMPLATE_ID" to CSM_RUN_TEMPLATE_ID, + ), entrypoint = "entrypoint.py", nodeLabel = runTemplate.computeSize!!.removeSuffix("pool"), runSizing = ContainerResourceSizing( requests = ContainerResourceSizeInfo(cpu = "70", memory = "130Gi"), - limits = ContainerResourceSizeInfo(cpu = "70", memory = "130Gi")), - solutionContainer = true) + limits = ContainerResourceSizeInfo(cpu = "70", memory = "130Gi"), + ), + solutionContainer = true, + ) } private fun getRunner(): Runner { @@ -206,11 +219,13 @@ class ContainerFactoryTests { parametersValues = mutableListOf( RunnerRunTemplateParameterValue(parameterId = "param1", value = "value1"), - RunnerRunTemplateParameterValue(parameterId = "param2", value = "value2")), + RunnerRunTemplateParameterValue(parameterId = "param2", value = "value2"), + ), validationStatus = RunnerValidationStatus.Draft, lastRunInfo = LastRunInfo(lastRunId = null, lastRunStatus = LastRunStatus.NotStarted), security = - RunnerSecurity(ROLE_ADMIN, mutableListOf(RunnerAccessControl("user", ROLE_ADMIN)))) + RunnerSecurity(ROLE_ADMIN, mutableListOf(RunnerAccessControl("user", ROLE_ADMIN))), + ) } private fun getRunTemplate(): RunTemplate { @@ -218,7 +233,8 @@ class ContainerFactoryTests { id = CSM_RUN_TEMPLATE_ID, name = "Test Run", computeSize = "highcpupool", - parameterGroups = mutableListOf()) + parameterGroups = mutableListOf(), + ) } private fun getSolution(): Solution { @@ -234,7 +250,8 @@ class ContainerFactoryTests { parameters = mutableListOf(RunTemplateParameter("parameter", "string")), parameterGroups = mutableListOf( - RunTemplateParameterGroup(id = "parameter", parameters = mutableListOf())), + RunTemplateParameterGroup(id = "parameter", parameters = mutableListOf()) + ), organizationId = "Organizationid", security = SolutionSecurity(ROLE_ADMIN, mutableListOf()), ) @@ -254,7 +271,8 @@ class ContainerFactoryTests { WorkspaceSolution( solutionId = "1", ), - security = WorkspaceSecurity(default = ROLE_ADMIN, accessControlList = mutableListOf())) + security = WorkspaceSecurity(default = ROLE_ADMIN, accessControlList = mutableListOf()), + ) } private fun getOrganization(): Organization { @@ -265,6 +283,9 @@ class ContainerFactoryTests { updateInfo = OrganizationEditInfo(0, ""), security = OrganizationSecurity( - ROLE_ADMIN, mutableListOf(OrganizationAccessControl("user", ROLE_ADMIN)))) + ROLE_ADMIN, + mutableListOf(OrganizationAccessControl("user", ROLE_ADMIN)), + ), + ) } } diff --git a/run/src/test/kotlin/com/cosmotech/run/workflow/argo/WorkflowBuildersTests.kt b/run/src/test/kotlin/com/cosmotech/run/workflow/argo/WorkflowBuildersTests.kt index edb18de04..65ba47f27 100644 --- a/run/src/test/kotlin/com/cosmotech/run/workflow/argo/WorkflowBuildersTests.kt +++ b/run/src/test/kotlin/com/cosmotech/run/workflow/argo/WorkflowBuildersTests.kt @@ -267,7 +267,8 @@ class WorkflowBuildersTests { .name("applyparameterscontainer") .template("applyparameterscontainer") .dependencies( - listOf("fetchdatasetcontainer-1", "fetchscenarioparameterscontainer")), + listOf("fetchdatasetcontainer-1", "fetchscenarioparameterscontainer") + ), IoArgoprojWorkflowV1alpha1DAGTask() .name("validatedatacontainer") .template("validatedatacontainer") @@ -428,7 +429,8 @@ class WorkflowBuildersTests { V1PersistentVolumeClaimSpec() .accessModes(emptyList()) .storageClassName(null) - .resources(V1VolumeResourceRequirements().requests(emptyMap()))) + .resources(V1VolumeResourceRequirements().requests(emptyMap())) + ) val expected = listOf(dataDir) assertEquals(expected, workflowSpec.volumeClaimTemplates) } @@ -450,7 +452,9 @@ class WorkflowBuildersTests { .storageClassName("cosmotech-api-test-phoenix") .resources( V1VolumeResourceRequirements() - .requests(mapOf("storage" to Quantity("300Gi"))))) + .requests(mapOf("storage" to Quantity("300Gi"))) + ) + ) val expected = listOf(dataDir) assertEquals(expected, workflowSpec.volumeClaimTemplates) } @@ -476,7 +480,8 @@ class WorkflowBuildersTests { V1VolumeMount() .name(VOLUME_CLAIM) .mountPath("/usr/tmp") - .subPath(VOLUME_CLAIM_TEMP_SUBPATH)) + .subPath(VOLUME_CLAIM_TEMP_SUBPATH), + ) assertEquals(expected, template.container?.volumeMounts) } @@ -539,7 +544,7 @@ class WorkflowBuildersTests { private fun getRunContainerDependencies( name: String = "default", - dependencies: List? = null + dependencies: List? = null, ): RunContainer { val src = RunContainer( @@ -555,27 +560,32 @@ class WorkflowBuildersTests { RunContainer( name = name, image = "cosmotech/testcontainer", - runArgs = listOf("arg1", "arg2", "arg3")) + runArgs = listOf("arg1", "arg2", "arg3"), + ) return src } private fun getRunContainerEntrypoint(name: String = "default"): RunContainer { val src = RunContainer( - name = name, image = "cosmotech/testcontainer", entrypoint = DEFAULT_ENTRY_POINT) + name = name, + image = "cosmotech/testcontainer", + entrypoint = DEFAULT_ENTRY_POINT, + ) return src } private fun getRunContainerEntrypointDependencies( name: String = "default", - dependencies: List? = null + dependencies: List? = null, ): RunContainer { val src = RunContainer( name = name, image = "cosmotech/testcontainer", entrypoint = DEFAULT_ENTRY_POINT, - dependencies = dependencies) + dependencies = dependencies, + ) return src } @@ -584,7 +594,8 @@ class WorkflowBuildersTests { RunContainer( name = name, image = "cosmotech/testcontainer", - envVars = mapOf("env1" to "envvar1", "env2" to "envvar2", "env3" to "envvar3")) + envVars = mapOf("env1" to "envvar1", "env2" to "envvar2", "env3" to "envvar3"), + ) return src } @@ -594,7 +605,8 @@ class WorkflowBuildersTests { RunStartContainers( nodeLabel = "basicpool", containers = listOf(getRunContainerEntrypoint()), - csmSimulationId = csmSimulationId) + csmSimulationId = csmSimulationId, + ) return sc } @@ -603,7 +615,8 @@ class WorkflowBuildersTests { RunStartContainers( nodeLabel = "highcpupool", containers = listOf(getRunContainerEntrypoint("runcontainer")), - csmSimulationId = csmSimulationId) + csmSimulationId = csmSimulationId, + ) return sc } @@ -611,7 +624,8 @@ class WorkflowBuildersTests { val sc = RunStartContainers( containers = listOf(getRunContainerEntrypoint("runcontainer")), - csmSimulationId = csmSimulationId) + csmSimulationId = csmSimulationId, + ) return sc } @@ -630,7 +644,8 @@ class WorkflowBuildersTests { getRunContainerEntrypoint("runcontainer"), getRunContainerEntrypoint("postruncontainer"), ), - csmSimulationId = csmSimulationId) + csmSimulationId = csmSimulationId, + ) return sc } @@ -642,20 +657,30 @@ class WorkflowBuildersTests { listOf( getRunContainerDependencies("fetchdatasetcontainer-1", listOf("DAG_ROOT")), getRunContainerDependencies( - "fetchscenarioparameterscontainer", listOf("DAG_ROOT")), + "fetchscenarioparameterscontainer", + listOf("DAG_ROOT"), + ), getRunContainerEntrypointDependencies( "applyparameterscontainer", - listOf("fetchdatasetcontainer-1", "fetchscenarioparameterscontainer")), + listOf("fetchdatasetcontainer-1", "fetchscenarioparameterscontainer"), + ), getRunContainerEntrypointDependencies( - "validatedatacontainer", listOf("applyparameterscontainer")), + "validatedatacontainer", + listOf("applyparameterscontainer"), + ), getRunContainerDependencies( - "senddatawarehousecontainer", listOf("validatedatacontainer")), + "senddatawarehousecontainer", + listOf("validatedatacontainer"), + ), getRunContainerEntrypointDependencies( - "preruncontainer", listOf("validatedatacontainer")), + "preruncontainer", + listOf("validatedatacontainer"), + ), getRunContainerEntrypoint("runcontainer"), getRunContainerEntrypoint("postruncontainer"), ), - csmSimulationId = csmSimulationId) + csmSimulationId = csmSimulationId, + ) return sc } @@ -674,7 +699,8 @@ class WorkflowBuildersTests { getRunContainerEntrypoint("runcontainer"), getRunContainerEntrypoint("postruncontainer"), ), - csmSimulationId = csmSimulationId) + csmSimulationId = csmSimulationId, + ) return sc } @@ -694,7 +720,8 @@ class WorkflowBuildersTests { getRunContainerEntrypoint("runcontainer"), getRunContainerEntrypoint("postruncontainer"), ), - csmSimulationId = csmSimulationId) + csmSimulationId = csmSimulationId, + ) return sc } @@ -707,9 +734,12 @@ class WorkflowBuildersTests { getRunContainerDependencies("Diamond-B", dependencies = listOf("Diamond-A")), getRunContainerDependencies("Diamond-C", dependencies = listOf("Diamond-A")), getRunContainerDependencies( - "Diamond-D", dependencies = listOf("Diamond-B", "Diamond-C")), + "Diamond-D", + dependencies = listOf("Diamond-B", "Diamond-C"), + ), ), - csmSimulationId = csmSimulationId) + csmSimulationId = csmSimulationId, + ) return sc } } diff --git a/runner/src/integrationTest/kotlin/com/cosmotech/runner/service/RunnerServiceIntegrationTest.kt b/runner/src/integrationTest/kotlin/com/cosmotech/runner/service/RunnerServiceIntegrationTest.kt index 52ae82591..b6ebba79e 100644 --- a/runner/src/integrationTest/kotlin/com/cosmotech/runner/service/RunnerServiceIntegrationTest.kt +++ b/runner/src/integrationTest/kotlin/com/cosmotech/runner/service/RunnerServiceIntegrationTest.kt @@ -127,11 +127,18 @@ class RunnerServiceIntegrationTest : CsmTestBase() { val runTemplateParameterValue1 = RunnerRunTemplateParameterValue( - parameterId = "param1", value = "param1value", isInherited = true, varType = "String") + parameterId = "param1", + value = "param1value", + isInherited = true, + varType = "String", + ) val runTemplateParameterValue2 = RunnerRunTemplateParameterValue( - parameterId = "param2", value = "param2value", varType = "String") + parameterId = "param2", + value = "param2value", + varType = "String", + ) @BeforeEach fun setUp() { @@ -140,7 +147,10 @@ class RunnerServiceIntegrationTest : CsmTestBase() { mockkStatic("org.springframework.web.context.request.RequestContextHolder") ReflectionTestUtils.setField( - solutionApiService, "containerRegistryService", containerRegistryService) + solutionApiService, + "containerRegistryService", + containerRegistryService, + ) every { containerRegistryService.getImageLabel(any(), any(), any()) } returns null mockkStatic("com.cosmotech.common.utils.SecurityUtilsKt") every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER @@ -169,13 +179,18 @@ class RunnerServiceIntegrationTest : CsmTestBase() { dataset = makeDataset("Dataset") datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) parentRunner = makeRunnerCreateRequest( name = "RunnerParent", datasetList = mutableListOf(datasetSaved.id), - parametersValues = mutableListOf(runTemplateParameterValue1)) + parametersValues = mutableListOf(runTemplateParameterValue1), + ) parentRunnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, parentRunner) @@ -185,7 +200,8 @@ class RunnerServiceIntegrationTest : CsmTestBase() { name = "Runner", parentId = parentRunnerSaved.id, datasetList = mutableListOf(datasetSaved.id), - parametersValues = mutableListOf(runTemplateParameterValue2)) + parametersValues = mutableListOf(runTemplateParameterValue2), + ) runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) } @@ -199,7 +215,8 @@ class RunnerServiceIntegrationTest : CsmTestBase() { fun `test createRunner and check parameterValues data`() { logger.info( - "should create a new Runner and retrieve parameter varType from solution ignoring the one declared") + "should create a new Runner and retrieve parameter varType from solution ignoring the one declared" + ) val newRunner = makeRunnerCreateRequest( name = "NewRunner", @@ -207,7 +224,12 @@ class RunnerServiceIntegrationTest : CsmTestBase() { parametersValues = mutableListOf( RunnerRunTemplateParameterValue( - parameterId = "param1", value = "7", varType = "ignored_var_type"))) + parameterId = "param1", + value = "7", + varType = "ignored_var_type", + ) + ), + ) val newRunnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, newRunner) @@ -222,15 +244,20 @@ class RunnerServiceIntegrationTest : CsmTestBase() { fun `test updateRunner and check parameterValues data`() { logger.info( - "should create a new Runner and retrieve parameter varType from solution ignoring the one declared") + "should create a new Runner and retrieve parameter varType from solution ignoring the one declared" + ) val creationParameterValue = RunnerRunTemplateParameterValue( - parameterId = "param1", value = "7", varType = "ignored_var_type") + parameterId = "param1", + value = "7", + varType = "ignored_var_type", + ) val newRunner = makeRunnerCreateRequest( name = "NewRunner", datasetList = mutableListOf(datasetSaved.id), - parametersValues = mutableListOf(creationParameterValue)) + parametersValues = mutableListOf(creationParameterValue), + ) val newRunnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, newRunner) @@ -240,13 +267,17 @@ class RunnerServiceIntegrationTest : CsmTestBase() { val newParameterValue = RunnerRunTemplateParameterValue( - parameterId = "param1", value = "10", varType = "still_ignored_var_type") + parameterId = "param1", + value = "10", + varType = "still_ignored_var_type", + ) val updateRunnerSaved = runnerApiService.updateRunner( organizationSaved.id, workspaceSaved.id, newRunnerSaved.id, - RunnerUpdateRequest(parametersValues = mutableListOf(newParameterValue))) + RunnerUpdateRequest(parametersValues = mutableListOf(newParameterValue)), + ) assertNotNull(updateRunnerSaved.parametersValues) assertTrue(updateRunnerSaved.parametersValues.size == 1) @@ -266,7 +297,8 @@ class RunnerServiceIntegrationTest : CsmTestBase() { makeRunnerCreateRequest( name = "NewRunner", datasetList = mutableListOf(datasetSaved.id), - parametersValues = mutableListOf(creationParameterValue)) + parametersValues = mutableListOf(creationParameterValue), + ) val newRunnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, newRunner) @@ -280,19 +312,24 @@ class RunnerServiceIntegrationTest : CsmTestBase() { organizationSaved.id, solutionSaved.id, parameterId, - RunTemplateParameterUpdateRequest(varType = DATASET_PART_VARTYPE_FILE)) + RunTemplateParameterUpdateRequest(varType = DATASET_PART_VARTYPE_FILE), + ) // 3 - try to update the runner and check that the parameters are updated too val newParameterValue = RunnerRunTemplateParameterValue( - parameterId = parameterId, value = "10", varType = "integer") + parameterId = parameterId, + value = "10", + varType = "integer", + ) val updateRunnerSaved = runnerApiService.updateRunner( organizationSaved.id, workspaceSaved.id, newRunnerSaved.id, - RunnerUpdateRequest(parametersValues = mutableListOf(newParameterValue))) + RunnerUpdateRequest(parametersValues = mutableListOf(newParameterValue)), + ) assertNotNull(updateRunnerSaved.parametersValues) assertTrue(updateRunnerSaved.parametersValues.isEmpty()) @@ -327,12 +364,14 @@ class RunnerServiceIntegrationTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, runnerRetrieved.id, - RunnerUpdateRequest(name = "Runner Updated")) + RunnerUpdateRequest(name = "Runner Updated"), + ) assertEquals( runnerRetrieved.copy(name = "Runner Updated"), runnerUpdated.copy(updateInfo = runnerRetrieved.updateInfo).apply { datasets.parameters = mutableListOf() - }) + }, + ) logger.info("should delete the Runner and assert there is one less Runner left") runnerApiService.deleteRunner(organizationSaved.id, workspaceSaved.id, newRunnerSaved.id) @@ -344,7 +383,10 @@ class RunnerServiceIntegrationTest : CsmTestBase() { // deleteAllRunners still works with high quantities of runners repeat(csmPlatformProperties.databases.resources.runner.defaultPageSize + 1) { runnerApiService.createRunner( - organizationSaved.id, workspaceSaved.id, makeRunnerCreateRequest()) + organizationSaved.id, + workspaceSaved.id, + makeRunnerCreateRequest(), + ) } } @@ -355,7 +397,9 @@ class RunnerServiceIntegrationTest : CsmTestBase() { name = "WorkspaceDataset", parts = mutableListOf( - DatasetPartCreateRequest(name = "defaultPart", sourceName = "test.txt"))) + DatasetPartCreateRequest(name = "defaultPart", sourceName = "test.txt") + ), + ) val workspaceDataset = datasetApiService.createDataset( organizationSaved.id, @@ -366,7 +410,10 @@ class RunnerServiceIntegrationTest : CsmTestBase() { "files", "test.txt", MediaType.MULTIPART_FORM_DATA_VALUE, - "test".toByteArray()))) + "test".toByteArray(), + ) + ), + ) workspaceSaved = workspaceApiService.updateWorkspace( organizationSaved.id, @@ -377,16 +424,21 @@ class RunnerServiceIntegrationTest : CsmTestBase() { solutionId = solutionSaved.id, datasetId = workspaceDataset.id, defaultParameterValues = - mutableMapOf("param2" to workspaceDataset.parts[0].id)))) + mutableMapOf("param2" to workspaceDataset.parts[0].id), + ) + ), + ) val runnerWithInheritedDatasetParameterCreateRequest = makeRunnerCreateRequest( name = "Runner_with_inherited_dataset_parameter", - datasetList = mutableListOf(datasetSaved.id)) + datasetList = mutableListOf(datasetSaved.id), + ) val runnerWithInheritedDatasetParameter = runnerApiService.createRunner( organizationSaved.id, workspaceSaved.id, - runnerWithInheritedDatasetParameterCreateRequest) + runnerWithInheritedDatasetParameterCreateRequest, + ) val runnerList = runnerApiService.listRunners(organizationSaved.id, workspaceSaved.id, null, null) @@ -408,7 +460,9 @@ class RunnerServiceIntegrationTest : CsmTestBase() { name = "WorkspaceDataset", parts = mutableListOf( - DatasetPartCreateRequest(name = "defaultPart", sourceName = "test.txt"))) + DatasetPartCreateRequest(name = "defaultPart", sourceName = "test.txt") + ), + ) val workspaceDataset = datasetApiService.createDataset( organizationSaved.id, @@ -419,7 +473,10 @@ class RunnerServiceIntegrationTest : CsmTestBase() { "files", "test.txt", MediaType.MULTIPART_FORM_DATA_VALUE, - "test".toByteArray()))) + "test".toByteArray(), + ) + ), + ) workspaceSaved = workspaceApiService.updateWorkspace( organizationSaved.id, @@ -430,16 +487,21 @@ class RunnerServiceIntegrationTest : CsmTestBase() { solutionId = solutionSaved.id, datasetId = workspaceDataset.id, defaultParameterValues = - mutableMapOf("param2" to workspaceDataset.parts[0].id)))) + mutableMapOf("param2" to workspaceDataset.parts[0].id), + ) + ), + ) val runnerWithInheritedDatasetParameterCreateRequest = makeRunnerCreateRequest( name = "Runner_with_inherited_dataset_parameter", - datasetList = mutableListOf(datasetSaved.id)) + datasetList = mutableListOf(datasetSaved.id), + ) val runnerWithInheritedDatasetParameter = runnerApiService.createRunner( organizationSaved.id, workspaceSaved.id, - runnerWithInheritedDatasetParameterCreateRequest) + runnerWithInheritedDatasetParameterCreateRequest, + ) assertNotNull(runnerWithInheritedDatasetParameter) val runnerDatasetParameters = @@ -457,7 +519,9 @@ class RunnerServiceIntegrationTest : CsmTestBase() { name = "WorkspaceDataset", parts = mutableListOf( - DatasetPartCreateRequest(name = "defaultPart", sourceName = "test.txt"))) + DatasetPartCreateRequest(name = "defaultPart", sourceName = "test.txt") + ), + ) val workspaceDataset = datasetApiService.createDataset( organizationSaved.id, @@ -468,7 +532,10 @@ class RunnerServiceIntegrationTest : CsmTestBase() { "files", "test.txt", MediaType.MULTIPART_FORM_DATA_VALUE, - "test".toByteArray()))) + "test".toByteArray(), + ) + ), + ) workspaceSaved = workspaceApiService.updateWorkspace( organizationSaved.id, @@ -479,23 +546,29 @@ class RunnerServiceIntegrationTest : CsmTestBase() { solutionId = solutionSaved.id, datasetId = workspaceDataset.id, defaultParameterValues = - mutableMapOf("param2" to workspaceDataset.parts[0].id)))) + mutableMapOf("param2" to workspaceDataset.parts[0].id), + ) + ), + ) val runnerWithInheritedDatasetParameterCreateRequest = makeRunnerCreateRequest( name = "Runner_with_inherited_dataset_parameter", - datasetList = mutableListOf(datasetSaved.id)) + datasetList = mutableListOf(datasetSaved.id), + ) val runnerWithInheritedDatasetParameter = runnerApiService.createRunner( organizationSaved.id, workspaceSaved.id, - runnerWithInheritedDatasetParameterCreateRequest) + runnerWithInheritedDatasetParameterCreateRequest, + ) val runnerUpdatedWithInheritedDatasetParameter = runnerApiService.updateRunner( organizationSaved.id, workspaceSaved.id, runnerWithInheritedDatasetParameter.id, - RunnerUpdateRequest(name = "New Dataset name")) + RunnerUpdateRequest(name = "New Dataset name"), + ) assertNotNull(runnerUpdatedWithInheritedDatasetParameter) val runnerDatasetParameters = @@ -618,19 +691,19 @@ class RunnerServiceIntegrationTest : CsmTestBase() { // Delete grand parent runnerApiService.deleteRunner(organizationSaved.id, workspaceSaved.id, grandParentRunner.id) assertNull( - runnerApiService - .getRunner(organizationSaved.id, workspaceSaved.id, parentRunner1.id) - .rootId) + runnerApiService.getRunner(organizationSaved.id, workspaceSaved.id, parentRunner1.id).rootId + ) assertNull( - runnerApiService - .getRunner(organizationSaved.id, workspaceSaved.id, parentRunner2.id) - .rootId) + runnerApiService.getRunner(organizationSaved.id, workspaceSaved.id, parentRunner2.id).rootId + ) assertEquals( parentRunner1.id, - runnerApiService.getRunner(organizationSaved.id, workspaceSaved.id, childRunner1.id).rootId) + runnerApiService.getRunner(organizationSaved.id, workspaceSaved.id, childRunner1.id).rootId, + ) assertEquals( parentRunner2.id, - runnerApiService.getRunner(organizationSaved.id, workspaceSaved.id, childRunner2.id).rootId) + runnerApiService.getRunner(organizationSaved.id, workspaceSaved.id, childRunner2.id).rootId, + ) } @Test @@ -646,7 +719,11 @@ class RunnerServiceIntegrationTest : CsmTestBase() { val runnerRole = RunnerRole(ROLE_VIEWER) val runnerSecurityRegistered = runnerApiService.updateRunnerDefaultSecurity( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, runnerRole) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + runnerRole, + ) assertEquals(runnerRole.role, runnerSecurityRegistered.default) } @@ -664,7 +741,11 @@ class RunnerServiceIntegrationTest : CsmTestBase() { val runnerRole = RunnerRole(ROLE_VIEWER) assertThrows { runnerApiService.updateRunnerDefaultSecurity( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, runnerRole) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + runnerRole, + ) } } @@ -674,20 +755,33 @@ class RunnerServiceIntegrationTest : CsmTestBase() { val runnerAccessControl = RunnerAccessControl(TEST_USER_MAIL, ROLE_VIEWER) var runnerAccessControlRegistered = runnerApiService.createRunnerAccessControl( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, runnerAccessControl) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + runnerAccessControl, + ) assertEquals(runnerAccessControl, runnerAccessControlRegistered) logger.info("should get the Access Control and assert it is the one created") runnerAccessControlRegistered = runnerApiService.getRunnerAccessControl( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + TEST_USER_MAIL, + ) assertEquals(runnerAccessControl, runnerAccessControlRegistered) logger.info( - "should add an Access Control and assert it is the one created in the parameter dataset") + "should add an Access Control and assert it is the one created in the parameter dataset" + ) assertDoesNotThrow { datasetApiService.getDatasetAccessControl( - organizationSaved.id, workspaceSaved.id, runnerSaved.datasets.parameter, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.datasets.parameter, + TEST_USER_MAIL, + ) } logger.info("should update the Access Control and assert it has been updated") @@ -697,11 +791,13 @@ class RunnerServiceIntegrationTest : CsmTestBase() { workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL, - RunnerRole(ROLE_EDITOR)) + RunnerRole(ROLE_EDITOR), + ) assertEquals(ROLE_EDITOR, runnerAccessControlRegistered.role) logger.info( - "Should not change the parameter dataset access control because ACL already exist on it") + "Should not change the parameter dataset access control because ACL already exist on it" + ) assertEquals( ROLE_VIEWER, datasetApiService @@ -709,28 +805,46 @@ class RunnerServiceIntegrationTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, runnerSaved.datasets.parameter, - TEST_USER_MAIL) - .role) + TEST_USER_MAIL, + ) + .role, + ) logger.info("should get the list of users and assert there are 2") val userList = runnerApiService.listRunnerSecurityUsers( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) assertEquals(3, userList.size) logger.info("should remove the Access Control and assert it has been removed") runnerApiService.deleteRunnerAccessControl( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + TEST_USER_MAIL, + ) assertThrows { runnerApiService.getRunnerAccessControl( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + TEST_USER_MAIL, + ) } logger.info( - "should remove the Access Control and assert it has been removed in the parameter dataset") + "should remove the Access Control and assert it has been removed in the parameter dataset" + ) assertThrows { datasetApiService.getDatasetAccessControl( - organizationSaved.id, workspaceSaved.id, runnerSaved.datasets.parameter, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.datasets.parameter, + TEST_USER_MAIL, + ) } } @@ -742,44 +856,66 @@ class RunnerServiceIntegrationTest : CsmTestBase() { val runnerAccessControl = RunnerAccessControl(TEST_USER_MAIL, ROLE_VIEWER) assertThrows { runnerApiService.createRunnerAccessControl( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, runnerAccessControl) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + runnerAccessControl, + ) } logger.info("should throw CsmAccessForbiddenException when trying to get RunnerAccessControl") assertThrows { runnerApiService.getRunnerAccessControl( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + TEST_USER_MAIL, + ) } logger.info( - "should throw CsmAccessForbiddenException when trying to update RunnerAccessControl") + "should throw CsmAccessForbiddenException when trying to update RunnerAccessControl" + ) assertThrows { runnerApiService.updateRunnerAccessControl( organizationSaved.id, workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL, - RunnerRole(ROLE_VIEWER)) + RunnerRole(ROLE_VIEWER), + ) } logger.info("should throw CsmAccessForbiddenException when getting the list of users") assertThrows { runnerApiService.listRunnerSecurityUsers( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } logger.info( - "should throw CsmAccessForbiddenException when trying to remove RunnerAccessControl") + "should throw CsmAccessForbiddenException when trying to remove RunnerAccessControl" + ) assertThrows { runnerApiService.deleteRunnerAccessControl( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + TEST_USER_MAIL, + ) } } @Test fun `test deleting a running runner`() { runnerApiService.updateRunner( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, RunnerUpdateRequest()) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + RunnerUpdateRequest(), + ) every { eventPublisher.publishEvent(any()) } answers { @@ -792,7 +928,8 @@ class RunnerServiceIntegrationTest : CsmTestBase() { } assertEquals( "Can't delete runner ${runnerSaved.id}: at least one run is still running", - exception.message) + exception.message, + ) } @Test @@ -813,7 +950,8 @@ class RunnerServiceIntegrationTest : CsmTestBase() { "Dataset $parameterDatasetId not found " + "in organization ${organizationSaved.id} " + "and workspace ${workspaceSaved.id}", - exception.message) + exception.message, + ) } @Test @@ -849,7 +987,10 @@ class RunnerServiceIntegrationTest : CsmTestBase() { val parentId = runnerApiService .createRunner( - organizationSaved.id, workspaceSaved.id, parentRunnerWithNonEmptyDatasetList) + organizationSaved.id, + workspaceSaved.id, + parentRunnerWithNonEmptyDatasetList, + ) .id val childRunnerWithNullDatasetList = makeRunnerCreateRequest(parentId = parentId, datasetList = null) @@ -875,7 +1016,10 @@ class RunnerServiceIntegrationTest : CsmTestBase() { val parentId = runnerApiService .createRunner( - organizationSaved.id, workspaceSaved.id, parentRunnerWithNonEmptyDatasetList) + organizationSaved.id, + workspaceSaved.id, + parentRunnerWithNonEmptyDatasetList, + ) .id val childRunnerWithEmptyDatasetList = makeRunnerCreateRequest(parentId = parentId, datasetList = mutableListOf()) @@ -900,7 +1044,10 @@ class RunnerServiceIntegrationTest : CsmTestBase() { val parentId = runnerApiService .createRunner( - organizationSaved.id, workspaceSaved.id, parentRunnerWithNonEmptyDatasetList) + organizationSaved.id, + workspaceSaved.id, + parentRunnerWithNonEmptyDatasetList, + ) .id val childDataset = @@ -908,7 +1055,8 @@ class RunnerServiceIntegrationTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, makeDataset(name = "For Child Runner"), - emptyArray()) + emptyArray(), + ) val childDatasetList = mutableListOf(childDataset.id) val childRunnerWithNonEmptyDatasetList = @@ -916,7 +1064,10 @@ class RunnerServiceIntegrationTest : CsmTestBase() { val childRunnerDatasetList = runnerApiService .createRunner( - organizationSaved.id, workspaceSaved.id, childRunnerWithNonEmptyDatasetList) + organizationSaved.id, + workspaceSaved.id, + childRunnerWithNonEmptyDatasetList, + ) .datasets .bases @@ -928,21 +1079,32 @@ class RunnerServiceIntegrationTest : CsmTestBase() { fun `test updating (adding) runner's datasetList add runner users to new dataset`() { val newDataset = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, makeDataset(), emptyArray()) + organizationSaved.id, + workspaceSaved.id, + makeDataset(), + emptyArray(), + ) runnerSaved = runnerApiService.updateRunner( organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerUpdateRequest(datasetList = mutableListOf(datasetSaved.id, newDataset.id))) + RunnerUpdateRequest(datasetList = mutableListOf(datasetSaved.id, newDataset.id)), + ) val runnerUserList = runnerApiService.listRunnerSecurityUsers( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) val datasetUserList = datasetApiService.listDatasetSecurityUsers( - organizationSaved.id, workspaceSaved.id, newDataset.id) + organizationSaved.id, + workspaceSaved.id, + newDataset.id, + ) datasetUserList.containsAll(runnerUserList) } @@ -965,7 +1127,10 @@ class RunnerServiceIntegrationTest : CsmTestBase() { accessControlList = mutableListOf( RunnerAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), - RunnerAccessControl(CONNECTED_ADMIN_USER, ROLE_EDITOR)))) + RunnerAccessControl(CONNECTED_ADMIN_USER, ROLE_EDITOR), + ), + ), + ) assertThrows { runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, brokenRunner) } @@ -984,7 +1149,10 @@ class RunnerServiceIntegrationTest : CsmTestBase() { val runnerSavedSecurityUsers = runnerApiService.listRunnerSecurityUsers( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) assertEquals(2, runnerSavedSecurityUsers.size) assertThrows { @@ -992,12 +1160,16 @@ class RunnerServiceIntegrationTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerAccessControl(defaultName, ROLE_EDITOR)) + RunnerAccessControl(defaultName, ROLE_EDITOR), + ) } val runnerSecurityUsers = runnerApiService.listRunnerSecurityUsers( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) assertEquals(2, runnerSecurityUsers.size) assert(runnerSavedSecurityUsers == runnerSecurityUsers) } @@ -1015,7 +1187,10 @@ class RunnerServiceIntegrationTest : CsmTestBase() { val runnerSavedSecurityUsers = runnerApiService.listRunnerSecurityUsers( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) assertEquals(2, runnerSavedSecurityUsers.size) assertThrows { @@ -1024,12 +1199,16 @@ class RunnerServiceIntegrationTest : CsmTestBase() { workspaceSaved.id, runnerSaved.id, "invalid user", - RunnerRole(ROLE_VIEWER)) + RunnerRole(ROLE_VIEWER), + ) } val runnerSecurityUsers = runnerApiService.listRunnerSecurityUsers( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) assertEquals(2, runnerSecurityUsers.size) assert(runnerSavedSecurityUsers == runnerSecurityUsers) } @@ -1041,18 +1220,26 @@ class RunnerServiceIntegrationTest : CsmTestBase() { key = "key", name = "workspace", solution = WorkspaceSolution(solutionSaved.id), - datasetCopy = false) + datasetCopy = false, + ) workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val runnerDataset = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, makeDataset(), emptyArray()) + organizationSaved.id, + workspaceSaved.id, + makeDataset(), + emptyArray(), + ) runner = makeRunnerCreateRequest(datasetList = mutableListOf(runnerDataset.id)) runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) val datasetRetrieved = datasetApiService.getDataset( - organizationSaved.id, workspaceSaved.id, runnerSaved.datasets.bases[0]) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.datasets.bases[0], + ) runnerApiService.deleteRunner(organizationSaved.id, workspaceSaved.id, runnerSaved.id) assertDoesNotThrow { @@ -1067,11 +1254,16 @@ class RunnerServiceIntegrationTest : CsmTestBase() { key = "key", name = "workspace", solution = WorkspaceSolution(solutionSaved.id), - datasetCopy = true) + datasetCopy = true, + ) workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val runnerDataset = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, makeDataset("runnerDataset"), emptyArray()) + organizationSaved.id, + workspaceSaved.id, + makeDataset("runnerDataset"), + emptyArray(), + ) runner = makeRunnerCreateRequest(datasetList = mutableListOf(runnerDataset.id)) runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) @@ -1079,16 +1271,24 @@ class RunnerServiceIntegrationTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerAccessControl(id = "id", role = ROLE_EDITOR)) + RunnerAccessControl(id = "id", role = ROLE_EDITOR), + ) val retrievedDataset = datasetApiService.getDataset( - organizationSaved.id, workspaceSaved.id, runnerSaved.datasets.bases[0]) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.datasets.bases[0], + ) val exception = assertThrows { datasetApiService.getDatasetAccessControl( - organizationSaved.id, workspaceSaved.id, retrievedDataset.id, "id") + organizationSaved.id, + workspaceSaved.id, + retrievedDataset.id, + "id", + ) } assertEquals("Entity id not found in ${retrievedDataset.id} component", exception.message) } @@ -1104,7 +1304,10 @@ class RunnerServiceIntegrationTest : CsmTestBase() { val runTemplateId = "runTemplateId" val newRunner = RunnerCreateRequest( - name = name, solutionId = solutionSaved.id, runTemplateId = runTemplateId) + name = name, + solutionId = solutionSaved.id, + runTemplateId = runTemplateId, + ) val newRunnerCreated = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, newRunner) @@ -1125,16 +1328,21 @@ class RunnerServiceIntegrationTest : CsmTestBase() { parentId = "unknown_parent_id", runTemplateId = "unknown_runtemplate_id", datasetList = mutableListOf(datasetSaved.id), - parametersValues = mutableListOf(runTemplateParameterValue2)) + parametersValues = mutableListOf(runTemplateParameterValue2), + ) val assertThrows = assertThrows { runnerApiService.createRunner( - organizationSaved.id, workspaceSaved.id, runnerWithWrongRunTemplateId) + organizationSaved.id, + workspaceSaved.id, + runnerWithWrongRunTemplateId, + ) } assertEquals( "Solution run template with id ${runnerWithWrongRunTemplateId.runTemplateId} does not exist", - assertThrows.message) + assertThrows.message, + ) } @Test @@ -1145,12 +1353,16 @@ class RunnerServiceIntegrationTest : CsmTestBase() { name = "Runner_With_unknown_parent", parentId = parentId, datasetList = mutableListOf(datasetSaved.id), - parametersValues = mutableListOf(runTemplateParameterValue2)) + parametersValues = mutableListOf(runTemplateParameterValue2), + ) val assertThrows = assertThrows { runnerApiService.createRunner( - organizationSaved.id, workspaceSaved.id, runnerWithWrongParentId) + organizationSaved.id, + workspaceSaved.id, + runnerWithWrongParentId, + ) } assertTrue(assertThrows.message!!.startsWith("Parent Id $parentId define on")) } @@ -1168,7 +1380,10 @@ class RunnerServiceIntegrationTest : CsmTestBase() { val parentRunnerWithEmptyParams = makeRunnerCreateRequest(name = "parent") val parentRunnerSaved = runnerApiService.createRunner( - organizationSaved.id, workspaceSaved.id, parentRunnerWithEmptyParams) + organizationSaved.id, + workspaceSaved.id, + parentRunnerWithEmptyParams, + ) val parentRunnerUpdated = runnerApiService.updateRunner( @@ -1182,19 +1397,28 @@ class RunnerServiceIntegrationTest : CsmTestBase() { parameterId = "param1", value = "param1value", isInherited = false, - varType = "String")))) + varType = "String", + ) + ) + ), + ) val childRunnerWithEmptyParams = makeRunnerCreateRequest(name = "child", parentId = parentRunnerUpdated.id) val childRunnerWithEmptyParamsSaved = runnerApiService.createRunner( - organizationSaved.id, workspaceSaved.id, childRunnerWithEmptyParams) + organizationSaved.id, + workspaceSaved.id, + childRunnerWithEmptyParams, + ) assertNotNull(childRunnerWithEmptyParamsSaved.parametersValues) assertEquals(1, childRunnerWithEmptyParamsSaved.parametersValues.size) assertEquals( - mutableListOf(runTemplateParameterValue1), childRunnerWithEmptyParamsSaved.parametersValues) + mutableListOf(runTemplateParameterValue1), + childRunnerWithEmptyParamsSaved.parametersValues, + ) } @Test @@ -1210,33 +1434,46 @@ class RunnerServiceIntegrationTest : CsmTestBase() { mutableListOf( RunTemplateParameterGroupCreateRequest( id = "defaultDatasetPartParameterGroup", - parameters = mutableListOf("datasetPartParam"))), + parameters = mutableListOf("datasetPartParam"), + ) + ), parameters = mutableListOf( RunTemplateParameterCreateRequest( id = "datasetPartParam", defaultValue = "this_value_is_ignored", - varType = DATASET_PART_VARTYPE_DB)), + varType = DATASET_PART_VARTYPE_DB, + ) + ), runTemplates = mutableListOf( RunTemplateCreateRequest( id = "runTemplateWithOneDatasetPartByDefault", - parameterGroups = mutableListOf("defaultDatasetPartParameterGroup"))), + parameterGroups = mutableListOf("defaultDatasetPartParameterGroup"), + ) + ), repository = "repository", - version = "1.0.0")) + version = "1.0.0", + ), + ) workspace = WorkspaceCreateRequest( key = "key", name = "workspace", solution = WorkspaceSolution(solutionSaved.id), - datasetCopy = false) + datasetCopy = false, + ) workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val customersFile = resourceLoader.getResource("classpath:/$CUSTOMERS_FILE_NAME").file val customersInputStream = FileInputStream(customersFile) val customersMultipartFile = MockMultipartFile( - "file", CUSTOMERS_FILE_NAME, "text/csv", IOUtils.toByteArray(customersInputStream)) + "file", + CUSTOMERS_FILE_NAME, + "text/csv", + IOUtils.toByteArray(customersInputStream), + ) val workspaceDataset = datasetApiService.createDataset( organizationSaved.id, @@ -1248,8 +1485,12 @@ class RunnerServiceIntegrationTest : CsmTestBase() { DatasetPartCreateRequest( name = "datasetPart1", sourceName = CUSTOMERS_FILE_NAME, - type = DatasetPartTypeEnum.DB))), - arrayOf(customersMultipartFile)) + type = DatasetPartTypeEnum.DB, + ) + ), + ), + arrayOf(customersMultipartFile), + ) workspaceSaved = workspaceApiService.updateWorkspace( organizationSaved.id, @@ -1260,20 +1501,28 @@ class RunnerServiceIntegrationTest : CsmTestBase() { solutionId = solutionSaved.id, datasetId = workspaceDataset.id, defaultParameterValues = - mutableMapOf("datasetPartParam" to workspaceDataset.parts[0].id)))) + mutableMapOf("datasetPartParam" to workspaceDataset.parts[0].id), + ) + ), + ) val runner = runnerApiService.createRunner( organizationSaved.id, workspaceSaved.id, - makeRunnerCreateRequest(runTemplateId = "runTemplateWithOneDatasetPartByDefault")) + makeRunnerCreateRequest(runTemplateId = "runTemplateWithOneDatasetPartByDefault"), + ) val runnerDatasetId = runner.datasets.parameter val runnerDataset = datasetApiService.getDataset(organizationSaved.id, workspaceSaved.id, runnerDatasetId) val inheritedRunnerDatasetPartContent = datasetApiService.downloadDatasetPart( - organizationSaved.id, workspaceSaved.id, runnerDataset.id, runnerDataset.parts[0].id) + organizationSaved.id, + workspaceSaved.id, + runnerDataset.id, + runnerDataset.parts[0].id, + ) val expectedText = FileInputStream(customersFile).bufferedReader().use { it.readText() } val retrievedText = InputStreamResource(inheritedRunnerDatasetPartContent).inputStream.bufferedReader().use { @@ -1295,33 +1544,46 @@ class RunnerServiceIntegrationTest : CsmTestBase() { mutableListOf( RunTemplateParameterGroupCreateRequest( id = "defaultDatasetPartParameterGroup", - parameters = mutableListOf("datasetPartParam"))), + parameters = mutableListOf("datasetPartParam"), + ) + ), parameters = mutableListOf( RunTemplateParameterCreateRequest( id = "datasetPartParam", defaultValue = "this_value_is_ignored", - varType = DATASET_PART_VARTYPE_DB)), + varType = DATASET_PART_VARTYPE_DB, + ) + ), runTemplates = mutableListOf( RunTemplateCreateRequest( id = "runTemplateWithOneDatasetPartByDefault", - parameterGroups = mutableListOf("defaultDatasetPartParameterGroup"))), + parameterGroups = mutableListOf("defaultDatasetPartParameterGroup"), + ) + ), repository = "repository", - version = "1.0.0")) + version = "1.0.0", + ), + ) workspace = WorkspaceCreateRequest( key = "key", name = "workspace", solution = WorkspaceSolution(solutionSaved.id), - datasetCopy = false) + datasetCopy = false, + ) workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val customersFile = resourceLoader.getResource("classpath:/$CUSTOMERS_FILE_NAME").file val customersInputStream = FileInputStream(customersFile) val customersMultipartFile = MockMultipartFile( - "file", CUSTOMERS_FILE_NAME, "text/csv", IOUtils.toByteArray(customersInputStream)) + "file", + CUSTOMERS_FILE_NAME, + "text/csv", + IOUtils.toByteArray(customersInputStream), + ) val workspaceDataset = datasetApiService.createDataset( organizationSaved.id, @@ -1333,8 +1595,12 @@ class RunnerServiceIntegrationTest : CsmTestBase() { DatasetPartCreateRequest( name = "datasetPart1", sourceName = CUSTOMERS_FILE_NAME, - type = DatasetPartTypeEnum.DB))), - arrayOf(customersMultipartFile)) + type = DatasetPartTypeEnum.DB, + ) + ), + ), + arrayOf(customersMultipartFile), + ) workspaceSaved = workspaceApiService.updateWorkspace( organizationSaved.id, @@ -1345,13 +1611,17 @@ class RunnerServiceIntegrationTest : CsmTestBase() { solutionId = solutionSaved.id, datasetId = workspaceDataset.id, defaultParameterValues = - mutableMapOf("datasetPartParam" to workspaceDataset.parts[0].id)))) + mutableMapOf("datasetPartParam" to workspaceDataset.parts[0].id), + ) + ), + ) val runner = runnerApiService.createRunner( organizationSaved.id, workspaceSaved.id, - makeRunnerCreateRequest(runTemplateId = "runTemplateWithOneDatasetPartByDefault")) + makeRunnerCreateRequest(runTemplateId = "runTemplateWithOneDatasetPartByDefault"), + ) val runnerDatasetId = runner.datasets.parameter val runnerDataset = @@ -1364,7 +1634,8 @@ class RunnerServiceIntegrationTest : CsmTestBase() { "file", CUSTOMERS_5_LINES_FILE_NAME, "text/csv", - IOUtils.toByteArray(customers5InputStream)) + IOUtils.toByteArray(customers5InputStream), + ) val runnerDatasetPartId = runnerDataset.parts[0].id @@ -1374,14 +1645,18 @@ class RunnerServiceIntegrationTest : CsmTestBase() { runnerDataset.id, runnerDatasetPartId, customers5MultipartFile, - DatasetPartUpdateRequest(sourceName = CUSTOMERS_5_LINES_FILE_NAME)) + DatasetPartUpdateRequest(sourceName = CUSTOMERS_5_LINES_FILE_NAME), + ) val childRunner = runnerApiService.createRunner( organizationSaved.id, workspaceSaved.id, makeRunnerCreateRequest( - runTemplateId = "runTemplateWithOneDatasetPartByDefault", parentId = runner.id)) + runTemplateId = "runTemplateWithOneDatasetPartByDefault", + parentId = runner.id, + ), + ) val childRunnerDatasetId = childRunner.datasets.parameter val childRunnerDataset = @@ -1392,7 +1667,8 @@ class RunnerServiceIntegrationTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, childRunnerDataset.id, - childRunnerDataset.parts[0].id) + childRunnerDataset.parts[0].id, + ) val expectedText = FileInputStream(customers5File).bufferedReader().use { it.readText() } val retrievedText = InputStreamResource(childRunnerDatasetPartContent).inputStream.bufferedReader().use { @@ -1427,7 +1703,10 @@ class RunnerServiceIntegrationTest : CsmTestBase() { val runner = runnerApiService.createRunner( - organizationSaved.id, workspaceSaved.id, makeRunnerCreateRequest()) + organizationSaved.id, + workspaceSaved.id, + makeRunnerCreateRequest(), + ) assertNull(runner.lastRunInfo.lastRunId) assertEquals(LastRunInfo.LastRunStatus.NotStarted, runner.lastRunInfo.lastRunStatus) @@ -1554,8 +1833,11 @@ class RunnerServiceIntegrationTest : CsmTestBase() { runnerApiService.getRunner(organizationSaved.id, workspaceSaved.id, runnerSaved.id) assertEquals( RunnerSecurity( - default = ROLE_NONE, mutableListOf(RunnerAccessControl(defaultName, ROLE_VIEWER))), - runnerSaved.security) + default = ROLE_NONE, + mutableListOf(RunnerAccessControl(defaultName, ROLE_VIEWER)), + ), + runnerSaved.security, + ) assertEquals(1, runnerSaved.security.accessControlList.size) } @@ -1573,8 +1855,11 @@ class RunnerServiceIntegrationTest : CsmTestBase() { runners.forEach { assertEquals( RunnerSecurity( - default = ROLE_NONE, mutableListOf(RunnerAccessControl(defaultName, ROLE_VIEWER))), - it.security) + default = ROLE_NONE, + mutableListOf(RunnerAccessControl(defaultName, ROLE_VIEWER)), + ), + it.security, + ) assertEquals(1, it.security.accessControlList.size) } } @@ -1592,9 +1877,12 @@ class RunnerServiceIntegrationTest : CsmTestBase() { assertEquals(ROLE_NONE, runnerSaved.security.default) assertEquals( RunnerAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), - runnerSaved.security.accessControlList[0]) + runnerSaved.security.accessControlList[0], + ) assertEquals( - RunnerAccessControl(defaultName, ROLE_VALIDATOR), runnerSaved.security.accessControlList[1]) + RunnerAccessControl(defaultName, ROLE_VALIDATOR), + runnerSaved.security.accessControlList[1], + ) } @Test @@ -1612,9 +1900,13 @@ class RunnerServiceIntegrationTest : CsmTestBase() { assertEquals(2, it.security.accessControlList.size) assertEquals(ROLE_NONE, it.security.default) assertEquals( - RunnerAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), it.security.accessControlList[0]) + RunnerAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), + it.security.accessControlList[0], + ) assertEquals( - RunnerAccessControl(defaultName, ROLE_VALIDATOR), it.security.accessControlList[1]) + RunnerAccessControl(defaultName, ROLE_VALIDATOR), + it.security.accessControlList[1], + ) } } @@ -1622,7 +1914,10 @@ class RunnerServiceIntegrationTest : CsmTestBase() { fun `assert timestamps are functional for base CRUD`() { runnerSaved = runnerApiService.createRunner( - organizationSaved.id, workspaceSaved.id, makeRunnerCreateRequest()) + organizationSaved.id, + workspaceSaved.id, + makeRunnerCreateRequest(), + ) assertTrue(runnerSaved.createInfo.timestamp > startTime) assertEquals(runnerSaved.createInfo, runnerSaved.updateInfo) @@ -1632,7 +1927,8 @@ class RunnerServiceIntegrationTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerUpdateRequest("runnerUpdated")) + RunnerUpdateRequest("runnerUpdated"), + ) assertTrue { updateTime < runnerUpdated.updateInfo.timestamp } assertEquals(runnerSaved.createInfo, runnerUpdated.createInfo) @@ -1650,12 +1946,16 @@ class RunnerServiceIntegrationTest : CsmTestBase() { fun `assert timestamps are functional for RBAC CRUD`() { runnerSaved = runnerApiService.createRunner( - organizationSaved.id, workspaceSaved.id, makeRunnerCreateRequest()) + organizationSaved.id, + workspaceSaved.id, + makeRunnerCreateRequest(), + ) runnerApiService.createRunnerAccessControl( organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerAccessControl("newUser", ROLE_VIEWER)) + RunnerAccessControl("newUser", ROLE_VIEWER), + ) val rbacAdded = runnerApiService.getRunner(organizationSaved.id, workspaceSaved.id, runnerSaved.id) @@ -1663,7 +1963,11 @@ class RunnerServiceIntegrationTest : CsmTestBase() { assertTrue { runnerSaved.updateInfo.timestamp < rbacAdded.updateInfo.timestamp } runnerApiService.getRunnerAccessControl( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, "newUser") + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + "newUser", + ) val rbacFetched = runnerApiService.getRunner(organizationSaved.id, workspaceSaved.id, runnerSaved.id) @@ -1671,7 +1975,12 @@ class RunnerServiceIntegrationTest : CsmTestBase() { assertEquals(rbacAdded.updateInfo, rbacFetched.updateInfo) runnerApiService.updateRunnerAccessControl( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, "newUser", RunnerRole(ROLE_VIEWER)) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + "newUser", + RunnerRole(ROLE_VIEWER), + ) val rbacUpdated = runnerApiService.getRunner(organizationSaved.id, workspaceSaved.id, runnerSaved.id) @@ -1679,7 +1988,11 @@ class RunnerServiceIntegrationTest : CsmTestBase() { assertTrue { rbacFetched.updateInfo.timestamp < rbacUpdated.updateInfo.timestamp } runnerApiService.deleteRunnerAccessControl( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, "newUser") + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + "newUser", + ) val rbacDeleted = runnerApiService.getRunner(organizationSaved.id, workspaceSaved.id, runnerSaved.id) @@ -1699,23 +2012,32 @@ class RunnerServiceIntegrationTest : CsmTestBase() { mutableListOf( RunTemplateParameterGroupCreateRequest( id = "testParameterGroups", - parameters = mutableListOf("my_property_name"))), + parameters = mutableListOf("my_property_name"), + ) + ), parameters = mutableListOf( RunTemplateParameterCreateRequest( id = "my_property_name", defaultValue = "ignored_default_value", - varType = DATASET_PART_VARTYPE_FILE)), + varType = DATASET_PART_VARTYPE_FILE, + ) + ), runTemplates = mutableListOf( RunTemplateCreateRequest( id = "runTemplateId", - parameterGroups = mutableListOf("testParameterGroups"))), + parameterGroups = mutableListOf("testParameterGroups"), + ) + ), repository = "repository", - version = "1.0.0") + version = "1.0.0", + ) solutionSaved = solutionApiService.createSolution( - organizationSaved.id, solutionCreateRequestWithDatasetParameters) + organizationSaved.id, + solutionCreateRequestWithDatasetParameters, + ) // 2 - Create a workspace workspace = makeWorkspaceCreateRequest("Workspace") @@ -1740,8 +2062,12 @@ class RunnerServiceIntegrationTest : CsmTestBase() { DatasetPartCreateRequest( name = "my_property_name", sourceName = CUSTOMERS_FILE_NAME, - type = DatasetPartTypeEnum.File))), - arrayOf(multipartFile)) + type = DatasetPartTypeEnum.File, + ) + ), + ), + arrayOf(multipartFile), + ) // 4- Create update workspace with default dataset @@ -1754,14 +2080,18 @@ class RunnerServiceIntegrationTest : CsmTestBase() { solutionId = solutionSaved.id, datasetId = workspaceDataset.id, defaultParameterValues = - mutableMapOf("my_property_name" to workspaceDataset.parts[0].id)))) + mutableMapOf("my_property_name" to workspaceDataset.parts[0].id), + ) + ), + ) // 5 - Create a runner with the newly created solution using the runTemplate val runnerCreateRequest = RunnerCreateRequest( name = "Runner with expected dataset parameter", solutionId = solutionSaved.id, - runTemplateId = "runTemplateId") + runTemplateId = "runTemplateId", + ) val createdRunner = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runnerCreateRequest) @@ -1774,7 +2104,10 @@ class RunnerServiceIntegrationTest : CsmTestBase() { val datasetParameter = datasetApiService.getDataset( - organizationSaved.id, workspaceSaved.id, retrievedRunner.datasets.parameter) + organizationSaved.id, + workspaceSaved.id, + retrievedRunner.datasets.parameter, + ) assertEquals(datasetParameter.parts.size, retrievedRunner.datasets.parameters!!.size) @@ -1786,7 +2119,8 @@ class RunnerServiceIntegrationTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, retrievedRunner.datasets.parameter, - runnerDatasetPartId) + runnerDatasetPartId, + ) val expectedText = FileInputStream(resourceTestFile).bufferedReader().use { it.readText() } val retrievedText = @@ -1809,23 +2143,33 @@ class RunnerServiceIntegrationTest : CsmTestBase() { parameterGroups = mutableListOf( RunTemplateParameterGroupCreateRequest( - id = "testParameterGroups", parameters = mutableListOf(simpleParameterId))), + id = "testParameterGroups", + parameters = mutableListOf(simpleParameterId), + ) + ), parameters = mutableListOf( RunTemplateParameterCreateRequest( id = simpleParameterId, defaultValue = simpleParameterDefaultValue, - varType = simpleParameterVarType)), + varType = simpleParameterVarType, + ) + ), runTemplates = mutableListOf( RunTemplateCreateRequest( id = "runTemplateId", - parameterGroups = mutableListOf("testParameterGroups"))), + parameterGroups = mutableListOf("testParameterGroups"), + ) + ), repository = "repository", - version = "1.0.0") + version = "1.0.0", + ) solutionSaved = solutionApiService.createSolution( - organizationSaved.id, solutionCreateRequestWithDatasetParameters) + organizationSaved.id, + solutionCreateRequestWithDatasetParameters, + ) workspace = makeWorkspaceCreateRequest("Workspace") workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) @@ -1835,7 +2179,8 @@ class RunnerServiceIntegrationTest : CsmTestBase() { RunnerCreateRequest( name = "Runner with expected dataset parameter", solutionId = solutionSaved.id, - runTemplateId = "runTemplateId") + runTemplateId = "runTemplateId", + ) val createdRunner = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runnerCreateRequest) @@ -1848,7 +2193,10 @@ class RunnerServiceIntegrationTest : CsmTestBase() { val datasetParameter = datasetApiService.getDataset( - organizationSaved.id, workspaceSaved.id, retrievedRunner.datasets.parameter) + organizationSaved.id, + workspaceSaved.id, + retrievedRunner.datasets.parameter, + ) assertEquals(0, datasetParameter.parts.size) @@ -1876,23 +2224,33 @@ class RunnerServiceIntegrationTest : CsmTestBase() { parameterGroups = mutableListOf( RunTemplateParameterGroupCreateRequest( - id = "testParameterGroups", parameters = mutableListOf(simpleParameterId))), + id = "testParameterGroups", + parameters = mutableListOf(simpleParameterId), + ) + ), parameters = mutableListOf( RunTemplateParameterCreateRequest( id = simpleParameterId, defaultValue = simpleParameterDefaultValue, - varType = simpleParameterVarType)), + varType = simpleParameterVarType, + ) + ), runTemplates = mutableListOf( RunTemplateCreateRequest( id = "runTemplateId", - parameterGroups = mutableListOf("testParameterGroups"))), + parameterGroups = mutableListOf("testParameterGroups"), + ) + ), repository = "repository", - version = "1.0.0") + version = "1.0.0", + ) solutionSaved = solutionApiService.createSolution( - organizationSaved.id, solutionCreateRequestWithDatasetParameters) + organizationSaved.id, + solutionCreateRequestWithDatasetParameters, + ) val simpleParameterOverridedValue = "my_override_value" workspace = @@ -1902,7 +2260,9 @@ class RunnerServiceIntegrationTest : CsmTestBase() { WorkspaceSolution( solutionId = solutionSaved.id, defaultParameterValues = - mutableMapOf(simpleParameterId to simpleParameterOverridedValue))) + mutableMapOf(simpleParameterId to simpleParameterOverridedValue), + ), + ) workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) // 2 - Create a runner with the newly created solution using the runTemplate @@ -1910,7 +2270,8 @@ class RunnerServiceIntegrationTest : CsmTestBase() { RunnerCreateRequest( name = "Runner with expected dataset parameter", solutionId = solutionSaved.id, - runTemplateId = "runTemplateId") + runTemplateId = "runTemplateId", + ) val createdRunner = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runnerCreateRequest) @@ -1923,7 +2284,10 @@ class RunnerServiceIntegrationTest : CsmTestBase() { val datasetParameter = datasetApiService.getDataset( - organizationSaved.id, workspaceSaved.id, retrievedRunner.datasets.parameter) + organizationSaved.id, + workspaceSaved.id, + retrievedRunner.datasets.parameter, + ) assertEquals(0, datasetParameter.parts.size) @@ -1949,21 +2313,31 @@ class RunnerServiceIntegrationTest : CsmTestBase() { mutableListOf( RunTemplateParameterGroupCreateRequest( id = "testParameterGroups", - parameters = mutableListOf("my_property_name"))), + parameters = mutableListOf("my_property_name"), + ) + ), parameters = mutableListOf( RunTemplateParameterCreateRequest( - id = "my_property_name", varType = DATASET_PART_VARTYPE_FILE)), + id = "my_property_name", + varType = DATASET_PART_VARTYPE_FILE, + ) + ), runTemplates = mutableListOf( RunTemplateCreateRequest( id = "runTemplateId", - parameterGroups = mutableListOf("testParameterGroups"))), + parameterGroups = mutableListOf("testParameterGroups"), + ) + ), repository = "repository", - version = "1.0.0") + version = "1.0.0", + ) solutionSaved = solutionApiService.createSolution( - organizationSaved.id, solutionCreateRequestWithDatasetParameters) + organizationSaved.id, + solutionCreateRequestWithDatasetParameters, + ) // 2 - Create a workspace @@ -1988,8 +2362,12 @@ class RunnerServiceIntegrationTest : CsmTestBase() { DatasetPartCreateRequest( name = "my_property_name", sourceName = CUSTOMERS_FILE_NAME, - type = DatasetPartTypeEnum.File))), - arrayOf(multipartFile)) + type = DatasetPartTypeEnum.File, + ) + ), + ), + arrayOf(multipartFile), + ) // 4- Create update workspace with default dataset workspaceApiService.updateWorkspace( @@ -2001,7 +2379,10 @@ class RunnerServiceIntegrationTest : CsmTestBase() { solutionId = solutionSaved.id, datasetId = workspaceDataset.id, defaultParameterValues = - mutableMapOf("my_property_name" to workspaceDataset.parts[0].id)))) + mutableMapOf("my_property_name" to workspaceDataset.parts[0].id), + ) + ), + ) // 5 - Create a parent runner with the newly created solution using the runTemplate with no // value @@ -2009,11 +2390,15 @@ class RunnerServiceIntegrationTest : CsmTestBase() { RunnerCreateRequest( name = "Parent Runner with expected dataset parameter", solutionId = solutionSaved.id, - runTemplateId = "runTemplateId") + runTemplateId = "runTemplateId", + ) val parentCreatedRunner = runnerApiService.createRunner( - organizationSaved.id, workspaceSaved.id, parentRunnerCreateRequest) + organizationSaved.id, + workspaceSaved.id, + parentRunnerCreateRequest, + ) // 4 - Check parent runner parameters val retrievedParentRunner = @@ -2023,7 +2408,10 @@ class RunnerServiceIntegrationTest : CsmTestBase() { val datasetParameterFromParentRunner = datasetApiService.getDataset( - organizationSaved.id, workspaceSaved.id, retrievedParentRunner.datasets.parameter) + organizationSaved.id, + workspaceSaved.id, + retrievedParentRunner.datasets.parameter, + ) assertEquals(1, datasetParameterFromParentRunner.parts.size) @@ -2033,11 +2421,15 @@ class RunnerServiceIntegrationTest : CsmTestBase() { name = "Child Runner with expected dataset parameter", solutionId = solutionSaved.id, runTemplateId = "runTemplateId", - parentId = parentCreatedRunner.id) + parentId = parentCreatedRunner.id, + ) val childCreatedRunner = runnerApiService.createRunner( - organizationSaved.id, workspaceSaved.id, childRunnerCreateRequest) + organizationSaved.id, + workspaceSaved.id, + childRunnerCreateRequest, + ) // 6 - Check child runner parameters val retrievedChildRunner = @@ -2045,19 +2437,26 @@ class RunnerServiceIntegrationTest : CsmTestBase() { assertNotNull(retrievedChildRunner.datasets.parameters) assertEquals(1, retrievedChildRunner.datasets.parameters!!.size) assertNotEquals( - retrievedParentRunner.datasets.parameter, retrievedChildRunner.datasets.parameter) + retrievedParentRunner.datasets.parameter, + retrievedChildRunner.datasets.parameter, + ) val datasetParameterFromChildRunner = datasetApiService.getDataset( - organizationSaved.id, workspaceSaved.id, retrievedChildRunner.datasets.parameter) + organizationSaved.id, + workspaceSaved.id, + retrievedChildRunner.datasets.parameter, + ) assertEquals( datasetParameterFromChildRunner.parts, - retrievedChildRunner.datasets.parameters as MutableList) + retrievedChildRunner.datasets.parameters as MutableList, + ) assertNotEquals( datasetParameterFromChildRunner.parts, - retrievedParentRunner.datasets.parameters as MutableList) + retrievedParentRunner.datasets.parameters as MutableList, + ) // 7 - Check DatasetPart content on child runner val childRunnerDatasetPartId = datasetParameterFromChildRunner.parts[0].id @@ -2067,7 +2466,8 @@ class RunnerServiceIntegrationTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, retrievedChildRunner.datasets.parameter, - childRunnerDatasetPartId) + childRunnerDatasetPartId, + ) val parentRunnerDatasetPartId = datasetParameterFromParentRunner.parts[0].id @@ -2076,7 +2476,8 @@ class RunnerServiceIntegrationTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, retrievedParentRunner.datasets.parameter, - parentRunnerDatasetPartId) + parentRunnerDatasetPartId, + ) val expectedText = FileInputStream(resourceTestFile).bufferedReader().use { it.readText() } @@ -2109,25 +2510,36 @@ class RunnerServiceIntegrationTest : CsmTestBase() { mutableListOf( RunTemplateParameterGroupCreateRequest( id = "testParameterGroups", - parameters = mutableListOf(parameterFileId, parameterStringId))), + parameters = mutableListOf(parameterFileId, parameterStringId), + ) + ), parameters = mutableListOf( RunTemplateParameterCreateRequest( - id = parameterFileId, varType = DATASET_PART_VARTYPE_FILE), + id = parameterFileId, + varType = DATASET_PART_VARTYPE_FILE, + ), RunTemplateParameterCreateRequest( id = parameterStringId, defaultValue = parameterStringDefaultValue, - varType = parameterStringVarType)), + varType = parameterStringVarType, + ), + ), runTemplates = mutableListOf( RunTemplateCreateRequest( id = "runTemplateId", - parameterGroups = mutableListOf("testParameterGroups"))), + parameterGroups = mutableListOf("testParameterGroups"), + ) + ), repository = "repository", - version = "1.0.0") + version = "1.0.0", + ) solutionSaved = solutionApiService.createSolution( - organizationSaved.id, solutionCreateRequestWithDatasetParameters) + organizationSaved.id, + solutionCreateRequestWithDatasetParameters, + ) workspace = makeWorkspaceCreateRequest("Workspace") workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) @@ -2150,8 +2562,12 @@ class RunnerServiceIntegrationTest : CsmTestBase() { DatasetPartCreateRequest( name = parameterFileId, sourceName = CUSTOMERS_FILE_NAME, - type = DatasetPartTypeEnum.File))), - arrayOf(multipartFile)) + type = DatasetPartTypeEnum.File, + ) + ), + ), + arrayOf(multipartFile), + ) // 3- Create update workspace with default dataset @@ -2164,18 +2580,25 @@ class RunnerServiceIntegrationTest : CsmTestBase() { solutionId = solutionSaved.id, datasetId = workspaceDataset.id, defaultParameterValues = - mutableMapOf(parameterFileId to workspaceDataset.parts[0].id)))) + mutableMapOf(parameterFileId to workspaceDataset.parts[0].id), + ) + ), + ) // 4 - Create a parent runner with the newly created solution using the runTemplate val parentRunnerCreateRequest = RunnerCreateRequest( name = "Parent Runner with expected dataset parameter", solutionId = solutionSaved.id, - runTemplateId = "runTemplateId") + runTemplateId = "runTemplateId", + ) val parentCreatedRunner = runnerApiService.createRunner( - organizationSaved.id, workspaceSaved.id, parentRunnerCreateRequest) + organizationSaved.id, + workspaceSaved.id, + parentRunnerCreateRequest, + ) // 5 - Check parent runner parameters val retrievedParentRunner = @@ -2190,14 +2613,19 @@ class RunnerServiceIntegrationTest : CsmTestBase() { val datasetParameterFromParentRunner = datasetApiService.getDataset( - organizationSaved.id, workspaceSaved.id, retrievedParentRunner.datasets.parameter) + organizationSaved.id, + workspaceSaved.id, + retrievedParentRunner.datasets.parameter, + ) assertEquals( datasetParameterFromParentRunner.parts.size, - retrievedParentRunner.datasets.parameters!!.size) + retrievedParentRunner.datasets.parameters!!.size, + ) assertEquals( datasetParameterFromParentRunner.parts, - retrievedParentRunner.datasets.parameters!! as MutableList) + retrievedParentRunner.datasets.parameters!! as MutableList, + ) // 6 - Create a child runner val childRunnerCreateRequest = @@ -2205,11 +2633,15 @@ class RunnerServiceIntegrationTest : CsmTestBase() { name = "Child Runner with expected dataset parameter", solutionId = solutionSaved.id, runTemplateId = "runTemplateId", - parentId = parentCreatedRunner.id) + parentId = parentCreatedRunner.id, + ) val childCreatedRunner = runnerApiService.createRunner( - organizationSaved.id, workspaceSaved.id, childRunnerCreateRequest) + organizationSaved.id, + workspaceSaved.id, + childRunnerCreateRequest, + ) // 7 - Check child runner parameters val retrievedChildRunner = @@ -2217,7 +2649,9 @@ class RunnerServiceIntegrationTest : CsmTestBase() { assertNotNull(retrievedChildRunner.datasets.parameters) assertEquals(1, retrievedChildRunner.datasets.parameters!!.size) assertNotEquals( - retrievedParentRunner.datasets.parameter, retrievedChildRunner.datasets.parameter) + retrievedParentRunner.datasets.parameter, + retrievedChildRunner.datasets.parameter, + ) assertEquals(1, retrievedChildRunner.parametersValues.size) val childRunnerParameterValue = retrievedChildRunner.parametersValues[0] assertEquals(parameterStringId, childRunnerParameterValue.parameterId) @@ -2226,15 +2660,20 @@ class RunnerServiceIntegrationTest : CsmTestBase() { val datasetParameterFromChildRunner = datasetApiService.getDataset( - organizationSaved.id, workspaceSaved.id, retrievedChildRunner.datasets.parameter) + organizationSaved.id, + workspaceSaved.id, + retrievedChildRunner.datasets.parameter, + ) assertEquals( datasetParameterFromChildRunner.parts, - retrievedChildRunner.datasets.parameters as MutableList) + retrievedChildRunner.datasets.parameters as MutableList, + ) assertNotEquals( datasetParameterFromChildRunner.parts, - retrievedParentRunner.datasets.parameters as MutableList) + retrievedParentRunner.datasets.parameters as MutableList, + ) } @Test @@ -2250,10 +2689,16 @@ class RunnerServiceIntegrationTest : CsmTestBase() { runTemplates = mutableListOf( RunTemplateCreateRequest( - id = "runTemplateId", parameterGroups = mutableListOf()))) + id = "runTemplateId", + parameterGroups = mutableListOf(), + ) + ), + ) solutionSaved = solutionApiService.createSolution( - organizationSaved.id, solutionCreateRequestWithDatasetParameters) + organizationSaved.id, + solutionCreateRequestWithDatasetParameters, + ) workspace = makeWorkspaceCreateRequest("Workspace") workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) @@ -2263,11 +2708,15 @@ class RunnerServiceIntegrationTest : CsmTestBase() { RunnerCreateRequest( name = "Parent Runner with expected dataset parameter", solutionId = solutionSaved.id, - runTemplateId = "runTemplateId") + runTemplateId = "runTemplateId", + ) val parentCreatedRunner = runnerApiService.createRunner( - organizationSaved.id, workspaceSaved.id, parentRunnerCreateRequest) + organizationSaved.id, + workspaceSaved.id, + parentRunnerCreateRequest, + ) // 4 - Check parent runner parameters val retrievedParentRunner = @@ -2278,7 +2727,10 @@ class RunnerServiceIntegrationTest : CsmTestBase() { val datasetParameterFromParentRunner = datasetApiService.getDataset( - organizationSaved.id, workspaceSaved.id, retrievedParentRunner.datasets.parameter) + organizationSaved.id, + workspaceSaved.id, + retrievedParentRunner.datasets.parameter, + ) assertEquals(0, datasetParameterFromParentRunner.parts.size) assertEquals(0, retrievedParentRunner.datasets.parameters!!.size) @@ -2289,11 +2741,15 @@ class RunnerServiceIntegrationTest : CsmTestBase() { name = "Child Runner with expected dataset parameter", solutionId = solutionSaved.id, runTemplateId = "runTemplateId", - parentId = parentCreatedRunner.id) + parentId = parentCreatedRunner.id, + ) val childCreatedRunner = runnerApiService.createRunner( - organizationSaved.id, workspaceSaved.id, childRunnerCreateRequest) + organizationSaved.id, + workspaceSaved.id, + childRunnerCreateRequest, + ) // 6 - Check child runner parameters val retrievedChildRunner = @@ -2301,12 +2757,17 @@ class RunnerServiceIntegrationTest : CsmTestBase() { assertNotNull(retrievedChildRunner.datasets.parameters) assertEquals(0, retrievedChildRunner.datasets.parameters!!.size) assertNotEquals( - retrievedParentRunner.datasets.parameter, retrievedChildRunner.datasets.parameter) + retrievedParentRunner.datasets.parameter, + retrievedChildRunner.datasets.parameter, + ) assertEquals(0, retrievedChildRunner.parametersValues.size) val datasetParameterFromChildRunner = datasetApiService.getDataset( - organizationSaved.id, workspaceSaved.id, retrievedChildRunner.datasets.parameter) + organizationSaved.id, + workspaceSaved.id, + retrievedChildRunner.datasets.parameter, + ) assertEquals(0, retrievedChildRunner.datasets.parameters!!.size) assertEquals(0, datasetParameterFromChildRunner.parts.size) @@ -2316,7 +2777,8 @@ class RunnerServiceIntegrationTest : CsmTestBase() { fun `test onGetRunnerAttachedToDataset behaviour`() { logger.info( - "should create a new Runner and retrieve parameter varType from solution ignoring the one declared") + "should create a new Runner and retrieve parameter varType from solution ignoring the one declared" + ) val newRunner = makeRunnerCreateRequest( name = "NewRunner", @@ -2324,7 +2786,12 @@ class RunnerServiceIntegrationTest : CsmTestBase() { parametersValues = mutableListOf( RunnerRunTemplateParameterValue( - parameterId = "param1", value = "7", varType = "ignored_var_type"))) + parameterId = "param1", + value = "7", + varType = "ignored_var_type", + ) + ), + ) val newRunnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, newRunner) @@ -2334,7 +2801,11 @@ class RunnerServiceIntegrationTest : CsmTestBase() { val getAttachedRunnerToDataset = GetRunnerAttachedToDataset( - this, organizationSaved.id, workspaceSaved.id, datasetParameterId) + this, + organizationSaved.id, + workspaceSaved.id, + datasetParameterId, + ) eventPublisher.publishEvent(getAttachedRunnerToDataset) assertEquals(newRunnerSaved.id, getAttachedRunnerToDataset.response) @@ -2354,7 +2825,10 @@ class RunnerServiceIntegrationTest : CsmTestBase() { parameterGroups = mutableListOf( RunTemplateParameterGroupCreateRequest( - id = "testParameterGroups", parameters = mutableListOf("param1", "param2"))), + id = "testParameterGroups", + parameters = mutableListOf("param1", "param2"), + ) + ), parameters = mutableListOf( RunTemplateParameterCreateRequest( @@ -2362,14 +2836,20 @@ class RunnerServiceIntegrationTest : CsmTestBase() { maxValue = "10", minValue = "0", defaultValue = "5", - varType = "integer"), + varType = "integer", + ), RunTemplateParameterCreateRequest( - id = "param2", varType = DATASET_PART_VARTYPE_FILE), + id = "param2", + varType = DATASET_PART_VARTYPE_FILE, + ), ), runTemplates = mutableListOf( RunTemplateCreateRequest( - id = "runTemplateId", parameterGroups = mutableListOf("testParameterGroups"))), + id = "runTemplateId", + parameterGroups = mutableListOf("testParameterGroups"), + ) + ), repository = "repository", version = "1.0.0", security = @@ -2378,7 +2858,10 @@ class RunnerServiceIntegrationTest : CsmTestBase() { accessControlList = mutableListOf( SolutionAccessControl(id = CONNECTED_ADMIN_USER, role = ROLE_ADMIN), - SolutionAccessControl(id = defaultName, role = ROLE_USER)))) + SolutionAccessControl(id = defaultName, role = ROLE_USER), + ), + ), + ) } fun makeOrganizationCreateRequest(userName: String = defaultName, role: String = ROLE_ADMIN) = @@ -2391,13 +2874,16 @@ class RunnerServiceIntegrationTest : CsmTestBase() { mutableListOf( OrganizationAccessControl(id = CONNECTED_READER_USER, role = "reader"), OrganizationAccessControl(id = CONNECTED_ADMIN_USER, role = "admin"), - OrganizationAccessControl(id = userName, role = role)))) + OrganizationAccessControl(id = userName, role = role), + ), + ), + ) fun makeWorkspaceCreateRequest( name: String = "name", workspaceSolution: WorkspaceSolution = WorkspaceSolution(solutionId = solutionSaved.id), userName: String = defaultName, - role: String = ROLE_ADMIN + role: String = ROLE_ADMIN, ) = WorkspaceCreateRequest( key = UUID.randomUUID().toString(), @@ -2408,7 +2894,10 @@ class RunnerServiceIntegrationTest : CsmTestBase() { default = ROLE_NONE, mutableListOf( WorkspaceAccessControl(id = userName, role = role), - WorkspaceAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN)))) + WorkspaceAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), + ), + ), + ) fun makeRunnerCreateRequest( name: String = "name", @@ -2417,7 +2906,7 @@ class RunnerServiceIntegrationTest : CsmTestBase() { userName: String = defaultName, role: String = ROLE_USER, runTemplateId: String = "runTemplateId", - parametersValues: MutableList? = null + parametersValues: MutableList? = null, ) = RunnerCreateRequest( name = name, @@ -2429,11 +2918,15 @@ class RunnerServiceIntegrationTest : CsmTestBase() { additionalData = mutableMapOf( "you_can_put" to "whatever_you_want_here", - "even" to mapOf("object" to "if_you_want")), + "even" to mapOf("object" to "if_you_want"), + ), security = RunnerSecurity( ROLE_NONE, mutableListOf( RunnerAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), - RunnerAccessControl(userName, role)))) + RunnerAccessControl(userName, role), + ), + ), + ) } diff --git a/runner/src/integrationTest/kotlin/com/cosmotech/runner/service/RunnerServiceRBACTest.kt b/runner/src/integrationTest/kotlin/com/cosmotech/runner/service/RunnerServiceRBACTest.kt index 52c0e839d..7e82510e2 100644 --- a/runner/src/integrationTest/kotlin/com/cosmotech/runner/service/RunnerServiceRBACTest.kt +++ b/runner/src/integrationTest/kotlin/com/cosmotech/runner/service/RunnerServiceRBACTest.kt @@ -110,7 +110,10 @@ class RunnerServiceRBACTest : CsmTestBase() { rediSearchIndexer.createIndexFor(Runner::class.java) ReflectionTestUtils.setField( - solutionApiService, "containerRegistryService", containerRegistryService) + solutionApiService, + "containerRegistryService", + containerRegistryService, + ) every { containerRegistryService.getImageLabel(any(), any(), any()) } returns null } @@ -134,21 +137,29 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) var datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -156,11 +167,16 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.listRunners( - organizationSaved.id, workspaceSaved.id, null, null) + organizationSaved.id, + workspaceSaved.id, + null, + null, + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.listRunners(organizationSaved.id, workspaceSaved.id, null, null) @@ -194,13 +210,18 @@ class RunnerServiceRBACTest : CsmTestBase() { val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -208,11 +229,16 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.listRunners( - organizationSaved.id, workspaceSaved.id, null, null) + organizationSaved.id, + workspaceSaved.id, + null, + null, + ) } assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.listRunners(organizationSaved.id, workspaceSaved.id, null, null) @@ -241,19 +267,27 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -261,11 +295,16 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.listRunners( - organizationSaved.id, workspaceSaved.id, null, null) + organizationSaved.id, + workspaceSaved.id, + null, + null, + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.listRunners(organizationSaved.id, workspaceSaved.id, null, null) @@ -294,20 +333,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = role) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -315,11 +362,16 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.listRunners( - organizationSaved.id, workspaceSaved.id, null, null) + organizationSaved.id, + workspaceSaved.id, + null, + null, + ) } assertEquals( "RBAC ${datasetSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.listRunners(organizationSaved.id, workspaceSaved.id, null, null) @@ -347,20 +399,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -371,7 +431,8 @@ class RunnerServiceRBACTest : CsmTestBase() { } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) @@ -400,20 +461,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = role) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -425,11 +494,13 @@ class RunnerServiceRBACTest : CsmTestBase() { if (role == ROLE_NONE || role == ROLE_VALIDATOR) { assertEquals( "RBAC ${datasetSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertEquals( "RBAC ${datasetSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } } else { assertDoesNotThrow { @@ -459,20 +530,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -483,7 +562,8 @@ class RunnerServiceRBACTest : CsmTestBase() { } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) @@ -512,20 +592,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = role) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = role, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -537,11 +625,13 @@ class RunnerServiceRBACTest : CsmTestBase() { if (role == ROLE_VALIDATOR || role == ROLE_NONE) { assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_CREATE_CHILDREN", - exception.message) + exception.message, + ) } } else { assertDoesNotThrow { @@ -570,20 +660,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -592,15 +690,22 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.getRunner( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.getRunner( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } } } @@ -626,20 +731,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = role) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -648,15 +761,22 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.getRunner( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } assertEquals( "RBAC ${datasetSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.getRunner( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } } } @@ -682,20 +802,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = role) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -704,15 +832,22 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.getRunner( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.getRunner( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } } } @@ -738,20 +873,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = role) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = role, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -760,15 +903,22 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.getRunner( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.getRunner( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } } } @@ -793,20 +943,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = role) + role = role, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -815,15 +973,22 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.getRunner( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } assertEquals( "RBAC ${runnerSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.getRunner( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } } } @@ -848,20 +1013,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -870,15 +1043,22 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.deleteRunner( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.deleteRunner( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } } } @@ -904,20 +1084,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = role) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -926,15 +1114,22 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.deleteRunner( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } assertEquals( "RBAC ${datasetSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.deleteRunner( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } } } @@ -960,20 +1155,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = role) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -982,15 +1185,22 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.deleteRunner( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.deleteRunner( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } } } @@ -1016,20 +1226,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = role) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = role, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -1038,15 +1256,22 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.deleteRunner( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.deleteRunner( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } } } @@ -1059,7 +1284,8 @@ class RunnerServiceRBACTest : CsmTestBase() { ROLE_EDITOR to true, ROLE_VALIDATOR to true, ROLE_NONE to true, - ROLE_ADMIN to false) + ROLE_ADMIN to false, + ) .map { (role, shouldThrow) -> dynamicTest("Test Runner RBAC deleteRunner : $role") { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER @@ -1070,20 +1296,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = role) + role = role, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -1092,21 +1326,29 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.deleteRunner( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } if (role == ROLE_NONE) { assertEquals( "RBAC ${runnerSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertEquals( "RBAC ${runnerSaved.id} - User does not have permission $PERMISSION_DELETE", - exception.message) + exception.message, + ) } } else { assertDoesNotThrow { runnerApiService.deleteRunner( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } } } @@ -1131,20 +1373,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -1156,18 +1406,21 @@ class RunnerServiceRBACTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerUpdateRequest(datasetList = mutableListOf(datasetSaved.id))) + RunnerUpdateRequest(datasetList = mutableListOf(datasetSaved.id)), + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.updateRunner( organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerUpdateRequest(datasetList = mutableListOf(datasetSaved.id))) + RunnerUpdateRequest(datasetList = mutableListOf(datasetSaved.id)), + ) } } } @@ -1193,20 +1446,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = role) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -1218,18 +1479,21 @@ class RunnerServiceRBACTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerUpdateRequest(datasetList = mutableListOf(datasetSaved.id))) + RunnerUpdateRequest(datasetList = mutableListOf(datasetSaved.id)), + ) } assertEquals( "RBAC ${datasetSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.updateRunner( organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerUpdateRequest(datasetList = mutableListOf(datasetSaved.id))) + RunnerUpdateRequest(datasetList = mutableListOf(datasetSaved.id)), + ) } } } @@ -1255,20 +1519,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -1280,18 +1552,21 @@ class RunnerServiceRBACTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerUpdateRequest(datasetList = mutableListOf(datasetSaved.id))) + RunnerUpdateRequest(datasetList = mutableListOf(datasetSaved.id)), + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.updateRunner( organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerUpdateRequest(datasetList = mutableListOf(datasetSaved.id))) + RunnerUpdateRequest(datasetList = mutableListOf(datasetSaved.id)), + ) } } } @@ -1317,20 +1592,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = role) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = role, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -1342,18 +1625,21 @@ class RunnerServiceRBACTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerUpdateRequest(datasetList = mutableListOf(datasetSaved.id))) + RunnerUpdateRequest(datasetList = mutableListOf(datasetSaved.id)), + ) } assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.updateRunner( organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerUpdateRequest(datasetList = mutableListOf(datasetSaved.id))) + RunnerUpdateRequest(datasetList = mutableListOf(datasetSaved.id)), + ) } } } @@ -1378,20 +1664,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = role) + role = role, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -1403,16 +1697,19 @@ class RunnerServiceRBACTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerUpdateRequest(datasetList = mutableListOf(datasetSaved.id))) + RunnerUpdateRequest(datasetList = mutableListOf(datasetSaved.id)), + ) } if (role == ROLE_NONE) { assertEquals( "RBAC ${runnerSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertEquals( "RBAC ${runnerSaved.id} - User does not have permission $PERMISSION_WRITE", - exception.message) + exception.message, + ) } } else { assertDoesNotThrow { @@ -1420,7 +1717,8 @@ class RunnerServiceRBACTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerUpdateRequest(datasetList = mutableListOf(datasetSaved.id))) + RunnerUpdateRequest(datasetList = mutableListOf(datasetSaved.id)), + ) } } } @@ -1445,20 +1743,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -1467,15 +1773,24 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.listRunnerPermissions( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, role) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + role, + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.listRunnerPermissions( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, role) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + role, + ) } } } @@ -1501,20 +1816,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = role) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -1523,15 +1846,24 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.listRunnerPermissions( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, role) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + role, + ) } assertEquals( "RBAC ${datasetSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.listRunnerPermissions( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, role) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + role, + ) } } } @@ -1557,20 +1889,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = role) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -1579,15 +1919,24 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.listRunnerPermissions( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, role) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + role, + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.listRunnerPermissions( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, role) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + role, + ) } } } @@ -1613,20 +1962,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = role) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = role, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -1635,15 +1992,24 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.listRunnerPermissions( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, role) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + role, + ) } assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.listRunnerPermissions( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, role) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + role, + ) } } } @@ -1668,20 +2034,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = role) + role = role, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -1690,21 +2064,31 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.listRunnerPermissions( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, role) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + role, + ) } if (role == ROLE_NONE) { assertEquals( "RBAC ${runnerSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertEquals( "RBAC ${runnerSaved.id} - User does not have permission $PERMISSION_READ_SECURITY", - exception.message) + exception.message, + ) } } else { assertDoesNotThrow { runnerApiService.listRunnerPermissions( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, role) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + role, + ) } } } @@ -1729,20 +2113,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -1751,15 +2143,22 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.getRunnerSecurity( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.getRunnerSecurity( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } } } @@ -1785,20 +2184,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = role) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -1807,15 +2214,22 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.getRunnerSecurity( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } assertEquals( "RBAC ${datasetSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.getRunnerSecurity( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } } } @@ -1841,20 +2255,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = role) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -1863,15 +2285,22 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.getRunnerSecurity( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.getRunnerSecurity( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } } } @@ -1897,20 +2326,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = role) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = role, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -1919,15 +2356,22 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.getRunnerSecurity( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.getRunnerSecurity( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } } } @@ -1952,20 +2396,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = role) + role = role, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -1974,21 +2426,29 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.getRunnerSecurity( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } if (role == ROLE_NONE) { assertEquals( "RBAC ${runnerSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertEquals( "RBAC ${runnerSaved.id} - User does not have permission $PERMISSION_READ_SECURITY", - exception.message) + exception.message, + ) } } else { assertDoesNotThrow { runnerApiService.getRunnerSecurity( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } } } @@ -2013,20 +2473,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -2038,18 +2506,21 @@ class RunnerServiceRBACTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerRole(ROLE_ADMIN)) + RunnerRole(ROLE_ADMIN), + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.updateRunnerDefaultSecurity( organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerRole(ROLE_ADMIN)) + RunnerRole(ROLE_ADMIN), + ) } } } @@ -2075,20 +2546,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = role) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -2100,18 +2579,21 @@ class RunnerServiceRBACTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerRole(ROLE_ADMIN)) + RunnerRole(ROLE_ADMIN), + ) } assertEquals( "RBAC ${datasetSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.updateRunnerDefaultSecurity( organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerRole(ROLE_ADMIN)) + RunnerRole(ROLE_ADMIN), + ) } } } @@ -2137,20 +2619,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = role) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -2162,18 +2652,21 @@ class RunnerServiceRBACTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerRole(ROLE_ADMIN)) + RunnerRole(ROLE_ADMIN), + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.updateRunnerDefaultSecurity( organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerRole(ROLE_ADMIN)) + RunnerRole(ROLE_ADMIN), + ) } } } @@ -2199,20 +2692,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = role) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = role, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -2224,18 +2725,21 @@ class RunnerServiceRBACTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerRole(ROLE_ADMIN)) + RunnerRole(ROLE_ADMIN), + ) } assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.updateRunnerDefaultSecurity( organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerRole(ROLE_ADMIN)) + RunnerRole(ROLE_ADMIN), + ) } } } @@ -2260,20 +2764,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = role) + role = role, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -2285,16 +2797,19 @@ class RunnerServiceRBACTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerRole(ROLE_ADMIN)) + RunnerRole(ROLE_ADMIN), + ) } if (role == ROLE_NONE) { assertEquals( "RBAC ${runnerSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertEquals( "RBAC ${runnerSaved.id} - User does not have permission $PERMISSION_WRITE_SECURITY", - exception.message) + exception.message, + ) } } else { assertDoesNotThrow { @@ -2302,7 +2817,8 @@ class RunnerServiceRBACTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerRole(ROLE_ADMIN)) + RunnerRole(ROLE_ADMIN), + ) } } } @@ -2327,20 +2843,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -2352,18 +2876,21 @@ class RunnerServiceRBACTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerAccessControl("id", ROLE_ADMIN)) + RunnerAccessControl("id", ROLE_ADMIN), + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.createRunnerAccessControl( organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerAccessControl("id", ROLE_ADMIN)) + RunnerAccessControl("id", ROLE_ADMIN), + ) } } } @@ -2380,63 +2907,81 @@ class RunnerServiceRBACTest : CsmTestBase() { .map { role -> dynamicTest( "Check Dataset RBAC modification " + - "when createRunnerAccessControl is called on a runner with role : $role") { - every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER - val organization = - makeOrganizationCreateRequest(userId = TEST_USER_MAIL, role = ROLE_ADMIN) - val organizationSaved = organizationApiService.createOrganization(organization) - val solution = makeSolution(userId = TEST_USER_MAIL, role = ROLE_ADMIN) - val solutionSaved = - solutionApiService.createSolution(organizationSaved.id, solution) - val workspace = - makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) - val workspaceSaved = - workspaceApiService.createWorkspace(organizationSaved.id, workspace) - - val dataset = makeDataset(userId = TEST_USER_MAIL, role = role) - val datasetSaved = - datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) - val runner = - makeRunnerWithRole( - solutionId = solutionSaved.id, - datasetList = mutableListOf(datasetSaved.id), - userId = TEST_USER_MAIL, - role = ROLE_ADMIN) - val runnerSaved = - runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) - - assertTrue( - datasetSaved.security.accessControlList.none { datasetAccessControl -> - datasetAccessControl.id == "unknown_user@test.com" - }) + "when createRunnerAccessControl is called on a runner with role : $role" + ) { + every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER + val organization = + makeOrganizationCreateRequest(userId = TEST_USER_MAIL, role = ROLE_ADMIN) + val organizationSaved = organizationApiService.createOrganization(organization) + val solution = makeSolution(userId = TEST_USER_MAIL, role = ROLE_ADMIN) + val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) + val workspace = + makeWorkspaceCreateRequest( + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) + val workspaceSaved = + workspaceApiService.createWorkspace(organizationSaved.id, workspace) - runnerApiService.createRunnerAccessControl( + val dataset = makeDataset(userId = TEST_USER_MAIL, role = role) + val datasetSaved = + datasetApiService.createDataset( organizationSaved.id, workspaceSaved.id, - runnerSaved.id, - RunnerAccessControl("unknown_user@test.com", role)) - - val baseDatasetRunner = - datasetApiService.getDataset( - organizationSaved.id, workspaceSaved.id, datasetSaved.id) + dataset, + emptyArray(), + ) + val runner = + makeRunnerWithRole( + solutionId = solutionSaved.id, + datasetList = mutableListOf(datasetSaved.id), + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) + val runnerSaved = + runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) - assertTrue( - baseDatasetRunner.security.accessControlList.none { - it.id == "unknown_user@test.com" - }) + assertTrue( + datasetSaved.security.accessControlList.none { datasetAccessControl -> + datasetAccessControl.id == "unknown_user@test.com" + } + ) + + runnerApiService.createRunnerAccessControl( + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + RunnerAccessControl("unknown_user@test.com", role), + ) + + val baseDatasetRunner = + datasetApiService.getDataset( + organizationSaved.id, + workspaceSaved.id, + datasetSaved.id, + ) - val parameterDatasetRunner = - datasetApiService.getDataset( - organizationSaved.id, workspaceSaved.id, runnerSaved.datasets.parameter) + assertTrue( + baseDatasetRunner.security.accessControlList.none { + it.id == "unknown_user@test.com" + } + ) - assertTrue( - parameterDatasetRunner.security.accessControlList.any { access -> - access.id == "unknown_user@test.com" && - access.role == (role.takeUnless { it == ROLE_VALIDATOR } ?: ROLE_USER) - }) - } + val parameterDatasetRunner = + datasetApiService.getDataset( + organizationSaved.id, + workspaceSaved.id, + runnerSaved.datasets.parameter, + ) + + assertTrue( + parameterDatasetRunner.security.accessControlList.any { access -> + access.id == "unknown_user@test.com" && + access.role == (role.takeUnless { it == ROLE_VALIDATOR } ?: ROLE_USER) + } + ) + } } @Test @@ -2452,19 +2997,25 @@ class RunnerServiceRBACTest : CsmTestBase() { val dataset = makeDataset(userId = "unknown_user@test.com", role = ROLE_NONE) var datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionSaved.id, mutableListOf(datasetSaved.id), userId = "unknown_user@test.com", - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) assertEquals( false, datasetSaved.security.accessControlList.any { datasetAccessControl -> datasetAccessControl.id == TEST_USER_MAIL - }) + }, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) @@ -2472,7 +3023,8 @@ class RunnerServiceRBACTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerAccessControl(TEST_USER_MAIL, ROLE_ADMIN)) + RunnerAccessControl(TEST_USER_MAIL, ROLE_ADMIN), + ) val baseDatasetsRunnerAccessShouldNotHaveBeenModified = datasetApiService.getDataset(organizationSaved.id, workspaceSaved.id, datasetSaved.id) assertEquals( @@ -2480,16 +3032,21 @@ class RunnerServiceRBACTest : CsmTestBase() { baseDatasetsRunnerAccessShouldNotHaveBeenModified.security.accessControlList.any { datasetAccessControl -> datasetAccessControl.id == TEST_USER_MAIL - }) + }, + ) val parameterDatasetsRunnerAccessShouldHaveBeenModified = datasetApiService.getDataset( - organizationSaved.id, workspaceSaved.id, runnerSaved.datasets.parameter) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.datasets.parameter, + ) assertEquals( true, parameterDatasetsRunnerAccessShouldHaveBeenModified.security.accessControlList.any { datasetAccessControl -> datasetAccessControl.id == TEST_USER_MAIL - }) + }, + ) } @TestFactory @@ -2512,20 +3069,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -2537,18 +3102,21 @@ class RunnerServiceRBACTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerAccessControl("id", ROLE_ADMIN)) + RunnerAccessControl("id", ROLE_ADMIN), + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.createRunnerAccessControl( organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerAccessControl("id", ROLE_ADMIN)) + RunnerAccessControl("id", ROLE_ADMIN), + ) } } } @@ -2574,20 +3142,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = role) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = role, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -2599,18 +3175,21 @@ class RunnerServiceRBACTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerAccessControl("id", ROLE_ADMIN)) + RunnerAccessControl("id", ROLE_ADMIN), + ) } assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.createRunnerAccessControl( organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerAccessControl("id", ROLE_ADMIN)) + RunnerAccessControl("id", ROLE_ADMIN), + ) } } } @@ -2635,20 +3214,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = role) + role = role, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -2660,16 +3247,19 @@ class RunnerServiceRBACTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerAccessControl("id", ROLE_ADMIN)) + RunnerAccessControl("id", ROLE_ADMIN), + ) } if (role == ROLE_NONE) { assertEquals( "RBAC ${runnerSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertEquals( "RBAC ${runnerSaved.id} - User does not have permission $PERMISSION_WRITE_SECURITY", - exception.message) + exception.message, + ) } } else { assertDoesNotThrow { @@ -2677,7 +3267,8 @@ class RunnerServiceRBACTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, runnerSaved.id, - RunnerAccessControl("id", ROLE_ADMIN)) + RunnerAccessControl("id", ROLE_ADMIN), + ) } } } @@ -2702,20 +3293,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -2724,15 +3323,24 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.getRunnerAccessControl( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + TEST_USER_MAIL, + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.getRunnerAccessControl( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + TEST_USER_MAIL, + ) } } } @@ -2758,20 +3366,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = role) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -2780,15 +3396,24 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.getRunnerAccessControl( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + TEST_USER_MAIL, + ) } assertEquals( "RBAC ${datasetSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.getRunnerAccessControl( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + TEST_USER_MAIL, + ) } } } @@ -2814,20 +3439,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = role) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -2836,15 +3469,24 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.getRunnerAccessControl( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + TEST_USER_MAIL, + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.getRunnerAccessControl( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + TEST_USER_MAIL, + ) } } } @@ -2870,20 +3512,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = role) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = role, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -2892,15 +3542,24 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.getRunnerAccessControl( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + TEST_USER_MAIL, + ) } assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.getRunnerAccessControl( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + TEST_USER_MAIL, + ) } } } @@ -2925,20 +3584,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = role) + role = role, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -2947,21 +3614,31 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.getRunnerAccessControl( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + TEST_USER_MAIL, + ) } if (role == ROLE_NONE) { assertEquals( "RBAC ${runnerSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertEquals( "RBAC ${runnerSaved.id} - User does not have permission $PERMISSION_READ_SECURITY", - exception.message) + exception.message, + ) } } else { assertDoesNotThrow { runnerApiService.getRunnerAccessControl( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + TEST_USER_MAIL, + ) } } } @@ -2986,20 +3663,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -3008,15 +3693,24 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.deleteRunnerAccessControl( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + TEST_USER_MAIL, + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.deleteRunnerAccessControl( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + TEST_USER_MAIL, + ) } } } @@ -3042,27 +3736,39 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = role) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL assertDoesNotThrow { runnerApiService.deleteRunnerAccessControl( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + TEST_USER_MAIL, + ) } } } @@ -3087,20 +3793,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -3109,15 +3823,24 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.deleteRunnerAccessControl( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + TEST_USER_MAIL, + ) } assertEquals( "RBAC ${datasetSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.deleteRunnerAccessControl( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + TEST_USER_MAIL, + ) } } } @@ -3143,20 +3866,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = role) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = role, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -3165,15 +3896,24 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.deleteRunnerAccessControl( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + TEST_USER_MAIL, + ) } assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.deleteRunnerAccessControl( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + TEST_USER_MAIL, + ) } } } @@ -3198,20 +3938,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = role) + role = role, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -3220,21 +3968,31 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.deleteRunnerAccessControl( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + TEST_USER_MAIL, + ) } if (role == ROLE_NONE) { assertEquals( "RBAC ${runnerSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertEquals( "RBAC ${runnerSaved.id} - User does not have permission $PERMISSION_WRITE_SECURITY", - exception.message) + exception.message, + ) } } else { assertDoesNotThrow { runnerApiService.deleteRunnerAccessControl( - organizationSaved.id, workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + TEST_USER_MAIL, + ) } } } @@ -3259,20 +4017,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -3285,11 +4051,13 @@ class RunnerServiceRBACTest : CsmTestBase() { workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL, - RunnerRole(ROLE_VIEWER)) + RunnerRole(ROLE_VIEWER), + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.updateRunnerAccessControl( @@ -3297,7 +4065,8 @@ class RunnerServiceRBACTest : CsmTestBase() { workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL, - RunnerRole(ROLE_VIEWER)) + RunnerRole(ROLE_VIEWER), + ) } } } @@ -3323,20 +4092,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = role) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -3349,11 +4126,13 @@ class RunnerServiceRBACTest : CsmTestBase() { workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL, - RunnerRole(ROLE_VIEWER)) + RunnerRole(ROLE_VIEWER), + ) } assertEquals( "RBAC ${datasetSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.updateRunnerAccessControl( @@ -3361,7 +4140,8 @@ class RunnerServiceRBACTest : CsmTestBase() { workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL, - RunnerRole(ROLE_VIEWER)) + RunnerRole(ROLE_VIEWER), + ) } } } @@ -3387,20 +4167,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = role) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -3413,11 +4201,13 @@ class RunnerServiceRBACTest : CsmTestBase() { workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL, - RunnerRole(ROLE_VIEWER)) + RunnerRole(ROLE_VIEWER), + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.updateRunnerAccessControl( @@ -3425,7 +4215,8 @@ class RunnerServiceRBACTest : CsmTestBase() { workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL, - RunnerRole(ROLE_VIEWER)) + RunnerRole(ROLE_VIEWER), + ) } } } @@ -3451,20 +4242,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = role) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = role, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -3477,11 +4276,13 @@ class RunnerServiceRBACTest : CsmTestBase() { workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL, - RunnerRole(ROLE_VIEWER)) + RunnerRole(ROLE_VIEWER), + ) } assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.updateRunnerAccessControl( @@ -3489,7 +4290,8 @@ class RunnerServiceRBACTest : CsmTestBase() { workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL, - RunnerRole(ROLE_VIEWER)) + RunnerRole(ROLE_VIEWER), + ) } } } @@ -3514,20 +4316,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = role) + role = role, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -3540,16 +4350,19 @@ class RunnerServiceRBACTest : CsmTestBase() { workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL, - RunnerRole(ROLE_VIEWER)) + RunnerRole(ROLE_VIEWER), + ) } if (role == ROLE_NONE) { assertEquals( "RBAC ${runnerSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertEquals( "RBAC ${runnerSaved.id} - User does not have permission $PERMISSION_WRITE_SECURITY", - exception.message) + exception.message, + ) } } else { assertDoesNotThrow { @@ -3558,7 +4371,8 @@ class RunnerServiceRBACTest : CsmTestBase() { workspaceSaved.id, runnerSaved.id, TEST_USER_MAIL, - RunnerRole(ROLE_VIEWER)) + RunnerRole(ROLE_VIEWER), + ) } } } @@ -3583,20 +4397,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -3605,15 +4427,22 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.listRunnerSecurityUsers( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.listRunnerSecurityUsers( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } } } @@ -3639,20 +4468,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = role) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -3661,15 +4498,22 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.listRunnerSecurityUsers( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } assertEquals( "RBAC ${datasetSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.listRunnerSecurityUsers( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } } } @@ -3695,20 +4539,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = role) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -3717,15 +4569,22 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.listRunnerSecurityUsers( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.listRunnerSecurityUsers( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } } } @@ -3751,20 +4610,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = role) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = role, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -3773,15 +4640,22 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.listRunnerSecurityUsers( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { runnerApiService.listRunnerSecurityUsers( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } } } @@ -3806,20 +4680,28 @@ class RunnerServiceRBACTest : CsmTestBase() { val solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val workspace = makeWorkspaceCreateRequest( - solutionId = solutionSaved.id, userId = TEST_USER_MAIL, role = ROLE_ADMIN) + solutionId = solutionSaved.id, + userId = TEST_USER_MAIL, + role = ROLE_ADMIN, + ) val workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspace) val dataset = makeDataset(userId = TEST_USER_MAIL, role = ROLE_ADMIN) val datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) val runner = makeRunnerWithRole( solutionId = solutionSaved.id, datasetList = mutableListOf(datasetSaved.id), userId = TEST_USER_MAIL, - role = role) + role = role, + ) val runnerSaved = runnerApiService.createRunner(organizationSaved.id, workspaceSaved.id, runner) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL @@ -3828,21 +4710,29 @@ class RunnerServiceRBACTest : CsmTestBase() { val exception = assertThrows { runnerApiService.listRunnerSecurityUsers( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } if (role == ROLE_NONE) { assertEquals( "RBAC ${runnerSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertEquals( "RBAC ${runnerSaved.id} - User does not have permission $PERMISSION_READ_SECURITY", - exception.message) + exception.message, + ) } } else { assertDoesNotThrow { runnerApiService.listRunnerSecurityUsers( - organizationSaved.id, workspaceSaved.id, runnerSaved.id) + organizationSaved.id, + workspaceSaved.id, + runnerSaved.id, + ) } } } @@ -3857,7 +4747,10 @@ class RunnerServiceRBACTest : CsmTestBase() { accessControlList = mutableListOf( DatasetAccessControl(id = CONNECTED_ADMIN_USER, role = ROLE_ADMIN), - DatasetAccessControl(id = userId, role = role)))) + DatasetAccessControl(id = userId, role = role), + ), + ), + ) fun makeSolution(userId: String, role: String) = SolutionCreateRequest( @@ -3873,7 +4766,10 @@ class RunnerServiceRBACTest : CsmTestBase() { default = ROLE_NONE, mutableListOf( SolutionAccessControl(id = CONNECTED_ADMIN_USER, role = ROLE_ADMIN), - SolutionAccessControl(id = userId, role = role)))) + SolutionAccessControl(id = userId, role = role), + ), + ), + ) fun makeOrganizationCreateRequest(userId: String, role: String) = OrganizationCreateRequest( @@ -3884,7 +4780,10 @@ class RunnerServiceRBACTest : CsmTestBase() { accessControlList = mutableListOf( OrganizationAccessControl(id = CONNECTED_ADMIN_USER, role = ROLE_ADMIN), - OrganizationAccessControl(id = userId, role = role)))) + OrganizationAccessControl(id = userId, role = role), + ), + ), + ) fun makeWorkspaceCreateRequest(solutionId: String, userId: String, role: String) = WorkspaceCreateRequest( @@ -3899,13 +4798,16 @@ class RunnerServiceRBACTest : CsmTestBase() { default = ROLE_NONE, mutableListOf( WorkspaceAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), - WorkspaceAccessControl(id = userId, role = role)))) + WorkspaceAccessControl(id = userId, role = role), + ), + ), + ) fun makeRunnerWithRole( solutionId: String, datasetList: MutableList, userId: String, - role: String + role: String, ) = RunnerCreateRequest( name = "Runner", @@ -3918,5 +4820,8 @@ class RunnerServiceRBACTest : CsmTestBase() { ROLE_NONE, mutableListOf( RunnerAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), - RunnerAccessControl(userId, role)))) + RunnerAccessControl(userId, role), + ), + ), + ) } diff --git a/runner/src/main/kotlin/com/cosmotech/runner/repository/RunnerRepository.kt b/runner/src/main/kotlin/com/cosmotech/runner/repository/RunnerRepository.kt index 61d8e303b..e33c085f2 100644 --- a/runner/src/main/kotlin/com/cosmotech/runner/repository/RunnerRepository.kt +++ b/runner/src/main/kotlin/com/cosmotech/runner/repository/RunnerRepository.kt @@ -20,7 +20,7 @@ interface RunnerRepository : RedisDocumentRepository { fun findBy( @Sanitize @Param("organizationId") organizationId: String, @Sanitize @Param("workspaceId") workspaceId: String, - @Sanitize @Param("runnerId") runnerId: String + @Sanitize @Param("runnerId") runnerId: String, ): Optional @Query("(@organizationId:{\$organizationId} @workspaceId:{\$workspaceId} @parentId:{\$parentId})") @@ -28,14 +28,14 @@ interface RunnerRepository : RedisDocumentRepository { @Sanitize @Param("organizationId") organizationId: String, @Sanitize @Param("workspaceId") workspaceId: String, @Sanitize @Param("parentId") parentId: String, - pageable: Pageable + pageable: Pageable, ): Page @Query("(@organizationId:{\$organizationId} @workspaceId:{\$workspaceId})") fun findByWorkspaceId( @Sanitize @Param("organizationId") organizationId: String, @Sanitize @Param("workspaceId") workspaceId: String, - pageable: Pageable + pageable: Pageable, ): Page @Query("(@organizationId:{\$organizationId} @workspaceId:{\$workspaceId}) \$securityConstraint") @@ -43,14 +43,15 @@ interface RunnerRepository : RedisDocumentRepository { @Sanitize @Param("organizationId") organizationId: String, @Sanitize @Param("workspaceId") workspaceId: String, @SecurityConstraint @Param("securityConstraint") securityConstraint: String, - pageable: Pageable + pageable: Pageable, ): Page @Query( - "@organizationId:{\$organizationId} @workspaceId:{\$workspaceId} @datasets_parameter:{\$datasetId}") + "@organizationId:{\$organizationId} @workspaceId:{\$workspaceId} @datasets_parameter:{\$datasetId}" + ) fun findByOrganizationIdAndWorkspaceIdAndDatasetsParameterValue( @Sanitize @Param("organizationId") organizationId: String, @Sanitize @Param("workspaceId") workspaceId: String, - @Sanitize @Param("datasetId") datasetId: String + @Sanitize @Param("datasetId") datasetId: String, ): Optional } diff --git a/runner/src/main/kotlin/com/cosmotech/runner/service/RunnerApiServiceImpl.kt b/runner/src/main/kotlin/com/cosmotech/runner/service/RunnerApiServiceImpl.kt index abd08deb2..9220b68c6 100644 --- a/runner/src/main/kotlin/com/cosmotech/runner/service/RunnerApiServiceImpl.kt +++ b/runner/src/main/kotlin/com/cosmotech/runner/service/RunnerApiServiceImpl.kt @@ -33,7 +33,7 @@ import org.springframework.stereotype.Service internal class RunnerApiServiceImpl( private val csmPlatformProperties: CsmPlatformProperties, private val runnerServiceManager: RunnerServiceManager, - private val datasetApiServiceInterface: DatasetApiServiceInterface + private val datasetApiServiceInterface: DatasetApiServiceInterface, ) : RunnerApiServiceInterface { private val logger = LoggerFactory.getLogger(RunnerApiServiceImpl::class.java) @@ -43,7 +43,7 @@ internal class RunnerApiServiceImpl( override fun createRunner( organizationId: String, workspaceId: String, - runnerCreateRequest: RunnerCreateRequest + runnerCreateRequest: RunnerCreateRequest, ): Runner { val runnerService = getRunnerService() @@ -67,7 +67,12 @@ internal class RunnerApiServiceImpl( val runnerSaved = runnerService.saveInstance(runnerInstance) val listDatasetParts = datasetApiServiceInterface.listDatasetParts( - organizationId, workspaceId, runnerSaved.datasets.parameter, null, null) + organizationId, + workspaceId, + runnerSaved.datasets.parameter, + null, + null, + ) return runnerSaved.apply { datasets.parameters = listDatasetParts as MutableList? } } @@ -78,7 +83,12 @@ internal class RunnerApiServiceImpl( val runner = runnerInstance.getRunnerDataObjet() val listDatasetParts = datasetApiServiceInterface.listDatasetParts( - organizationId, workspaceId, runner.datasets.parameter, null, null) + organizationId, + workspaceId, + runner.datasets.parameter, + null, + null, + ) return runner.apply { datasets.parameters = listDatasetParts as MutableList? } } @@ -86,7 +96,7 @@ internal class RunnerApiServiceImpl( organizationId: String, workspaceId: String, runnerId: String, - runnerUpdateRequest: RunnerUpdateRequest + runnerUpdateRequest: RunnerUpdateRequest, ): Runner { val runnerService = getRunnerService().inOrganization(organizationId).inWorkspace(workspaceId) val runnerInstance = runnerService.getInstance(runnerId).userHasPermission(PERMISSION_WRITE) @@ -96,7 +106,12 @@ internal class RunnerApiServiceImpl( val listDatasetParts = datasetApiServiceInterface.listDatasetParts( - organizationId, workspaceId, runnerSaved.datasets.parameter, null, null) + organizationId, + workspaceId, + runnerSaved.datasets.parameter, + null, + null, + ) return runnerSaved.apply { datasets.parameters = listDatasetParts as MutableList? } } @@ -112,7 +127,7 @@ internal class RunnerApiServiceImpl( organizationId: String, workspaceId: String, page: Int?, - size: Int? + size: Int?, ): List { val runnerService = getRunnerService().inOrganization(organizationId).inWorkspace(workspaceId) @@ -137,11 +152,14 @@ internal class RunnerApiServiceImpl( val lastRunInfo = runnerInstance.getRunnerDataObjet().lastRunInfo - if (lastRunInfo.lastRunStatus in - listOf( - LastRunInfo.LastRunStatus.Running, - LastRunInfo.LastRunStatus.NotStarted, - LastRunInfo.LastRunStatus.Unknown)) { + if ( + lastRunInfo.lastRunStatus in + listOf( + LastRunInfo.LastRunStatus.Running, + LastRunInfo.LastRunStatus.NotStarted, + LastRunInfo.LastRunStatus.Unknown, + ) + ) { runnerService.stopLastRunOf(runnerInstance) return } @@ -153,7 +171,7 @@ internal class RunnerApiServiceImpl( organizationId: String, workspaceId: String, runnerId: String, - runnerAccessControl: RunnerAccessControl + runnerAccessControl: RunnerAccessControl, ): RunnerAccessControl { val runnerService = getRunnerService().inOrganization(organizationId).inWorkspace(workspaceId) val runnerInstance = @@ -173,7 +191,7 @@ internal class RunnerApiServiceImpl( organizationId: String, workspaceId: String, runnerId: String, - identityId: String + identityId: String, ): RunnerAccessControl { val runnerService = getRunnerService().inOrganization(organizationId).inWorkspace(workspaceId) val runnerInstance = @@ -187,7 +205,7 @@ internal class RunnerApiServiceImpl( workspaceId: String, runnerId: String, identityId: String, - runnerRole: RunnerRole + runnerRole: RunnerRole, ): RunnerAccessControl { val runnerService = getRunnerService().inOrganization(organizationId).inWorkspace(workspaceId) val runnerInstance = @@ -206,7 +224,7 @@ internal class RunnerApiServiceImpl( organizationId: String, workspaceId: String, runnerId: String, - identityId: String + identityId: String, ) { val runnerService = getRunnerService().inOrganization(organizationId).inWorkspace(workspaceId) val runnerInstance = @@ -220,7 +238,7 @@ internal class RunnerApiServiceImpl( override fun getRunnerSecurity( organizationId: String, workspaceId: String, - runnerId: String + runnerId: String, ): RunnerSecurity { val runnerService = getRunnerService().inOrganization(organizationId).inWorkspace(workspaceId) val runnerInstance = @@ -233,7 +251,7 @@ internal class RunnerApiServiceImpl( organizationId: String, workspaceId: String, runnerId: String, - role: String + role: String, ): List { val runnerService = getRunnerService().inOrganization(organizationId).inWorkspace(workspaceId) runnerService.getInstance(runnerId).userHasPermission(PERMISSION_READ_SECURITY) @@ -244,7 +262,7 @@ internal class RunnerApiServiceImpl( override fun listRunnerSecurityUsers( organizationId: String, workspaceId: String, - runnerId: String + runnerId: String, ): List { val runnerService = getRunnerService().inOrganization(organizationId).inWorkspace(workspaceId) val runnerInstance = @@ -257,7 +275,7 @@ internal class RunnerApiServiceImpl( organizationId: String, workspaceId: String, runnerId: String, - runnerRole: RunnerRole + runnerRole: RunnerRole, ): RunnerSecurity { val runnerService = getRunnerService().inOrganization(organizationId).inWorkspace(workspaceId) val runnerInstance = @@ -279,7 +297,9 @@ internal class RunnerApiServiceImpl( if (runnerInstance.getRunnerDataObjet().lastRunInfo.lastRunId == runDeleted.runId) { runnerInstance.getRunnerDataObjet().lastRunInfo = LastRunInfo( - lastRunId = runDeleted.lastRun, lastRunStatus = LastRunInfo.LastRunStatus.NotStarted) + lastRunId = runDeleted.lastRun, + lastRunStatus = LastRunInfo.LastRunStatus.NotStarted, + ) } runnerService.saveInstance(runnerInstance) if (runDeleted.lastRun != null) { diff --git a/runner/src/main/kotlin/com/cosmotech/runner/service/RunnerExtensions.kt b/runner/src/main/kotlin/com/cosmotech/runner/service/RunnerExtensions.kt index 91b0d7d91..e0f079c4b 100644 --- a/runner/src/main/kotlin/com/cosmotech/runner/service/RunnerExtensions.kt +++ b/runner/src/main/kotlin/com/cosmotech/runner/service/RunnerExtensions.kt @@ -12,5 +12,6 @@ fun Runner.getRbac(): RbacSecurity { return RbacSecurity( this.id, this.security.default, - this.security.accessControlList.map { RbacAccessControl(it.id, it.role) }.toMutableList()) + this.security.accessControlList.map { RbacAccessControl(it.id, it.role) }.toMutableList(), + ) } diff --git a/runner/src/main/kotlin/com/cosmotech/runner/service/RunnerService.kt b/runner/src/main/kotlin/com/cosmotech/runner/service/RunnerService.kt index 436daca6f..68380de79 100644 --- a/runner/src/main/kotlin/com/cosmotech/runner/service/RunnerService.kt +++ b/runner/src/main/kotlin/com/cosmotech/runner/service/RunnerService.kt @@ -65,7 +65,7 @@ const val DATASET_PART_VARTYPE_DB = "%DATASET_PART_ID_DB%" @Component @Scope("prototype") -@Suppress("TooManyFunctions") +@Suppress("TooManyFunctions", "LargeClass") class RunnerService( private val runnerRepository: RunnerRepository, private val organizationApiService: OrganizationApiServiceInterface, @@ -78,9 +78,9 @@ class RunnerService( ) : CsmPhoenixService() { fun updateSecurityVisibility(runner: Runner): Runner { - if (csmRbac - .check(runner.getRbac(), PERMISSION_READ_SECURITY, getRunnerRolesDefinition()) - .not()) { + if ( + csmRbac.check(runner.getRbac(), PERMISSION_READ_SECURITY, getRunnerRolesDefinition()).not() + ) { val username = getCurrentAccountIdentifier(csmPlatformProperties) val retrievedAC = runner.security.accessControlList.firstOrNull { it.id == username } @@ -122,7 +122,8 @@ class RunnerService( this.eventPublisher.publishEvent(hasRunningRuns) if (hasRunningRuns.response == true) { throw CsmClientException( - "Can't delete runner ${runner.id}: at least one run is still running") + "Can't delete runner ${runner.id}: at least one run is still running" + ) } // Update parent and root references to deleted runner @@ -143,7 +144,12 @@ class RunnerService( // Notify the deletion val runnerDeleted = RunnerDeleted( - this, runner.organizationId, runner.workspaceId, runner.id, runner.datasets.parameter) + this, + runner.organizationId, + runner.workspaceId, + runner.id, + runner.datasets.parameter, + ) this.eventPublisher.publishEvent(runnerDeleted) return runnerRepository.delete(runnerInstance.getRunnerDataObjet()) @@ -152,7 +158,7 @@ class RunnerService( private fun listAllRunnerByParentId( organizationId: String, workspaceId: String, - parentId: String + parentId: String, ): List { val defaultPageSize = csmPlatformProperties.databases.resources.runner.defaultPageSize var pageRequest: Pageable = PageRequest.ofSize(defaultPageSize) @@ -180,11 +186,14 @@ class RunnerService( fun findRunnerByDatasetParameter( organizationId: String, workspaceId: String, - datasetId: String + datasetId: String, ): Runner? { return runnerRepository .findByOrganizationIdAndWorkspaceIdAndDatasetsParameterValue( - organizationId, workspaceId, datasetId) + organizationId, + workspaceId, + datasetId, + ) .getOrNull() } @@ -201,11 +210,14 @@ class RunnerService( var runner = runnerRepository.findBy(organization!!.id, workspace!!.id, runnerId).orElseThrow { CsmResourceNotFoundException( - "Runner $runnerId not found in workspace ${workspace!!.id} and organization ${organization!!.id}") + "Runner $runnerId not found in workspace ${workspace!!.id} and organization ${organization!!.id}" + ) } if (runner.lastRunInfo.lastRunId != null) { - if (runner.lastRunInfo.lastRunStatus != LastRunStatus.Failed || - runner.lastRunInfo.lastRunStatus != LastRunStatus.Successful) { + if ( + runner.lastRunInfo.lastRunStatus != LastRunStatus.Failed || + runner.lastRunInfo.lastRunStatus != LastRunStatus.Successful + ) { runner = updateRunnerStatus(runner) } } @@ -220,7 +232,8 @@ class RunnerService( runner.organizationId, runner.workspaceId, runner.id, - runner.lastRunInfo.lastRunId ?: "") + runner.lastRunInfo.lastRunId ?: "", + ) eventPublisher.publishEvent(updateRunnerStatusEvent) val runStatus = LastRunStatus.forValue(updateRunnerStatusEvent.response!!) return runnerRepository.save(runner.apply { lastRunInfo.lastRunStatus = runStatus }) @@ -238,14 +251,23 @@ class RunnerService( val currentUser = getCurrentAccountIdentifier(this.csmPlatformProperties) runnerRepository .findByWorkspaceIdAndSecurity( - organization!!.id, workspace!!.id, currentUser, pageRequest) + organization!!.id, + workspace!!.id, + currentUser, + pageRequest, + ) .toList() } runners.forEach { it.security = updateSecurityVisibility(it).security } runners.forEach { runner -> val listDatasetParts = datasetApiService.listDatasetParts( - organization!!.id, workspace!!.id, runner.datasets.parameter, null, null) + organization!!.id, + workspace!!.id, + runner.datasets.parameter, + null, + null, + ) runner.apply { datasets.parameters = listDatasetParts as MutableList? } } return runners @@ -280,10 +302,14 @@ class RunnerService( name = "init", createInfo = RunnerEditInfo( - timestamp = now, userId = getCurrentAccountIdentifier(csmPlatformProperties)), + timestamp = now, + userId = getCurrentAccountIdentifier(csmPlatformProperties), + ), updateInfo = RunnerEditInfo( - timestamp = now, userId = getCurrentAccountIdentifier(csmPlatformProperties)), + timestamp = now, + userId = getCurrentAccountIdentifier(csmPlatformProperties), + ), solutionId = "init", runTemplateId = "init", organizationId = organization!!.id, @@ -303,7 +329,8 @@ class RunnerService( this.runner.updateInfo = RunnerEditInfo( timestamp = Instant.now().toEpochMilli(), - userId = getCurrentAccountIdentifier(csmPlatformProperties)) + userId = getCurrentAccountIdentifier(csmPlatformProperties), + ) } fun getRunnerDataObjet(): Runner = this.runner @@ -319,9 +346,11 @@ class RunnerService( organization!!.id, workspace!!.id, workspace!!.solution.solutionId, - runner.runTemplateId)) { - "Run Template not found: ${runner.runTemplateId}" - } + runner.runTemplateId, + ) + ) { + "Run Template not found: ${runner.runTemplateId}" + } val excludeFields = arrayOf( @@ -331,11 +360,13 @@ class RunnerService( "organizationId", "workspaceId", "creationDate", - "security") + "security", + ) this.runner.compareToAndMutateIfNeeded(runner, excludedFields = excludeFields) consolidateParametersVarType() } + @Suppress("LongMethod") fun setValueFrom(runnerCreateRequest: RunnerCreateRequest): RunnerInstance { val runnerSecurity = runnerCreateRequest.security @@ -351,23 +382,29 @@ class RunnerService( .map { access -> DatasetAccessControl( id = access.id, - role = access.role.takeUnless { it == ROLE_VALIDATOR } ?: ROLE_USER) + role = access.role.takeUnless { it == ROLE_VALIDATOR } ?: ROLE_USER, + ) } - .toMutableList()) + .toMutableList(), + ) val parameterDataset = datasetApiService.createDataset( organization!!.id, workspace!!.id, DatasetCreateRequest( - name = "Dataset attached to ${this.runner.id}", security = datasetSecurity), - emptyArray()) + name = "Dataset attached to ${this.runner.id}", + security = datasetSecurity, + ), + emptyArray(), + ) val filteredParameterValues = useOnlyDefinedParameterValues( runnerCreateRequest.solutionId, runnerCreateRequest.runTemplateId, - runnerCreateRequest.parametersValues) + runnerCreateRequest.parametersValues, + ) return setValueFrom( Runner( @@ -379,13 +416,15 @@ class RunnerService( datasets = RunnerDatasets( bases = runnerCreateRequest.datasetList ?: mutableListOf(), - parameter = parameterDataset.id), + parameter = parameterDataset.id, + ), parametersValues = filteredParameterValues, parentId = runnerCreateRequest.parentId, lastRunInfo = LastRunInfo( lastRunId = this.runner.lastRunInfo.lastRunId, - lastRunStatus = this.runner.lastRunInfo.lastRunStatus), + lastRunStatus = this.runner.lastRunInfo.lastRunStatus, + ), solutionName = runnerCreateRequest.solutionName, solutionId = runnerCreateRequest.solutionId, validationStatus = this.runner.validationStatus, @@ -397,7 +436,8 @@ class RunnerService( updateInfo = this.runner.updateInfo, organizationId = this.runner.organizationId, workspaceId = this.runner.workspaceId, - )) + ) + ) } fun setValueFrom(runnerUpdateRequest: RunnerUpdateRequest): RunnerInstance { @@ -409,7 +449,10 @@ class RunnerService( this.runner.parametersValues } else { useOnlyDefinedParameterValues( - this.runner.solutionId, runTemplateId, runnerUpdateRequest.parametersValues) + this.runner.solutionId, + runTemplateId, + runnerUpdateRequest.parametersValues, + ) } return setValueFrom( @@ -422,7 +465,8 @@ class RunnerService( datasets = RunnerDatasets( bases = runnerUpdateRequest.datasetList ?: this.runner.datasets.bases, - parameter = this.runner.datasets.parameter), + parameter = this.runner.datasets.parameter, + ), parametersValues = filteredParameterValues, id = this.runner.id, organizationId = this.runner.organizationId, @@ -436,14 +480,18 @@ class RunnerService( updateInfo = RunnerEditInfo( timestamp = Instant.now().toEpochMilli(), - userId = getCurrentAccountIdentifier(csmPlatformProperties)), + userId = getCurrentAccountIdentifier(csmPlatformProperties), + ), parentId = this.runner.parentId, workspaceId = this.runner.workspaceId, lastRunInfo = LastRunInfo( lastRunStatus = this.runner.lastRunInfo.lastRunStatus, - lastRunId = this.runner.lastRunInfo.lastRunId), - validationStatus = this.runner.validationStatus)) + lastRunId = this.runner.lastRunInfo.lastRunId, + ), + validationStatus = this.runner.validationStatus, + ) + ) } fun setLastRunInfo(runId: String, runStatus: LastRunStatus = LastRunStatus.Running) { @@ -511,14 +559,22 @@ class RunnerService( val inheritedParameterValues = constructParametersValuesFromParent( - runTemplateParametersIds, parentId, parentRunner, this.runner) + runTemplateParametersIds, + parentId, + parentRunner, + this.runner, + ) val parameterValueList = this.runner.parametersValues parameterValueList.addAll(inheritedParameterValues) this.runner.parametersValues = parameterValueList consolidateParametersVarType() constructDatasetParametersFromParent( - runTemplateParametersIds, parentId, parentRunner, this.runner) + runTemplateParametersIds, + parentId, + parentRunner, + this.runner, + ) // Compute rootId this.runner.parentId?.let { @@ -533,7 +589,7 @@ class RunnerService( private fun useOnlyDefinedParameterValues( solutionId: String, runTemplateId: String, - parametersValues: MutableList? + parametersValues: MutableList?, ): MutableList { if (parametersValues.isNullOrEmpty()) return mutableListOf() @@ -562,7 +618,7 @@ class RunnerService( runTemplateParametersIds: List, parentId: String, parent: Runner, - runner: Runner + runner: Runner, ): List { val datasetPartList = mutableListOf() @@ -570,7 +626,12 @@ class RunnerService( val parentDatasetParameters = datasetApiService .listDatasetParts( - organization!!.id, workspace!!.id, parent.datasets.parameter, null, null) + organization!!.id, + workspace!!.id, + parent.datasets.parameter, + null, + null, + ) .associateBy { it.name } runTemplateParametersIds @@ -578,16 +639,23 @@ class RunnerService( .forEach { parameterId -> logger.debug( "Creating dataset part from parent for parameter $parameterId " + - "in Dataset ${runner.datasets.parameter}") + "in Dataset ${runner.datasets.parameter}" + ) val parentDatasetParameter = parentDatasetParameters[parameterId] if (parentDatasetParameter != null) { datasetPartList.add( addDatasetPartInDatasetParameter( - parentDatasetParameter, runner.datasets.parameter, parameterId, runner.id)) + parentDatasetParameter, + runner.datasets.parameter, + parameterId, + runner.id, + ) + ) } else { logger.warn( "Parameter $parameterId not found in parent ($parentId) dataset parameters: " + - "No dataset part will be created") + "No dataset part will be created" + ) } } } @@ -599,7 +667,7 @@ class RunnerService( datasetPartToAdd: DatasetPart, datasetId: String, parameterId: String, - runnerId: String + runnerId: String, ): DatasetPart { val sourceName = datasetPartToAdd.sourceName @@ -609,19 +677,22 @@ class RunnerService( description = "Dataset Part associated to $parameterId parameter", sourceName = sourceName, tags = mutableListOf(runnerId, parameterId), - type = datasetPartToAdd.type) + type = datasetPartToAdd.type, + ) val datasetPartResource = datasetApiService.downloadDatasetPart( datasetPartToAdd.organizationId, datasetPartToAdd.workspaceId, datasetPartToAdd.datasetId, - datasetPartToAdd.id) + datasetPartToAdd.id, + ) return datasetApiService.createDatasetPartFromResource( datasetPartToAdd.organizationId, datasetPartToAdd.workspaceId, datasetId, datasetPartResource, - datasetPartCreateRequest) + datasetPartCreateRequest, + ) } private fun createPartInDatasetParameter( @@ -631,12 +702,16 @@ class RunnerService( workspaceDatasetId: String, parameterId: String, defaultParameterPartId: String, - runnerId: String + runnerId: String, ): DatasetPart { val defaultDatasetPart = datasetApiService.getDatasetPart( - organizationId, workspaceId, workspaceDatasetId, defaultParameterPartId) + organizationId, + workspaceId, + workspaceDatasetId, + defaultParameterPartId, + ) val datasetPartCreateRequest = DatasetPartCreateRequest( @@ -645,18 +720,24 @@ class RunnerService( sourceName = defaultDatasetPart.sourceName, tags = mutableListOf(runnerId, parameterId, datasetParameterId, defaultParameterPartId), - type = defaultDatasetPart.type) + type = defaultDatasetPart.type, + ) val datasetPartResource = datasetApiService.downloadDatasetPart( - organizationId, workspaceId, workspaceDatasetId, defaultParameterPartId) + organizationId, + workspaceId, + workspaceDatasetId, + defaultParameterPartId, + ) return datasetApiService.createDatasetPartFromResource( organizationId, workspaceId, datasetParameterId, datasetPartResource, - datasetPartCreateRequest) + datasetPartCreateRequest, + ) } private fun consolidateParametersVarType() { @@ -681,7 +762,7 @@ class RunnerService( fun initBaseDatasetListFromParent( parentId: String, - newDatasetList: List? + newDatasetList: List?, ): RunnerInstance = apply { val runnerId = this.runner.id val parentRunner = @@ -704,7 +785,8 @@ class RunnerService( this.runner.getRbac(), runnerAccessControl.id, runnerAccessControl.role, - this.roleDefinition) + this.roleDefinition, + ) this.setRbacSecurity(rbacSecurity) val userId = runnerAccessControl.id @@ -715,7 +797,10 @@ class RunnerService( // Assign roles on parameter datasets if not already present on dataset resource val parameterDataset = datasetApiService.findByOrganizationIdWorkspaceIdAndDatasetId( - organizationId, workspaceId, this.runner.datasets.parameter) + organizationId, + workspaceId, + this.runner.datasets.parameter, + ) parameterDataset?.let { addUserAccessControlOnDataset(parameterDataset, RunnerAccessControl(userId, datasetRole)) } @@ -736,7 +821,10 @@ class RunnerService( fun checkUserExists(userId: String) { csmRbac.checkEntityExists( - runner.getRbac(), userId, "User '$userId' not found in runner ${runner.id}") + runner.getRbac(), + userId, + "User '$userId' not found in runner ${runner.id}", + ) } private fun getRbacSecurity(): RbacSecurity { @@ -750,14 +838,16 @@ class RunnerService( rbacSecurity.accessControlList .distinctBy { it.id } .map { RunnerAccessControl(it.id, it.role) } - .toMutableList()) + .toMutableList(), + ) } private fun extractRbacSecurity(security: RunnerSecurity): RbacSecurity { return RbacSecurity( this.runner.id, security.default, - security.accessControlList.map { RbacAccessControl(it.id, it.role) }.toMutableList()) + security.accessControlList.map { RbacAccessControl(it.id, it.role) }.toMutableList(), + ) } private fun constructParametersValues( @@ -779,7 +869,8 @@ class RunnerService( parameterId = runTemplateParameter.id, varType = runTemplateParameter.varType, value = defaultParameterValue ?: "", - )) + ) + ) } return runnerParameters @@ -787,7 +878,7 @@ class RunnerService( private fun constructDatasetParameters( runTemplateParameters: List, - datasetParameterId: String + datasetParameterId: String, ): List { val datasetPartList = mutableListOf() @@ -810,7 +901,9 @@ class RunnerService( workspaceDatasetId, parameterId, defaultParameterPartId, - runner.id)) + runner.id, + ) + ) } } } @@ -823,7 +916,7 @@ class RunnerService( runTemplateParametersIds: List, parentId: String, parent: Runner, - runner: Runner + runner: Runner, ): List { val parametersValuesList = mutableListOf() @@ -857,7 +950,8 @@ class RunnerService( parametersValuesList.add(parameterValue) } else { logger.warn( - "Parameter $parameterId not found in parent ($parentId) parameters values") + "Parameter $parameterId not found in parent ($parentId) parameters values" + ) } } } @@ -877,7 +971,11 @@ class RunnerService( if (datasetACL != null && datasetACL.any { it.id == userId }) datasetApiService.deleteDatasetAccessControl( - organizationId, workspaceId, datasetId, userId) + organizationId, + workspaceId, + datasetId, + userId, + ) } fun getUsers(): List { @@ -898,7 +996,8 @@ class RunnerService( organization!!.id, workspace!!.id, dataset.id, - DatasetAccessControl(roleDefinition.id, roleDefinition.role)) + DatasetAccessControl(roleDefinition.id, roleDefinition.role), + ) } } } @@ -908,4 +1007,5 @@ fun RunnerSecurity?.toGenericSecurity(runnerId: String) = runnerId, this?.default ?: ROLE_NONE, this?.accessControlList?.map { RbacAccessControl(it.id, it.role) }?.toMutableList() - ?: mutableListOf()) + ?: mutableListOf(), + ) diff --git a/settings.gradle.kts b/settings.gradle.kts index 7feb07ca9..036d54fc6 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -24,7 +24,8 @@ include( "metrics", "runner", "run", - "common") + "common", +) project(":api").name = "cosmotech-api" diff --git a/solution/src/integrationTest/kotlin/com/cosmotech/solution/service/SolutionServiceIntegrationTest.kt b/solution/src/integrationTest/kotlin/com/cosmotech/solution/service/SolutionServiceIntegrationTest.kt index 3972f6334..e2d08b982 100644 --- a/solution/src/integrationTest/kotlin/com/cosmotech/solution/service/SolutionServiceIntegrationTest.kt +++ b/solution/src/integrationTest/kotlin/com/cosmotech/solution/service/SolutionServiceIntegrationTest.kt @@ -81,7 +81,10 @@ class SolutionServiceIntegrationTest : CsmTestBase() { fun setUp() { mockkStatic("com.cosmotech.common.utils.SecurityUtilsKt") ReflectionTestUtils.setField( - solutionApiService, "containerRegistryService", containerRegistryService) + solutionApiService, + "containerRegistryService", + containerRegistryService, + ) every { containerRegistryService.getImageLabel(any(), any(), any()) } returns null every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER every { getCurrentAccountGroups(any()) } returns listOf("myTestGroup") @@ -107,7 +110,9 @@ class SolutionServiceIntegrationTest : CsmTestBase() { runTemplates = mutableListOf( RunTemplateCreateRequest(id = "one", parameterGroups = mutableListOf()), - RunTemplateCreateRequest(id = "two", parameterGroups = mutableListOf()))) + RunTemplateCreateRequest(id = "two", parameterGroups = mutableListOf()), + ) + ) solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) val runTemplateUpdated = @@ -115,7 +120,8 @@ class SolutionServiceIntegrationTest : CsmTestBase() { organizationSaved.id, solutionSaved.id, "one", - RunTemplateUpdateRequest(name = "name_one")) + RunTemplateUpdateRequest(name = "name_one"), + ) val solutionUpdated = solutionApiService.getSolution(organizationSaved.id, solutionSaved.id) // Assert that no runTemplate were deleted @@ -137,7 +143,8 @@ class SolutionServiceIntegrationTest : CsmTestBase() { assertEquals(solutionCreated, solutionFound) logger.info( - "should find all solutions for the organization and assert the list contains 2 elements") + "should find all solutions for the organization and assert the list contains 2 elements" + ) val solutionsFound = solutionApiService.listSolutions(organizationSaved.id, null, null) assertTrue(solutionsFound.size == 2) @@ -145,11 +152,15 @@ class SolutionServiceIntegrationTest : CsmTestBase() { val solutionUpdateRequest = SolutionUpdateRequest(name = "My solution updated") val solutionUpdated = solutionApiService.updateSolution( - organizationSaved.id, solutionCreated.id, solutionUpdateRequest) + organizationSaved.id, + solutionCreated.id, + solutionUpdateRequest, + ) assertEquals("My solution updated", solutionUpdated.name) logger.info( - "should delete the solution and assert that the list of solutions contains only 1 element") + "should delete the solution and assert that the list of solutions contains only 1 element" + ) solutionApiService.deleteSolution(organizationSaved.id, solutionCreated.id) val solutionsFoundAfterDelete = solutionApiService.listSolutions(organizationSaved.id, null, null) @@ -182,12 +193,13 @@ class SolutionServiceIntegrationTest : CsmTestBase() { parameterGroups = solutionParameterGroups, parameters = mutableListOf( - RunTemplateParameterCreateRequest(id = "parameterName", varType = "string")), + RunTemplateParameterCreateRequest(id = "parameterName", varType = "string") + ), security = SolutionSecurity( default = ROLE_ADMIN, - accessControlList = - mutableListOf(SolutionAccessControl("user_id", ROLE_ADMIN))), + accessControlList = mutableListOf(SolutionAccessControl("user_id", ROLE_ADMIN)), + ), url = solutionUrl, alwaysPull = true, ) @@ -195,7 +207,10 @@ class SolutionServiceIntegrationTest : CsmTestBase() { val solutionUpdated = solutionApiService.updateSolution( - organizationSaved.id, newSolution.id, SolutionUpdateRequest()) + organizationSaved.id, + newSolution.id, + SolutionUpdateRequest(), + ) assertEquals(newSolution, solutionUpdated) } @@ -212,14 +227,17 @@ class SolutionServiceIntegrationTest : CsmTestBase() { val solutionCreated = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) assertEquals(imageLabel, solutionCreated.sdkVersion) assertEquals( imageLabel, solutionApiService .getSolution(organizationSaved.id, solutionCreated.id) - .sdkVersion) + .sdkVersion, + ) val solutions = solutionApiService.listSolutions(organizationSaved.id, null, null) assertFalse(solutions.isEmpty()) @@ -228,7 +246,10 @@ class SolutionServiceIntegrationTest : CsmTestBase() { val solutionUpdateRequest = SolutionUpdateRequest(name = "New name") val solutionUpdated = solutionApiService.updateSolution( - organizationSaved.id, solutionCreated.id, solutionUpdateRequest) + organizationSaved.id, + solutionCreated.id, + solutionUpdateRequest, + ) assertEquals(solutionUpdateRequest.name, solutionUpdated.name) assertEquals(imageLabel, solutionUpdated.sdkVersion) } @@ -278,7 +299,10 @@ class SolutionServiceIntegrationTest : CsmTestBase() { val updateSolution = solutionApiService.updateSolution( - organizationSaved.id, solutionCreated.id, solutionUpdateRequest) + organizationSaved.id, + solutionCreated.id, + solutionUpdateRequest, + ) updateSolution.id.let { solutionApiService.getSolution(organizationSaved.id, it) } @@ -298,7 +322,10 @@ class SolutionServiceIntegrationTest : CsmTestBase() { assertThrows { solutionApiService.updateSolution( - organizationSaved.id, solutionCreated.id, solutionUpdateRequest) + organizationSaved.id, + solutionCreated.id, + solutionUpdateRequest, + ) } } @@ -314,11 +341,14 @@ class SolutionServiceIntegrationTest : CsmTestBase() { val exception = assertThrows { solutionApiService.listSolutionParameters( - organizationSaved.id, "non-existing-solution-id") + organizationSaved.id, + "non-existing-solution-id", + ) } assertEquals( "Solution non-existing-solution-id not found in organization ${organizationSaved.id}", - exception.message) + exception.message, + ) } @Test @@ -337,7 +367,8 @@ class SolutionServiceIntegrationTest : CsmTestBase() { maxValue = "100", description = "this_is_a_description", labels = mutableMapOf("fr" to "this_is_a_label"), - additionalData = mutableMapOf("option1" to "value1", "option2" to 10.0)), + additionalData = mutableMapOf("option1" to "value1", "option2" to 10.0), + ), RunTemplateParameterCreateRequest( id = "parameterName2", varType = "int", @@ -346,7 +377,10 @@ class SolutionServiceIntegrationTest : CsmTestBase() { maxValue = "1000", description = "this_is_a_description2", labels = mutableMapOf("fr" to "this_is_a_label2"), - additionalData = mutableMapOf("option1" to "value1", "option2" to 100.8)))) + additionalData = mutableMapOf("option1" to "value1", "option2" to 100.8), + ), + ), + ) val newSolution = solutionApiService.createSolution(organizationSaved.id, newSolutionWithParameters) @@ -393,7 +427,8 @@ class SolutionServiceIntegrationTest : CsmTestBase() { maxValue = "100", description = "this_is_a_description", labels = mutableMapOf("fr" to "this_is_a_label"), - additionalData = mutableMapOf("option1" to "value1", "option2" to 10.0)), + additionalData = mutableMapOf("option1" to "value1", "option2" to 10.0), + ), RunTemplateParameterCreateRequest( id = "parameterName2", varType = "int", @@ -402,14 +437,20 @@ class SolutionServiceIntegrationTest : CsmTestBase() { maxValue = "1000", description = "this_is_a_description2", labels = mutableMapOf("fr" to "this_is_a_label2"), - additionalData = mutableMapOf("option1" to "value1", "option2" to 100.8)))) + additionalData = mutableMapOf("option1" to "value1", "option2" to 100.8), + ), + ), + ) val newSolution = solutionApiService.createSolution(organizationSaved.id, newSolutionWithParameters) val solutionParameter = solutionApiService.getSolutionParameter( - organizationSaved.id, newSolution.id, newSolution.parameters[0].id) + organizationSaved.id, + newSolution.id, + newSolution.parameters[0].id, + ) assertNotNull(solutionParameter) assertEquals("parameterName", solutionParameter.id) @@ -429,11 +470,15 @@ class SolutionServiceIntegrationTest : CsmTestBase() { val exception = assertThrows { solutionApiService.getSolutionParameter( - organizationSaved.id, solutionSaved.id, "non-existing-solution-parameter-id") + organizationSaved.id, + solutionSaved.id, + "non-existing-solution-parameter-id", + ) } assertEquals( "Solution parameter with id non-existing-solution-parameter-id does not exist", - exception.message) + exception.message, + ) } @Test @@ -451,7 +496,8 @@ class SolutionServiceIntegrationTest : CsmTestBase() { maxValue = "100", description = "this_is_a_description", labels = mutableMapOf("fr" to "this_is_a_label"), - additionalData = mutableMapOf("option1" to "value1", "option2" to 10.0)), + additionalData = mutableMapOf("option1" to "value1", "option2" to 10.0), + ), RunTemplateParameterCreateRequest( id = "parameterName2", varType = "int", @@ -460,7 +506,10 @@ class SolutionServiceIntegrationTest : CsmTestBase() { maxValue = "1000", description = "this_is_a_description2", labels = mutableMapOf("fr" to "this_is_a_label2"), - additionalData = mutableMapOf("option1" to "value1", "option2" to 100.8)))) + additionalData = mutableMapOf("option1" to "value1", "option2" to 100.8), + ), + ), + ) val newSolution = solutionApiService.createSolution(organizationSaved.id, newSolutionWithParameters) @@ -478,7 +527,9 @@ class SolutionServiceIntegrationTest : CsmTestBase() { maxValue = "", description = "new_this_is_a_description2", labels = mutableMapOf("en" to "new_this_is_a_label2"), - additionalData = mutableMapOf("option1" to "newValue1"))) + additionalData = mutableMapOf("option1" to "newValue1"), + ), + ) assertNotNull(solutionParameter) assertEquals(parameterId, solutionParameter.id) assertEquals("string", solutionParameter.varType) @@ -499,11 +550,13 @@ class SolutionServiceIntegrationTest : CsmTestBase() { organizationSaved.id, solutionSaved.id, "non-existing-solution-parameter-id", - RunTemplateParameterUpdateRequest()) + RunTemplateParameterUpdateRequest(), + ) } assertEquals( "Solution parameter with id non-existing-solution-parameter-id does not exist", - exception.message) + exception.message, + ) } @Test @@ -522,7 +575,8 @@ class SolutionServiceIntegrationTest : CsmTestBase() { maxValue = "100", description = "this_is_a_description", labels = mutableMapOf("fr" to "this_is_a_label"), - additionalData = mutableMapOf("option1" to "value1", "option2" to 10.0)), + additionalData = mutableMapOf("option1" to "value1", "option2" to 10.0), + ), RunTemplateParameterCreateRequest( id = "parameterName2", varType = "int", @@ -531,7 +585,10 @@ class SolutionServiceIntegrationTest : CsmTestBase() { maxValue = "1000", description = "this_is_a_description2", labels = mutableMapOf("fr" to "this_is_a_label2"), - additionalData = mutableMapOf("option1" to "value1", "option2" to 100.8)))) + additionalData = mutableMapOf("option1" to "value1", "option2" to 100.8), + ), + ), + ) val newSolution = solutionApiService.createSolution(organizationSaved.id, newSolutionWithParameters) @@ -542,7 +599,10 @@ class SolutionServiceIntegrationTest : CsmTestBase() { val parameterIdToDelete = listSolutionParameters[0].id val parameterIdToKeep = listSolutionParameters[1].id solutionApiService.deleteSolutionParameter( - organizationSaved.id, newSolution.id, parameterIdToDelete) + organizationSaved.id, + newSolution.id, + parameterIdToDelete, + ) listSolutionParameters = solutionApiService.listSolutionParameters(organizationSaved.id, newSolution.id) @@ -557,11 +617,15 @@ class SolutionServiceIntegrationTest : CsmTestBase() { val exception = assertThrows { solutionApiService.deleteSolutionParameter( - organizationSaved.id, solutionSaved.id, "non-existing-solution-parameter-id") + organizationSaved.id, + solutionSaved.id, + "non-existing-solution-parameter-id", + ) } assertEquals( "Solution parameter with id non-existing-solution-parameter-id does not exist", - exception.message) + exception.message, + ) } @Test @@ -572,11 +636,15 @@ class SolutionServiceIntegrationTest : CsmTestBase() { organizationSaved.id, "non-existing-solution-id", RunTemplateParameterCreateRequest( - id = "my_parameter_name", varType = "my_varType_parameter")) + id = "my_parameter_name", + varType = "my_varType_parameter", + ), + ) } assertEquals( "Solution non-existing-solution-id not found in organization ${organizationSaved.id}", - exception.message) + exception.message, + ) } @Test @@ -597,10 +665,14 @@ class SolutionServiceIntegrationTest : CsmTestBase() { maxValue = "1000", description = "this_is_a_description2", labels = mutableMapOf("fr" to "this_is_a_label2"), - additionalData = mutableMapOf("option1" to "value1", "option2" to 100.8)) + additionalData = mutableMapOf("option1" to "value1", "option2" to 100.8), + ) solutionApiService.createSolutionParameter( - organizationSaved.id, newSolutionWithEmptyParameters.id, parameterCreateRequest) + organizationSaved.id, + newSolutionWithEmptyParameters.id, + parameterCreateRequest, + ) val newSolutionWithNewParameter = solutionApiService.getSolution(organizationSaved.id, newSolutionWithEmptyParameters.id) @@ -630,7 +702,8 @@ class SolutionServiceIntegrationTest : CsmTestBase() { maxValue = "1000", description = "this_is_a_description2", labels = mutableMapOf("fr" to "this_is_a_label2"), - additionalData = mutableMapOf("option1" to "value1", "option2" to 100.8)) + additionalData = mutableMapOf("option1" to "value1", "option2" to 100.8), + ) val newSolutionWithParameter = makeSolution(parameter = mutableListOf(solutionParameterCreateRequest)) @@ -644,7 +717,8 @@ class SolutionServiceIntegrationTest : CsmTestBase() { solutionApiService.createSolutionParameter( organizationSaved.id, newSolutionWithEmptyParameters.id, - solutionParameterCreateRequest) + solutionParameterCreateRequest, + ) } assertEquals("Parameter with id 'pAramEterName' already exists", exception.message) @@ -663,7 +737,8 @@ class SolutionServiceIntegrationTest : CsmTestBase() { maxValue = "1000", description = "this_is_a_description2", labels = mutableMapOf("fr" to "this_is_a_label2"), - additionalData = mutableMapOf("option1" to "value1", "option2" to 100.8)), + additionalData = mutableMapOf("option1" to "value1", "option2" to 100.8), + ), RunTemplateParameterCreateRequest( id = "ParaMeterName", varType = "int", @@ -672,7 +747,9 @@ class SolutionServiceIntegrationTest : CsmTestBase() { maxValue = "1000", description = "this_is_a_description2", labels = mutableMapOf("fr" to "this_is_a_label2"), - additionalData = mutableMapOf("option1" to "value1", "option2" to 100.8))) + additionalData = mutableMapOf("option1" to "value1", "option2" to 100.8), + ), + ) val newSolutionWithoutParameters = makeSolution(parameter = parametersCreateRequest) @@ -692,7 +769,8 @@ class SolutionServiceIntegrationTest : CsmTestBase() { IntRange(1, numberOfSolutions - 1).forEach { solutionApiService.createSolution( organizationId = organizationSaved.id, - solutionCreateRequest = makeSolution(organizationSaved.id)) + solutionCreateRequest = makeSolution(organizationSaved.id), + ) } logger.info("should find all solutions and assert there are $numberOfSolutions") var solutions = solutionApiService.listSolutions(organizationSaved.id, null, null) @@ -764,10 +842,13 @@ class SolutionServiceIntegrationTest : CsmTestBase() { organizationSaved.id, baseSolutionSaved.id, "WrongRunTemplateId", - RunTemplateUpdateRequest()) + RunTemplateUpdateRequest(), + ) } assertEquals( - "Solution run template with id WrongRunTemplateId does not exist", assertThrows.message) + "Solution run template with id WrongRunTemplateId does not exist", + assertThrows.message, + ) } @Test @@ -783,7 +864,10 @@ class SolutionServiceIntegrationTest : CsmTestBase() { // should update the default security and assert it worked val solutionDefaultSecurity = solutionApiService.updateSolutionDefaultSecurity( - organizationSaved.id, solutionSaved.id, SolutionRole(ROLE_VIEWER)) + organizationSaved.id, + solutionSaved.id, + SolutionRole(ROLE_VIEWER), + ) solutionSaved = solutionApiService.getSolution(organizationSaved.id, solutionSaved.id) assertEquals(solutionSaved.security, solutionDefaultSecurity) } @@ -808,7 +892,10 @@ class SolutionServiceIntegrationTest : CsmTestBase() { accessControlList = mutableListOf( SolutionAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), - SolutionAccessControl(CONNECTED_ADMIN_USER, ROLE_EDITOR)))) + SolutionAccessControl(CONNECTED_ADMIN_USER, ROLE_EDITOR), + ), + ), + ) assertThrows { solutionApiService.createSolution(organizationSaved.id, brokenSolution) } @@ -825,7 +912,8 @@ class SolutionServiceIntegrationTest : CsmTestBase() { solutionApiService.createSolutionAccessControl( organizationSaved.id, solutionSaved.id, - SolutionAccessControl(CONNECTED_ADMIN_USER, ROLE_EDITOR)) + SolutionAccessControl(CONNECTED_ADMIN_USER, ROLE_EDITOR), + ) } } @@ -838,8 +926,10 @@ class SolutionServiceIntegrationTest : CsmTestBase() { assertEquals( SolutionSecurity( default = ROLE_NONE, - mutableListOf(SolutionAccessControl(CONNECTED_READER_USER, ROLE_VIEWER))), - solutionSaved.security) + mutableListOf(SolutionAccessControl(CONNECTED_READER_USER, ROLE_VIEWER)), + ), + solutionSaved.security, + ) assertEquals(1, solutionSaved.security.accessControlList.size) } @@ -853,8 +943,10 @@ class SolutionServiceIntegrationTest : CsmTestBase() { assertEquals( SolutionSecurity( default = ROLE_NONE, - mutableListOf(SolutionAccessControl(CONNECTED_READER_USER, ROLE_VIEWER))), - it.security) + mutableListOf(SolutionAccessControl(CONNECTED_READER_USER, ROLE_VIEWER)), + ), + it.security, + ) assertEquals(1, it.security.accessControlList.size) } } @@ -884,12 +976,13 @@ class SolutionServiceIntegrationTest : CsmTestBase() { parameterGroups = solutionParameterGroups, parameters = mutableListOf( - RunTemplateParameterCreateRequest(id = "parameterName", varType = "string")), + RunTemplateParameterCreateRequest(id = "parameterName", varType = "string") + ), security = SolutionSecurity( default = ROLE_ADMIN, - accessControlList = - mutableListOf(SolutionAccessControl("user_id", ROLE_ADMIN))), + accessControlList = mutableListOf(SolutionAccessControl("user_id", ROLE_ADMIN)), + ), url = solutionUrl, alwaysPull = true, ) @@ -942,12 +1035,13 @@ class SolutionServiceIntegrationTest : CsmTestBase() { parameterGroups = solutionParameterGroups, parameters = mutableListOf( - RunTemplateParameterCreateRequest(id = "parameterName", varType = "string")), + RunTemplateParameterCreateRequest(id = "parameterName", varType = "string") + ), security = SolutionSecurity( default = ROLE_ADMIN, - accessControlList = - mutableListOf(SolutionAccessControl("user_id", ROLE_ADMIN))), + accessControlList = mutableListOf(SolutionAccessControl("user_id", ROLE_ADMIN)), + ), url = solutionUrl, alwaysPull = true, ) @@ -971,14 +1065,18 @@ class SolutionServiceIntegrationTest : CsmTestBase() { runTemplates = solutionRunTemplates, parameters = mutableListOf( - RunTemplateParameterCreateRequest( - id = "parameterNameUpdated", varType = "int")), + RunTemplateParameterCreateRequest(id = "parameterNameUpdated", varType = "int") + ), url = newUrl, - version = newVersion) + version = newVersion, + ) solutionSaved = solutionApiService.updateSolution( - organizationSaved.id, solutionSaved.id, solutionUpdateRequest) + organizationSaved.id, + solutionSaved.id, + solutionUpdateRequest, + ) assertEquals(updatedKey, solutionSaved.key) assertEquals(updatedName, solutionSaved.name) @@ -1024,12 +1122,13 @@ class SolutionServiceIntegrationTest : CsmTestBase() { parameterGroups = solutionParameterGroups, parameters = mutableListOf( - RunTemplateParameterCreateRequest(id = "parameterName", varType = "string")), + RunTemplateParameterCreateRequest(id = "parameterName", varType = "string") + ), security = SolutionSecurity( default = ROLE_ADMIN, - accessControlList = - mutableListOf(SolutionAccessControl("user_id", ROLE_ADMIN))), + accessControlList = mutableListOf(SolutionAccessControl("user_id", ROLE_ADMIN)), + ), url = solutionUrl, alwaysPull = true, ) @@ -1053,11 +1152,15 @@ class SolutionServiceIntegrationTest : CsmTestBase() { repository = updatedRepository, url = newUrl, version = newVersion, - parameters = mutableListOf()) + parameters = mutableListOf(), + ) solutionSaved = solutionApiService.updateSolution( - organizationSaved.id, solutionSaved.id, solutionUpdateRequest) + organizationSaved.id, + solutionSaved.id, + solutionUpdateRequest, + ) assertEquals(updatedKey, solutionSaved.key) assertEquals(updatedName, solutionSaved.name) @@ -1101,12 +1204,13 @@ class SolutionServiceIntegrationTest : CsmTestBase() { parameterGroups = solutionParameterGroups, parameters = mutableListOf( - RunTemplateParameterCreateRequest(id = "parameterName", varType = "string")), + RunTemplateParameterCreateRequest(id = "parameterName", varType = "string") + ), security = SolutionSecurity( default = ROLE_ADMIN, - accessControlList = - mutableListOf(SolutionAccessControl("user_id", ROLE_ADMIN))), + accessControlList = mutableListOf(SolutionAccessControl("user_id", ROLE_ADMIN)), + ), url = solutionUrl, alwaysPull = true, ) @@ -1130,14 +1234,19 @@ class SolutionServiceIntegrationTest : CsmTestBase() { parameters = mutableListOf( RunTemplateParameterCreateRequest(id = "PaRaMeTeRnAmE", varType = "string"), - RunTemplateParameterCreateRequest(id = "pArAmEtErNaMe", varType = "string")), + RunTemplateParameterCreateRequest(id = "pArAmEtErNaMe", varType = "string"), + ), url = newUrl, - version = newVersion) + version = newVersion, + ) val exception = assertThrows { solutionApiService.updateSolution( - organizationSaved.id, solutionSaved.id, solutionUpdateRequest) + organizationSaved.id, + solutionSaved.id, + solutionUpdateRequest, + ) } assertEquals("One or several solution items have same id : parameters", exception.message) @@ -1168,12 +1277,13 @@ class SolutionServiceIntegrationTest : CsmTestBase() { parameterGroups = solutionParameterGroups, parameters = mutableListOf( - RunTemplateParameterCreateRequest(id = "parameterName", varType = "string")), + RunTemplateParameterCreateRequest(id = "parameterName", varType = "string") + ), security = SolutionSecurity( default = ROLE_ADMIN, - accessControlList = - mutableListOf(SolutionAccessControl("user_id", ROLE_ADMIN))), + accessControlList = mutableListOf(SolutionAccessControl("user_id", ROLE_ADMIN)), + ), url = solutionUrl, alwaysPull = true, ) @@ -1202,7 +1312,10 @@ class SolutionServiceIntegrationTest : CsmTestBase() { solutionSaved = solutionApiService.updateSolution( - organizationSaved.id, solutionSaved.id, solutionUpdateRequest) + organizationSaved.id, + solutionSaved.id, + solutionUpdateRequest, + ) assertEquals(updatedKey, solutionSaved.key) assertEquals(updatedName, solutionSaved.name) @@ -1245,12 +1358,13 @@ class SolutionServiceIntegrationTest : CsmTestBase() { parameterGroups = solutionParameterGroups, parameters = mutableListOf( - RunTemplateParameterCreateRequest(id = "parameterName", varType = "string")), + RunTemplateParameterCreateRequest(id = "parameterName", varType = "string") + ), security = SolutionSecurity( default = ROLE_ADMIN, - accessControlList = - mutableListOf(SolutionAccessControl("user_id", ROLE_ADMIN))), + accessControlList = mutableListOf(SolutionAccessControl("user_id", ROLE_ADMIN)), + ), url = solutionUrl, alwaysPull = true, ) @@ -1275,14 +1389,19 @@ class SolutionServiceIntegrationTest : CsmTestBase() { runTemplates = mutableListOf( RunTemplateCreateRequest(id = "PaRaMeTeRnAmE"), - RunTemplateCreateRequest(id = "pArAmEtErNaMe")), + RunTemplateCreateRequest(id = "pArAmEtErNaMe"), + ), url = newUrl, - version = newVersion) + version = newVersion, + ) val exception = assertThrows { solutionApiService.updateSolution( - organizationSaved.id, solutionSaved.id, solutionUpdateRequest) + organizationSaved.id, + solutionSaved.id, + solutionUpdateRequest, + ) } assertEquals("One or several solution items have same id : runTemplates", exception.message) @@ -1300,11 +1419,14 @@ class SolutionServiceIntegrationTest : CsmTestBase() { val exception = assertThrows { solutionApiService.listSolutionParameterGroups( - organizationSaved.id, "non-existing-solution-id") + organizationSaved.id, + "non-existing-solution-id", + ) } assertEquals( "Solution non-existing-solution-id not found in organization ${organizationSaved.id}", - exception.message) + exception.message, + ) } @Test @@ -1320,13 +1442,17 @@ class SolutionServiceIntegrationTest : CsmTestBase() { description = "this_is_a_description", labels = mutableMapOf("fr" to "this_is_a_label"), additionalData = mutableMapOf("option1" to "value1", "option2" to 10.0), - parameters = mutableListOf("parameterId1", "parameterId2")), + parameters = mutableListOf("parameterId1", "parameterId2"), + ), RunTemplateParameterGroupCreateRequest( id = "parameterGroupId2", description = "this_is_a_description2", labels = mutableMapOf("fr" to "this_is_a_label2"), additionalData = mutableMapOf("option2" to "value2", "option3" to 20.0), - parameters = mutableListOf("parameterId3", "parameterId4")))) + parameters = mutableListOf("parameterId3", "parameterId4"), + ), + ), + ) val newSolution = solutionApiService.createSolution(organizationSaved.id, newSolutionWithParameterGroups) @@ -1362,20 +1488,27 @@ class SolutionServiceIntegrationTest : CsmTestBase() { description = "this_is_a_description", labels = mutableMapOf("fr" to "this_is_a_label"), additionalData = mutableMapOf("option1" to "value1", "option2" to 10.0), - parameters = mutableListOf("parameterId1", "parameterId2")), + parameters = mutableListOf("parameterId1", "parameterId2"), + ), RunTemplateParameterGroupCreateRequest( id = "parameterGroupId2", description = "this_is_a_description2", labels = mutableMapOf("fr" to "this_is_a_label2"), additionalData = mutableMapOf("option2" to "value2", "option3" to 20.0), - parameters = mutableListOf("parameterId3", "parameterId4")))) + parameters = mutableListOf("parameterId3", "parameterId4"), + ), + ), + ) val newSolution = solutionApiService.createSolution(organizationSaved.id, newSolutionWithParameterGroups) val solutionParameterGroup = solutionApiService.getSolutionParameterGroup( - organizationSaved.id, newSolution.id, newSolution.parameterGroups[0].id) + organizationSaved.id, + newSolution.id, + newSolution.parameterGroups[0].id, + ) assertNotNull(solutionParameterGroup) assertEquals("parameterGroupId", solutionParameterGroup.id) @@ -1392,11 +1525,15 @@ class SolutionServiceIntegrationTest : CsmTestBase() { val exception = assertThrows { solutionApiService.getSolutionParameterGroup( - organizationSaved.id, solutionSaved.id, "non-existing-solution-parameter-group-id") + organizationSaved.id, + solutionSaved.id, + "non-existing-solution-parameter-group-id", + ) } assertEquals( "Solution parameter group with id non-existing-solution-parameter-group-id does not exist", - exception.message) + exception.message, + ) } @Test @@ -1411,13 +1548,17 @@ class SolutionServiceIntegrationTest : CsmTestBase() { description = "this_is_a_description", labels = mutableMapOf("fr" to "this_is_a_label"), additionalData = mutableMapOf("option1" to "value1", "option2" to 10.0), - parameters = mutableListOf("parameterId1", "parameterId2")), + parameters = mutableListOf("parameterId1", "parameterId2"), + ), RunTemplateParameterGroupCreateRequest( id = "parameterGroupId2", description = "this_is_a_description2", labels = mutableMapOf("fr" to "this_is_a_label2"), additionalData = mutableMapOf("option2" to "value2", "option3" to 20.0), - parameters = mutableListOf("parameterId3", "parameterId4")))) + parameters = mutableListOf("parameterId3", "parameterId4"), + ), + ), + ) val newSolution = solutionApiService.createSolution(organizationSaved.id, newSolutionWithParameterGroups) @@ -1432,7 +1573,9 @@ class SolutionServiceIntegrationTest : CsmTestBase() { description = "this_is_a_description3", labels = mutableMapOf("fr" to "this_is_a_label3"), additionalData = mutableMapOf("option3" to "value1"), - parameters = mutableListOf("parameterId13", "parameterId23"))) + parameters = mutableListOf("parameterId13", "parameterId23"), + ), + ) assertNotNull(solutionParameterGroup) assertEquals(parameterGroupId, solutionParameterGroup.id) assertEquals("this_is_a_description3", solutionParameterGroup.description) @@ -1450,11 +1593,13 @@ class SolutionServiceIntegrationTest : CsmTestBase() { organizationSaved.id, solutionSaved.id, "non-existing-solution-parameter-group-id", - RunTemplateParameterGroupUpdateRequest()) + RunTemplateParameterGroupUpdateRequest(), + ) } assertEquals( "Solution parameter group with id non-existing-solution-parameter-group-id does not exist", - exception.message) + exception.message, + ) } @Test @@ -1470,13 +1615,17 @@ class SolutionServiceIntegrationTest : CsmTestBase() { description = "this_is_a_description", labels = mutableMapOf("fr" to "this_is_a_label"), additionalData = mutableMapOf("option1" to "value1", "option2" to 10.0), - parameters = mutableListOf("parameterId1", "parameterId2")), + parameters = mutableListOf("parameterId1", "parameterId2"), + ), RunTemplateParameterGroupCreateRequest( id = "parameterGroupId2", description = "this_is_a_description2", labels = mutableMapOf("fr" to "this_is_a_label2"), additionalData = mutableMapOf("option2" to "value2", "option3" to 20.0), - parameters = mutableListOf("parameterId3", "parameterId4")))) + parameters = mutableListOf("parameterId3", "parameterId4"), + ), + ), + ) val newSolution = solutionApiService.createSolution(organizationSaved.id, newSolutionWithParameterGroups) @@ -1487,7 +1636,10 @@ class SolutionServiceIntegrationTest : CsmTestBase() { val parameterGroupIdToDelete = listSolutionParameterGroups[0].id val parameterGroupIdToKeep = listSolutionParameterGroups[1].id solutionApiService.deleteSolutionParameterGroup( - organizationSaved.id, newSolution.id, parameterGroupIdToDelete) + organizationSaved.id, + newSolution.id, + parameterGroupIdToDelete, + ) listSolutionParameterGroups = solutionApiService.listSolutionParameterGroups(organizationSaved.id, newSolution.id) @@ -1502,11 +1654,15 @@ class SolutionServiceIntegrationTest : CsmTestBase() { val exception = assertThrows { solutionApiService.deleteSolutionParameterGroup( - organizationSaved.id, solutionSaved.id, "non-existing-solution-parameter-group-id") + organizationSaved.id, + solutionSaved.id, + "non-existing-solution-parameter-group-id", + ) } assertEquals( "Solution parameter group with id non-existing-solution-parameter-group-id does not exist", - exception.message) + exception.message, + ) } @Test @@ -1516,11 +1672,13 @@ class SolutionServiceIntegrationTest : CsmTestBase() { solutionApiService.createSolutionParameterGroup( organizationSaved.id, "non-existing-solution-id", - RunTemplateParameterGroupCreateRequest(id = "my_parameter_group_name")) + RunTemplateParameterGroupCreateRequest(id = "my_parameter_group_name"), + ) } assertEquals( "Solution non-existing-solution-id not found in organization ${organizationSaved.id}", - exception.message) + exception.message, + ) } @Test @@ -1538,10 +1696,14 @@ class SolutionServiceIntegrationTest : CsmTestBase() { description = "this_is_a_description", labels = mutableMapOf("fr" to "this_is_a_label"), additionalData = mutableMapOf("option1" to "value1", "option2" to 10.0), - parameters = mutableListOf("parameterId1", "parameterId2")) + parameters = mutableListOf("parameterId1", "parameterId2"), + ) solutionApiService.createSolutionParameterGroup( - organizationSaved.id, newSolutionWithEmptyParameterGroups.id, parameterGroupCreateRequest) + organizationSaved.id, + newSolutionWithEmptyParameterGroups.id, + parameterGroupCreateRequest, + ) val newSolutionWithNewParameter = solutionApiService.getSolution(organizationSaved.id, newSolutionWithEmptyParameterGroups.id) @@ -1566,19 +1728,24 @@ class SolutionServiceIntegrationTest : CsmTestBase() { description = "this_is_a_description", labels = mutableMapOf("fr" to "this_is_a_label"), additionalData = mutableMapOf("option1" to "value1", "option2" to 10.0), - parameters = mutableListOf("parameterId1", "parameterId2")) + parameters = mutableListOf("parameterId1", "parameterId2"), + ) val newSolutionWithParameterGroup = solutionApiService.createSolution( organizationSaved.id, - makeSolution(parameterGroup = mutableListOf(parameterGroupCreateRequest))) + makeSolution(parameterGroup = mutableListOf(parameterGroupCreateRequest)), + ) assertEquals(1, newSolutionWithParameterGroup.parameterGroups.size) val exception = assertThrows { solutionApiService.createSolutionParameterGroup( - organizationSaved.id, newSolutionWithParameterGroup.id, parameterGroupCreateRequest) + organizationSaved.id, + newSolutionWithParameterGroup.id, + parameterGroupCreateRequest, + ) } assertEquals("Parameter Group with id 'parameterGroupId' already exists", exception.message) @@ -1597,18 +1764,24 @@ class SolutionServiceIntegrationTest : CsmTestBase() { description = "this_is_a_description", labels = mutableMapOf("fr" to "this_is_a_label"), additionalData = mutableMapOf("option1" to "value1", "option2" to 10.0), - parameters = mutableListOf("parameterId1", "parameterId2")), + parameters = mutableListOf("parameterId1", "parameterId2"), + ), RunTemplateParameterGroupCreateRequest( id = "pArAmEtErGrOuPId", description = "this_is_a_description2", labels = mutableMapOf("fr" to "this_is_a_label2"), additionalData = mutableMapOf("option2" to "value2", "option3" to 20.0), - parameters = mutableListOf("parameterId3", "parameterId4")))) + parameters = mutableListOf("parameterId3", "parameterId4"), + ), + ), + ) val exception = assertThrows { solutionApiService.createSolution( - organizationSaved.id, newSolutionWithParameterGroupsDuplicateIds) + organizationSaved.id, + newSolutionWithParameterGroupsDuplicateIds, + ) } assertEquals("One or several solution items have same id : parameterGroups", exception.message) @@ -1629,7 +1802,8 @@ class SolutionServiceIntegrationTest : CsmTestBase() { } assertEquals( "Solution non-existing-solution-id not found in organization ${organizationSaved.id}", - exception.message) + exception.message, + ) } @Test @@ -1653,7 +1827,8 @@ class SolutionServiceIntegrationTest : CsmTestBase() { limits = ResourceSizeInfo(cpu = "2Go", memory = "2Go"), ), parameterGroups = mutableListOf("parameterGroup1", "parameterGroup2"), - executionTimeout = 10), + executionTimeout = 10, + ), RunTemplateCreateRequest( id = "runTemplateId2", description = "this_is_a_description2", @@ -1667,7 +1842,10 @@ class SolutionServiceIntegrationTest : CsmTestBase() { limits = ResourceSizeInfo(cpu = "4Go", memory = "4Go"), ), parameterGroups = mutableListOf("parameterGroup3", "parameterGroup4"), - executionTimeout = 20))) + executionTimeout = 20, + ), + ), + ) val newSolution = solutionApiService.createSolution(organizationSaved.id, newSolutionWithRunTemplates) @@ -1682,7 +1860,9 @@ class SolutionServiceIntegrationTest : CsmTestBase() { assertEquals(mutableListOf("runTemplateTag1", "runTemplateTag2"), firstRunTemplate.tags) assertEquals("this_is_a_computeSize", firstRunTemplate.computeSize) assertEquals( - mutableListOf("parameterGroup1", "parameterGroup2"), firstRunTemplate.parameterGroups) + mutableListOf("parameterGroup1", "parameterGroup2"), + firstRunTemplate.parameterGroups, + ) assertEquals(10, firstRunTemplate.executionTimeout!!) assertEquals("1Go", firstRunTemplate.runSizing?.requests?.cpu) assertEquals("1Go", firstRunTemplate.runSizing?.requests?.memory) @@ -1696,7 +1876,9 @@ class SolutionServiceIntegrationTest : CsmTestBase() { assertEquals(mutableListOf("runTemplateTag3", "runTemplateTag4"), secondRunTemplate.tags) assertEquals("this_is_a_computeSize2", secondRunTemplate.computeSize) assertEquals( - mutableListOf("parameterGroup3", "parameterGroup4"), secondRunTemplate.parameterGroups) + mutableListOf("parameterGroup3", "parameterGroup4"), + secondRunTemplate.parameterGroups, + ) assertEquals(20, secondRunTemplate.executionTimeout!!) assertEquals("3Go", secondRunTemplate.runSizing?.requests?.cpu) assertEquals("3Go", secondRunTemplate.runSizing?.requests?.memory) @@ -1724,7 +1906,8 @@ class SolutionServiceIntegrationTest : CsmTestBase() { limits = ResourceSizeInfo(cpu = "2Go", memory = "2Go"), ), parameterGroups = mutableListOf("parameterGroup1", "parameterGroup2"), - executionTimeout = 10), + executionTimeout = 10, + ), RunTemplateCreateRequest( id = "runTemplateId2", description = "this_is_a_description2", @@ -1738,14 +1921,20 @@ class SolutionServiceIntegrationTest : CsmTestBase() { limits = ResourceSizeInfo(cpu = "4Go", memory = "4Go"), ), parameterGroups = mutableListOf("parameterGroup3", "parameterGroup4"), - executionTimeout = 20))) + executionTimeout = 20, + ), + ), + ) val newSolution = solutionApiService.createSolution(organizationSaved.id, newSolutionWithRunTemplates) val runTemplate = solutionApiService.getRunTemplate( - organizationSaved.id, newSolution.id, newSolution.runTemplates[0].id) + organizationSaved.id, + newSolution.id, + newSolution.runTemplates[0].id, + ) assertNotNull(runTemplate) assertEquals("runTemplateId", runTemplate.id) @@ -1767,11 +1956,15 @@ class SolutionServiceIntegrationTest : CsmTestBase() { val exception = assertThrows { solutionApiService.getRunTemplate( - organizationSaved.id, solutionSaved.id, "non-existing-solution-run-template-id") + organizationSaved.id, + solutionSaved.id, + "non-existing-solution-run-template-id", + ) } assertEquals( "Solution run template with id non-existing-solution-run-template-id does not exist", - exception.message) + exception.message, + ) } @Test @@ -1794,7 +1987,8 @@ class SolutionServiceIntegrationTest : CsmTestBase() { limits = ResourceSizeInfo(cpu = "2Go", memory = "2Go"), ), parameterGroups = mutableListOf("parameterGroup1", "parameterGroup2"), - executionTimeout = 10), + executionTimeout = 10, + ), RunTemplateCreateRequest( id = "runTemplateId2", description = "this_is_a_description2", @@ -1808,7 +2002,10 @@ class SolutionServiceIntegrationTest : CsmTestBase() { limits = ResourceSizeInfo(cpu = "4Go", memory = "4Go"), ), parameterGroups = mutableListOf("parameterGroup3", "parameterGroup4"), - executionTimeout = 20))) + executionTimeout = 20, + ), + ), + ) val newSolution = solutionApiService.createSolution(organizationSaved.id, newSolutionWithRunTemplates) @@ -1831,7 +2028,9 @@ class SolutionServiceIntegrationTest : CsmTestBase() { limits = ResourceSizeInfo(cpu = "1Go", memory = "1Go"), ), parameterGroups = mutableListOf("parameterGroup5"), - executionTimeout = 5)) + executionTimeout = 5, + ), + ) assertNotNull(runTemplate) assertEquals("runTemplateId", runTemplate.id) assertEquals("this_is_a_description3", runTemplate.description) @@ -1855,11 +2054,13 @@ class SolutionServiceIntegrationTest : CsmTestBase() { organizationSaved.id, solutionSaved.id, "non-existing-solution-run-template-id", - RunTemplateUpdateRequest()) + RunTemplateUpdateRequest(), + ) } assertEquals( "Solution run template with id non-existing-solution-run-template-id does not exist", - exception.message) + exception.message, + ) } @Test @@ -1883,7 +2084,8 @@ class SolutionServiceIntegrationTest : CsmTestBase() { limits = ResourceSizeInfo(cpu = "2Go", memory = "2Go"), ), parameterGroups = mutableListOf("parameterGroup1", "parameterGroup2"), - executionTimeout = 10), + executionTimeout = 10, + ), RunTemplateCreateRequest( id = "runTemplateId2", description = "this_is_a_description2", @@ -1897,7 +2099,10 @@ class SolutionServiceIntegrationTest : CsmTestBase() { limits = ResourceSizeInfo(cpu = "4Go", memory = "4Go"), ), parameterGroups = mutableListOf("parameterGroup3", "parameterGroup4"), - executionTimeout = 20))) + executionTimeout = 20, + ), + ), + ) val newSolution = solutionApiService.createSolution(organizationSaved.id, newSolutionWithRunTemplates) @@ -1907,7 +2112,10 @@ class SolutionServiceIntegrationTest : CsmTestBase() { val runTemplateIdToDelete = listRunTemplates[0].id val runTemplateIdToKeep = listRunTemplates[1].id solutionApiService.deleteSolutionRunTemplate( - organizationSaved.id, newSolution.id, runTemplateIdToDelete) + organizationSaved.id, + newSolution.id, + runTemplateIdToDelete, + ) listRunTemplates = solutionApiService.listRunTemplates(organizationSaved.id, newSolution.id) @@ -1921,11 +2129,15 @@ class SolutionServiceIntegrationTest : CsmTestBase() { val exception = assertThrows { solutionApiService.deleteSolutionRunTemplate( - organizationSaved.id, solutionSaved.id, "non-existing-solution-run-template-id") + organizationSaved.id, + solutionSaved.id, + "non-existing-solution-run-template-id", + ) } assertEquals( "Solution run template with id non-existing-solution-run-template-id does not exist", - exception.message) + exception.message, + ) } @Test @@ -1935,11 +2147,13 @@ class SolutionServiceIntegrationTest : CsmTestBase() { solutionApiService.createSolutionRunTemplate( organizationSaved.id, "non-existing-solution-id", - RunTemplateCreateRequest(id = "my_run_template_id")) + RunTemplateCreateRequest(id = "my_run_template_id"), + ) } assertEquals( "Solution non-existing-solution-id not found in organization ${organizationSaved.id}", - exception.message) + exception.message, + ) } @Test @@ -1965,10 +2179,14 @@ class SolutionServiceIntegrationTest : CsmTestBase() { limits = ResourceSizeInfo(cpu = "2Go", memory = "2Go"), ), parameterGroups = mutableListOf("parameterGroup1", "parameterGroup2"), - executionTimeout = 10) + executionTimeout = 10, + ) solutionApiService.createSolutionRunTemplate( - organizationSaved.id, newSolutionWithEmptyRunTemplates.id, runTemplateCreateRequest) + organizationSaved.id, + newSolutionWithEmptyRunTemplates.id, + runTemplateCreateRequest, + ) val newSolutionWithNewRunTemplate = solutionApiService.getSolution(organizationSaved.id, newSolutionWithEmptyRunTemplates.id) @@ -1983,7 +2201,9 @@ class SolutionServiceIntegrationTest : CsmTestBase() { assertEquals(mutableListOf("runTemplateTag1", "runTemplateTag2"), newRunTemplate.tags) assertEquals("this_is_a_computeSize", newRunTemplate.computeSize) assertEquals( - mutableListOf("parameterGroup1", "parameterGroup2"), newRunTemplate.parameterGroups) + mutableListOf("parameterGroup1", "parameterGroup2"), + newRunTemplate.parameterGroups, + ) assertEquals(10, newRunTemplate.executionTimeout!!) assertEquals("1Go", newRunTemplate.runSizing?.requests?.cpu) assertEquals("1Go", newRunTemplate.runSizing?.requests?.memory) @@ -2007,19 +2227,24 @@ class SolutionServiceIntegrationTest : CsmTestBase() { limits = ResourceSizeInfo(cpu = "2Go", memory = "2Go"), ), parameterGroups = mutableListOf("parameterGroup1", "parameterGroup2"), - executionTimeout = 10) + executionTimeout = 10, + ) val newSolutionWithRunTemplate = solutionApiService.createSolution( organizationSaved.id, - makeSolution(runTemplates = mutableListOf(runTemplateCreateRequest))) + makeSolution(runTemplates = mutableListOf(runTemplateCreateRequest)), + ) assertEquals(1, newSolutionWithRunTemplate.runTemplates.size) val exception = assertThrows { solutionApiService.createSolutionRunTemplate( - organizationSaved.id, newSolutionWithRunTemplate.id, runTemplateCreateRequest) + organizationSaved.id, + newSolutionWithRunTemplate.id, + runTemplateCreateRequest, + ) } assertEquals("Run template with id 'runTemplateId' already exists", exception.message) @@ -2046,7 +2271,8 @@ class SolutionServiceIntegrationTest : CsmTestBase() { limits = ResourceSizeInfo(cpu = "2Go", memory = "2Go"), ), parameterGroups = mutableListOf("parameterGroup1", "parameterGroup2"), - executionTimeout = 10), + executionTimeout = 10, + ), RunTemplateCreateRequest( id = "RuNtEmPlAtEId", description = "this_is_a_description2", @@ -2060,7 +2286,10 @@ class SolutionServiceIntegrationTest : CsmTestBase() { limits = ResourceSizeInfo(cpu = "4Go", memory = "4Go"), ), parameterGroups = mutableListOf("parameterGroup3", "parameterGroup4"), - executionTimeout = 20))) + executionTimeout = 20, + ), + ), + ) val exception = assertThrows { @@ -2079,7 +2308,10 @@ class SolutionServiceIntegrationTest : CsmTestBase() { val updateTime = Instant.now().toEpochMilli() val solutionUpdated = solutionApiService.updateSolution( - organizationSaved.id, solutionSaved.id, SolutionUpdateRequest("solutionUpdated")) + organizationSaved.id, + solutionSaved.id, + SolutionUpdateRequest("solutionUpdated"), + ) assertTrue { updateTime < solutionUpdated.updateInfo.timestamp } assertEquals(solutionSaved.createInfo, solutionUpdated.createInfo) @@ -2098,7 +2330,8 @@ class SolutionServiceIntegrationTest : CsmTestBase() { solutionApiService.createSolutionParameter( organizationSaved.id, solutionSaved.id, - RunTemplateParameterCreateRequest(id = "id", varType = "varType")) + RunTemplateParameterCreateRequest(id = "id", varType = "varType"), + ) val parameterAdded = solutionApiService.getSolution(organizationSaved.id, solutionSaved.id) assertEquals(solutionSaved.createInfo, parameterAdded.createInfo) @@ -2114,7 +2347,8 @@ class SolutionServiceIntegrationTest : CsmTestBase() { organizationSaved.id, solutionSaved.id, "id", - RunTemplateParameterUpdateRequest("description")) + RunTemplateParameterUpdateRequest("description"), + ) val parameterUpdated = solutionApiService.getSolution(organizationSaved.id, solutionSaved.id) assertEquals(parameterFetched.createInfo, parameterUpdated.createInfo) @@ -2131,7 +2365,10 @@ class SolutionServiceIntegrationTest : CsmTestBase() { fun `assert timestamps are functional for parameterGroups CRUD`() { solutionSaved = solutionApiService.createSolution(organizationSaved.id, makeSolution()) solutionApiService.createSolutionParameterGroup( - organizationSaved.id, solutionSaved.id, RunTemplateParameterGroupCreateRequest("id")) + organizationSaved.id, + solutionSaved.id, + RunTemplateParameterGroupCreateRequest("id"), + ) val parameterGroupAdded = solutionApiService.getSolution(organizationSaved.id, solutionSaved.id) assertEquals(solutionSaved.createInfo, parameterGroupAdded.createInfo) @@ -2148,7 +2385,8 @@ class SolutionServiceIntegrationTest : CsmTestBase() { organizationSaved.id, solutionSaved.id, "id", - RunTemplateParameterGroupUpdateRequest("description")) + RunTemplateParameterGroupUpdateRequest("description"), + ) val parameterGroupUpdated = solutionApiService.getSolution(organizationSaved.id, solutionSaved.id) @@ -2171,7 +2409,10 @@ class SolutionServiceIntegrationTest : CsmTestBase() { fun `assert timestamps are functional for runTemplates CRUD`() { solutionSaved = solutionApiService.createSolution(organizationSaved.id, makeSolution()) solutionApiService.createSolutionRunTemplate( - organizationSaved.id, solutionSaved.id, RunTemplateCreateRequest("id")) + organizationSaved.id, + solutionSaved.id, + RunTemplateCreateRequest("id"), + ) val runTemplatedAdded = solutionApiService.getSolution(organizationSaved.id, solutionSaved.id) assertEquals(solutionSaved.createInfo, runTemplatedAdded.createInfo) @@ -2184,7 +2425,11 @@ class SolutionServiceIntegrationTest : CsmTestBase() { assertEquals(runTemplatedAdded.updateInfo, runTemplateFetched.updateInfo) solutionApiService.updateSolutionRunTemplate( - organizationSaved.id, solutionSaved.id, "id", RunTemplateUpdateRequest("description")) + organizationSaved.id, + solutionSaved.id, + "id", + RunTemplateUpdateRequest("description"), + ) val runTemplateUpdated = solutionApiService.getSolution(organizationSaved.id, solutionSaved.id) assertEquals(runTemplateFetched.createInfo, runTemplateUpdated.createInfo) @@ -2201,7 +2446,10 @@ class SolutionServiceIntegrationTest : CsmTestBase() { fun `assert timestamps are functional for RBAC CRUD`() { solutionSaved = solutionApiService.createSolution(organizationSaved.id, makeSolution()) solutionApiService.createSolutionAccessControl( - organizationSaved.id, solutionSaved.id, SolutionAccessControl("newUser", ROLE_USER)) + organizationSaved.id, + solutionSaved.id, + SolutionAccessControl("newUser", ROLE_USER), + ) val rbacAdded = solutionApiService.getSolution(organizationSaved.id, solutionSaved.id) assertEquals(solutionSaved.createInfo, rbacAdded.createInfo) @@ -2214,14 +2462,21 @@ class SolutionServiceIntegrationTest : CsmTestBase() { assertEquals(rbacAdded.updateInfo, rbacFetched.updateInfo) solutionApiService.updateSolutionAccessControl( - organizationSaved.id, solutionSaved.id, "newUser", SolutionRole(ROLE_VIEWER)) + organizationSaved.id, + solutionSaved.id, + "newUser", + SolutionRole(ROLE_VIEWER), + ) val rbacUpdated = solutionApiService.getSolution(organizationSaved.id, solutionSaved.id) assertEquals(rbacFetched.createInfo, rbacUpdated.createInfo) assertTrue { rbacFetched.updateInfo.timestamp < rbacUpdated.updateInfo.timestamp } solutionApiService.deleteSolutionAccessControl( - organizationSaved.id, solutionSaved.id, "newUser") + organizationSaved.id, + solutionSaved.id, + "newUser", + ) val rbacDeleted = solutionApiService.getSolution(organizationSaved.id, solutionSaved.id) assertEquals(rbacUpdated.createInfo, rbacDeleted.createInfo) @@ -2237,7 +2492,10 @@ class SolutionServiceIntegrationTest : CsmTestBase() { accessControlList = mutableListOf( OrganizationAccessControl(id = CONNECTED_READER_USER, role = ROLE_VIEWER), - OrganizationAccessControl(id = CONNECTED_ADMIN_USER, role = ROLE_ADMIN)))) + OrganizationAccessControl(id = CONNECTED_ADMIN_USER, role = ROLE_ADMIN), + ), + ), + ) } fun makeSolution( @@ -2248,7 +2506,7 @@ class SolutionServiceIntegrationTest : CsmTestBase() { parameter: MutableList = mutableListOf(), parameterGroup: MutableList = mutableListOf(), userName: String = CONNECTED_READER_USER, - role: String = ROLE_VIEWER + role: String = ROLE_VIEWER, ) = SolutionCreateRequest( key = UUID.randomUUID().toString(), @@ -2264,5 +2522,8 @@ class SolutionServiceIntegrationTest : CsmTestBase() { accessControlList = mutableListOf( SolutionAccessControl(id = userName, role = role), - SolutionAccessControl(id = CONNECTED_ADMIN_USER, role = ROLE_ADMIN)))) + SolutionAccessControl(id = CONNECTED_ADMIN_USER, role = ROLE_ADMIN), + ), + ), + ) } diff --git a/solution/src/integrationTest/kotlin/com/cosmotech/solution/service/SolutionServiceRBACTest.kt b/solution/src/integrationTest/kotlin/com/cosmotech/solution/service/SolutionServiceRBACTest.kt index 4bc84925e..b575294ab 100644 --- a/solution/src/integrationTest/kotlin/com/cosmotech/solution/service/SolutionServiceRBACTest.kt +++ b/solution/src/integrationTest/kotlin/com/cosmotech/solution/service/SolutionServiceRBACTest.kt @@ -86,7 +86,10 @@ class SolutionServiceRBACTest : CsmTestBase() { fun setUp() { mockkStatic("com.cosmotech.common.utils.SecurityUtilsKt") ReflectionTestUtils.setField( - solutionApiService, "containerRegistryService", containerRegistryService) + solutionApiService, + "containerRegistryService", + containerRegistryService, + ) every { containerRegistryService.getImageLabel(any(), any(), any()) } returns null every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER every { getCurrentAccountGroups(any()) } returns listOf("myTestGroup") @@ -125,7 +128,8 @@ class SolutionServiceRBACTest : CsmTestBase() { } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.getSolution(organizationSaved.id, solutionSaved.id) @@ -162,7 +166,8 @@ class SolutionServiceRBACTest : CsmTestBase() { } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.getSolution(organizationSaved.id, solutionSaved.id) @@ -185,10 +190,12 @@ class SolutionServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role) + ) solutionApiService.createSolution( organizationSaved.id, - makeSolutionWithRole(id = TEST_USER_MAIL, role = ROLE_ADMIN)) + makeSolutionWithRole(id = TEST_USER_MAIL, role = ROLE_ADMIN), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL if (shouldThrow) { @@ -198,7 +205,8 @@ class SolutionServiceRBACTest : CsmTestBase() { } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.listSolutions(organizationSaved.id, null, null) @@ -234,7 +242,8 @@ class SolutionServiceRBACTest : CsmTestBase() { assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_CREATE_CHILDREN", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.createSolution(organizationSaved.id, solution) @@ -270,7 +279,8 @@ class SolutionServiceRBACTest : CsmTestBase() { } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.deleteSolution(organizationSaved.id, solutionSaved.id) @@ -308,7 +318,8 @@ class SolutionServiceRBACTest : CsmTestBase() { assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_DELETE", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.deleteSolution(organizationSaved.id, solutionSaved.id) @@ -345,15 +356,22 @@ class SolutionServiceRBACTest : CsmTestBase() { val exception = assertThrows { solutionApiService.updateSolution( - organizationSaved.id, solutionSaved.id, solutionUpdateRequest) + organizationSaved.id, + solutionSaved.id, + solutionUpdateRequest, + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.updateSolution( - organizationSaved.id, solutionSaved.id, solutionUpdateRequest) + organizationSaved.id, + solutionSaved.id, + solutionUpdateRequest, + ) } } } @@ -387,16 +405,23 @@ class SolutionServiceRBACTest : CsmTestBase() { val exception = assertThrows { solutionApiService.updateSolution( - organizationSaved.id, solutionSaved.id, solutionUpdateRequest) + organizationSaved.id, + solutionSaved.id, + solutionUpdateRequest, + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_WRITE", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.updateSolution( - organizationSaved.id, solutionSaved.id, solutionUpdateRequest) + organizationSaved.id, + solutionSaved.id, + solutionUpdateRequest, + ) } } } @@ -428,17 +453,20 @@ class SolutionServiceRBACTest : CsmTestBase() { solutionApiService.createSolutionAccessControl( organizationSaved.id, solutionSaved.id, - SolutionAccessControl("user", ROLE_USER)) + SolutionAccessControl("user", ROLE_USER), + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.createSolutionAccessControl( organizationSaved.id, solutionSaved.id, - SolutionAccessControl("user", ROLE_USER)) + SolutionAccessControl("user", ROLE_USER), + ) } } } @@ -470,18 +498,21 @@ class SolutionServiceRBACTest : CsmTestBase() { solutionApiService.createSolutionAccessControl( organizationSaved.id, solutionSaved.id, - SolutionAccessControl("user", ROLE_USER)) + SolutionAccessControl("user", ROLE_USER), + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_WRITE_SECURITY", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.createSolutionAccessControl( organizationSaved.id, solutionSaved.id, - SolutionAccessControl("user", ROLE_USER)) + SolutionAccessControl("user", ROLE_USER), + ) } } } @@ -511,15 +542,22 @@ class SolutionServiceRBACTest : CsmTestBase() { val exception = assertThrows { solutionApiService.getSolutionAccessControl( - organizationSaved.id, solutionSaved.id, TEST_USER_MAIL) + organizationSaved.id, + solutionSaved.id, + TEST_USER_MAIL, + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.getSolutionAccessControl( - organizationSaved.id, solutionSaved.id, TEST_USER_MAIL) + organizationSaved.id, + solutionSaved.id, + TEST_USER_MAIL, + ) } } } @@ -549,16 +587,23 @@ class SolutionServiceRBACTest : CsmTestBase() { val exception = assertThrows { solutionApiService.getSolutionAccessControl( - organizationSaved.id, solutionSaved.id, TEST_USER_MAIL) + organizationSaved.id, + solutionSaved.id, + TEST_USER_MAIL, + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_READ_SECURITY", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.getSolutionAccessControl( - organizationSaved.id, solutionSaved.id, TEST_USER_MAIL) + organizationSaved.id, + solutionSaved.id, + TEST_USER_MAIL, + ) } } } @@ -588,15 +633,20 @@ class SolutionServiceRBACTest : CsmTestBase() { val exception = assertThrows { solutionApiService.listSolutionSecurityUsers( - organizationSaved.id, solutionSaved.id) + organizationSaved.id, + solutionSaved.id, + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.listSolutionSecurityUsers( - organizationSaved.id, solutionSaved.id) + organizationSaved.id, + solutionSaved.id, + ) } } } @@ -626,16 +676,21 @@ class SolutionServiceRBACTest : CsmTestBase() { val exception = assertThrows { solutionApiService.listSolutionSecurityUsers( - organizationSaved.id, solutionSaved.id) + organizationSaved.id, + solutionSaved.id, + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_READ_SECURITY", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.listSolutionSecurityUsers( - organizationSaved.id, solutionSaved.id) + organizationSaved.id, + solutionSaved.id, + ) } } } @@ -665,15 +720,22 @@ class SolutionServiceRBACTest : CsmTestBase() { val exception = assertThrows { solutionApiService.deleteSolutionAccessControl( - organizationSaved.id, solutionSaved.id, TEST_USER_MAIL) + organizationSaved.id, + solutionSaved.id, + TEST_USER_MAIL, + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.deleteSolutionAccessControl( - organizationSaved.id, solutionSaved.id, TEST_USER_MAIL) + organizationSaved.id, + solutionSaved.id, + TEST_USER_MAIL, + ) } } } @@ -703,16 +765,23 @@ class SolutionServiceRBACTest : CsmTestBase() { val exception = assertThrows { solutionApiService.deleteSolutionAccessControl( - organizationSaved.id, solutionSaved.id, TEST_USER_MAIL) + organizationSaved.id, + solutionSaved.id, + TEST_USER_MAIL, + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_WRITE_SECURITY", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.deleteSolutionAccessControl( - organizationSaved.id, solutionSaved.id, TEST_USER_MAIL) + organizationSaved.id, + solutionSaved.id, + TEST_USER_MAIL, + ) } } } @@ -745,18 +814,21 @@ class SolutionServiceRBACTest : CsmTestBase() { organizationSaved.id, solutionSaved.id, TEST_USER_MAIL, - SolutionRole(ROLE_USER)) + SolutionRole(ROLE_USER), + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.updateSolutionAccessControl( organizationSaved.id, solutionSaved.id, TEST_USER_MAIL, - SolutionRole(ROLE_USER)) + SolutionRole(ROLE_USER), + ) } } } @@ -789,18 +861,21 @@ class SolutionServiceRBACTest : CsmTestBase() { organizationSaved.id, solutionSaved.id, TEST_USER_MAIL, - SolutionRole(ROLE_USER)) + SolutionRole(ROLE_USER), + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_WRITE_SECURITY", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.updateSolutionAccessControl( organizationSaved.id, solutionSaved.id, TEST_USER_MAIL, - SolutionRole(ROLE_USER)) + SolutionRole(ROLE_USER), + ) } } } @@ -830,15 +905,22 @@ class SolutionServiceRBACTest : CsmTestBase() { val exception = assertThrows { solutionApiService.deleteSolutionRunTemplate( - organizationSaved.id, solutionSaved.id, "runTemplate") + organizationSaved.id, + solutionSaved.id, + "runTemplate", + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.deleteSolutionRunTemplate( - organizationSaved.id, solutionSaved.id, "runTemplate") + organizationSaved.id, + solutionSaved.id, + "runTemplate", + ) } } } @@ -869,15 +951,22 @@ class SolutionServiceRBACTest : CsmTestBase() { val exception = assertThrows { solutionApiService.deleteSolutionRunTemplate( - organizationSaved.id, solutionSaved.id, "runTemplate") + organizationSaved.id, + solutionSaved.id, + "runTemplate", + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_WRITE", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.deleteSolutionRunTemplate( - organizationSaved.id, solutionSaved.id, "runTemplate") + organizationSaved.id, + solutionSaved.id, + "runTemplate", + ) } } } @@ -909,15 +998,24 @@ class SolutionServiceRBACTest : CsmTestBase() { val exception = assertThrows { solutionApiService.updateSolutionRunTemplate( - organizationSaved.id, solutionSaved.id, "runTemplate", runTemplate) + organizationSaved.id, + solutionSaved.id, + "runTemplate", + runTemplate, + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.updateSolutionRunTemplate( - organizationSaved.id, solutionSaved.id, "runTemplate", runTemplate) + organizationSaved.id, + solutionSaved.id, + "runTemplate", + runTemplate, + ) } } } @@ -950,15 +1048,24 @@ class SolutionServiceRBACTest : CsmTestBase() { val exception = assertThrows { solutionApiService.updateSolutionRunTemplate( - organizationSaved.id, solutionSaved.id, "runTemplate", runTemplate) + organizationSaved.id, + solutionSaved.id, + "runTemplate", + runTemplate, + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_WRITE", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.updateSolutionRunTemplate( - organizationSaved.id, solutionSaved.id, "runTemplate", runTemplate) + organizationSaved.id, + solutionSaved.id, + "runTemplate", + runTemplate, + ) } } } @@ -992,7 +1099,8 @@ class SolutionServiceRBACTest : CsmTestBase() { } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.getSolutionSecurity(organizationSaved.id, solutionSaved.id) @@ -1030,7 +1138,8 @@ class SolutionServiceRBACTest : CsmTestBase() { assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_READ_SECURITY", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.getSolutionSecurity(organizationSaved.id, solutionSaved.id) @@ -1050,33 +1159,41 @@ class SolutionServiceRBACTest : CsmTestBase() { ) .map { (role, shouldThrow) -> DynamicTest.dynamicTest( - "Test Organization RBAC updateSolutionDefaultSecurity : $role") { - every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER - - val organization = makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role) - organizationSaved = organizationApiService.createOrganization(organization) - val solution = - makeSolutionWithRole(organizationSaved.id, TEST_USER_MAIL, role = ROLE_ADMIN) - solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) - - every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL - - if (shouldThrow) { - val exception = - assertThrows { - solutionApiService.updateSolutionDefaultSecurity( - organizationSaved.id, solutionSaved.id, SolutionRole(ROLE_VIEWER)) - } - assertEquals( - "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) - } else { - assertDoesNotThrow { + "Test Organization RBAC updateSolutionDefaultSecurity : $role" + ) { + every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER + + val organization = makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role) + organizationSaved = organizationApiService.createOrganization(organization) + val solution = + makeSolutionWithRole(organizationSaved.id, TEST_USER_MAIL, role = ROLE_ADMIN) + solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) + + every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL + + if (shouldThrow) { + val exception = + assertThrows { solutionApiService.updateSolutionDefaultSecurity( - organizationSaved.id, solutionSaved.id, SolutionRole(ROLE_VIEWER)) + organizationSaved.id, + solutionSaved.id, + SolutionRole(ROLE_VIEWER), + ) } - } + assertEquals( + "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", + exception.message, + ) + } else { + assertDoesNotThrow { + solutionApiService.updateSolutionDefaultSecurity( + organizationSaved.id, + solutionSaved.id, + SolutionRole(ROLE_VIEWER), + ) } + } + } } @TestFactory @@ -1104,16 +1221,23 @@ class SolutionServiceRBACTest : CsmTestBase() { val exception = assertThrows { solutionApiService.updateSolutionDefaultSecurity( - organizationSaved.id, solutionSaved.id, SolutionRole(ROLE_VIEWER)) + organizationSaved.id, + solutionSaved.id, + SolutionRole(ROLE_VIEWER), + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_WRITE_SECURITY", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.updateSolutionDefaultSecurity( - organizationSaved.id, solutionSaved.id, SolutionRole(ROLE_VIEWER)) + organizationSaved.id, + solutionSaved.id, + SolutionRole(ROLE_VIEWER), + ) } } } @@ -1144,11 +1268,14 @@ class SolutionServiceRBACTest : CsmTestBase() { val exception = assertThrows { solutionApiService.listSolutionParameters( - organizationSaved.id, solutionSaved.id) + organizationSaved.id, + solutionSaved.id, + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.listSolutionParameters(organizationSaved.id, solutionSaved.id) @@ -1182,15 +1309,22 @@ class SolutionServiceRBACTest : CsmTestBase() { val exception = assertThrows { solutionApiService.getSolutionParameter( - organizationSaved.id, solutionSaved.id, "parameter") + organizationSaved.id, + solutionSaved.id, + "parameter", + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.getSolutionParameter( - organizationSaved.id, solutionSaved.id, "parameter") + organizationSaved.id, + solutionSaved.id, + "parameter", + ) } } } @@ -1224,15 +1358,22 @@ class SolutionServiceRBACTest : CsmTestBase() { val exception = assertThrows { solutionApiService.createSolutionParameter( - organizationSaved.id, solutionSaved.id, parameterToCreate) + organizationSaved.id, + solutionSaved.id, + parameterToCreate, + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_WRITE", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.createSolutionParameter( - organizationSaved.id, solutionSaved.id, parameterToCreate) + organizationSaved.id, + solutionSaved.id, + parameterToCreate, + ) } } } @@ -1265,15 +1406,24 @@ class SolutionServiceRBACTest : CsmTestBase() { val exception = assertThrows { solutionApiService.updateSolutionParameter( - organizationSaved.id, solutionSaved.id, "parameter", parameterToUpdate) + organizationSaved.id, + solutionSaved.id, + "parameter", + parameterToUpdate, + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_WRITE", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.updateSolutionParameter( - organizationSaved.id, solutionSaved.id, "parameter", parameterToUpdate) + organizationSaved.id, + solutionSaved.id, + "parameter", + parameterToUpdate, + ) } } } @@ -1304,15 +1454,22 @@ class SolutionServiceRBACTest : CsmTestBase() { val exception = assertThrows { solutionApiService.deleteSolutionParameter( - organizationSaved.id, solutionSaved.id, "parameter") + organizationSaved.id, + solutionSaved.id, + "parameter", + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_WRITE", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.deleteSolutionParameter( - organizationSaved.id, solutionSaved.id, "parameter") + organizationSaved.id, + solutionSaved.id, + "parameter", + ) } } } @@ -1343,15 +1500,20 @@ class SolutionServiceRBACTest : CsmTestBase() { val exception = assertThrows { solutionApiService.listSolutionParameterGroups( - organizationSaved.id, solutionSaved.id) + organizationSaved.id, + solutionSaved.id, + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.listSolutionParameterGroups( - organizationSaved.id, solutionSaved.id) + organizationSaved.id, + solutionSaved.id, + ) } } } @@ -1382,15 +1544,22 @@ class SolutionServiceRBACTest : CsmTestBase() { val exception = assertThrows { solutionApiService.getSolutionParameterGroup( - organizationSaved.id, solutionSaved.id, "group") + organizationSaved.id, + solutionSaved.id, + "group", + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.getSolutionParameterGroup( - organizationSaved.id, solutionSaved.id, "group") + organizationSaved.id, + solutionSaved.id, + "group", + ) } } } @@ -1423,15 +1592,22 @@ class SolutionServiceRBACTest : CsmTestBase() { val exception = assertThrows { solutionApiService.createSolutionParameterGroup( - organizationSaved.id, solutionSaved.id, parameterGroupToCreate) + organizationSaved.id, + solutionSaved.id, + parameterGroupToCreate, + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_WRITE", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.createSolutionParameterGroup( - organizationSaved.id, solutionSaved.id, parameterGroupToCreate) + organizationSaved.id, + solutionSaved.id, + parameterGroupToCreate, + ) } } } @@ -1465,15 +1641,24 @@ class SolutionServiceRBACTest : CsmTestBase() { val exception = assertThrows { solutionApiService.updateSolutionParameterGroup( - organizationSaved.id, solutionSaved.id, "group", parameterGroupToUpdate) + organizationSaved.id, + solutionSaved.id, + "group", + parameterGroupToUpdate, + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_WRITE", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.updateSolutionParameterGroup( - organizationSaved.id, solutionSaved.id, "group", parameterGroupToUpdate) + organizationSaved.id, + solutionSaved.id, + "group", + parameterGroupToUpdate, + ) } } } @@ -1504,15 +1689,22 @@ class SolutionServiceRBACTest : CsmTestBase() { val exception = assertThrows { solutionApiService.deleteSolutionParameterGroup( - organizationSaved.id, solutionSaved.id, "group") + organizationSaved.id, + solutionSaved.id, + "group", + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_WRITE", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.deleteSolutionParameterGroup( - organizationSaved.id, solutionSaved.id, "group") + organizationSaved.id, + solutionSaved.id, + "group", + ) } } } @@ -1546,7 +1738,8 @@ class SolutionServiceRBACTest : CsmTestBase() { } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.listRunTemplates(organizationSaved.id, solutionSaved.id) @@ -1580,15 +1773,22 @@ class SolutionServiceRBACTest : CsmTestBase() { val exception = assertThrows { solutionApiService.getRunTemplate( - organizationSaved.id, solutionSaved.id, "runTemplate") + organizationSaved.id, + solutionSaved.id, + "runTemplate", + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.getRunTemplate( - organizationSaved.id, solutionSaved.id, "runTemplate") + organizationSaved.id, + solutionSaved.id, + "runTemplate", + ) } } } @@ -1621,15 +1821,22 @@ class SolutionServiceRBACTest : CsmTestBase() { val exception = assertThrows { solutionApiService.createSolutionRunTemplate( - organizationSaved.id, solutionSaved.id, runTemplateToCreate) + organizationSaved.id, + solutionSaved.id, + runTemplateToCreate, + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_WRITE", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.createSolutionRunTemplate( - organizationSaved.id, solutionSaved.id, runTemplateToCreate) + organizationSaved.id, + solutionSaved.id, + runTemplateToCreate, + ) } } } @@ -1665,15 +1872,21 @@ class SolutionServiceRBACTest : CsmTestBase() { organizationSaved.id, solutionSaved.id, "runTemplate", - runTemplateToUpdate) + runTemplateToUpdate, + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_WRITE", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.updateSolutionRunTemplate( - organizationSaved.id, solutionSaved.id, "runTemplate", runTemplateToUpdate) + organizationSaved.id, + solutionSaved.id, + "runTemplate", + runTemplateToUpdate, + ) } } } @@ -1704,15 +1917,22 @@ class SolutionServiceRBACTest : CsmTestBase() { val exception = assertThrows { solutionApiService.deleteSolutionRunTemplate( - organizationSaved.id, solutionSaved.id, "runTemplate") + organizationSaved.id, + solutionSaved.id, + "runTemplate", + ) } assertEquals( "RBAC ${solutionSaved.id} - User does not have permission $PERMISSION_WRITE", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { solutionApiService.deleteSolutionRunTemplate( - organizationSaved.id, solutionSaved.id, "runTemplate") + organizationSaved.id, + solutionSaved.id, + "runTemplate", + ) } } } @@ -1720,7 +1940,7 @@ class SolutionServiceRBACTest : CsmTestBase() { fun makeOrganizationCreateRequest( id: String = TEST_USER_MAIL, - role: String = ROLE_ADMIN + role: String = ROLE_ADMIN, ): OrganizationCreateRequest { return OrganizationCreateRequest( name = "Organization Name", @@ -1730,13 +1950,16 @@ class SolutionServiceRBACTest : CsmTestBase() { accessControlList = mutableListOf( OrganizationAccessControl(id = CONNECTED_ADMIN_USER, role = ROLE_ADMIN), - OrganizationAccessControl(id = id, role = role)))) + OrganizationAccessControl(id = id, role = role), + ), + ), + ) } fun makeSolutionWithRole( organizationId: String = organizationSaved.id, id: String, - role: String + role: String, ) = SolutionCreateRequest( key = UUID.randomUUID().toString(), @@ -1747,12 +1970,16 @@ class SolutionServiceRBACTest : CsmTestBase() { parameterGroups = mutableListOf(RunTemplateParameterGroupCreateRequest(id = "group")), parameters = mutableListOf( - RunTemplateParameterCreateRequest(id = "parameter", varType = "string")), + RunTemplateParameterCreateRequest(id = "parameter", varType = "string") + ), security = SolutionSecurity( default = ROLE_NONE, accessControlList = mutableListOf( SolutionAccessControl(id = CONNECTED_ADMIN_USER, role = ROLE_ADMIN), - SolutionAccessControl(id = id, role = role)))) + SolutionAccessControl(id = id, role = role), + ), + ), + ) } diff --git a/solution/src/main/kotlin/com/cosmotech/solution/SolutionApiServiceInterface.kt b/solution/src/main/kotlin/com/cosmotech/solution/SolutionApiServiceInterface.kt index 77ed20e46..df5174340 100644 --- a/solution/src/main/kotlin/com/cosmotech/solution/SolutionApiServiceInterface.kt +++ b/solution/src/main/kotlin/com/cosmotech/solution/SolutionApiServiceInterface.kt @@ -11,13 +11,13 @@ interface SolutionApiServiceInterface : SolutionApiService { fun getVerifiedSolution( organizationId: String, solutionId: String, - requiredPermission: String = PERMISSION_READ + requiredPermission: String = PERMISSION_READ, ): Solution fun isRunTemplateExist( organizationId: String, workspaceId: String, solutionId: String, - runTemplateId: String + runTemplateId: String, ): Boolean } diff --git a/solution/src/main/kotlin/com/cosmotech/solution/repository/SolutionRepository.kt b/solution/src/main/kotlin/com/cosmotech/solution/repository/SolutionRepository.kt index 80abb2492..b127c5eea 100644 --- a/solution/src/main/kotlin/com/cosmotech/solution/repository/SolutionRepository.kt +++ b/solution/src/main/kotlin/com/cosmotech/solution/repository/SolutionRepository.kt @@ -17,19 +17,19 @@ interface SolutionRepository : RedisDocumentRepository { @Query("@organizationId:{\$organizationId} @id:{\$solutionId}") fun findBy( @Sanitize @Param("organizationId") organizationId: String, - @Sanitize @Param("solutionId") solutionId: String + @Sanitize @Param("solutionId") solutionId: String, ): Optional @Query("(@organizationId:{\$organizationId}) \$securityConstraint") fun findByOrganizationIdAndSecurity( @Sanitize @Param("organizationId") organizationId: String, @SecurityConstraint @Param("securityConstraint") securityConstraint: String, - pageable: Pageable + pageable: Pageable, ): Page @Query("@organizationId:{\$organizationId}") fun findByOrganizationId( @Sanitize @Param("organizationId") organizationId: String, - pageable: Pageable + pageable: Pageable, ): Page } diff --git a/solution/src/main/kotlin/com/cosmotech/solution/service/SolutionServiceImpl.kt b/solution/src/main/kotlin/com/cosmotech/solution/service/SolutionServiceImpl.kt index 13dcb4a7c..7699053f9 100644 --- a/solution/src/main/kotlin/com/cosmotech/solution/service/SolutionServiceImpl.kt +++ b/solution/src/main/kotlin/com/cosmotech/solution/service/SolutionServiceImpl.kt @@ -55,7 +55,7 @@ class SolutionServiceImpl( private val organizationApiService: OrganizationApiServiceInterface, private val csmRbac: CsmRbac, private val csmAdmin: CsmAdmin, - private val containerRegistryService: ContainerRegistryService + private val containerRegistryService: ContainerRegistryService, ) : CsmPhoenixService(), SolutionApiServiceInterface { override fun listSolutions(organizationId: String, page: Int?, size: Int?): List { @@ -102,7 +102,7 @@ class SolutionServiceImpl( organizationId: String, workspaceId: String, solutionId: String, - runTemplateId: String + runTemplateId: String, ): Boolean { val solution = getSolution(organizationId, solutionId) @@ -111,7 +111,7 @@ class SolutionServiceImpl( override fun createSolution( organizationId: String, - solutionCreateRequest: SolutionCreateRequest + solutionCreateRequest: SolutionCreateRequest, ): Solution { organizationApiService.getVerifiedOrganization(organizationId, PERMISSION_CREATE_CHILDREN) @@ -125,7 +125,8 @@ class SolutionServiceImpl( checkParametersAndRunTemplateUnicity( solutionCreateRequest.parameters, solutionCreateRequest.parameterGroups, - solutionCreateRequest.runTemplates) + solutionCreateRequest.runTemplates, + ) val solutionRunTemplateParameters = solutionCreateRequest.parameters?.map { convertToRunTemplateParameter(it) }?.toMutableList() @@ -147,10 +148,14 @@ class SolutionServiceImpl( name = solutionCreateRequest.name, createInfo = SolutionEditInfo( - timestamp = now, userId = getCurrentAccountIdentifier(csmPlatformProperties)), + timestamp = now, + userId = getCurrentAccountIdentifier(csmPlatformProperties), + ), updateInfo = SolutionEditInfo( - timestamp = now, userId = getCurrentAccountIdentifier(csmPlatformProperties)), + timestamp = now, + userId = getCurrentAccountIdentifier(csmPlatformProperties), + ), description = solutionCreateRequest.description, repository = solutionCreateRequest.repository, version = solutionCreateRequest.version, @@ -161,7 +166,8 @@ class SolutionServiceImpl( parameterGroups = solutionRunTemplateParameterGroups, url = solutionCreateRequest.url, alwaysPull = solutionCreateRequest.alwaysPull, - security = security) + security = security, + ) return fillSdkVersion(solutionRepository.save(createdSolution)) } @@ -179,7 +185,7 @@ class SolutionServiceImpl( override fun createSolutionRunTemplate( organizationId: String, solutionId: String, - runTemplateCreateRequest: RunTemplateCreateRequest + runTemplateCreateRequest: RunTemplateCreateRequest, ): RunTemplate { val existingSolution = getVerifiedSolution(organizationId, solutionId, PERMISSION_WRITE) val runTemplateIdAlreadyExist = @@ -201,13 +207,14 @@ class SolutionServiceImpl( override fun getRunTemplate( organizationId: String, solutionId: String, - runTemplateId: String + runTemplateId: String, ): RunTemplate { val solution = getVerifiedSolution(organizationId, solutionId) val solutionRunTemplate = solution.runTemplates.firstOrNull { it.id == runTemplateId } ?: throw CsmResourceNotFoundException( - "Solution run template with id $runTemplateId does not exist") + "Solution run template with id $runTemplateId does not exist" + ) return solutionRunTemplate } @@ -215,7 +222,7 @@ class SolutionServiceImpl( organizationId: String, solutionId: String, runTemplateId: String, - runTemplateUpdateRequest: RunTemplateUpdateRequest + runTemplateUpdateRequest: RunTemplateUpdateRequest, ): RunTemplate { val existingSolution = getVerifiedSolution(organizationId, solutionId, PERMISSION_WRITE) existingSolution.runTemplates @@ -231,7 +238,8 @@ class SolutionServiceImpl( executionTimeout = runTemplateUpdateRequest.executionTimeout ?: this.executionTimeout } ?: throw CsmResourceNotFoundException( - "Solution run template with id $runTemplateId does not exist") + "Solution run template with id $runTemplateId does not exist" + ) val solutionSaved = save(existingSolution) @@ -241,13 +249,14 @@ class SolutionServiceImpl( override fun deleteSolutionRunTemplate( organizationId: String, solutionId: String, - runTemplateId: String + runTemplateId: String, ) { val existingSolution = getVerifiedSolution(organizationId, solutionId, PERMISSION_WRITE) if (!existingSolution.runTemplates.removeIf { it.id == runTemplateId }) { throw CsmResourceNotFoundException( - "Solution run template with id $runTemplateId does not exist") + "Solution run template with id $runTemplateId does not exist" + ) } save(existingSolution) } @@ -255,14 +264,15 @@ class SolutionServiceImpl( override fun updateSolution( organizationId: String, solutionId: String, - solutionUpdateRequest: SolutionUpdateRequest + solutionUpdateRequest: SolutionUpdateRequest, ): Solution { val existingSolution = getVerifiedSolution(organizationId, solutionId, PERMISSION_WRITE) checkParametersAndRunTemplateUnicity( solutionUpdateRequest.parameters, solutionUpdateRequest.parameterGroups, - solutionUpdateRequest.runTemplates) + solutionUpdateRequest.runTemplates, + ) val solutionRunTemplateParameters = solutionUpdateRequest.parameters?.map { convertToRunTemplateParameter(it) }?.toMutableList() @@ -294,7 +304,8 @@ class SolutionServiceImpl( parameters = solutionRunTemplateParameters, parameterGroups = solutionRunTemplateParameterGroups, runTemplates = solutionRunTemplates, - security = existingSolution.security) + security = existingSolution.security, + ) val hasChanged = existingSolution @@ -324,7 +335,7 @@ class SolutionServiceImpl( override fun listSolutionParameters( organizationId: String, - solutionId: String + solutionId: String, ): List { val solution = getVerifiedSolution(organizationId, solutionId) return solution.parameters @@ -333,7 +344,7 @@ class SolutionServiceImpl( override fun updateSolutionDefaultSecurity( organizationId: String, solutionId: String, - solutionRole: SolutionRole + solutionRole: SolutionRole, ): SolutionSecurity { val solution = getVerifiedSolution(organizationId, solutionId, PERMISSION_WRITE_SECURITY) val rbacSecurity = @@ -346,7 +357,7 @@ class SolutionServiceImpl( override fun createSolutionAccessControl( organizationId: String, solutionId: String, - solutionAccessControl: SolutionAccessControl + solutionAccessControl: SolutionAccessControl, ): SolutionAccessControl { val organization = organizationApiService.getVerifiedOrganization(organizationId) val solution = getVerifiedSolution(organizationId, solutionId, PERMISSION_WRITE_SECURITY) @@ -361,18 +372,21 @@ class SolutionServiceImpl( organization.security.toGenericSecurity(organizationId), solution.security.toGenericSecurity(solutionId), solutionAccessControl.id, - solutionAccessControl.role) + solutionAccessControl.role, + ) solution.security = rbacSecurity.toResourceSecurity() save(solution) val rbacAccessControl = csmRbac.getAccessControl( - solution.security.toGenericSecurity(solutionId), solutionAccessControl.id) + solution.security.toGenericSecurity(solutionId), + solutionAccessControl.id, + ) return SolutionAccessControl(rbacAccessControl.id, rbacAccessControl.role) } override fun listSolutionParameterGroups( organizationId: String, - solutionId: String + solutionId: String, ): List { val solution = getVerifiedSolution(organizationId, solutionId) return solution.parameterGroups @@ -381,7 +395,7 @@ class SolutionServiceImpl( override fun createSolutionParameterGroup( organizationId: String, solutionId: String, - runTemplateParameterGroupCreateRequest: RunTemplateParameterGroupCreateRequest + runTemplateParameterGroupCreateRequest: RunTemplateParameterGroupCreateRequest, ): RunTemplateParameterGroup { val existingSolution = getVerifiedSolution(organizationId, solutionId, PERMISSION_WRITE) val parameterIdAlreadyExist = @@ -404,13 +418,14 @@ class SolutionServiceImpl( override fun getSolutionParameterGroup( organizationId: String, solutionId: String, - parameterGroupId: String + parameterGroupId: String, ): RunTemplateParameterGroup { val solution = getVerifiedSolution(organizationId, solutionId) val solutionParameterGroup = solution.parameterGroups.firstOrNull { it.id == parameterGroupId } ?: throw CsmResourceNotFoundException( - "Solution parameter group with id $parameterGroupId does not exist") + "Solution parameter group with id $parameterGroupId does not exist" + ) return solutionParameterGroup } @@ -418,7 +433,7 @@ class SolutionServiceImpl( organizationId: String, solutionId: String, parameterGroupId: String, - runTemplateParameterGroupUpdateRequest: RunTemplateParameterGroupUpdateRequest + runTemplateParameterGroupUpdateRequest: RunTemplateParameterGroupUpdateRequest, ): RunTemplateParameterGroup { val existingSolution = getVerifiedSolution(organizationId, solutionId, PERMISSION_WRITE) @@ -432,7 +447,8 @@ class SolutionServiceImpl( parameters = runTemplateParameterGroupUpdateRequest.parameters ?: this.parameters } ?: throw CsmResourceNotFoundException( - "Solution parameter group with id $parameterGroupId does not exist") + "Solution parameter group with id $parameterGroupId does not exist" + ) val solutionSaved = save(existingSolution) @@ -442,13 +458,14 @@ class SolutionServiceImpl( override fun deleteSolutionParameterGroup( organizationId: String, solutionId: String, - parameterGroupId: String + parameterGroupId: String, ) { val solution = getVerifiedSolution(organizationId, solutionId, PERMISSION_WRITE) val solutionParameterGroup = solution.parameterGroups.firstOrNull { it.id == parameterGroupId } ?: throw CsmResourceNotFoundException( - "Solution parameter group with id $parameterGroupId does not exist") + "Solution parameter group with id $parameterGroupId does not exist" + ) solution.parameterGroups.remove(solutionParameterGroup) save(solution) } @@ -456,7 +473,7 @@ class SolutionServiceImpl( override fun getSolutionAccessControl( organizationId: String, solutionId: String, - identityId: String + identityId: String, ): SolutionAccessControl { val solution = getVerifiedSolution(organizationId, solutionId, PERMISSION_READ_SECURITY) val rbacAccessControl = @@ -467,7 +484,7 @@ class SolutionServiceImpl( override fun createSolutionParameter( organizationId: String, solutionId: String, - runTemplateParameterCreateRequest: RunTemplateParameterCreateRequest + runTemplateParameterCreateRequest: RunTemplateParameterCreateRequest, ): RunTemplateParameter { val existingSolution = getVerifiedSolution(organizationId, solutionId, PERMISSION_WRITE) @@ -493,7 +510,7 @@ class SolutionServiceImpl( organizationId: String, solutionId: String, parameterId: String, - runTemplateParameterUpdateRequest: RunTemplateParameterUpdateRequest + runTemplateParameterUpdateRequest: RunTemplateParameterUpdateRequest, ): RunTemplateParameter { val existingSolution = getVerifiedSolution(organizationId, solutionId, PERMISSION_WRITE) @@ -509,7 +526,8 @@ class SolutionServiceImpl( additionalData = runTemplateParameterUpdateRequest.additionalData ?: this.additionalData } ?: throw CsmResourceNotFoundException( - "Solution parameter with id $parameterId does not exist") + "Solution parameter with id $parameterId does not exist" + ) val solutionSaved = save(existingSolution) @@ -519,26 +537,28 @@ class SolutionServiceImpl( override fun getSolutionParameter( organizationId: String, solutionId: String, - parameterId: String + parameterId: String, ): RunTemplateParameter { val solution = getVerifiedSolution(organizationId, solutionId) val solutionParameter = solution.parameters.firstOrNull { it.id == parameterId } ?: throw CsmResourceNotFoundException( - "Solution parameter with id $parameterId does not exist") + "Solution parameter with id $parameterId does not exist" + ) return solutionParameter } override fun deleteSolutionParameter( organizationId: String, solutionId: String, - parameterId: String + parameterId: String, ) { val solution = getVerifiedSolution(organizationId, solutionId, PERMISSION_WRITE) val solutionParameter = solution.parameters.firstOrNull { it.id == parameterId } ?: throw CsmResourceNotFoundException( - "Solution parameter with id $parameterId does not exist") + "Solution parameter with id $parameterId does not exist" + ) solution.parameters.remove(solutionParameter) save(solution) @@ -548,16 +568,20 @@ class SolutionServiceImpl( organizationId: String, solutionId: String, identityId: String, - solutionRole: SolutionRole + solutionRole: SolutionRole, ): SolutionAccessControl { val solution = getVerifiedSolution(organizationId, solutionId, PERMISSION_WRITE_SECURITY) csmRbac.checkEntityExists( solution.security.toGenericSecurity(solutionId), identityId, - "User '$identityId' not found in solution $solutionId") + "User '$identityId' not found in solution $solutionId", + ) val rbacSecurity = csmRbac.setEntityRole( - solution.security.toGenericSecurity(solutionId), identityId, solutionRole.role) + solution.security.toGenericSecurity(solutionId), + identityId, + solutionRole.role, + ) solution.security = rbacSecurity.toResourceSecurity() save(solution) val rbacAccessControl = @@ -568,7 +592,7 @@ class SolutionServiceImpl( override fun deleteSolutionAccessControl( organizationId: String, solutionId: String, - identityId: String + identityId: String, ) { val solution = getVerifiedSolution(organizationId, solutionId, PERMISSION_WRITE_SECURITY) val rbacSecurity = @@ -585,22 +609,25 @@ class SolutionServiceImpl( override fun getVerifiedSolution( organizationId: String, solutionId: String, - requiredPermission: String + requiredPermission: String, ): Solution { organizationApiService.getVerifiedOrganization(organizationId) val solution = solutionRepository.findBy(organizationId, solutionId).orElseThrow { CsmResourceNotFoundException( - "Solution $solutionId not found in organization $organizationId") + "Solution $solutionId not found in organization $organizationId" + ) } csmRbac.verify(solution.security.toGenericSecurity(solutionId), requiredPermission) return solution } fun updateSecurityVisibility(solution: Solution): Solution { - if (csmRbac - .check(solution.security.toGenericSecurity(solution.id), PERMISSION_READ_SECURITY) - .not()) { + if ( + csmRbac + .check(solution.security.toGenericSecurity(solution.id), PERMISSION_READ_SECURITY) + .not() + ) { val username = getCurrentAccountIdentifier(csmPlatformProperties) val retrievedAC = solution.security.accessControlList.firstOrNull { it.id == username } @@ -614,7 +641,10 @@ class SolutionServiceImpl( return solution.copy( security = SolutionSecurity( - default = solution.security.default, accessControlList = accessControlList)) + default = solution.security.default, + accessControlList = accessControlList, + ) + ) } return solution } @@ -623,7 +653,11 @@ class SolutionServiceImpl( solution.copy( sdkVersion = containerRegistryService.getImageLabel( - solution.repository, solution.version, "com.cosmotech.sdk-version")) + solution.repository, + solution.version, + "com.cosmotech.sdk-version", + ) + ) fun convertToRunTemplateParameter( runTemplateParameterCreateRequest: RunTemplateParameterCreateRequest @@ -636,7 +670,8 @@ class SolutionServiceImpl( defaultValue = runTemplateParameterCreateRequest.defaultValue, minValue = runTemplateParameterCreateRequest.minValue, maxValue = runTemplateParameterCreateRequest.maxValue, - additionalData = runTemplateParameterCreateRequest.additionalData) + additionalData = runTemplateParameterCreateRequest.additionalData, + ) } fun convertToRunTemplateParameterGroup( @@ -647,7 +682,8 @@ class SolutionServiceImpl( description = runTemplateParameterGroupCreateRequest.description, labels = runTemplateParameterGroupCreateRequest.labels, additionalData = runTemplateParameterGroupCreateRequest.additionalData, - parameters = runTemplateParameterGroupCreateRequest.parameters!!) + parameters = runTemplateParameterGroupCreateRequest.parameters!!, + ) } fun convertToRunTemplate(runTemplateCreateRequest: RunTemplateCreateRequest): RunTemplate { @@ -660,31 +696,38 @@ class SolutionServiceImpl( tags = runTemplateCreateRequest.tags, computeSize = runTemplateCreateRequest.computeSize, runSizing = runTemplateCreateRequest.runSizing, - executionTimeout = runTemplateCreateRequest.executionTimeout) + executionTimeout = runTemplateCreateRequest.executionTimeout, + ) } private fun checkParametersAndRunTemplateUnicity( parameters: MutableList?, parameterGroups: MutableList?, - runTemplates: MutableList? + runTemplates: MutableList?, ) { val duplicatedFieldIds = mutableListOf() - if (parameters?.groupBy { it.id.lowercase() }?.filterValues { it.size > 1 }?.isNotEmpty() == - true) { + if ( + parameters?.groupBy { it.id.lowercase() }?.filterValues { it.size > 1 }?.isNotEmpty() == + true + ) { duplicatedFieldIds.add("parameters") } - if (parameterGroups - ?.groupBy { it.id.lowercase() } - ?.filterValues { it.size > 1 } - ?.isNotEmpty() == true) { + if ( + parameterGroups + ?.groupBy { it.id.lowercase() } + ?.filterValues { it.size > 1 } + ?.isNotEmpty() == true + ) { duplicatedFieldIds.add("parameterGroups") } - if (runTemplates?.groupBy { it.id.lowercase() }?.filterValues { it.size > 1 }?.isNotEmpty() == - true) { + if ( + runTemplates?.groupBy { it.id.lowercase() }?.filterValues { it.size > 1 }?.isNotEmpty() == + true + ) { duplicatedFieldIds.add("runTemplates") } @@ -697,7 +740,8 @@ class SolutionServiceImpl( solution.updateInfo = SolutionEditInfo( timestamp = Instant.now().toEpochMilli(), - userId = getCurrentAccountIdentifier(csmPlatformProperties)) + userId = getCurrentAccountIdentifier(csmPlatformProperties), + ) return solutionRepository.save(solution) } @@ -708,9 +752,11 @@ fun SolutionSecurity?.toGenericSecurity(solutionId: String) = solutionId, this?.default ?: ROLE_NONE, this?.accessControlList?.map { RbacAccessControl(it.id, it.role) }?.toMutableList() - ?: mutableListOf()) + ?: mutableListOf(), + ) fun RbacSecurity.toResourceSecurity() = SolutionSecurity( this.default, - this.accessControlList.map { SolutionAccessControl(it.id, it.role) }.toMutableList()) + this.accessControlList.map { SolutionAccessControl(it.id, it.role) }.toMutableList(), + ) diff --git a/workspace/src/integrationTest/kotlin/com/cosmotech/workspace/service/WorkspaceServiceIntegrationTest.kt b/workspace/src/integrationTest/kotlin/com/cosmotech/workspace/service/WorkspaceServiceIntegrationTest.kt index 77c55da89..e434cee9c 100644 --- a/workspace/src/integrationTest/kotlin/com/cosmotech/workspace/service/WorkspaceServiceIntegrationTest.kt +++ b/workspace/src/integrationTest/kotlin/com/cosmotech/workspace/service/WorkspaceServiceIntegrationTest.kt @@ -109,7 +109,11 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { dataset = makeDatasetCreateRequest() datasetSaved = datasetApiService.createDataset( - organizationSaved.id, workspaceSaved.id, dataset, emptyArray()) + organizationSaved.id, + workspaceSaved.id, + dataset, + emptyArray(), + ) } @Test @@ -134,7 +138,8 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { workspaceApiService.updateWorkspace( organizationSaved.id, workspaceSaved.id, - WorkspaceUpdateRequest(key = "key", name = "Workspace 1 updated")) + WorkspaceUpdateRequest(key = "key", name = "Workspace 1 updated"), + ) assertEquals("Workspace 1 updated", updatedWorkspace.name) assertEquals(workspaceSaved.organizationId, updatedWorkspace.organizationId) } @@ -146,13 +151,22 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { val input = FileInputStream(resourceTestFile) val multipartFile = MockMultipartFile( - "file", resourceTestFile.getName(), "text/plain", IOUtils.toByteArray(input)) + "file", + resourceTestFile.getName(), + "text/plain", + IOUtils.toByteArray(input), + ) every { getCurrentAuthenticatedRoles(any()) } returns listOf("Platform.Admin") logger.info("should create a workspace file") val savedFile = workspaceApiService.createWorkspaceFile( - organizationSaved.id, workspaceSaved.id, multipartFile, true, null) + organizationSaved.id, + workspaceSaved.id, + multipartFile, + true, + null, + ) assertEquals(fileName, savedFile.fileName) } @@ -165,9 +179,18 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { val expectedFile = FileInputStream(resourceTestFile) val multipartFile = MockMultipartFile( - "file", resourceTestFile.getName(), "text/plain", IOUtils.toByteArray(input)) + "file", + resourceTestFile.getName(), + "text/plain", + IOUtils.toByteArray(input), + ) workspaceApiService.createWorkspaceFile( - organizationSaved.id, workspaceSaved.id, multipartFile, true, null) + organizationSaved.id, + workspaceSaved.id, + multipartFile, + true, + null, + ) val fetchedFile = workspaceApiService.getWorkspaceFile(organizationSaved.id, workspaceSaved.id, fileName) @@ -182,9 +205,18 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { val input = FileInputStream(resourceTestFile) val multipartFile = MockMultipartFile( - "file", resourceTestFile.getName(), "text/plain", IOUtils.toByteArray(input)) + "file", + resourceTestFile.getName(), + "text/plain", + IOUtils.toByteArray(input), + ) workspaceApiService.createWorkspaceFile( - organizationSaved.id, workspaceSaved.id, multipartFile, true, null) + organizationSaved.id, + workspaceSaved.id, + multipartFile, + true, + null, + ) val exception = assertThrows { @@ -203,14 +235,23 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { val input = FileInputStream(resourceTestFile) val multipartFile = MockMultipartFile( - "file", resourceTestFile.getName(), "text/plain", IOUtils.toByteArray(input)) + "file", + resourceTestFile.getName(), + "text/plain", + IOUtils.toByteArray(input), + ) var workspaceFiles = workspaceApiService.listWorkspaceFiles(organizationSaved.id, workspaceSaved.id) assertTrue(workspaceFiles.isEmpty()) workspaceApiService.createWorkspaceFile( - organizationSaved.id, workspaceSaved.id, multipartFile, true, null) + organizationSaved.id, + workspaceSaved.id, + multipartFile, + true, + null, + ) workspaceFiles = workspaceApiService.listWorkspaceFiles(organizationSaved.id, workspaceSaved.id) assertEquals(1, workspaceFiles.size) @@ -226,7 +267,12 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { MockMultipartFile("file", originalFilename, "text/plain", IOUtils.toByteArray(input)) workspaceApiService.createWorkspaceFile( - organizationSaved.id, workspaceSaved.id, multipartFile, true, null) + organizationSaved.id, + workspaceSaved.id, + multipartFile, + true, + null, + ) workspaceApiService.deleteWorkspaceFile(organizationSaved.id, workspaceSaved.id, fileName) @@ -245,12 +291,26 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { val input = FileInputStream(resourceTestFile) val multipartFile = MockMultipartFile( - "file", resourceTestFile.getName(), "text/plain", IOUtils.toByteArray(input)) + "file", + resourceTestFile.getName(), + "text/plain", + IOUtils.toByteArray(input), + ) workspaceApiService.createWorkspaceFile( - organizationSaved.id, workspaceSaved.id, multipartFile, true, null) + organizationSaved.id, + workspaceSaved.id, + multipartFile, + true, + null, + ) workspaceApiService.createWorkspaceFile( - organizationSaved.id, workspaceSaved.id, multipartFile, true, null) + organizationSaved.id, + workspaceSaved.id, + multipartFile, + true, + null, + ) workspaceApiService.deleteWorkspaceFiles(organizationSaved.id, workspaceSaved.id) @@ -293,7 +353,8 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { workspaceApiService.updateWorkspace( organizationSaved.id, workspaceSaved.id, - WorkspaceUpdateRequest(key = "key", name = "Workspace 1 updated")) + WorkspaceUpdateRequest(key = "key", name = "Workspace 1 updated"), + ) } logger.info("should not delete a workspace") @@ -359,7 +420,10 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { val workspaceRole = WorkspaceRole(ROLE_VIEWER) val workspaceSecurityRegistered = workspaceApiService.updateWorkspaceDefaultSecurity( - organizationSaved.id, workspaceSaved.id, workspaceRole) + organizationSaved.id, + workspaceSaved.id, + workspaceRole, + ) assertEquals(workspaceRole.role, workspaceSecurityRegistered.default) } @@ -377,19 +441,29 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { val workspaceAccessControl = WorkspaceAccessControl(TEST_USER_MAIL, ROLE_VIEWER) var workspaceAccessControlRegistered = workspaceApiService.createWorkspaceAccessControl( - organizationSaved.id, workspaceSaved.id, workspaceAccessControl) + organizationSaved.id, + workspaceSaved.id, + workspaceAccessControl, + ) assertEquals(workspaceAccessControl, workspaceAccessControlRegistered) logger.info("should get the access control") workspaceAccessControlRegistered = workspaceApiService.getWorkspaceAccessControl( - organizationSaved.id, workspaceSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + TEST_USER_MAIL, + ) assertEquals(workspaceAccessControl, workspaceAccessControlRegistered) logger.info("should update the access control") workspaceAccessControlRegistered = workspaceApiService.updateWorkspaceAccessControl( - organizationSaved.id, workspaceSaved.id, TEST_USER_MAIL, WorkspaceRole(ROLE_EDITOR)) + organizationSaved.id, + workspaceSaved.id, + TEST_USER_MAIL, + WorkspaceRole(ROLE_EDITOR), + ) assertEquals(ROLE_EDITOR, workspaceAccessControlRegistered.role) logger.info("should get the list of users and assert there are 3") @@ -399,11 +473,17 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { logger.info("should remove the access control") workspaceApiService.deleteWorkspaceAccessControl( - organizationSaved.id, workspaceSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + TEST_USER_MAIL, + ) assertThrows { workspaceAccessControlRegistered = workspaceApiService.getWorkspaceAccessControl( - organizationSaved.id, workspaceSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + TEST_USER_MAIL, + ) } } @@ -416,19 +496,29 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { val workspaceAccessControl = WorkspaceAccessControl(TEST_USER_MAIL, ROLE_VIEWER) assertThrows { workspaceApiService.createWorkspaceAccessControl( - organizationSaved.id, workspaceSaved.id, workspaceAccessControl) + organizationSaved.id, + workspaceSaved.id, + workspaceAccessControl, + ) } logger.info("should throw CsmAccessForbiddenException when getting the access control") assertThrows { workspaceApiService.getWorkspaceAccessControl( - organizationSaved.id, workspaceSaved.id, "userLambda") + organizationSaved.id, + workspaceSaved.id, + "userLambda", + ) } logger.info("should throw CsmAccessForbiddenException when updating the access control") assertThrows { workspaceApiService.updateWorkspaceAccessControl( - organizationSaved.id, workspaceSaved.id, TEST_USER_MAIL, WorkspaceRole(ROLE_VIEWER)) + organizationSaved.id, + workspaceSaved.id, + TEST_USER_MAIL, + WorkspaceRole(ROLE_VIEWER), + ) } logger.info("should throw CsmAccessForbiddenException when getting the list of users") @@ -439,7 +529,10 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { logger.info("should throw CsmAccessForbiddenException when removing the access control") assertThrows { workspaceApiService.deleteWorkspaceAccessControl( - organizationSaved.id, workspaceSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + TEST_USER_MAIL, + ) } } @@ -459,7 +552,10 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { accessControlList = mutableListOf( WorkspaceAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), - WorkspaceAccessControl(CONNECTED_ADMIN_USER, ROLE_EDITOR)))) + WorkspaceAccessControl(CONNECTED_ADMIN_USER, ROLE_EDITOR), + ), + ), + ) assertThrows { workspaceApiService.createWorkspace(organizationSaved.id, brokenWorkspace) } @@ -477,7 +573,8 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { workspaceApiService.createWorkspaceAccessControl( organizationSaved.id, workspaceSaved.id, - WorkspaceAccessControl(CONNECTED_ADMIN_USER, ROLE_EDITOR)) + WorkspaceAccessControl(CONNECTED_ADMIN_USER, ROLE_EDITOR), + ) } } @@ -486,7 +583,10 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_DEFAULT_USER organization = makeOrganizationCreateRequest( - name = "Organization test", userName = CONNECTED_DEFAULT_USER, role = ROLE_VIEWER) + name = "Organization test", + userName = CONNECTED_DEFAULT_USER, + role = ROLE_VIEWER, + ) organizationSaved = organizationApiService.createOrganization(organization) solution = makeSolution(userName = CONNECTED_DEFAULT_USER, role = ROLE_VIEWER) solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) @@ -499,8 +599,10 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { assertEquals( WorkspaceSecurity( default = ROLE_NONE, - mutableListOf(WorkspaceAccessControl(CONNECTED_DEFAULT_USER, ROLE_VIEWER))), - workspaceRetrieved.security) + mutableListOf(WorkspaceAccessControl(CONNECTED_DEFAULT_USER, ROLE_VIEWER)), + ), + workspaceRetrieved.security, + ) assertEquals(1, workspaceRetrieved.security.accessControlList.size) } @@ -509,7 +611,10 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_DEFAULT_USER organization = makeOrganizationCreateRequest( - name = "Organization test", userName = CONNECTED_DEFAULT_USER, role = ROLE_VIEWER) + name = "Organization test", + userName = CONNECTED_DEFAULT_USER, + role = ROLE_VIEWER, + ) organizationSaved = organizationApiService.createOrganization(organization) solution = makeSolution(userName = CONNECTED_DEFAULT_USER, role = ROLE_VIEWER) solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) @@ -522,8 +627,10 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { assertEquals( WorkspaceSecurity( default = ROLE_NONE, - mutableListOf(WorkspaceAccessControl(CONNECTED_DEFAULT_USER, ROLE_VIEWER))), - it.security) + mutableListOf(WorkspaceAccessControl(CONNECTED_DEFAULT_USER, ROLE_VIEWER)), + ), + it.security, + ) assertEquals(1, it.security.accessControlList.size) } } @@ -547,7 +654,8 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { security = WorkspaceSecurity( default = ROLE_NONE, - accessControlList = mutableListOf(WorkspaceAccessControl("id", ROLE_ADMIN))), + accessControlList = mutableListOf(WorkspaceAccessControl("id", ROLE_ADMIN)), + ), ) val workspaceCreateRequest = WorkspaceCreateRequest( @@ -559,7 +667,8 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { tags = workspaceToCreate.tags, additionalData = workspaceToCreate.additionalData, datasetCopy = workspaceToCreate.datasetCopy, - security = workspaceToCreate.security) + security = workspaceToCreate.security, + ) workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspaceCreateRequest) @@ -589,7 +698,8 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { security = WorkspaceSecurity( default = ROLE_ADMIN, - accessControlList = mutableListOf(WorkspaceAccessControl("id", ROLE_ADMIN))), + accessControlList = mutableListOf(WorkspaceAccessControl("id", ROLE_ADMIN)), + ), ) val workspaceCreateRequest = WorkspaceCreateRequest( @@ -601,7 +711,8 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { tags = workspaceToCreate.tags, additionalData = workspaceToCreate.additionalData, datasetCopy = workspaceToCreate.datasetCopy, - security = workspaceToCreate.security) + security = workspaceToCreate.security, + ) workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, workspaceCreateRequest) solutionSaved = solutionApiService.createSolution(organizationSaved.id, solution) @@ -624,11 +735,15 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { description = workspaceUpdateRequest.description, tags = workspaceUpdateRequest.tags, additionalData = workspaceUpdateRequest.additionalData, - datasetCopy = workspaceUpdateRequest.datasetCopy) + datasetCopy = workspaceUpdateRequest.datasetCopy, + ) workspaceSaved = workspaceApiService.updateWorkspace( - organizationSaved.id, workspaceSaved.id, workspaceUpdateRequest) + organizationSaved.id, + workspaceSaved.id, + workspaceUpdateRequest, + ) workspaceToCreate.createInfo = workspaceSaved.createInfo workspaceToCreate.updateInfo = workspaceSaved.updateInfo @@ -642,7 +757,10 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { workspaceSaved = workspaceApiService.updateWorkspace( - organizationSaved.id, workspaceSaved.id, WorkspaceUpdateRequest(key = "new_key")) + organizationSaved.id, + workspaceSaved.id, + WorkspaceUpdateRequest(key = "new_key"), + ) assertEquals("new_key", workspaceSaved.key) assertEquals(workspace.name, workspaceSaved.name) assertEquals(workspace.solution, workspaceSaved.solution) @@ -656,7 +774,8 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { WorkspaceCreateRequest( key = "minimal-key", name = "Minimal Workspace", - solution = WorkspaceSolution(solutionSaved.id)) + solution = WorkspaceSolution(solutionSaved.id), + ) val createdWorkspace = workspaceApiService.createWorkspace(organizationSaved.id, minimalRequest) assertEquals("minimal-key", createdWorkspace.key) assertEquals("Minimal Workspace", createdWorkspace.name) @@ -669,7 +788,8 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { workspaceApiService.updateWorkspace( organizationSaved.id, createdWorkspace.id, - WorkspaceUpdateRequest(key = "updated-key", name = "Updated Workspace")) + WorkspaceUpdateRequest(key = "updated-key", name = "Updated Workspace"), + ) assertEquals("updated-key", updatedWorkspace.key) assertEquals("Updated Workspace", updatedWorkspace.name) assertEquals(createdWorkspace.solution, updatedWorkspace.solution) @@ -694,7 +814,8 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { assertEquals( "Workspace ${workspaceSaved.id} not found in organization ${anotherOrganizationSaved.id}", - exception.message) + exception.message, + ) } @Test @@ -707,7 +828,10 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { val updateTime = Instant.now().toEpochMilli() val workspaceUpdated = workspaceApiService.updateWorkspace( - organizationSaved.id, workspaceSaved.id, WorkspaceUpdateRequest("workspaceUpdated")) + organizationSaved.id, + workspaceSaved.id, + WorkspaceUpdateRequest("workspaceUpdated"), + ) assertTrue { updateTime < workspaceUpdated.updateInfo.timestamp } assertEquals(workspaceSaved.createInfo, workspaceUpdated.createInfo) @@ -725,28 +849,41 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { workspaceSaved = workspaceApiService.createWorkspace(organizationSaved.id, makeWorkspaceCreateRequest()) workspaceApiService.createWorkspaceAccessControl( - organizationSaved.id, workspaceSaved.id, WorkspaceAccessControl("newUser", ROLE_USER)) + organizationSaved.id, + workspaceSaved.id, + WorkspaceAccessControl("newUser", ROLE_USER), + ) val rbacAdded = workspaceApiService.getWorkspace(organizationSaved.id, workspaceSaved.id) assertEquals(workspaceSaved.createInfo, rbacAdded.createInfo) assertTrue { workspaceSaved.updateInfo.timestamp < rbacAdded.updateInfo.timestamp } workspaceApiService.getWorkspaceAccessControl( - organizationSaved.id, workspaceSaved.id, "newUser") + organizationSaved.id, + workspaceSaved.id, + "newUser", + ) val rbacFetched = workspaceApiService.getWorkspace(organizationSaved.id, workspaceSaved.id) assertEquals(rbacAdded.createInfo, rbacFetched.createInfo) assertEquals(rbacAdded.updateInfo, rbacFetched.updateInfo) workspaceApiService.updateWorkspaceAccessControl( - organizationSaved.id, workspaceSaved.id, "newUser", WorkspaceRole(ROLE_VIEWER)) + organizationSaved.id, + workspaceSaved.id, + "newUser", + WorkspaceRole(ROLE_VIEWER), + ) val rbacUpdated = workspaceApiService.getWorkspace(organizationSaved.id, workspaceSaved.id) assertEquals(rbacFetched.createInfo, rbacUpdated.createInfo) assertTrue { rbacFetched.updateInfo.timestamp < rbacUpdated.updateInfo.timestamp } workspaceApiService.deleteWorkspaceAccessControl( - organizationSaved.id, workspaceSaved.id, "newUser") + organizationSaved.id, + workspaceSaved.id, + "newUser", + ) val rbacDeleted = workspaceApiService.getWorkspace(organizationSaved.id, workspaceSaved.id) assertEquals(rbacUpdated.createInfo, rbacDeleted.createInfo) @@ -758,7 +895,7 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { fun makeOrganizationCreateRequest( name: String = "Organization Name", userName: String = CONNECTED_ADMIN_USER, - role: String = ROLE_ADMIN + role: String = ROLE_ADMIN, ) = OrganizationCreateRequest( name = name, @@ -768,7 +905,10 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { accessControlList = mutableListOf( OrganizationAccessControl(id = userName, role = role), - OrganizationAccessControl("userLambda", "viewer")))) + OrganizationAccessControl("userLambda", "viewer"), + ), + ), + ) fun makeSolution(userName: String = CONNECTED_DEFAULT_USER, role: String = ROLE_USER) = SolutionCreateRequest( @@ -785,13 +925,16 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { accessControlList = mutableListOf( SolutionAccessControl(id = CONNECTED_ADMIN_USER, role = ROLE_ADMIN), - SolutionAccessControl(id = userName, role = role)))) + SolutionAccessControl(id = userName, role = role), + ), + ), + ) fun makeWorkspaceCreateRequest( solutionId: String = solutionSaved.id, name: String = "name", userName: String = CONNECTED_DEFAULT_USER, - role: String = ROLE_VIEWER + role: String = ROLE_VIEWER, ) = WorkspaceCreateRequest( key = UUID.randomUUID().toString(), @@ -806,7 +949,10 @@ class WorkspaceServiceIntegrationTest : CsmTestBase() { accessControlList = mutableListOf( WorkspaceAccessControl(id = userName, role = role), - WorkspaceAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN)))) + WorkspaceAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), + ), + ), + ) fun makeDataset( name: String = "my_dataset_test", diff --git a/workspace/src/integrationTest/kotlin/com/cosmotech/workspace/service/WorkspaceServiceRBACTest.kt b/workspace/src/integrationTest/kotlin/com/cosmotech/workspace/service/WorkspaceServiceRBACTest.kt index 313e7e569..f178e7435 100644 --- a/workspace/src/integrationTest/kotlin/com/cosmotech/workspace/service/WorkspaceServiceRBACTest.kt +++ b/workspace/src/integrationTest/kotlin/com/cosmotech/workspace/service/WorkspaceServiceRBACTest.kt @@ -92,7 +92,10 @@ class WorkspaceServiceRBACTest : CsmTestBase() { fun beforeEach() { mockkStatic("com.cosmotech.common.utils.SecurityUtilsKt") ReflectionTestUtils.setField( - solutionApiService, "containerRegistryService", containerRegistryService) + solutionApiService, + "containerRegistryService", + containerRegistryService, + ) ReflectionTestUtils.setField(workspaceApiService, "s3Client", s3Client) ReflectionTestUtils.setField(workspaceApiService, "s3Template", s3Template) every { containerRegistryService.getImageLabel(any(), any(), any()) } returns null @@ -122,17 +125,22 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) workspaceApiService.createWorkspace( organizationSaved.id, makeWorkspaceCreateRequest( organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, - role = ROLE_ADMIN)) + role = ROLE_ADMIN, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL if (shouldThrow) { @@ -142,7 +150,8 @@ class WorkspaceServiceRBACTest : CsmTestBase() { } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { workspaceApiService.listWorkspaces(organizationSaved.id, null, null) @@ -165,17 +174,22 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) workspaceApiService.createWorkspace( organizationSaved.id, makeWorkspaceCreateRequest( organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, - role = ROLE_ADMIN)) + role = ROLE_ADMIN, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL if (shouldThrow) { @@ -187,16 +201,20 @@ class WorkspaceServiceRBACTest : CsmTestBase() { organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, - role = ROLE_ADMIN)) + role = ROLE_ADMIN, + ), + ) } if (role == ROLE_NONE) { assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_CREATE_CHILDREN", - exception.message) + exception.message, + ) } } else { assertDoesNotThrow { @@ -206,7 +224,9 @@ class WorkspaceServiceRBACTest : CsmTestBase() { organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, - role = ROLE_ADMIN)) + role = ROLE_ADMIN, + ), + ) } } } @@ -226,10 +246,13 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) val workspaceSaved = workspaceApiService.createWorkspace( organizationSaved.id, @@ -237,7 +260,9 @@ class WorkspaceServiceRBACTest : CsmTestBase() { organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, - role = ROLE_ADMIN)) + role = ROLE_ADMIN, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL if (shouldThrow) { @@ -248,11 +273,13 @@ class WorkspaceServiceRBACTest : CsmTestBase() { if (role == ROLE_NONE) { assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } } else { assertDoesNotThrow { @@ -276,15 +303,23 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = ROLE_ADMIN)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = ROLE_ADMIN) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) val workspaceSaved = workspaceApiService.createWorkspace( organizationSaved.id, makeWorkspaceCreateRequest( - organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, role = role)) + organizationSaved.id, + solutionSaved.id, + id = TEST_USER_MAIL, + role = role, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL if (shouldThrow) { @@ -294,7 +329,8 @@ class WorkspaceServiceRBACTest : CsmTestBase() { } assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { workspaceApiService.getWorkspace(organizationSaved.id, workspaceSaved.id) @@ -317,10 +353,13 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) val workspaceSaved = workspaceApiService.createWorkspace( organizationSaved.id, @@ -328,7 +367,9 @@ class WorkspaceServiceRBACTest : CsmTestBase() { organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, - role = ROLE_ADMIN)) + role = ROLE_ADMIN, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL if (shouldThrow) { @@ -338,7 +379,8 @@ class WorkspaceServiceRBACTest : CsmTestBase() { } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { workspaceApiService.deleteWorkspace(organizationSaved.id, workspaceSaved.id) @@ -361,15 +403,23 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = ROLE_ADMIN)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = ROLE_ADMIN) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) val workspaceSaved = workspaceApiService.createWorkspace( organizationSaved.id, makeWorkspaceCreateRequest( - organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, role = role)) + organizationSaved.id, + solutionSaved.id, + id = TEST_USER_MAIL, + role = role, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL if (shouldThrow) { @@ -379,7 +429,8 @@ class WorkspaceServiceRBACTest : CsmTestBase() { } assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_DELETE", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { workspaceApiService.deleteWorkspace(organizationSaved.id, workspaceSaved.id) @@ -402,10 +453,13 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) val workspaceSaved = workspaceApiService.createWorkspace( organizationSaved.id, @@ -413,7 +467,9 @@ class WorkspaceServiceRBACTest : CsmTestBase() { organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, - role = ROLE_ADMIN)) + role = ROLE_ADMIN, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL if (shouldThrow) { @@ -422,17 +478,20 @@ class WorkspaceServiceRBACTest : CsmTestBase() { workspaceApiService.updateWorkspace( organizationSaved.id, workspaceSaved.id, - WorkspaceUpdateRequest(key = "key", "new name")) + WorkspaceUpdateRequest(key = "key", "new name"), + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { workspaceApiService.updateWorkspace( organizationSaved.id, workspaceSaved.id, - WorkspaceUpdateRequest("key", "new name")) + WorkspaceUpdateRequest("key", "new name"), + ) } } } @@ -452,15 +511,23 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = ROLE_ADMIN)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = ROLE_ADMIN) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) val workspaceSaved = workspaceApiService.createWorkspace( organizationSaved.id, makeWorkspaceCreateRequest( - organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, role = role)) + organizationSaved.id, + solutionSaved.id, + id = TEST_USER_MAIL, + role = role, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL if (shouldThrow) { @@ -469,17 +536,20 @@ class WorkspaceServiceRBACTest : CsmTestBase() { workspaceApiService.updateWorkspace( organizationSaved.id, workspaceSaved.id, - WorkspaceUpdateRequest("key", "new name")) + WorkspaceUpdateRequest("key", "new name"), + ) } assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_WRITE", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { workspaceApiService.updateWorkspace( organizationSaved.id, workspaceSaved.id, - WorkspaceUpdateRequest("key", "new name")) + WorkspaceUpdateRequest("key", "new name"), + ) } } } @@ -499,10 +569,13 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) val workspaceSaved = workspaceApiService.createWorkspace( organizationSaved.id, @@ -510,18 +583,23 @@ class WorkspaceServiceRBACTest : CsmTestBase() { organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, - role = ROLE_ADMIN)) + role = ROLE_ADMIN, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL if (shouldThrow) { val exception = assertThrows { workspaceApiService.listWorkspaceFiles( - organizationSaved.id, workspaceSaved.id) + organizationSaved.id, + workspaceSaved.id, + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { workspaceApiService.listWorkspaceFiles(organizationSaved.id, workspaceSaved.id) @@ -544,26 +622,37 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = ROLE_ADMIN)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = ROLE_ADMIN) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) val workspaceSaved = workspaceApiService.createWorkspace( organizationSaved.id, makeWorkspaceCreateRequest( - organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, role = role)) + organizationSaved.id, + solutionSaved.id, + id = TEST_USER_MAIL, + role = role, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL if (shouldThrow) { val exception = assertThrows { workspaceApiService.listWorkspaceFiles( - organizationSaved.id, workspaceSaved.id) + organizationSaved.id, + workspaceSaved.id, + ) } assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { workspaceApiService.listWorkspaceFiles(organizationSaved.id, workspaceSaved.id) @@ -586,10 +675,13 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) val workspaceSaved = workspaceApiService.createWorkspace( organizationSaved.id, @@ -597,28 +689,44 @@ class WorkspaceServiceRBACTest : CsmTestBase() { organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, - role = ROLE_ADMIN)) + role = ROLE_ADMIN, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL ReflectionTestUtils.setField(workspaceApiService, "resourceScanner", resourceScanner) every { resource.originalFilename } returns "fakeName" every { resourceScanner.scanMimeTypes( - "fakeName", any(), csmPlatformProperties.upload.authorizedMimeTypes.workspaces) + "fakeName", + any(), + csmPlatformProperties.upload.authorizedMimeTypes.workspaces, + ) } returns Unit if (shouldThrow) { val exception = assertThrows { workspaceApiService.createWorkspaceFile( - organizationSaved.id, workspaceSaved.id, resource, true, "") + organizationSaved.id, + workspaceSaved.id, + resource, + true, + "", + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { workspaceApiService.createWorkspaceFile( - organizationSaved.id, workspaceSaved.id, resource, true, "name") + organizationSaved.id, + workspaceSaved.id, + resource, + true, + "name", + ) } } } @@ -638,36 +746,58 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = ROLE_ADMIN)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = ROLE_ADMIN) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) val workspaceSaved = workspaceApiService.createWorkspace( organizationSaved.id, makeWorkspaceCreateRequest( - organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, role = role)) + organizationSaved.id, + solutionSaved.id, + id = TEST_USER_MAIL, + role = role, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL ReflectionTestUtils.setField(workspaceApiService, "resourceScanner", resourceScanner) every { resource.originalFilename } returns "fakeName" every { resourceScanner.scanMimeTypes( - "fakeName", any(), csmPlatformProperties.upload.authorizedMimeTypes.workspaces) + "fakeName", + any(), + csmPlatformProperties.upload.authorizedMimeTypes.workspaces, + ) } returns Unit if (shouldThrow) { val exception = assertThrows { workspaceApiService.createWorkspaceFile( - organizationSaved.id, workspaceSaved.id, resource, true, "") + organizationSaved.id, + workspaceSaved.id, + resource, + true, + "", + ) } assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_WRITE", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { workspaceApiService.createWorkspaceFile( - organizationSaved.id, workspaceSaved.id, resource, true, "name") + organizationSaved.id, + workspaceSaved.id, + resource, + true, + "name", + ) } } } @@ -687,10 +817,13 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) val workspaceSaved = workspaceApiService.createWorkspace( organizationSaved.id, @@ -698,18 +831,23 @@ class WorkspaceServiceRBACTest : CsmTestBase() { organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, - role = ROLE_ADMIN)) + role = ROLE_ADMIN, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL if (shouldThrow) { val exception = assertThrows { workspaceApiService.deleteWorkspaceFiles( - organizationSaved.id, workspaceSaved.id) + organizationSaved.id, + workspaceSaved.id, + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { workspaceApiService.deleteWorkspaceFiles(organizationSaved.id, workspaceSaved.id) @@ -732,26 +870,37 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = ROLE_ADMIN)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = ROLE_ADMIN) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) val workspaceSaved = workspaceApiService.createWorkspace( organizationSaved.id, makeWorkspaceCreateRequest( - organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, role = role)) + organizationSaved.id, + solutionSaved.id, + id = TEST_USER_MAIL, + role = role, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL if (shouldThrow) { val exception = assertThrows { workspaceApiService.deleteWorkspaceFiles( - organizationSaved.id, workspaceSaved.id) + organizationSaved.id, + workspaceSaved.id, + ) } assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_WRITE", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { workspaceApiService.deleteWorkspaceFiles(organizationSaved.id, workspaceSaved.id) @@ -774,10 +923,13 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) val workspaceSaved = workspaceApiService.createWorkspace( organizationSaved.id, @@ -785,22 +937,31 @@ class WorkspaceServiceRBACTest : CsmTestBase() { organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, - role = ROLE_ADMIN)) + role = ROLE_ADMIN, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL if (shouldThrow) { val exception = assertThrows { workspaceApiService.getWorkspaceFile( - organizationSaved.id, workspaceSaved.id, "") + organizationSaved.id, + workspaceSaved.id, + "", + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { workspaceApiService.getWorkspaceFile( - organizationSaved.id, workspaceSaved.id, "name") + organizationSaved.id, + workspaceSaved.id, + "name", + ) } } } @@ -820,30 +981,45 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = ROLE_ADMIN)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = ROLE_ADMIN) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) val workspaceSaved = workspaceApiService.createWorkspace( organizationSaved.id, makeWorkspaceCreateRequest( - organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, role = role)) + organizationSaved.id, + solutionSaved.id, + id = TEST_USER_MAIL, + role = role, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL if (shouldThrow) { val exception = assertThrows { workspaceApiService.getWorkspaceFile( - organizationSaved.id, workspaceSaved.id, "") + organizationSaved.id, + workspaceSaved.id, + "", + ) } assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { workspaceApiService.getWorkspaceFile( - organizationSaved.id, workspaceSaved.id, "name") + organizationSaved.id, + workspaceSaved.id, + "name", + ) } } } @@ -863,10 +1039,13 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) val workspaceSaved = workspaceApiService.createWorkspace( organizationSaved.id, @@ -874,22 +1053,31 @@ class WorkspaceServiceRBACTest : CsmTestBase() { organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, - role = ROLE_ADMIN)) + role = ROLE_ADMIN, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL if (shouldThrow) { val exception = assertThrows { workspaceApiService.deleteWorkspaceFile( - organizationSaved.id, workspaceSaved.id, "") + organizationSaved.id, + workspaceSaved.id, + "", + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { workspaceApiService.deleteWorkspaceFile( - organizationSaved.id, workspaceSaved.id, "") + organizationSaved.id, + workspaceSaved.id, + "", + ) } } } @@ -909,30 +1097,45 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = ROLE_ADMIN)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = ROLE_ADMIN) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) val workspaceSaved = workspaceApiService.createWorkspace( organizationSaved.id, makeWorkspaceCreateRequest( - organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, role = role)) + organizationSaved.id, + solutionSaved.id, + id = TEST_USER_MAIL, + role = role, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL if (shouldThrow) { val exception = assertThrows { workspaceApiService.deleteWorkspaceFile( - organizationSaved.id, workspaceSaved.id, "") + organizationSaved.id, + workspaceSaved.id, + "", + ) } assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_WRITE", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { workspaceApiService.deleteWorkspaceFile( - organizationSaved.id, workspaceSaved.id, "") + organizationSaved.id, + workspaceSaved.id, + "", + ) } } } @@ -952,10 +1155,13 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) val workspaceSaved = workspaceApiService.createWorkspace( organizationSaved.id, @@ -963,22 +1169,31 @@ class WorkspaceServiceRBACTest : CsmTestBase() { organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, - role = ROLE_ADMIN)) + role = ROLE_ADMIN, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL if (shouldThrow) { val exception = assertThrows { workspaceApiService.listWorkspaceRolePermissions( - organizationSaved.id, workspaceSaved.id, ROLE_USER) + organizationSaved.id, + workspaceSaved.id, + ROLE_USER, + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { workspaceApiService.listWorkspaceRolePermissions( - organizationSaved.id, workspaceSaved.id, ROLE_USER) + organizationSaved.id, + workspaceSaved.id, + ROLE_USER, + ) } } } @@ -998,30 +1213,45 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = ROLE_ADMIN)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = ROLE_ADMIN) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) val workspaceSaved = workspaceApiService.createWorkspace( organizationSaved.id, makeWorkspaceCreateRequest( - organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, role = role)) + organizationSaved.id, + solutionSaved.id, + id = TEST_USER_MAIL, + role = role, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL if (shouldThrow) { val exception = assertThrows { workspaceApiService.listWorkspaceRolePermissions( - organizationSaved.id, workspaceSaved.id, ROLE_USER) + organizationSaved.id, + workspaceSaved.id, + ROLE_USER, + ) } assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_READ_SECURITY", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { workspaceApiService.listWorkspaceRolePermissions( - organizationSaved.id, workspaceSaved.id, ROLE_USER) + organizationSaved.id, + workspaceSaved.id, + ROLE_USER, + ) } } } @@ -1041,10 +1271,13 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) val workspaceSaved = workspaceApiService.createWorkspace( organizationSaved.id, @@ -1052,18 +1285,23 @@ class WorkspaceServiceRBACTest : CsmTestBase() { organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, - role = ROLE_ADMIN)) + role = ROLE_ADMIN, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL if (shouldThrow) { val exception = assertThrows { workspaceApiService.getWorkspaceSecurity( - organizationSaved.id, workspaceSaved.id) + organizationSaved.id, + workspaceSaved.id, + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { workspaceApiService.getWorkspaceSecurity(organizationSaved.id, workspaceSaved.id) @@ -1086,26 +1324,37 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = ROLE_ADMIN)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = ROLE_ADMIN) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) val workspaceSaved = workspaceApiService.createWorkspace( organizationSaved.id, makeWorkspaceCreateRequest( - organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, role = role)) + organizationSaved.id, + solutionSaved.id, + id = TEST_USER_MAIL, + role = role, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL if (shouldThrow) { val exception = assertThrows { workspaceApiService.getWorkspaceSecurity( - organizationSaved.id, workspaceSaved.id) + organizationSaved.id, + workspaceSaved.id, + ) } assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_READ_SECURITY", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { workspaceApiService.getWorkspaceSecurity(organizationSaved.id, workspaceSaved.id) @@ -1128,10 +1377,13 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) val workspaceSaved = workspaceApiService.createWorkspace( organizationSaved.id, @@ -1139,22 +1391,31 @@ class WorkspaceServiceRBACTest : CsmTestBase() { organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, - role = ROLE_ADMIN)) + role = ROLE_ADMIN, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL if (shouldThrow) { val exception = assertThrows { workspaceApiService.updateWorkspaceDefaultSecurity( - organizationSaved.id, workspaceSaved.id, WorkspaceRole(ROLE_USER)) + organizationSaved.id, + workspaceSaved.id, + WorkspaceRole(ROLE_USER), + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { workspaceApiService.updateWorkspaceDefaultSecurity( - organizationSaved.id, workspaceSaved.id, WorkspaceRole(ROLE_USER)) + organizationSaved.id, + workspaceSaved.id, + WorkspaceRole(ROLE_USER), + ) } } } @@ -1174,30 +1435,45 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = ROLE_ADMIN)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = ROLE_ADMIN) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) val workspaceSaved = workspaceApiService.createWorkspace( organizationSaved.id, makeWorkspaceCreateRequest( - organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, role = role)) + organizationSaved.id, + solutionSaved.id, + id = TEST_USER_MAIL, + role = role, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL if (shouldThrow) { val exception = assertThrows { workspaceApiService.updateWorkspaceDefaultSecurity( - organizationSaved.id, workspaceSaved.id, WorkspaceRole(ROLE_USER)) + organizationSaved.id, + workspaceSaved.id, + WorkspaceRole(ROLE_USER), + ) } assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_WRITE_SECURITY", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { workspaceApiService.updateWorkspaceDefaultSecurity( - organizationSaved.id, workspaceSaved.id, WorkspaceRole(ROLE_USER)) + organizationSaved.id, + workspaceSaved.id, + WorkspaceRole(ROLE_USER), + ) } } } @@ -1217,10 +1493,13 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) val workspaceSaved = workspaceApiService.createWorkspace( organizationSaved.id, @@ -1228,7 +1507,9 @@ class WorkspaceServiceRBACTest : CsmTestBase() { organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, - role = ROLE_ADMIN)) + role = ROLE_ADMIN, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL if (shouldThrow) { @@ -1237,17 +1518,20 @@ class WorkspaceServiceRBACTest : CsmTestBase() { workspaceApiService.createWorkspaceAccessControl( organizationSaved.id, workspaceSaved.id, - WorkspaceAccessControl("id", ROLE_USER)) + WorkspaceAccessControl("id", ROLE_USER), + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { workspaceApiService.createWorkspaceAccessControl( organizationSaved.id, workspaceSaved.id, - WorkspaceAccessControl("id", ROLE_USER)) + WorkspaceAccessControl("id", ROLE_USER), + ) } } } @@ -1267,15 +1551,23 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = ROLE_ADMIN)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = ROLE_ADMIN) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) val workspaceSaved = workspaceApiService.createWorkspace( organizationSaved.id, makeWorkspaceCreateRequest( - organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, role = role)) + organizationSaved.id, + solutionSaved.id, + id = TEST_USER_MAIL, + role = role, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL if (shouldThrow) { @@ -1284,17 +1576,20 @@ class WorkspaceServiceRBACTest : CsmTestBase() { workspaceApiService.createWorkspaceAccessControl( organizationSaved.id, workspaceSaved.id, - WorkspaceAccessControl("id", ROLE_USER)) + WorkspaceAccessControl("id", ROLE_USER), + ) } assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_WRITE_SECURITY", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { workspaceApiService.createWorkspaceAccessControl( organizationSaved.id, workspaceSaved.id, - WorkspaceAccessControl("id", ROLE_USER)) + WorkspaceAccessControl("id", ROLE_USER), + ) } } } @@ -1314,10 +1609,13 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) val workspaceSaved = workspaceApiService.createWorkspace( organizationSaved.id, @@ -1325,22 +1623,31 @@ class WorkspaceServiceRBACTest : CsmTestBase() { organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, - role = ROLE_ADMIN)) + role = ROLE_ADMIN, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL if (shouldThrow) { val exception = assertThrows { workspaceApiService.getWorkspaceAccessControl( - organizationSaved.id, workspaceSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + TEST_USER_MAIL, + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { workspaceApiService.getWorkspaceAccessControl( - organizationSaved.id, workspaceSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + TEST_USER_MAIL, + ) } } } @@ -1360,30 +1667,45 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = ROLE_ADMIN)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = ROLE_ADMIN) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) val workspaceSaved = workspaceApiService.createWorkspace( organizationSaved.id, makeWorkspaceCreateRequest( - organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, role = role)) + organizationSaved.id, + solutionSaved.id, + id = TEST_USER_MAIL, + role = role, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL if (shouldThrow) { val exception = assertThrows { workspaceApiService.getWorkspaceAccessControl( - organizationSaved.id, workspaceSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + TEST_USER_MAIL, + ) } assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_READ_SECURITY", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { workspaceApiService.getWorkspaceAccessControl( - organizationSaved.id, workspaceSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + TEST_USER_MAIL, + ) } } } @@ -1403,10 +1725,13 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) val workspaceSaved = workspaceApiService.createWorkspace( organizationSaved.id, @@ -1414,22 +1739,31 @@ class WorkspaceServiceRBACTest : CsmTestBase() { organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, - role = ROLE_ADMIN)) + role = ROLE_ADMIN, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL if (shouldThrow) { val exception = assertThrows { workspaceApiService.deleteWorkspaceAccessControl( - organizationSaved.id, workspaceSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + TEST_USER_MAIL, + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { workspaceApiService.deleteWorkspaceAccessControl( - organizationSaved.id, workspaceSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + TEST_USER_MAIL, + ) } } } @@ -1449,30 +1783,45 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = ROLE_ADMIN)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = ROLE_ADMIN) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) val workspaceSaved = workspaceApiService.createWorkspace( organizationSaved.id, makeWorkspaceCreateRequest( - organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, role = role)) + organizationSaved.id, + solutionSaved.id, + id = TEST_USER_MAIL, + role = role, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL if (shouldThrow) { val exception = assertThrows { workspaceApiService.deleteWorkspaceAccessControl( - organizationSaved.id, workspaceSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + TEST_USER_MAIL, + ) } assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_WRITE_SECURITY", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { workspaceApiService.deleteWorkspaceAccessControl( - organizationSaved.id, workspaceSaved.id, TEST_USER_MAIL) + organizationSaved.id, + workspaceSaved.id, + TEST_USER_MAIL, + ) } } } @@ -1492,10 +1841,13 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) val workspaceSaved = workspaceApiService.createWorkspace( organizationSaved.id, @@ -1503,7 +1855,9 @@ class WorkspaceServiceRBACTest : CsmTestBase() { organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, - role = ROLE_ADMIN)) + role = ROLE_ADMIN, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL if (shouldThrow) { @@ -1513,18 +1867,21 @@ class WorkspaceServiceRBACTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, TEST_USER_MAIL, - WorkspaceRole(ROLE_ADMIN)) + WorkspaceRole(ROLE_ADMIN), + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { workspaceApiService.updateWorkspaceAccessControl( organizationSaved.id, workspaceSaved.id, TEST_USER_MAIL, - WorkspaceRole(ROLE_ADMIN)) + WorkspaceRole(ROLE_ADMIN), + ) } } } @@ -1544,15 +1901,23 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = ROLE_ADMIN)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = ROLE_ADMIN) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) val workspaceSaved = workspaceApiService.createWorkspace( organizationSaved.id, makeWorkspaceCreateRequest( - organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, role = role)) + organizationSaved.id, + solutionSaved.id, + id = TEST_USER_MAIL, + role = role, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL if (shouldThrow) { @@ -1562,18 +1927,21 @@ class WorkspaceServiceRBACTest : CsmTestBase() { organizationSaved.id, workspaceSaved.id, TEST_USER_MAIL, - WorkspaceRole(ROLE_ADMIN)) + WorkspaceRole(ROLE_ADMIN), + ) } assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_WRITE_SECURITY", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { workspaceApiService.updateWorkspaceAccessControl( organizationSaved.id, workspaceSaved.id, TEST_USER_MAIL, - WorkspaceRole(ROLE_ADMIN)) + WorkspaceRole(ROLE_ADMIN), + ) } } } @@ -1593,10 +1961,13 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = role) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) val workspaceSaved = workspaceApiService.createWorkspace( organizationSaved.id, @@ -1604,22 +1975,29 @@ class WorkspaceServiceRBACTest : CsmTestBase() { organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, - role = ROLE_ADMIN)) + role = ROLE_ADMIN, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL if (shouldThrow) { val exception = assertThrows { workspaceApiService.listWorkspaceSecurityUsers( - organizationSaved.id, workspaceSaved.id) + organizationSaved.id, + workspaceSaved.id, + ) } assertEquals( "RBAC ${organizationSaved.id} - User does not have permission $PERMISSION_READ", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { workspaceApiService.listWorkspaceSecurityUsers( - organizationSaved.id, workspaceSaved.id) + organizationSaved.id, + workspaceSaved.id, + ) } } } @@ -1639,30 +2017,43 @@ class WorkspaceServiceRBACTest : CsmTestBase() { every { getCurrentAccountIdentifier(any()) } returns CONNECTED_ADMIN_USER val organizationSaved = organizationApiService.createOrganization( - makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = ROLE_ADMIN)) + makeOrganizationCreateRequest(id = TEST_USER_MAIL, role = ROLE_ADMIN) + ) val solutionSaved = solutionApiService.createSolution( - organizationSaved.id, makeSolution(organizationSaved.id)) + organizationSaved.id, + makeSolution(organizationSaved.id), + ) val workspaceSaved = workspaceApiService.createWorkspace( organizationSaved.id, makeWorkspaceCreateRequest( - organizationSaved.id, solutionSaved.id, id = TEST_USER_MAIL, role = role)) + organizationSaved.id, + solutionSaved.id, + id = TEST_USER_MAIL, + role = role, + ), + ) every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL if (shouldThrow) { val exception = assertThrows { workspaceApiService.listWorkspaceSecurityUsers( - organizationSaved.id, workspaceSaved.id) + organizationSaved.id, + workspaceSaved.id, + ) } assertEquals( "RBAC ${workspaceSaved.id} - User does not have permission $PERMISSION_READ_SECURITY", - exception.message) + exception.message, + ) } else { assertDoesNotThrow { workspaceApiService.listWorkspaceSecurityUsers( - organizationSaved.id, workspaceSaved.id) + organizationSaved.id, + workspaceSaved.id, + ) } } } @@ -1677,7 +2068,10 @@ class WorkspaceServiceRBACTest : CsmTestBase() { accessControlList = mutableListOf( OrganizationAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), - OrganizationAccessControl(id = id, role = role)))) + OrganizationAccessControl(id = id, role = role), + ), + ), + ) fun makeSolution(organizationId: String) = SolutionCreateRequest( @@ -1693,13 +2087,16 @@ class WorkspaceServiceRBACTest : CsmTestBase() { default = ROLE_NONE, mutableListOf( SolutionAccessControl(id = CONNECTED_ADMIN_USER, role = ROLE_ADMIN), - SolutionAccessControl(id = TEST_USER_MAIL, role = ROLE_ADMIN)))) + SolutionAccessControl(id = TEST_USER_MAIL, role = ROLE_ADMIN), + ), + ), + ) fun makeWorkspaceCreateRequest( organizationId: String, solutionId: String, id: String, - role: String + role: String, ) = WorkspaceCreateRequest( key = UUID.randomUUID().toString(), @@ -1714,5 +2111,8 @@ class WorkspaceServiceRBACTest : CsmTestBase() { accessControlList = mutableListOf( WorkspaceAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), - WorkspaceAccessControl(id = id, role = role)))) + WorkspaceAccessControl(id = id, role = role), + ), + ), + ) } diff --git a/workspace/src/main/kotlin/com/cosmotech/workspace/WorkspaceApiServiceInterface.kt b/workspace/src/main/kotlin/com/cosmotech/workspace/WorkspaceApiServiceInterface.kt index 2504efede..59f790378 100644 --- a/workspace/src/main/kotlin/com/cosmotech/workspace/WorkspaceApiServiceInterface.kt +++ b/workspace/src/main/kotlin/com/cosmotech/workspace/WorkspaceApiServiceInterface.kt @@ -11,6 +11,6 @@ interface WorkspaceApiServiceInterface : WorkspaceApiService { fun getVerifiedWorkspace( organizationId: String, workspaceId: String, - requiredPermission: String = PERMISSION_READ + requiredPermission: String = PERMISSION_READ, ): Workspace } diff --git a/workspace/src/main/kotlin/com/cosmotech/workspace/repository/WorkspaceRepository.kt b/workspace/src/main/kotlin/com/cosmotech/workspace/repository/WorkspaceRepository.kt index 8ef5cda09..d9a66f666 100644 --- a/workspace/src/main/kotlin/com/cosmotech/workspace/repository/WorkspaceRepository.kt +++ b/workspace/src/main/kotlin/com/cosmotech/workspace/repository/WorkspaceRepository.kt @@ -17,19 +17,19 @@ interface WorkspaceRepository : RedisDocumentRepository { @Query("@organizationId:{\$organizationId} @id:{\$workspaceId}") fun findBy( @Sanitize @Param("organizationId") organizationId: String, - @Sanitize @Param("workspaceId") workspaceId: String + @Sanitize @Param("workspaceId") workspaceId: String, ): Optional @Query("@organizationId:{\$organizationId}") fun findByOrganizationId( @Sanitize @Param("organizationId") organizationId: String, - pageable: Pageable + pageable: Pageable, ): Page @Query("(@organizationId:{\$organizationId}) \$securityConstraint") fun findByOrganizationIdAndSecurity( @Sanitize @Param("organizationId") organizationId: String, @SecurityConstraint @Param("securityConstraint") securityConstraint: String, - pageable: Pageable + pageable: Pageable, ): Page } diff --git a/workspace/src/main/kotlin/com/cosmotech/workspace/service/WorkspaceServiceImpl.kt b/workspace/src/main/kotlin/com/cosmotech/workspace/service/WorkspaceServiceImpl.kt index 9baacb0b0..56c21825f 100644 --- a/workspace/src/main/kotlin/com/cosmotech/workspace/service/WorkspaceServiceImpl.kt +++ b/workspace/src/main/kotlin/com/cosmotech/workspace/service/WorkspaceServiceImpl.kt @@ -70,14 +70,16 @@ internal class WorkspaceServiceImpl( private val s3Template: S3Template, private val csmRbac: CsmRbac, private val resourceScanner: ResourceScanner, - private val workspaceRepository: WorkspaceRepository + private val workspaceRepository: WorkspaceRepository, ) : CsmPhoenixService(), WorkspaceApiServiceInterface { override fun listWorkspaces(organizationId: String, page: Int?, size: Int?): List { val organization = organizationService.getVerifiedOrganization(organizationId) val isAdmin = csmRbac.isAdmin( - organization.security.toGenericSecurity(organizationId), getCommonRolesDefinition()) + organization.security.toGenericSecurity(organizationId), + getCommonRolesDefinition(), + ) val defaultPageSize = csmPlatformProperties.databases.resources.workspace.defaultPageSize var result: List var pageable = constructPageRequest(page, size, defaultPageSize) @@ -115,10 +117,12 @@ internal class WorkspaceServiceImpl( override fun createWorkspace( organizationId: String, - workspaceCreateRequest: WorkspaceCreateRequest + workspaceCreateRequest: WorkspaceCreateRequest, ): Workspace { organizationService.getVerifiedOrganization( - organizationId, listOf(PERMISSION_READ, PERMISSION_CREATE_CHILDREN)) + organizationId, + listOf(PERMISSION_READ, PERMISSION_CREATE_CHILDREN), + ) // Validate Solution ID workspaceCreateRequest.solution.solutionId.let { @@ -137,10 +141,14 @@ internal class WorkspaceServiceImpl( organizationId = organizationId, createInfo = WorkspaceEditInfo( - timestamp = now, userId = getCurrentAccountIdentifier(csmPlatformProperties)), + timestamp = now, + userId = getCurrentAccountIdentifier(csmPlatformProperties), + ), updateInfo = WorkspaceEditInfo( - timestamp = now, userId = getCurrentAccountIdentifier(csmPlatformProperties)), + timestamp = now, + userId = getCurrentAccountIdentifier(csmPlatformProperties), + ), key = workspaceCreateRequest.key, name = workspaceCreateRequest.name, solution = workspaceCreateRequest.solution, @@ -165,7 +173,7 @@ internal class WorkspaceServiceImpl( override fun updateWorkspace( organizationId: String, workspaceId: String, - workspaceUpdateRequest: WorkspaceUpdateRequest + workspaceUpdateRequest: WorkspaceUpdateRequest, ): Workspace { val existingWorkspace = this.getVerifiedWorkspace(organizationId, workspaceId, PERMISSION_WRITE) @@ -183,7 +191,8 @@ internal class WorkspaceServiceImpl( additionalData = workspaceUpdateRequest.additionalData ?: existingWorkspace.additionalData, datasetCopy = workspaceUpdateRequest.datasetCopy ?: existingWorkspace.datasetCopy, - security = existingWorkspace.security) + security = existingWorkspace.security, + ) // Validate that solutionId refers to an existing one if (updatedWorkspace.solution.solutionId != existingWorkspace.solution.solutionId) { @@ -193,7 +202,9 @@ internal class WorkspaceServiceImpl( val hasChanged = existingWorkspace .compareToAndMutateIfNeeded( - updatedWorkspace, excludedFields = arrayOf("ownerId", "security")) + updatedWorkspace, + excludedFields = arrayOf("ownerId", "security"), + ) .isNotEmpty() return if (hasChanged) { @@ -225,7 +236,7 @@ internal class WorkspaceServiceImpl( override fun getWorkspaceFile( organizationId: String, workspaceId: String, - fileName: String + fileName: String, ): Resource { require(".." !in fileName) { "Invalid filename: '$fileName'. '..' is not allowed" } val workspace = getVerifiedWorkspace(organizationId, workspaceId, PERMISSION_READ) @@ -233,7 +244,8 @@ internal class WorkspaceServiceImpl( "Downloading file resource from workspace #{} ({}): {}", workspace.id, workspace.name, - fileName) + fileName, + ) var fileResource: Resource try { fileResource = @@ -241,8 +253,10 @@ internal class WorkspaceServiceImpl( s3Template .download( csmPlatformProperties.s3.bucketName, - "$organizationId/$workspaceId/$WORKSPACE_FILES_BASE_FOLDER/$fileName") - .inputStream) + "$organizationId/$workspaceId/$WORKSPACE_FILES_BASE_FOLDER/$fileName", + ) + .inputStream + ) } catch (exception: NoSuchKeyException) { throw CsmResourceNotFoundException("$fileName does not exist.", exception) } @@ -255,7 +269,7 @@ internal class WorkspaceServiceImpl( workspaceId: String, file: MultipartFile, overwrite: Boolean, - destination: String? + destination: String?, ): WorkspaceFile { require(destination?.contains("..") != true) { "Invalid destination: '$destination'. '..' is not allowed" @@ -263,9 +277,10 @@ internal class WorkspaceServiceImpl( require(file.originalFilename?.isBlank() != true) { "File name must not be blank" } require( file.originalFilename?.contains("..") != true && - file.originalFilename?.startsWith("/") != true) { - "Invalid filename: '${file.originalFilename}'. File name should neither contains '..' nor and starts by '/'." - } + file.originalFilename?.startsWith("/") != true + ) { + "Invalid filename: '${file.originalFilename}'. File name should neither contains '..' nor and starts by '/'." + } val workspace = getVerifiedWorkspace(organizationId, workspaceId, PERMISSION_WRITE) logger.debug( @@ -273,12 +288,14 @@ internal class WorkspaceServiceImpl( workspace.id, workspace.name, file.originalFilename, - destination) + destination, + ) resourceScanner.scanMimeTypes( file.originalFilename!!, file.inputStream, - csmPlatformProperties.upload.authorizedMimeTypes.workspaces) + csmPlatformProperties.upload.authorizedMimeTypes.workspaces, + ) val fileRelativeDestinationBuilder = StringBuilder() if (destination.isNullOrBlank()) { fileRelativeDestinationBuilder.append(file.originalFilename) @@ -295,7 +312,8 @@ internal class WorkspaceServiceImpl( if (!overwrite && s3Template.objectExists(csmPlatformProperties.s3.bucketName, objectKey)) { throw IllegalArgumentException( - "File '$fileRelativeDestinationBuilder' already exists, not overwriting it") + "File '$fileRelativeDestinationBuilder' already exists, not overwriting it" + ) } s3Template.upload(csmPlatformProperties.s3.bucketName, objectKey, file.inputStream) @@ -304,7 +322,7 @@ internal class WorkspaceServiceImpl( override fun listWorkspaceFiles( organizationId: String, - workspaceId: String + workspaceId: String, ): List { val workspace = getVerifiedWorkspace(organizationId, workspaceId) @@ -357,17 +375,19 @@ internal class WorkspaceServiceImpl( private fun deleteS3WorkspaceObject( organizationId: String, workspace: Workspace, - fileName: String + fileName: String, ) { logger.debug( "Deleting file resource from workspace #{} ({}): {}", workspace.id, workspace.name, - fileName) + fileName, + ) try { s3Template.deleteObject( csmPlatformProperties.s3.bucketName, - "$organizationId/${workspace.id}/$WORKSPACE_FILES_BASE_FOLDER/$fileName") + "$organizationId/${workspace.id}/$WORKSPACE_FILES_BASE_FOLDER/$fileName", + ) } catch (e: AwsServiceException) { logger.error("Something wrong happened during $fileName deletion", e) } catch (e: SdkClientException) { @@ -392,7 +412,7 @@ internal class WorkspaceServiceImpl( override fun listWorkspaceRolePermissions( organizationId: String, workspaceId: String, - role: String + role: String, ): List { getVerifiedWorkspace(organizationId, workspaceId, PERMISSION_READ_SECURITY) return getPermissions(role, getCommonRolesDefinition()) @@ -400,7 +420,7 @@ internal class WorkspaceServiceImpl( override fun getWorkspaceSecurity( organizationId: String, - workspaceId: String + workspaceId: String, ): WorkspaceSecurity { val workspace = getVerifiedWorkspace(organizationId, workspaceId, PERMISSION_READ_SECURITY) return workspace.security @@ -409,7 +429,7 @@ internal class WorkspaceServiceImpl( override fun updateWorkspaceDefaultSecurity( organizationId: String, workspaceId: String, - workspaceRole: WorkspaceRole + workspaceRole: WorkspaceRole, ): WorkspaceSecurity { val workspace = getVerifiedWorkspace(organizationId, workspaceId, PERMISSION_WRITE_SECURITY) val rbacSecurity = @@ -422,7 +442,7 @@ internal class WorkspaceServiceImpl( override fun getWorkspaceAccessControl( organizationId: String, workspaceId: String, - identityId: String + identityId: String, ): WorkspaceAccessControl { val workspace = getVerifiedWorkspace(organizationId, workspaceId, PERMISSION_READ_SECURITY) val rbacAccessControl = @@ -433,13 +453,14 @@ internal class WorkspaceServiceImpl( override fun getVerifiedWorkspace( organizationId: String, workspaceId: String, - requiredPermission: String + requiredPermission: String, ): Workspace { organizationService.getVerifiedOrganization(organizationId) val workspace = workspaceRepository.findBy(organizationId, workspaceId).orElseThrow { CsmResourceNotFoundException( - "Workspace $workspaceId not found in organization $organizationId") + "Workspace $workspaceId not found in organization $organizationId" + ) } csmRbac.verify(workspace.security.toGenericSecurity(workspaceId), requiredPermission) return workspace @@ -448,7 +469,7 @@ internal class WorkspaceServiceImpl( override fun createWorkspaceAccessControl( organizationId: String, workspaceId: String, - workspaceAccessControl: WorkspaceAccessControl + workspaceAccessControl: WorkspaceAccessControl, ): WorkspaceAccessControl { val organization = organizationService.getVerifiedOrganization(organizationId) val workspace = getVerifiedWorkspace(organizationId, workspaceId, PERMISSION_WRITE_SECURITY) @@ -461,12 +482,15 @@ internal class WorkspaceServiceImpl( organization.security.toGenericSecurity(organizationId), workspace.security.toGenericSecurity(workspaceId), workspaceAccessControl.id, - workspaceAccessControl.role) + workspaceAccessControl.role, + ) workspace.security = rbacSecurity.toResourceSecurity() save(workspace) val rbacAccessControl = csmRbac.getAccessControl( - workspace.security.toGenericSecurity(workspaceId), workspaceAccessControl.id) + workspace.security.toGenericSecurity(workspaceId), + workspaceAccessControl.id, + ) return WorkspaceAccessControl(rbacAccessControl.id, rbacAccessControl.role) } @@ -474,16 +498,20 @@ internal class WorkspaceServiceImpl( organizationId: String, workspaceId: String, identityId: String, - workspaceRole: WorkspaceRole + workspaceRole: WorkspaceRole, ): WorkspaceAccessControl { val workspace = getVerifiedWorkspace(organizationId, workspaceId, PERMISSION_WRITE_SECURITY) csmRbac.checkEntityExists( workspace.security.toGenericSecurity(workspaceId), identityId, - "User '$identityId' not found in workspace $workspaceId") + "User '$identityId' not found in workspace $workspaceId", + ) val rbacSecurity = csmRbac.setEntityRole( - workspace.security.toGenericSecurity(workspaceId), identityId, workspaceRole.role) + workspace.security.toGenericSecurity(workspaceId), + identityId, + workspaceRole.role, + ) workspace.security = rbacSecurity.toResourceSecurity() save(workspace) val rbacAccessControl = @@ -494,7 +522,7 @@ internal class WorkspaceServiceImpl( override fun deleteWorkspaceAccessControl( organizationId: String, workspaceId: String, - identityId: String + identityId: String, ) { val workspace = getVerifiedWorkspace(organizationId, workspaceId, PERMISSION_WRITE_SECURITY) val rbacSecurity = @@ -505,16 +533,18 @@ internal class WorkspaceServiceImpl( override fun listWorkspaceSecurityUsers( organizationId: String, - workspaceId: String + workspaceId: String, ): List { val workspace = getVerifiedWorkspace(organizationId, workspaceId, PERMISSION_READ_SECURITY) return csmRbac.getEntities(workspace.security.toGenericSecurity(workspaceId)) } fun updateSecurityVisibility(workspace: Workspace): Workspace { - if (csmRbac - .check(workspace.security.toGenericSecurity(workspace.id), PERMISSION_READ_SECURITY) - .not()) { + if ( + csmRbac + .check(workspace.security.toGenericSecurity(workspace.id), PERMISSION_READ_SECURITY) + .not() + ) { val username = getCurrentAccountIdentifier(csmPlatformProperties) val retrievedAC = workspace.security.accessControlList.firstOrNull { it.id == username } @@ -528,7 +558,10 @@ internal class WorkspaceServiceImpl( return workspace.copy( security = WorkspaceSecurity( - default = workspace.security.default, accessControlList = accessControlList)) + default = workspace.security.default, + accessControlList = accessControlList, + ) + ) } return workspace } @@ -537,7 +570,8 @@ internal class WorkspaceServiceImpl( workspace.updateInfo = WorkspaceEditInfo( timestamp = Instant.now().toEpochMilli(), - userId = getCurrentAccountIdentifier(csmPlatformProperties)) + userId = getCurrentAccountIdentifier(csmPlatformProperties), + ) return workspaceRepository.save(workspace) } } @@ -547,9 +581,11 @@ fun WorkspaceSecurity?.toGenericSecurity(workspaceId: String) = workspaceId, this?.default ?: ROLE_NONE, this?.accessControlList?.map { RbacAccessControl(it.id, it.role) }?.toMutableList() - ?: mutableListOf()) + ?: mutableListOf(), + ) fun RbacSecurity.toResourceSecurity() = WorkspaceSecurity( this.default, - this.accessControlList.map { WorkspaceAccessControl(it.id, it.role) }.toMutableList()) + this.accessControlList.map { WorkspaceAccessControl(it.id, it.role) }.toMutableList(), + ) diff --git a/workspace/src/test/kotlin/com/cosmotech/workspace/service/WorkspaceServiceImplTests.kt b/workspace/src/test/kotlin/com/cosmotech/workspace/service/WorkspaceServiceImplTests.kt index 4e644b252..04a40bfa0 100644 --- a/workspace/src/test/kotlin/com/cosmotech/workspace/service/WorkspaceServiceImplTests.kt +++ b/workspace/src/test/kotlin/com/cosmotech/workspace/service/WorkspaceServiceImplTests.kt @@ -191,7 +191,12 @@ class WorkspaceServiceImplTests { val workspaceFile = workspaceServiceImpl.createWorkspaceFile( - ORGANIZATION_ID, WORKSPACE_ID, file, false, "my/destination/") + ORGANIZATION_ID, + WORKSPACE_ID, + file, + false, + "my/destination/", + ) assertNotNull(workspaceFile.fileName) assertEquals("my/destination/my_file.txt", workspaceFile.fileName) } @@ -209,7 +214,12 @@ class WorkspaceServiceImplTests { val workspaceFile = workspaceServiceImpl.createWorkspaceFile( - ORGANIZATION_ID, WORKSPACE_ID, file, false, "my/destination/file") + ORGANIZATION_ID, + WORKSPACE_ID, + file, + false, + "my/destination/file", + ) assertNotNull(workspaceFile.fileName) assertEquals("my/destination/file", workspaceFile.fileName) } @@ -227,7 +237,12 @@ class WorkspaceServiceImplTests { val workspaceFile = workspaceServiceImpl.createWorkspaceFile( - ORGANIZATION_ID, WORKSPACE_ID, file, false, "my//other/destination////////file") + ORGANIZATION_ID, + WORKSPACE_ID, + file, + false, + "my//other/destination////////file", + ) assertNotNull(workspaceFile.fileName) assertEquals("my/other/destination/file", workspaceFile.fileName) } @@ -236,7 +251,12 @@ class WorkspaceServiceImplTests { fun `Calling uploadWorkspaceFile is not allowed when destination contains double-dot`() { assertThrows { workspaceServiceImpl.createWorkspaceFile( - ORGANIZATION_ID, WORKSPACE_ID, mockk(), false, "my/../other/destination/../../file") + ORGANIZATION_ID, + WORKSPACE_ID, + mockk(), + false, + "my/../other/destination/../../file", + ) } } @@ -244,7 +264,10 @@ class WorkspaceServiceImplTests { fun `Calling downloadWorkspaceFile is not allowed when filename contains double-dot`() { assertThrows { workspaceServiceImpl.getWorkspaceFile( - ORGANIZATION_ID, WORKSPACE_ID, "my/../../other/destination/file") + ORGANIZATION_ID, + WORKSPACE_ID, + "my/../../other/destination/file", + ) } } @@ -257,7 +280,8 @@ class WorkspaceServiceImplTests { solutionId = "SOL-my-solution-id", workspaceName = "my workspace name", roleName = "", - role = "") + role = "", + ) workspace.security = WorkspaceSecurity(ROLE_ADMIN, mutableListOf()) every { solutionService.getSolution(ORGANIZATION_ID, any()) } throws CsmResourceNotFoundException("Solution not found") @@ -276,7 +300,8 @@ class WorkspaceServiceImplTests { organizationId = ORGANIZATION_ID, workspaceName = "my workspace name", roleName = CONNECTED_DEFAULT_USER, - role = ROLE_ADMIN) + role = ROLE_ADMIN, + ) every { workspaceRepository.findBy(any(), WORKSPACE_ID) } returns Optional.of(workspace) every { solutionService.getSolution(ORGANIZATION_ID, any()) } throws CsmResourceNotFoundException("Solution not found") @@ -287,7 +312,9 @@ class WorkspaceServiceImplTests { WorkspaceUpdateRequest( key = "my-workspace-key-renamed", name = "my workspace name (renamed)", - solution = WorkspaceSolution(solutionId = "SOL-my-new-solution-id"))) + solution = WorkspaceSolution(solutionId = "SOL-my-new-solution-id"), + ), + ) } verify(exactly = 0) { workspaceRepository.save(ofType(Workspace::class)) } @@ -301,7 +328,8 @@ class WorkspaceServiceImplTests { ROLE_ADMIN to false, ROLE_VALIDATOR to true, ROLE_USER to false, - ROLE_NONE to true) + ROLE_NONE to true, + ) .map { (role, shouldThrow) -> rbacTest("Test RBAC read workspace: $role", role, shouldThrow) { every { workspaceRepository.findBy(any(), any()) } returns Optional.of(it.workspace) @@ -317,20 +345,26 @@ class WorkspaceServiceImplTests { ROLE_ADMIN to false, ROLE_VALIDATOR to true, ROLE_USER to false, - ROLE_NONE to true) + ROLE_NONE to true, + ) .map { (role, shouldThrow) -> rbacTest("Test RBAC create workspace: $role", role, shouldThrow) { every { organizationRepository.findByIdOrNull(any()) } returns it.organization listOf(PERMISSION_READ, PERMISSION_CREATE_CHILDREN).forEach { permission -> csmRbac.verify( - it.organization.security.toGenericSecurity(it.organization.id), permission) + it.organization.security.toGenericSecurity(it.organization.id), + permission, + ) } every { workspaceRepository.save(any()) } returns it.workspace every { solutionService.getSolution(any(), any()) } returns it.solution workspaceServiceImpl.createWorkspace( it.organization.id, mockWorkspaceCreateRequest( - solutionId = it.solution.id, workspaceName = "workspace")) + solutionId = it.solution.id, + workspaceName = "workspace", + ), + ) } } @@ -342,7 +376,8 @@ class WorkspaceServiceImplTests { ROLE_ADMIN to false, ROLE_VALIDATOR to true, ROLE_USER to true, - ROLE_NONE to true) + ROLE_NONE to true, + ) .map { (role, shouldThrow) -> rbacTest("Test RBAC delete all workspace files: $role", role, shouldThrow) { every { workspaceRepository.findBy(any(), any()) } returns Optional.of(it.workspace) @@ -358,7 +393,8 @@ class WorkspaceServiceImplTests { ROLE_ADMIN to false, ROLE_VALIDATOR to true, ROLE_USER to true, - ROLE_NONE to true) + ROLE_NONE to true, + ) .map { (role, shouldThrow) -> rbacTest("test RBAC update workspace: $role", role, shouldThrow) { every { solutionService.getSolution(any(), any()) } returns it.solution @@ -367,7 +403,8 @@ class WorkspaceServiceImplTests { workspaceServiceImpl.updateWorkspace( it.organization.id, it.workspace.id, - WorkspaceUpdateRequest(key = it.workspace.key, name = "new name")) + WorkspaceUpdateRequest(key = it.workspace.key, name = "new name"), + ) } } @@ -379,7 +416,8 @@ class WorkspaceServiceImplTests { ROLE_ADMIN to false, ROLE_VALIDATOR to true, ROLE_USER to true, - ROLE_NONE to true) + ROLE_NONE to true, + ) .map { (role, shouldThrow) -> rbacTest("Test RBAC delete workspace: $role", role, shouldThrow) { every { workspaceRepository.findBy(any(), any()) } returns Optional.of(it.workspace) @@ -395,7 +433,8 @@ class WorkspaceServiceImplTests { ROLE_ADMIN to false, ROLE_VALIDATOR to true, ROLE_USER to true, - ROLE_NONE to true) + ROLE_NONE to true, + ) .map { (role, shouldThrow) -> rbacTest("Test RBAC delete workspace file: $role", role, shouldThrow) { every { workspaceRepository.findBy(any(), any()) } returns Optional.of(it.workspace) @@ -411,7 +450,8 @@ class WorkspaceServiceImplTests { ROLE_ADMIN to false, ROLE_VALIDATOR to true, ROLE_USER to false, - ROLE_NONE to true) + ROLE_NONE to true, + ) .map { (role, shouldThrow) -> rbacTest("Test RBAC download workspace file: $role", role, shouldThrow) { every { workspaceRepository.findBy(any(), any()) } returns Optional.of(it.workspace) @@ -427,13 +467,19 @@ class WorkspaceServiceImplTests { ROLE_ADMIN to false, ROLE_VALIDATOR to true, ROLE_USER to true, - ROLE_NONE to true) + ROLE_NONE to true, + ) .map { (role, shouldThrow) -> rbacTest("Test RBAC upload workspace file: $role", role, shouldThrow) { every { workspaceRepository.findBy(any(), any()) } returns Optional.of(it.workspace) every { workspaceFile.originalFilename } returns "fakeName" workspaceServiceImpl.createWorkspaceFile( - it.organization.id, it.workspace.id, workspaceFile, true, "name") + it.organization.id, + it.workspace.id, + workspaceFile, + true, + "name", + ) } } @@ -445,7 +491,8 @@ class WorkspaceServiceImplTests { ROLE_ADMIN to false, ROLE_VALIDATOR to true, ROLE_USER to false, - ROLE_NONE to true) + ROLE_NONE to true, + ) .map { (role, shouldThrow) -> rbacTest("Test RBAC findAllWorkspaceFiles: $role", role, shouldThrow) { every { workspaceRepository.findBy(any(), any()) } returns Optional.of(it.workspace) @@ -461,7 +508,8 @@ class WorkspaceServiceImplTests { ROLE_ADMIN to false, ROLE_VALIDATOR to true, ROLE_USER to false, - ROLE_NONE to true) + ROLE_NONE to true, + ) .map { (role, shouldThrow) -> rbacTest("Test RBAC get workspace security: $role", role, shouldThrow) { every { workspaceRepository.findBy(any(), any()) } returns Optional.of(it.workspace) @@ -477,13 +525,17 @@ class WorkspaceServiceImplTests { ROLE_ADMIN to false, ROLE_VALIDATOR to true, ROLE_USER to true, - ROLE_NONE to true) + ROLE_NONE to true, + ) .map { (role, shouldThrow) -> rbacTest("Test RBAC set workspace default security: $role", role, shouldThrow) { every { workspaceRepository.findBy(any(), any()) } returns Optional.of(it.workspace) every { workspaceRepository.save(any()) } returns it.workspace workspaceServiceImpl.updateWorkspaceDefaultSecurity( - it.organization.id, it.workspace.id, WorkspaceRole(ROLE_NONE)) + it.organization.id, + it.workspace.id, + WorkspaceRole(ROLE_NONE), + ) } } @@ -495,12 +547,16 @@ class WorkspaceServiceImplTests { ROLE_ADMIN to false, ROLE_VALIDATOR to true, ROLE_USER to false, - ROLE_NONE to true) + ROLE_NONE to true, + ) .map { (role, shouldThrow) -> rbacTest("test RBAC get workspace access control: $role", role, shouldThrow) { every { workspaceRepository.findBy(any(), any()) } returns Optional.of(it.workspace) workspaceServiceImpl.getWorkspaceAccessControl( - it.organization.id, it.workspace.id, CONNECTED_DEFAULT_USER) + it.organization.id, + it.workspace.id, + CONNECTED_DEFAULT_USER, + ) } } @@ -512,7 +568,8 @@ class WorkspaceServiceImplTests { ROLE_ADMIN to false, ROLE_VALIDATOR to true, ROLE_USER to true, - ROLE_NONE to true) + ROLE_NONE to true, + ) .map { (role, shouldThrow) -> rbacTest("test RBAC add workspace access control: $role", role, shouldThrow) { every { workspaceRepository.save(any()) } returns it.workspace @@ -520,7 +577,8 @@ class WorkspaceServiceImplTests { workspaceServiceImpl.createWorkspaceAccessControl( it.organization.id, it.workspace.id, - WorkspaceAccessControl("3$CONNECTED_DEFAULT_USER", ROLE_USER)) + WorkspaceAccessControl("3$CONNECTED_DEFAULT_USER", ROLE_USER), + ) } } @@ -532,7 +590,8 @@ class WorkspaceServiceImplTests { ROLE_ADMIN to false, ROLE_VALIDATOR to true, ROLE_USER to true, - ROLE_NONE to true) + ROLE_NONE to true, + ) .map { (role, shouldThrow) -> rbacTest("test RBAC update workspace access control: $role", role, shouldThrow) { every { workspaceRepository.findBy(any(), any()) } returns Optional.of(it.workspace) @@ -541,7 +600,8 @@ class WorkspaceServiceImplTests { it.organization.id, it.workspace.id, "2$CONNECTED_DEFAULT_USER", - WorkspaceRole(ROLE_USER)) + WorkspaceRole(ROLE_USER), + ) } } @@ -553,13 +613,17 @@ class WorkspaceServiceImplTests { ROLE_ADMIN to false, ROLE_VALIDATOR to true, ROLE_USER to true, - ROLE_NONE to true) + ROLE_NONE to true, + ) .map { (role, shouldThrow) -> rbacTest("test RBAC remove workspace access control: $role", role, shouldThrow) { every { workspaceRepository.findBy(any(), any()) } returns Optional.of(it.workspace) every { workspaceRepository.save(any()) } returns it.workspace workspaceServiceImpl.deleteWorkspaceAccessControl( - it.organization.id, it.workspace.id, "2$CONNECTED_DEFAULT_USER") + it.organization.id, + it.workspace.id, + "2$CONNECTED_DEFAULT_USER", + ) } } @@ -571,7 +635,8 @@ class WorkspaceServiceImplTests { ROLE_ADMIN to false, ROLE_VALIDATOR to true, ROLE_USER to false, - ROLE_NONE to true) + ROLE_NONE to true, + ) .map { (role, shouldThrow) -> rbacTest("test RBAC get workspace security users: $role", role, shouldThrow) { every { workspaceRepository.findBy(any(), any()) } returns Optional.of(it.workspace) @@ -584,7 +649,7 @@ class WorkspaceServiceImplTests { testName: String, role: String, shouldThrow: Boolean, - testLambda: (ctx: WorkspaceTestContext) -> Unit + testLambda: (ctx: WorkspaceTestContext) -> Unit, ): DynamicTest? { val organization = mockOrganization(username = CONNECTED_DEFAULT_USER, role = role) val solution = mockSolution(organization.id) @@ -604,12 +669,12 @@ class WorkspaceServiceImplTests { data class WorkspaceTestContext( val organization: Organization, val solution: Solution, - val workspace: Workspace + val workspace: Workspace, ) fun mockOrganization( username: String = CONNECTED_DEFAULT_USER, - role: String = ROLE_ADMIN + role: String = ROLE_ADMIN, ): Organization { return Organization( id = "organizationId", @@ -622,7 +687,10 @@ class WorkspaceServiceImplTests { accessControlList = mutableListOf( OrganizationAccessControl(id = username, role = role), - OrganizationAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN)))) + OrganizationAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN), + ), + ), + ) } fun mockSolution(organizationId: String): Solution { @@ -642,14 +710,17 @@ class WorkspaceServiceImplTests { mutableListOf(RunTemplate(id = "template", parameterGroups = mutableListOf())), security = SolutionSecurity( - ROLE_ADMIN, mutableListOf(SolutionAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN)))) + ROLE_ADMIN, + mutableListOf(SolutionAccessControl(CONNECTED_ADMIN_USER, ROLE_ADMIN)), + ), + ) } private fun mockWorkspaceCreateRequest( solutionId: String, workspaceName: String, roleName: String = CONNECTED_ADMIN_USER, - role: String = ROLE_ADMIN + role: String = ROLE_ADMIN, ) = WorkspaceCreateRequest( key = UUID.randomUUID().toString(), @@ -661,14 +732,17 @@ class WorkspaceServiceImplTests { accessControlList = mutableListOf( WorkspaceAccessControl(id = roleName, role = role), - WorkspaceAccessControl("2$roleName", "viewer")))) + WorkspaceAccessControl("2$roleName", "viewer"), + ), + ), + ) private fun mockWorkspace( organizationId: String, solutionId: String, workspaceName: String, roleName: String = CONNECTED_ADMIN_USER, - role: String = ROLE_ADMIN + role: String = ROLE_ADMIN, ): Workspace { return Workspace( id = UUID.randomUUID().toString(), @@ -687,6 +761,9 @@ class WorkspaceServiceImplTests { accessControlList = mutableListOf( WorkspaceAccessControl(id = roleName, role = role), - WorkspaceAccessControl("2$roleName", "viewer")))) + WorkspaceAccessControl("2$roleName", "viewer"), + ), + ), + ) } }