From 46b38a2350bfd29331f9a18529c23b2d672a13d8 Mon Sep 17 00:00:00 2001 From: sharath reddy Date: Thu, 26 May 2022 19:07:03 +0530 Subject: Changed code to not construct the path from user-controlled data. Issue-ID: VNFSDK-834 Signed-off-by: sharath reddy Change-Id: If9eb5ee546436ed9c4495bac8706883ee1ca98ce Signed-off-by: sharath reddy --- .../src/main/java/org/onap/vtp/scenario/VTPScenarioResource.java | 8 ++++++-- .../src/test/java/org/onap/vtp/VTPScenarioResourceTest.java | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/VTPScenarioResource.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/VTPScenarioResource.java index 915cd144..1a8de345 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/VTPScenarioResource.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/VTPScenarioResource.java @@ -431,8 +431,12 @@ public class VTPScenarioResource extends VTPResource{ } try { - FileUtils.deleteQuietly(new File(VTP_YAML_STORE, scenarioName)); - FileUtils.deleteDirectory(scenarioDir); + if(FileUtils.directoryContains(new File(VTP_YAML_STORE), new File(scenarioName))) { + FileUtils.deleteQuietly(new File(VTP_YAML_STORE, scenarioName)); + } + if(FileUtils.directoryContains(new File(VTP_YAML_STORE), scenarioDir)) { + FileUtils.deleteDirectory(scenarioDir); + } } catch (IOException e) { LOG.error("Delete scenario yaml {} failed", scenarioName, e); throw new VTPException( diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/VTPScenarioResourceTest.java b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/VTPScenarioResourceTest.java index 55457795..b743615b 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/VTPScenarioResourceTest.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/test/java/org/onap/vtp/VTPScenarioResourceTest.java @@ -108,9 +108,11 @@ public class VTPScenarioResourceTest { @Test public void testDeleteScenario() throws Exception { + String yamlStore = vtpScenarioResource.VTP_YAML_STORE; + vtpScenarioResource.VTP_YAML_STORE = "/tmp"; vtpScenarioResource.deleteScenario("demo-registry.yaml"); + vtpScenarioResource.VTP_YAML_STORE = yamlStore; } - @Test(expected = NullPointerException.class) public void testStorageTestcases() throws Exception { -- cgit 1.2.3-korg