diff --git a/ice-rest-catalog/src/test/java/com/altinity/ice/rest/catalog/DockerScenarioBasedIT.java b/ice-rest-catalog/src/test/java/com/altinity/ice/rest/catalog/DockerScenarioBasedIT.java index f3fc088..8bfbf92 100644 --- a/ice-rest-catalog/src/test/java/com/altinity/ice/rest/catalog/DockerScenarioBasedIT.java +++ b/ice-rest-catalog/src/test/java/com/altinity/ice/rest/catalog/DockerScenarioBasedIT.java @@ -169,7 +169,8 @@ protected ScenarioTestRunner createScenarioRunner(String scenarioName) throws Ex templateVars.put("CLI_CONFIG", "/tmp/ice-cli.yaml"); templateVars.put("SCENARIO_DIR", "/scenarios/" + scenarioName); templateVars.put("MINIO_ENDPOINT", ""); - templateVars.put("CATALOG_URI", "http://localhost:5000"); + templateVars.put( + "CATALOG_URI", "http://" + catalog.getHost() + ":" + catalog.getMappedPort(5000)); return new ScenarioTestRunner(scenariosDir, templateVars); } diff --git a/ice-rest-catalog/src/test/resources/scenarios/empty-namespace/run.sh.tmpl b/ice-rest-catalog/src/test/resources/scenarios/empty-namespace/run.sh.tmpl new file mode 100644 index 0000000..e37d93d --- /dev/null +++ b/ice-rest-catalog/src/test/resources/scenarios/empty-namespace/run.sh.tmpl @@ -0,0 +1,23 @@ +#!/bin/bash +set -e + +echo "Running empty namespace test..." + +for namespace in $INVALID_NAMESPACES; do + if ! {{ICE_CLI}} -c {{CLI_CONFIG}} create-namespace "$namespace"; then + echo "OK create-namespace failed as expected" + else + echo "FAIL create-namespace should have failed with invalid namespace: $namespace" + exit 1 + fi +done + +namespaces=$(curl {{CATALOG_URI}}/v1/namespaces) +expected='{"namespaces":[],"next-page-token":null}' + +if [ "$namespaces" == "$expected" ]; then + echo "OK list of namespaces is empty" +else + echo "FAIL list of namespaces is not empty: $namespaces" + exit 1 +fi diff --git a/ice-rest-catalog/src/test/resources/scenarios/empty-namespace/scenario.yaml b/ice-rest-catalog/src/test/resources/scenarios/empty-namespace/scenario.yaml new file mode 100644 index 0000000..13cdd6c --- /dev/null +++ b/ice-rest-catalog/src/test/resources/scenarios/empty-namespace/scenario.yaml @@ -0,0 +1,6 @@ +name: "Empty Namespace Creation" +description: "Ensures empty namespaces cannot be created" + +env: + # space-separate list of namespaces that should cause an error with create-namespace + INVALID_NAMESPACES: ".. .test .a. a..b" \ No newline at end of file diff --git a/ice/src/main/java/com/altinity/ice/cli/Main.java b/ice/src/main/java/com/altinity/ice/cli/Main.java index 014d2ec..a10e1da 100644 --- a/ice/src/main/java/com/altinity/ice/cli/Main.java +++ b/ice/src/main/java/com/altinity/ice/cli/Main.java @@ -628,7 +628,18 @@ void createNamespace( boolean createNamespaceIfNotExists) throws IOException { try (RESTCatalog catalog = loadCatalog()) { - CreateNamespace.run(catalog, Namespace.of(name.split("[.]")), createNamespaceIfNotExists); + String[] split = name.split("[.]"); + for (String level : split) { + if (level.isEmpty()) { + throw new IllegalArgumentException( + "Invalid namespace name: '.' cannot separate empty names"); + } + } + if (split.length == 0) { + throw new IllegalArgumentException("Invalid namespace name: name cannot be empty"); + } + + CreateNamespace.run(catalog, Namespace.of(split), createNamespaceIfNotExists); } }