Skip to content

Commit 225f6fd

Browse files
committed
check dataset id list format
1 parent 9a2f930 commit 225f6fd

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

scenariorun/src/main/kotlin/com/cosmotech/scenariorun/dataset/DatasetUtils.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package com.cosmotech.scenariorun.dataset
44

55
import com.cosmotech.api.config.CsmPlatformProperties
6+
import com.cosmotech.api.exceptions.CsmClientException
67
import com.cosmotech.connector.api.ConnectorApiService
78
import com.cosmotech.connector.domain.Connector
89
import com.cosmotech.dataset.api.DatasetApiService
@@ -84,6 +85,9 @@ private fun addParameterValue(
8485

8586
internal fun getDatasetIdListFromValue(paramValue: String): List<String> {
8687
if (paramValue.startsWith("[")) {
88+
if (!(paramValue.last().equals(']'))) {
89+
throw CsmClientException("Malformed dataset id list: must start with [ and end with ]")
90+
}
8791
val datasetIds = paramValue.substring(1, paramValue.length - 1)
8892
return datasetIds.split(",")
8993
} else {

scenariorun/src/test/kotlin/com/cosmotech/scenariorun/ContainerFactoryTests.kt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import com.cosmotech.api.config.CsmPlatformProperties.CsmPlatformAzure.CsmPlatfo
1111
import com.cosmotech.api.config.CsmPlatformProperties.CsmPlatformAzure.CsmPlatformAzureEventBus.Authentication.SharedAccessPolicyDetails
1212
import com.cosmotech.api.config.CsmPlatformProperties.CsmPlatformAzure.CsmPlatformAzureEventBus.Authentication.Strategy.SHARED_ACCESS_POLICY
1313
import com.cosmotech.api.config.CsmPlatformProperties.CsmPlatformAzure.CsmPlatformAzureEventBus.Authentication.Strategy.TENANT_CLIENT_CREDENTIALS
14+
import com.cosmotech.api.exceptions.CsmClientException
1415
import com.cosmotech.connector.api.ConnectorApiService
1516
import com.cosmotech.connector.domain.Connector
1617
import com.cosmotech.connector.domain.Connector.IoTypes
@@ -1468,6 +1469,19 @@ class ContainerFactoryTests {
14681469
parametersDatasetEnvTest(getScenarioTwoDatasetIds(), "3", "param3")
14691470
}
14701471

1472+
@Test
1473+
fun `Build all containers for a Scenario DATASETID malformed list`() {
1474+
val scenario = getScenarioMalformedDatasetIds()
1475+
val datasets = listOf(getDataset(), getDataset2(), getDataset3())
1476+
val connectors = listOf(getConnector(), getConnector2(), getConnector3())
1477+
val workspace = getWorkspace()
1478+
val solution = getSolutionDatasetIds()
1479+
assertThrows(CsmClientException::class.java) {
1480+
factory.buildContainersPipeline(
1481+
scenario, datasets, connectors, workspace, getOrganization(), solution, CSM_SIMULATION_ID)
1482+
}
1483+
}
1484+
14711485
@Test
14721486
fun `Full get Start Info csmSimulationId`() {
14731487
val startInfo = getStartInfoFromIds()
@@ -2603,6 +2617,37 @@ class ContainerFactoryTests {
26032617
))
26042618
}
26052619

2620+
private fun getScenarioMalformedDatasetIds(): Scenario {
2621+
return Scenario(
2622+
id = "AQWXSZ",
2623+
name = "Test Scenario",
2624+
runTemplateId = "testruntemplate",
2625+
datasetList = listOf("1"),
2626+
parametersValues =
2627+
listOf(
2628+
ScenarioRunTemplateParameterValue(
2629+
parameterId = "param1",
2630+
value = "valParam1",
2631+
),
2632+
ScenarioRunTemplateParameterValue(
2633+
parameterId = "param2",
2634+
value = "[",
2635+
),
2636+
ScenarioRunTemplateParameterValue(
2637+
parameterId = "param3",
2638+
value = "2",
2639+
),
2640+
ScenarioRunTemplateParameterValue(
2641+
parameterId = "param4",
2642+
value = "3",
2643+
),
2644+
ScenarioRunTemplateParameterValue(
2645+
parameterId = "param5",
2646+
value = "999",
2647+
),
2648+
))
2649+
}
2650+
26062651
private fun getScenarioTwoDatasetsAndDatasetIds(): Scenario {
26072652
return Scenario(
26082653
id = "AQWXSZ",

0 commit comments

Comments
 (0)