From 35d4e259c80c9edeb362de0af9bd77bd3f4412b0 Mon Sep 17 00:00:00 2001 From: Bartosz Gardziejewski Date: Wed, 14 Oct 2020 14:01:03 +0200 Subject: Add handling of CSAR with no TOSCA meta and no certificate. Signed-off-by: Bartosz Gardziejewski Change-Id: Ic9914b13e0bd5d9844849f20051d99d18e369ae9 Issue-ID: VNFSDK-481 --- Changelog.md | 4 +++ .../main/java/org/onap/cvc/csar/CSARArchive.java | 16 +++++++-- .../VTPValidateCSARR130206IntegrationTest.java | 38 +++++++++++++++++++++ .../resources/pnf/r130206/csar-cert-in-root.csar | Bin 0 -> 7473 bytes .../pnf/r130206/csar-no-cert-no-tosca-dir.csar | Bin 0 -> 6276 bytes 5 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-root.csar create mode 100644 csarvalidation/src/test/resources/pnf/r130206/csar-no-cert-no-tosca-dir.csar diff --git a/Changelog.md b/Changelog.md index cc04a01..f55bc84 100644 --- a/Changelog.md +++ b/Changelog.md @@ -95,3 +95,7 @@ All notable changes to this project will be documented in this file. - https://jira.onap.org/browse/VNFSDK-596 ## [1.2.14] + +## Fixed +- Fixed rule R130206 handling of CSARs with no TOSCA meta and no Certificate in root directory + - https://jira.onap.org/browse/VNFSDK-481 diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/CSARArchive.java b/csarvalidation/src/main/java/org/onap/cvc/csar/CSARArchive.java index 70cd8f3..05f2070 100644 --- a/csarvalidation/src/main/java/org/onap/cvc/csar/CSARArchive.java +++ b/csarvalidation/src/main/java/org/onap/cvc/csar/CSARArchive.java @@ -531,6 +531,13 @@ public class CSARArchive implements AutoCloseable { } } + public static class CSARErrorNoManifestsFound extends CSARError { + public CSARErrorNoManifestsFound() { + super("0x0016"); + this.message = "No manifest file found in CSAR!"; + } + } + /** * Holds the CSAR meta data values in both Modes * @@ -1091,7 +1098,10 @@ public class CSARArchive implements AutoCloseable { //manifest files = this.tempDir.toFile().listFiles((dir, name) -> name.endsWith(MF)); - if (files.length > 1) { + if (files.length == 0) { + errors.add(new CSARErrorNoManifestsFound()); + this.toscaMeta.setEntryManifestMf(null); + } else if (files.length > 1) { List fileNames = new ArrayList<>(); for (File f: files) { fileNames.add(f.getName()); @@ -1118,7 +1128,9 @@ public class CSARArchive implements AutoCloseable { //certificate files = this.tempDir.toFile().listFiles((dir, name) -> name.endsWith(CERT)); - if (files.length > 1) { + if (files.length == 0) { + this.toscaMeta.setEntryCertificate(null); + } else if (files.length > 1) { List fileNames = new ArrayList<>(); for (File f: files) { fileNames.add(f.getName()); diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR130206IntegrationTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR130206IntegrationTest.java index 443a61a..2d6d058 100644 --- a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR130206IntegrationTest.java +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR130206IntegrationTest.java @@ -428,4 +428,42 @@ public class VTPValidateCSARR130206IntegrationTest { "Unable to find cms signature!" ); } + + @Test + public void shouldReturnNoCertificationErrorWhenCertIsOnlyInRoot() throws Exception { + + // given + configureTestCase(testCase, "pnf/r130206/csar-cert-in-root.csar", "vtp-validate-csar-r130206.yaml", IS_PNF); + + // when + testCase.execute(); + + // then + List errors = testCase.getErrors(); + + // This test returns other errors that are connected with missing tosca entry, + // in order to simplify testing, assertion only checks if certificate in root was found and used to validate CMS + assertThat(convertToMessagesList(errors)).contains( + "File has invalid signature!" + ); + } + + @Test + public void shouldReturnCertificateNotFoundErrorWhenCertIsNotPresentInCmsInRootAndTocsaDirectoryIsMissing() throws Exception { + + // given + configureTestCase(testCase, "pnf/r130206/csar-no-cert-no-tosca-dir.csar", "vtp-validate-csar-r130206.yaml", IS_PNF); + + // when + testCase.execute(); + + // then + List errors = testCase.getErrors(); + + // This test returns other errors that are connected with missing tosca entry, + // in order to simplify testing, assertion only checks if "certificate not found" error was reported + assertThat(convertToMessagesList(errors)).contains( + "Unable to find cert file!" + ); + } } diff --git a/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-root.csar b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-root.csar new file mode 100644 index 0000000..66c1a71 Binary files /dev/null and b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-root.csar differ diff --git a/csarvalidation/src/test/resources/pnf/r130206/csar-no-cert-no-tosca-dir.csar b/csarvalidation/src/test/resources/pnf/r130206/csar-no-cert-no-tosca-dir.csar new file mode 100644 index 0000000..0b00af1 Binary files /dev/null and b/csarvalidation/src/test/resources/pnf/r130206/csar-no-cert-no-tosca-dir.csar differ -- cgit 1.2.3-korg