summaryrefslogtreecommitdiffstats
path: root/csarvalidation/src
diff options
context:
space:
mode:
authorBartosz Gardziejewski <bartosz.gardziejewski@nokia.com>2020-10-14 14:01:03 +0200
committerBartosz Gardziejewski <bartosz.gardziejewski@nokia.com>2020-10-15 10:26:41 +0200
commit35d4e259c80c9edeb362de0af9bd77bd3f4412b0 (patch)
tree1f07f1d56114656a2460594be8b87fce86ee8bd2 /csarvalidation/src
parent5e085985d5e333fbb000c37c8c508c0d46b7d7ee (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
Diffstat (limited to 'csarvalidation/src')
-rw-r--r--csarvalidation/src/main/java/org/onap/cvc/csar/CSARArchive.java16
-rw-r--r--csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR130206IntegrationTest.java38
-rw-r--r--csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-root.csarbin0 -> 7473 bytes
-rw-r--r--csarvalidation/src/test/resources/pnf/r130206/csar-no-cert-no-tosca-dir.csarbin0 -> 6276 bytes
4 files changed, 52 insertions, 2 deletions
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
new file mode 100644
index 0000000..66c1a71
--- /dev/null
+++ b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-root.csar
Binary files 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
--- /dev/null
+++ b/csarvalidation/src/test/resources/pnf/r130206/csar-no-cert-no-tosca-dir.csar
Binary files differ