From 167aea9954cfe9e6528671dd37445d4fc3378a97 Mon Sep 17 00:00:00 2001 From: Bogumil Zebek Date: Tue, 17 Sep 2019 10:24:53 +0200 Subject: Non mano artifacts Change-Id: I4d7eefc999f9cd6cb5255b764da3c5ae7e84f0af Issue-ID: VNFSDK-476 Signed-off-by: Zebek Bogumil --- .../cvc/csar/cc/sol004/VTPValidateCSARR130206.java | 34 +++++++++++++++++++++ .../VTPValidateCSARR130206IntegrationTest.java | 8 +++-- .../resources/pnf/r130206/csar-option1-valid.csar | Bin 7324 -> 7530 bytes 3 files changed, 39 insertions(+), 3 deletions(-) (limited to 'csarvalidation/src') diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR130206.java b/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR130206.java index 2d85e35..e36314a 100644 --- a/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR130206.java +++ b/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR130206.java @@ -38,7 +38,9 @@ import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.security.NoSuchAlgorithmException; +import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; @@ -102,6 +104,13 @@ public class VTPValidateCSARR130206 extends VTPValidateCSARBase { } } + public static class CSARErrorContentMismatch extends CSARArchive.CSARError { + CSARErrorContentMismatch() { + super("0x4008"); + this.message = "Mismatch between contents of non-mano-artifact-sets and source files of the package"; + } + } + @Override protected void validateCSAR(CSARArchive csar) throws OnapCommandException { @@ -126,12 +135,37 @@ public class VTPValidateCSARR130206 extends VTPValidateCSARBase { validateSecurityStructure(csar, csarRootDirectory); validateSources(csarRootDirectory, manifest); + final Map>> nonMano = manifest.getNonMano(); + final List sources = manifest.getSources(); + + validateNonManoCohesionWithSources(nonMano, sources); + final File manifestMfFile = csar.getManifestMfFile(); if (manifestMfFile != null) { validateFileSignature(manifestMfFile); } } + private void validateNonManoCohesionWithSources(final Map>> nonMano, final List sources) { + + final Collection>> values = nonMano.values(); + final List nonManoSourcePaths = values.stream() + .map(Map::values) + .flatMap(Collection::stream) + .flatMap(List::stream) + .filter(it -> !it.isEmpty()) + .collect(Collectors.toList()); + + final List sourcePaths = sources.stream() + .map(SourcesParser.Source::getValue) + .collect(Collectors.toList()); + + if(!sourcePaths.containsAll(nonManoSourcePaths)){ + this.errors.add(new CSARErrorContentMismatch()); + } + + } + private void validateFileSignature(File manifestMfFile) { final boolean isValid = this.manifestFileSignatureValidator.isValid(manifestMfFile); if (!isValid) { 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 90da946..036e169 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 @@ -73,9 +73,10 @@ public class VTPValidateCSARR130206IntegrationTest { // then List errors = testCase.getErrors(); - assertThat(errors.size()).isEqualTo(1); + assertThat(errors.size()).isEqualTo(2); assertThat(convertToMessagesList(errors)).contains( - "File has invalid CMS signature!" + "File has invalid CMS signature!", + "Mismatch between contents of non-mano-artifact-sets and source files of the package" ); } @@ -90,12 +91,13 @@ public class VTPValidateCSARR130206IntegrationTest { // then List errors = testCase.getErrors(); - assertThat(errors.size()).isEqualTo(5); + assertThat(errors.size()).isEqualTo(6); assertThat(convertToMessagesList(errors)).contains( "Unable to find CMS section in manifest!", "Source 'Definitions/MainServiceTemplate.yaml' has wrong hash!", "Source 'Artifacts/Other/my_script.csh' has hash, but unable to find algorithm tag!", "Unable to calculate digest - file missing: Artifacts/NonExisting2.txt", + "Mismatch between contents of non-mano-artifact-sets and source files of the package", "File has invalid CMS signature!" ); } diff --git a/csarvalidation/src/test/resources/pnf/r130206/csar-option1-valid.csar b/csarvalidation/src/test/resources/pnf/r130206/csar-option1-valid.csar index 7cca18d..08c3605 100644 Binary files a/csarvalidation/src/test/resources/pnf/r130206/csar-option1-valid.csar and b/csarvalidation/src/test/resources/pnf/r130206/csar-option1-valid.csar differ -- cgit 1.2.3-korg