@@ -47,15 +47,15 @@ import com.cosmotech.organization.domain.Organization
4747import com.cosmotech.organization.domain.OrganizationAccessControl
4848import com.cosmotech.organization.domain.OrganizationSecurity
4949import com.ninjasquad.springmockk.SpykBean
50- import com.redis.om.spring.RediSearchIndexer
50+ import com.redis.om.spring.indexing. RediSearchIndexer
5151import com.redis.testcontainers.RedisStackContainer
5252import io.mockk.clearAllMocks
5353import io.mockk.every
5454import io.mockk.impl.annotations.MockK
5555import io.mockk.junit5.MockKExtension
5656import io.mockk.mockk
5757import io.mockk.mockkStatic
58- import java.io.File
58+ import java.io.InputStream
5959import java.util.*
6060import kotlin.test.assertEquals
6161import kotlinx.coroutines.test.advanceUntilIdle
@@ -72,13 +72,13 @@ import org.junit.runner.RunWith
7272import org.slf4j.LoggerFactory
7373import org.springframework.beans.factory.annotation.Autowired
7474import org.springframework.boot.test.context.SpringBootTest
75- import org.springframework.core.io.ByteArrayResource
7675import org.springframework.test.context.ActiveProfiles
7776import org.springframework.test.context.junit.jupiter.SpringExtension
7877import org.springframework.test.context.junit4.SpringRunner
7978import org.springframework.test.util.ReflectionTestUtils
8079import org.springframework.web.context.request.RequestContextHolder
8180import org.springframework.web.context.request.ServletRequestAttributes
81+ import org.springframework.web.multipart.MultipartFile
8282import redis.clients.jedis.HostAndPort
8383import redis.clients.jedis.UnifiedJedis
8484
@@ -105,7 +105,6 @@ class DatasetServiceRBACTest : CsmRedisTestBase() {
105105 lateinit var dataset: Dataset
106106 lateinit var dataset2: Dataset
107107 lateinit var datasetSaved: Dataset
108- lateinit var retrievedDataset1: Dataset
109108
110109 lateinit var jedis: UnifiedJedis
111110 lateinit var organization: Organization
@@ -243,26 +242,29 @@ class DatasetServiceRBACTest : CsmRedisTestBase() {
243242 materializeTwingraph()
244243
245244 val datasetTwinGraphQuery = DatasetTwinGraphQuery (" MATCH (n) RETURN n" )
246- val resource = ByteArrayResource (" " .toByteArray())
247- every { resourceScanner.scanMimeTypes(any(), any()) } returns Unit
245+
246+ every {
247+ resourceScanner.scanMimeTypes(any(), any(), listOf (" text/csv" , " text/plain" ))
248+ } returns Unit
248249 every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL
249250
251+ val file = mockk<MultipartFile >(relaxed = true )
252+ val inputStream = this ::class .java.getResourceAsStream(" /integrationTest.zip" )
253+ every { file.originalFilename } returns " integrationTest.zip"
254+ every { file.inputStream } returns inputStream!!
250255 if (shouldThrow) {
251256 val exception =
252257 assertThrows<CsmAccessForbiddenException > {
253258 datasetApiService.twingraphBatchUpdate(
254- organizationSaved.id!! ,
255- datasetSaved.id!! ,
256- datasetTwinGraphQuery,
257- resource)
259+ organizationSaved.id!! , datasetSaved.id!! , datasetTwinGraphQuery, file)
258260 }
259261 assertEquals(
260262 " RBAC ${organizationSaved.id!! } - User does not have permission $PERMISSION_READ " ,
261263 exception.message)
262264 } else {
263265 assertDoesNotThrow {
264266 datasetApiService.twingraphBatchUpdate(
265- organizationSaved.id!! , datasetSaved.id!! , datasetTwinGraphQuery, resource )
267+ organizationSaved.id!! , datasetSaved.id!! , datasetTwinGraphQuery, file )
266268 }
267269 }
268270 }
@@ -288,18 +290,18 @@ class DatasetServiceRBACTest : CsmRedisTestBase() {
288290 materializeTwingraph()
289291
290292 val datasetTwinGraphQuery = DatasetTwinGraphQuery (" MATCH (n) RETURN n" )
291- val resource = ByteArrayResource (" " .toByteArray())
292- every { resourceScanner.scanMimeTypes(any(), any()) } returns Unit
293+ every {
294+ resourceScanner.scanMimeTypes(any(), any(), listOf (" text/csv" , " text/plain" ))
295+ } returns Unit
293296 every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL
294-
297+ val file = mockk<MultipartFile >(relaxed = true )
298+ every { file.originalFilename } returns " nullEmptyStream.zip"
299+ every { file.inputStream } returns InputStream .nullInputStream()
295300 if (shouldThrow) {
296301 val exception =
297302 assertThrows<CsmAccessForbiddenException > {
298303 datasetApiService.twingraphBatchUpdate(
299- organizationSaved.id!! ,
300- datasetSaved.id!! ,
301- datasetTwinGraphQuery,
302- resource)
304+ organizationSaved.id!! , datasetSaved.id!! , datasetTwinGraphQuery, file)
303305 }
304306 if (role == ROLE_NONE ) {
305307 assertEquals(
@@ -313,7 +315,7 @@ class DatasetServiceRBACTest : CsmRedisTestBase() {
313315 } else {
314316 assertDoesNotThrow {
315317 datasetApiService.twingraphBatchUpdate(
316- organizationSaved.id!! , datasetSaved.id!! , datasetTwinGraphQuery, resource )
318+ organizationSaved.id!! , datasetSaved.id!! , datasetTwinGraphQuery, file )
317319 }
318320 }
319321 }
@@ -1663,25 +1665,28 @@ class DatasetServiceRBACTest : CsmRedisTestBase() {
16631665 val dataset =
16641666 makeDatasetWithRole(role = ROLE_ADMIN , sourceType = DatasetSourceType .File )
16651667 datasetSaved = datasetApiService.createDataset(organizationSaved.id!! , dataset)
1666- val fileName = this ::class .java.getResource(" /integrationTest.zip" )?.file
1667- val file = File (fileName!! )
1668- val resource = ByteArrayResource (file.readBytes())
1669-
1668+ every {
1669+ resourceScanner.scanMimeTypes(any(), any(), listOf (" text/csv" , " text/plain" ))
1670+ } returns Unit
16701671 every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL
16711672
1673+ val file = mockk<MultipartFile >(relaxed = true )
1674+ val inputStream = this ::class .java.getResourceAsStream(" /integrationTest.zip" )
1675+ every { file.originalFilename } returns " integrationTest.zip"
1676+ every { file.inputStream } returns inputStream!!
1677+
16721678 if (shouldThrow) {
16731679 val exception =
16741680 assertThrows<CsmAccessForbiddenException > {
16751681 datasetApiService.uploadTwingraph(
1676- organizationSaved.id!! , datasetSaved.id!! , resource )
1682+ organizationSaved.id!! , datasetSaved.id!! , file )
16771683 }
16781684 assertEquals(
16791685 " RBAC ${organizationSaved.id!! } - User does not have permission $PERMISSION_READ " ,
16801686 exception.message)
16811687 } else {
16821688 assertDoesNotThrow {
1683- datasetApiService.uploadTwingraph(
1684- organizationSaved.id!! , datasetSaved.id!! , resource)
1689+ datasetApiService.uploadTwingraph(organizationSaved.id!! , datasetSaved.id!! , file)
16851690 }
16861691 }
16871692 }
@@ -1704,17 +1709,23 @@ class DatasetServiceRBACTest : CsmRedisTestBase() {
17041709 organizationSaved = organizationApiService.registerOrganization(organization)
17051710 val dataset = makeDatasetWithRole(role = role, sourceType = DatasetSourceType .File )
17061711 datasetSaved = datasetApiService.createDataset(organizationSaved.id!! , dataset)
1707- val fileName = this ::class .java.getResource(" /integrationTest.zip" )?.file
1708- val file = File (fileName!! )
1709- val resource = ByteArrayResource (file.readBytes())
1712+ every {
1713+ resourceScanner.scanMimeTypes(any(), any(), listOf (" text/csv" , " text/plain" ))
1714+ } returns Unit
1715+ every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL
1716+
1717+ val file = mockk<MultipartFile >(relaxed = true )
1718+ val inputStream = this ::class .java.getResourceAsStream(" /integrationTest.zip" )
1719+ every { file.originalFilename } returns " integrationTest.zip"
1720+ every { file.inputStream } returns inputStream!!
17101721
17111722 every { getCurrentAccountIdentifier(any()) } returns TEST_USER_MAIL
17121723
17131724 if (shouldThrow) {
17141725 val exception =
17151726 assertThrows<CsmAccessForbiddenException > {
17161727 datasetApiService.uploadTwingraph(
1717- organizationSaved.id!! , datasetSaved.id!! , resource )
1728+ organizationSaved.id!! , datasetSaved.id!! , file )
17181729 }
17191730 if (role == ROLE_NONE ) {
17201731 assertEquals(
@@ -1727,8 +1738,7 @@ class DatasetServiceRBACTest : CsmRedisTestBase() {
17271738 }
17281739 } else {
17291740 assertDoesNotThrow {
1730- datasetApiService.uploadTwingraph(
1731- organizationSaved.id!! , datasetSaved.id!! , resource)
1741+ datasetApiService.uploadTwingraph(organizationSaved.id!! , datasetSaved.id!! , file)
17321742 }
17331743 }
17341744 }
@@ -2312,6 +2322,7 @@ class DatasetServiceRBACTest : CsmRedisTestBase() {
23122322 ioTypes = listOf (),
23132323 id = " c-AbCdEf123" )
23142324 }
2325+
23152326 fun makeDataset (
23162327 id : String ,
23172328 name : String ,
0 commit comments