diff options
author | sharath reddy <bs.reddy@huawei.com> | 2022-05-26 19:07:03 +0530 |
---|---|---|
committer | sharath reddy <bs.reddy@huawei.com> | 2022-06-01 14:26:44 +0530 |
commit | 46b38a2350bfd29331f9a18529c23b2d672a13d8 (patch) | |
tree | 16351134bfcda6092a9b98c3f830c99bf0480b56 | |
parent | 0bf80c915d8c4e7b2dabee463459d8198fdeacc6 (diff) |
Changed code to not construct the path from user-controlled data.
Issue-ID: VNFSDK-834
Signed-off-by: sharath reddy <bs.reddy@huawei.com>
Change-Id: If9eb5ee546436ed9c4495bac8706883ee1ca98ce
Signed-off-by: sharath reddy <bs.reddy@huawei.com>
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 { |