Skip to content

Commit 2947c30

Browse files
committed
Check types for workspace file upload
1 parent ef1eac1 commit 2947c30

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ group = "com.cosmotech"
3939
version = scmVersion.version
4040

4141
val kotlinJvmTarget = 17
42-
val cosmotechApiCommonVersion = "0.1.22-SNAPSHOT"
42+
val cosmotechApiCommonVersion = "0.1.23-SNAPSHOT"
4343
val cosmotechApiAzureVersion = "0.1.6-SNAPSHOT"
4444
val azureSpringBootBomVersion = "3.14.0"
4545

@@ -49,6 +49,7 @@ allprojects {
4949
apply(plugin = "io.gitlab.arturbosch.detekt")
5050

5151
repositories {
52+
mavenLocal()
5253
maven {
5354
name = "GitHubPackages"
5455
url = uri("https://maven.pkg.github.com/Cosmo-Tech/cosmotech-api-common")

workspace/src/main/kotlin/com/cosmotech/workspace/azure/WorkspaceServiceImpl.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import com.cosmotech.api.rbac.getCommonRolesDefinition
3333
import com.cosmotech.api.rbac.getPermissions
3434
import com.cosmotech.api.rbac.model.RbacAccessControl
3535
import com.cosmotech.api.rbac.model.RbacSecurity
36+
import com.cosmotech.api.utils.ResourceScanner
3637
import com.cosmotech.api.utils.compareToAndMutateIfNeeded
3738
import com.cosmotech.api.utils.getCurrentAuthenticatedMail
3839
import com.cosmotech.api.utils.getCurrentAuthenticatedUserName
@@ -69,7 +70,8 @@ internal class WorkspaceServiceImpl(
6970
private val solutionService: SolutionApiService,
7071
private val azureStorageBlobServiceClient: BlobServiceClient,
7172
private val azureStorageBlobBatchClient: BlobBatchClient,
72-
private val csmRbac: CsmRbac
73+
private val csmRbac: CsmRbac,
74+
private val resourceScanner: ResourceScanner,
7375
) : CsmAzureService(), WorkspaceApiService {
7476

7577
override fun findAllWorkspaces(organizationId: String): List<Workspace> {
@@ -255,6 +257,7 @@ internal class WorkspaceServiceImpl(
255257
file.filename,
256258
destination)
257259

260+
resourceScanner.scanMimeTypes(file, csmPlatformProperties.upload.authorizedMimeTypes.workspaces)
258261
val fileRelativeDestinationBuilder = StringBuilder()
259262
if (destination.isNullOrBlank()) {
260263
fileRelativeDestinationBuilder.append(file.filename)

workspace/src/test/kotlin/com/cosmotech/workspace/azure/WorkspaceServiceImplTests.kt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.cosmotech.api.azure.sanitizeForAzureStorage
1010
import com.cosmotech.api.config.CsmPlatformProperties
1111
import com.cosmotech.api.exceptions.CsmResourceNotFoundException
1212
import com.cosmotech.api.rbac.CsmRbac
13+
import com.cosmotech.api.utils.ResourceScanner
1314
import com.cosmotech.api.utils.getCurrentAuthenticatedMail
1415
import com.cosmotech.organization.api.OrganizationApiService
1516
import com.cosmotech.solution.api.SolutionApiService
@@ -44,6 +45,7 @@ class WorkspaceServiceImplTests {
4445
@MockK private lateinit var azureStorageBlobBatchClient: BlobBatchClient
4546

4647
@RelaxedMockK private lateinit var csmRbac: CsmRbac
48+
@RelaxedMockK private lateinit var resourceScanner: ResourceScanner
4749

4850
@Suppress("unused") @MockK private lateinit var cosmosTemplate: CosmosTemplate
4951

@@ -59,10 +61,30 @@ class WorkspaceServiceImplTests {
5961
solutionService,
6062
azureStorageBlobServiceClient,
6163
azureStorageBlobBatchClient,
62-
csmRbac))
64+
csmRbac,
65+
resourceScanner,
66+
))
6367
mockkStatic(::getCurrentAuthenticatedMail)
6468
every { getCurrentAuthenticatedMail(csmPlatformProperties) } returns "[email protected]"
6569

70+
val csmPlatformPropertiesUpload = mockk<CsmPlatformProperties.Upload>()
71+
val csmPlatformPropertiesAuthorizedMimeTypes =
72+
mockk<CsmPlatformProperties.Upload.AuthorizedMimeTypes>()
73+
every { csmPlatformPropertiesAuthorizedMimeTypes.workspaces } returns
74+
listOf(
75+
"application/zip",
76+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
77+
"application/x-tika-ooxml",
78+
"text/csv",
79+
"text/plain",
80+
"text/x-yaml",
81+
)
82+
every { csmPlatformPropertiesUpload.authorizedMimeTypes } returns
83+
csmPlatformPropertiesAuthorizedMimeTypes
84+
every { csmPlatformProperties.upload } returns csmPlatformPropertiesUpload
85+
86+
every { workspaceServiceImpl getProperty "csmPlatformProperties" } returns csmPlatformProperties
87+
6688
MockKAnnotations.init(this, relaxUnitFun = true)
6789
this.csmRbac = mockk<CsmRbac>(relaxed = true)
6890
}

0 commit comments

Comments
 (0)