Skip to content

Commit 68429de

Browse files
committed
[PROD-12947] Add integration tests
1 parent 8f541b9 commit 68429de

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

dataset/src/integrationTest/kotlin/com/cosmotech/dataset/service/DatasetServiceIntegrationTest.kt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,48 @@ class DatasetServiceIntegrationTest : CsmRedisTestBase() {
397397
assertEquals(0, datasetList.size)
398398
}
399399

400+
@Test
401+
fun `PROD-12947 - test find All Datasets as Organization User`() {
402+
organizationSaved = organizationApiService.registerOrganization(organization)
403+
404+
// Create a dataset that current user should not see because he does not have permission to
405+
val numberOfDatasets = 200
406+
IntRange(1, numberOfDatasets).forEach {
407+
datasetApiService.createDataset(
408+
organizationSaved.id!!,
409+
makeDatasetWithRole(
410+
organizationId = organizationSaved.id!!, userName = "[email protected]"))
411+
}
412+
413+
// Explicitly set connected user information
414+
every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL
415+
every { getCurrentAuthenticatedUserName(csmPlatformProperties) } returns "test.user"
416+
every { getCurrentAuthenticatedRoles(any()) } returns listOf(ROLE_ORGANIZATION_USER)
417+
418+
logger.info("should not find a dataset because of lake of permission")
419+
var datasetList = datasetApiService.findAllDatasets(organizationSaved.id!!, null, null)
420+
assertEquals(0, datasetList.size)
421+
422+
// Create a dataset that current user should not see because it has been created under another
423+
// organization
424+
val newOrganization = organizationApiService.registerOrganization(makeOrganizationWithRole())
425+
val datasetNotReachableByCurrentUserBecausePartOfAnotherOrganization =
426+
datasetApiService.createDataset(
427+
newOrganization.id!!, makeDatasetWithRole(organizationId = newOrganization.id!!))
428+
assertNotNull(datasetNotReachableByCurrentUserBecausePartOfAnotherOrganization)
429+
logger.info(
430+
"should not find a dataset because:" +
431+
" one was created with no permission assigned " +
432+
" one was created in another organization")
433+
datasetList = datasetApiService.findAllDatasets(organizationSaved.id!!, null, null)
434+
assertEquals(0, datasetList.size)
435+
436+
logger.info("should find only one dataset")
437+
datasetList = datasetApiService.findAllDatasets(newOrganization.id!!, null, null)
438+
assertEquals(1, datasetList.size)
439+
assertEquals(datasetNotReachableByCurrentUserBecausePartOfAnotherOrganization, datasetList[0])
440+
}
441+
400442
@Test
401443
fun `test find All Datasets with different pagination params`() {
402444
organizationSaved = organizationApiService.registerOrganization(organization)

dataset/src/main/kotlin/com/cosmotech/dataset/repository/DatasetRepository.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ interface DatasetRepository : RedisDocumentRepository<Dataset, String> {
2020
@Sanitize @Param("datasetId") datasetId: String
2121
): Optional<Dataset>
2222

23-
@Query("(@organizationId:{\$organizationId}) \$securityConstraint")
23+
@Query("(@organizationId:{\$organizationId}) \$securityConstraint")
2424
fun findByOrganizationId(
2525
@Sanitize @Param("organizationId") organizationId: String,
2626
@SecurityConstraint @Param("securityConstraint") securityConstraint: String,

runner/src/main/kotlin/com/cosmotech/runner/service/RunnerService.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import org.springframework.stereotype.Component
4949

5050
@Component
5151
@Scope("prototype")
52+
@Suppress("TooManyFunctions")
5253
class RunnerService(
5354
private val runnerRepository: RunnerRepository,
5455
private val organizationApiService: OrganizationApiServiceInterface,
@@ -228,7 +229,7 @@ class RunnerService(
228229
runner.runTemplateId!!))
229230
throw IllegalArgumentException("Run Template not found: ${runner.runTemplateId}")
230231

231-
val beforeMutateDatasetList = this.runner.datasetList
232+
val beforeMutateDatasetList = this.runner.datasetList ?: mutableListOf()
232233

233234
val excludeFields =
234235
arrayOf(

0 commit comments

Comments
 (0)