summaryrefslogtreecommitdiffstats
path: root/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR787966.java
diff options
context:
space:
mode:
Diffstat (limited to 'csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR787966.java')
-rw-r--r--csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR787966.java42
1 files changed, 31 insertions, 11 deletions
diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR787966.java b/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR787966.java
index 2be0db8..7a14709 100644
--- a/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR787966.java
+++ b/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR787966.java
@@ -22,7 +22,6 @@ import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.schema.OnapCommandSchema;
import org.onap.cvc.csar.CSARArchive;
import org.onap.cvc.csar.FileArchive;
-import org.onap.cvc.csar.PnfCSARArchive;
import org.onap.cvc.csar.cc.VTPValidateCSARBase;
import org.onap.cvc.csar.parser.SourcesParser;
import org.onap.cvc.csar.security.ShaHashCodeGenerator;
@@ -82,6 +81,13 @@ public class VTPValidateCSARR787966 extends VTPValidateCSARBase {
}
}
+ public static class CSARErrorUnableToFindSource extends CSARArchive.CSARError {
+ CSARErrorUnableToFindSource(String path) {
+ super("0x4006");
+ this.message = String.format("Source '%s' does not exist!", path);
+ }
+ }
+
@Override
protected void validateCSAR(CSARArchive csar) throws OnapCommandException {
@@ -102,28 +108,42 @@ public class VTPValidateCSARR787966 extends VTPValidateCSARBase {
private void validate(CSARArchive csar, Path csarRootDirectory ) throws IOException, NoSuchAlgorithmException {
- final PnfCSARArchive.PnfManifest manifest = (PnfCSARArchive.PnfManifest) csar.getManifest();
+ final CSARArchive.Manifest manifest = csar.getManifest();
final CSARArchive.TOSCAMeta toscaMeta = csar.getToscaMeta();
validateSecurityStructure(toscaMeta, csarRootDirectory, manifest);
validateSources(csarRootDirectory, manifest);
}
- private void validateSecurityStructure(CSARArchive.TOSCAMeta toscaMeta , Path csarRootDirectory, PnfCSARArchive.PnfManifest manifest) {
- final File entryCertificate = csarRootDirectory.resolve(toscaMeta.getEntryCertificate()).toFile();
- if (!entryCertificate.exists() && !manifest.getCms().isEmpty()) {
+ private void validateSecurityStructure(CSARArchive.TOSCAMeta toscaMeta , Path csarRootDirectory, CSARArchive.Manifest manifest) {
+ final Optional<File> entryCertificate = resolveCertificateFilePath(toscaMeta, csarRootDirectory);
+ if (!entryCertificate.isPresent() || !entryCertificate.get().exists() && !manifest.getCms().isEmpty()) {
this.errors.add(new CSARErrorUnableToFindCertificate());
- } else if (entryCertificate.exists() && manifest.getCms().isEmpty()) {
+ } else if (entryCertificate.get().exists() && manifest.getCms().isEmpty()) {
this.errors.add(new CSARErrorUnableToFindCmsSection());
}
}
- private void validateSources(Path csarRootDirectory, PnfCSARArchive.PnfManifest manifest) throws NoSuchAlgorithmException, IOException {
+ private Optional<File> resolveCertificateFilePath(CSARArchive.TOSCAMeta toscaMeta, Path csarRootDirectory) {
+ final String certificatePath = toscaMeta.getEntryCertificate();
+ if(certificatePath == null){
+ return Optional.empty();
+ } else {
+ return Optional.of(csarRootDirectory.resolve(certificatePath).toFile());
+ }
+ }
+
+ private void validateSources(Path csarRootDirectory, CSARArchive.Manifest manifest) throws NoSuchAlgorithmException, IOException {
final List<SourcesParser.Source> sources = manifest.getSources();
for (SourcesParser.Source source: sources){
- if(!source.getAlgorithm().isEmpty()) {
- validateSourceHashCode(csarRootDirectory, source);
- } else if(source.getAlgorithm().isEmpty() && !source.getHash().isEmpty()){
- this.errors.add(new CSARErrorUnableToFindAlgorithm(source.getValue()));
+ final Path sourcePath = csarRootDirectory.resolve(source.getValue());
+ if(!Files.exists(sourcePath)){
+ this.errors.add(new CSARErrorUnableToFindSource(source.getValue()));
+ } else {
+ if (!source.getAlgorithm().isEmpty()) {
+ validateSourceHashCode(csarRootDirectory, source);
+ } else if (source.getAlgorithm().isEmpty() && !source.getHash().isEmpty()) {
+ this.errors.add(new CSARErrorUnableToFindAlgorithm(source.getValue()));
+ }
}
}
}