diff options
author | Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com> | 2020-10-14 14:01:03 +0200 |
---|---|---|
committer | Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com> | 2020-10-15 10:26:41 +0200 |
commit | 35d4e259c80c9edeb362de0af9bd77bd3f4412b0 (patch) | |
tree | 1f07f1d56114656a2460594be8b87fce86ee8bd2 | |
parent | 5e085985d5e333fbb000c37c8c508c0d46b7d7ee (diff) |
Add handling of CSAR with no TOSCA meta and no certificate.
Signed-off-by: Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com>
Change-Id: Ic9914b13e0bd5d9844849f20051d99d18e369ae9
Issue-ID: VNFSDK-481
-rw-r--r-- | Changelog.md | 4 | ||||
-rw-r--r-- | csarvalidation/src/main/java/org/onap/cvc/csar/CSARArchive.java | 16 | ||||
-rw-r--r-- | csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR130206IntegrationTest.java | 38 | ||||
-rw-r--r-- | csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-root.csar | bin | 0 -> 7473 bytes | |||
-rw-r--r-- | csarvalidation/src/test/resources/pnf/r130206/csar-no-cert-no-tosca-dir.csar | bin | 0 -> 6276 bytes |
5 files changed, 56 insertions, 2 deletions
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<String> 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<String> 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<CSARArchive.CSARError> 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<CSARArchive.CSARError> 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 Binary files differnew file mode 100644 index 0000000..66c1a71 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-root.csar 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 Binary files differnew file mode 100644 index 0000000..0b00af1 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r130206/csar-no-cert-no-tosca-dir.csar |