diff options
author | 2020-12-15 09:59:13 +0100 | |
---|---|---|
committer | 2020-12-29 11:12:18 +0100 | |
commit | 25673a3551f2bf15f23afbbfe986947c6a975c91 (patch) | |
tree | 548a4fa35f28280a8f49dbb3e28b7636522f764b /csarvalidation/src/test/java/org | |
parent | d2f0552ea27a481bdbe9099ee52422bca8b6b314 (diff) |
Add individual artifact validation using common cert.
Signed-off-by: Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com>
Change-Id: I2aa4e862f3d343a3f452e1564dc8a97a34960b83
Issue-ID: VNFSDK-714
Diffstat (limited to 'csarvalidation/src/test/java/org')
3 files changed, 198 insertions, 32 deletions
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 7337a29..4d6adc4 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 @@ -113,7 +113,7 @@ public class VTPValidateCSARR130206IntegrationTest { List<CSARArchive.CSARError> errors = testCase.getErrors(); assertThat(errors.size()).isEqualTo(1); assertThat(convertToMessagesList(errors)).containsExactlyInAnyOrder( - "File has invalid signature!" + "Manifest file has invalid signature!" ); } @@ -130,7 +130,7 @@ public class VTPValidateCSARR130206IntegrationTest { List<CSARArchive.CSARError> errors = testCase.getErrors(); assertThat(errors.size()).isEqualTo(1); assertThat(convertToMessagesList(errors)).containsExactlyInAnyOrder( - "File has invalid signature!" + "Manifest file has invalid signature!" ); } @@ -165,7 +165,7 @@ public class VTPValidateCSARR130206IntegrationTest { assertThat(errors.size()).isEqualTo(2); assertThat(convertToMessagesList(errors)).containsExactlyInAnyOrder( "Source 'Artifacts/Other/my_script.csh' has wrong hash!", - "File has invalid signature!" + "Manifest file has invalid signature!" ); } @@ -183,7 +183,7 @@ public class VTPValidateCSARR130206IntegrationTest { assertThat(errors.size()).isEqualTo(2); assertThat(convertToMessagesList(errors)).containsExactlyInAnyOrder( "Source 'Artifacts/Deployment/Measurements/PM_Dictionary.yml' has wrong hash!", - "File has invalid signature!" + "Manifest file has invalid signature!" ); } @@ -198,9 +198,7 @@ public class VTPValidateCSARR130206IntegrationTest { // then List<CSARArchive.CSARError> errors = testCase.getErrors(); - assertThat(errors.size()).isEqualTo(3); assertThat(convertToMessagesList(errors)).containsExactlyInAnyOrder( - "Source 'Artifacts/Deployment/Events/RadioNode_Pnf_v1.yaml' has wrong hash!", "Unable to find ETSI-Entry-Certificate in Tosca file", "Certificate present in root catalog despite the TOSCA.meta file" ); @@ -236,7 +234,7 @@ public class VTPValidateCSARR130206IntegrationTest { List<CSARArchive.CSARError> errors = testCase.getErrors(); assertThat(errors.size()).isEqualTo(3); assertThat(convertToMessagesList(errors)).containsExactlyInAnyOrder( - "File has invalid signature!", + "Manifest file has invalid signature!", "ETSI-Entry-Certificate entry in Tosca.meta is defined despite the certificate is included in the signature container", "ETSI-Entry-Certificate certificate present despite the certificate is included in the signature container" ); @@ -256,7 +254,7 @@ public class VTPValidateCSARR130206IntegrationTest { assertThat(errors.size()).isEqualTo(4); assertThat(convertToMessagesList(errors)).containsExactlyInAnyOrder( "Source 'Artifacts/Informational/user_guide.txt' has wrong hash!", - "File has invalid signature!", + "Manifest file has invalid signature!", "ETSI-Entry-Certificate entry in Tosca.meta is defined despite the certificate is included in the signature container", "ETSI-Entry-Certificate certificate present despite the certificate is included in the signature container" ); @@ -278,7 +276,7 @@ public class VTPValidateCSARR130206IntegrationTest { "ETSI-Entry-Certificate entry in Tosca.meta is defined despite the certificate is included in the signature container", "ETSI-Entry-Certificate certificate present despite the certificate is included in the signature container", "Certificate present in root catalog despite the certificate is included in the signature container", - "File has invalid signature!" + "Manifest file has invalid signature!" ); } @@ -300,7 +298,7 @@ public class VTPValidateCSARR130206IntegrationTest { "ETSI-Entry-Certificate certificate present despite the certificate is included in the signature container", "Certificate present in root catalog despite the certificate is included in the signature container", "Source 'Artifacts/Informational/user_guide.txt' has wrong hash!", - "File has invalid signature!" + "Manifest file has invalid signature!" ); } @@ -318,7 +316,7 @@ public class VTPValidateCSARR130206IntegrationTest { assertThat(errors.size()).isEqualTo(2); assertThat(convertToMessagesList(errors)).containsExactlyInAnyOrder( "Certificate present in root catalog despite the certificate is included in the signature container", - "File has invalid signature!" + "Manifest file has invalid signature!" ); } @@ -337,7 +335,7 @@ public class VTPValidateCSARR130206IntegrationTest { assertThat(convertToMessagesList(errors)).containsExactlyInAnyOrder( "Certificate present in root catalog despite the certificate is included in the signature container", "Source 'Artifacts/Informational/user_guide.txt' has wrong hash!", - "File has invalid signature!" + "Manifest file has invalid signature!" ); } @@ -355,7 +353,7 @@ public class VTPValidateCSARR130206IntegrationTest { assertThat(errors.size()).isEqualTo(2); assertThat(convertToMessagesList(errors)).containsExactlyInAnyOrder( "Certificate present in root catalog despite the TOSCA.meta file", - "File has invalid signature!" + "Manifest file has invalid signature!" ); } @@ -374,7 +372,7 @@ public class VTPValidateCSARR130206IntegrationTest { assertThat(convertToMessagesList(errors)).containsExactlyInAnyOrder( "Certificate present in root catalog despite the TOSCA.meta file", "Source 'Artifacts/Deployment/Yang_module/yang-module1.yang' has wrong hash!", - "File has invalid signature!" + "Manifest file has invalid signature!" ); } @@ -391,7 +389,7 @@ public class VTPValidateCSARR130206IntegrationTest { List<CSARArchive.CSARError> errors = testCase.getErrors(); assertThat(errors.size()).isEqualTo(1); assertThat(convertToMessagesList(errors)).containsExactlyInAnyOrder( - "File has invalid signature!" + "Manifest file has invalid signature!" ); } @@ -444,7 +442,7 @@ public class VTPValidateCSARR130206IntegrationTest { // 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!" + "Manifest file has invalid signature!" ); } @@ -480,7 +478,25 @@ public class VTPValidateCSARR130206IntegrationTest { List<CSARArchive.CSARError> errors = testCase.getErrors(); assertThat(convertToMessagesList(errors)).containsExactlyInAnyOrder( - "File has invalid signature!" + "Manifest file has invalid signature!" + ); + } + + @Test + public void shouldReturnErrorWhenCertIsPresentInCmsAndIndividualArtifactHaveIncorrectSignature() throws Exception { + + // given + configureTestCaseForRule130206("pnf/r130206/csar-cert-in-cms-valid-with-incorrect-signature-of-individual-artifact.csar"); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + + assertThat(convertToMessagesList(errors)).containsExactlyInAnyOrder( + "Manifest file has invalid signature!", + "Source 'Files/Scripts/my_script.sh' has incorrect signature!" ); } @@ -498,8 +514,9 @@ public class VTPValidateCSARR130206IntegrationTest { assertThat(convertToMessagesList(errors)).containsExactlyInAnyOrder( "Source 'Files/Scripts/my_script.sh' has certificate tag, but unable to find signature tag!", + "Source 'Files/Scripts/my_script.sh' has 'certificate' tag, pointing to non existing file!. Pointed file 'Files/Scripts/my_script.cert'", "Source 'Files/pnf-sw-information/pnf-sw-information.yaml' has signature tag, but unable to find certificate tag!", - "File has invalid signature!" + "Manifest file has invalid signature!" ); } @@ -516,17 +533,73 @@ public class VTPValidateCSARR130206IntegrationTest { List<CSARArchive.CSARError> errors = testCase.getErrors(); assertThat(convertToMessagesList(errors)).containsExactlyInAnyOrder( - "Source 'Files/Yang_module/mynetconf.yang' has signature tag, pointing to non existing file!", - "Source 'Files/Yang_module/mynetconf.yang' has certificate tag, pointing to non existing file!", - "File has invalid signature!" + "Source 'Files/Yang_module/mynetconf.yang' has 'signature' tag, pointing to non existing file!. Pointed file 'Files/Yang_module/mynetconf.sig.cms'", + "Source 'Files/Yang_module/mynetconf.yang' has 'certificate' tag, pointing to non existing file!. Pointed file 'Files/Yang_module/mynetconf.cert'", + "Manifest file has invalid signature!" ); } @Test - public void shouldReturnErrorWhenCertIsPresentInCmsAndIndividualArtifactHaveIncorrectSignature() throws Exception { + public void shouldReturnErrorWhenCertIsPresentInCmsAndIndividualArtifactHaveSignatureInWrongDirectory() throws Exception { // given - configureTestCaseForRule130206("pnf/r130206/csar-cert-in-cms-valid-with-incorrect-signature-of-individual-artifact.csar"); + configureTestCaseForRule130206("pnf/r130206/csar-cert-in-cms-valid-with-signature-for-individual-artifact-in-wrong-directory.csar"); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + + assertThat(convertToMessagesList(errors)).containsExactlyInAnyOrder( + "Source 'Files/ChangeLog.txt' has 'signature' file located in wrong directory, directory: 'Files/pnf-sw-information/pnf-sw-information.sig.cms'.Signature should be in same directory as source file!", + "Source 'Files/ChangeLog.txt' has 'certificate' file located in wrong directory, directory: 'Files/pnf-sw-information/pnf-sw-information.cert'.Signature should be in same directory as source file!", + "Manifest file has invalid signature!" + ); + } + + @Test + public void shouldReturnErrorWhenCertIsPresentInCmsAndIndividualArtifactHaveSignatureWithIncorrectName() throws Exception { + + // given + configureTestCaseForRule130206("pnf/r130206/csar-cert-in-cms-valid-with-signature-with-wrong-name-for-individual-artifact.csar"); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + + assertThat(convertToMessagesList(errors)).containsExactlyInAnyOrder( + "Source 'Files/ChangeLog.txt' has 'signature' file with wrong name, signature name: 'pnf-sw-information.sig.cms'.Signature should have same name as source file!", + "Source 'Files/ChangeLog.txt' has 'certificate' file with wrong name, signature name: 'pnf-sw-information.cert'.Signature should have same name as source file!", + "Manifest file has invalid signature!" + ); + } + + @Test + public void shouldUseCommonCertWhenCertIsPresentInToscaAndIndividualArtifactHaveOnlySignature() throws Exception { + + // given + configureTestCaseForRule130206("pnf/r130206/csar-cert-in-tosca-individual-signature.csar"); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + + assertThat(convertToMessagesList(errors)).containsExactlyInAnyOrder( + "Manifest file has invalid signature!", + "Source 'Artifacts/Other/my_script.csh' has incorrect signature!" + ); + } + + @Test + public void shouldReportErrorWhenCertIsPresentInToscaAndIndividualArtifactHaveSignatureAndIncorrectCert() throws Exception { + + // given + configureTestCaseForRule130206("pnf/r130206/csar-cert-in-tosca-individual-signature-nonexistent-cert.csar"); // when testCase.execute(); @@ -535,8 +608,8 @@ public class VTPValidateCSARR130206IntegrationTest { List<CSARArchive.CSARError> errors = testCase.getErrors(); assertThat(convertToMessagesList(errors)).containsExactlyInAnyOrder( - "Source 'Files/ChangeLog.txt' has incorrect signature!", - "File has invalid signature!" + "Manifest file has invalid signature!", + "Source 'Artifacts/Other/my_script.csh' has 'certificate' tag, pointing to non existing file!. Pointed file 'Artifacts/Other/my_script.cert'" ); } diff --git a/csarvalidation/src/test/java/org/onap/functional/CsarValidationUtility.java b/csarvalidation/src/test/java/org/onap/functional/CsarValidationUtility.java index 11292d8..d9cc50b 100644 --- a/csarvalidation/src/test/java/org/onap/functional/CsarValidationUtility.java +++ b/csarvalidation/src/test/java/org/onap/functional/CsarValidationUtility.java @@ -36,6 +36,7 @@ public final class CsarValidationUtility { public static final String CERTIFICATION_RULE = "r130206"; public static final String PM_DICTIONARY_YAML_RULE = "r816745"; public static final String MANIFEST_FILE_RULE = "r01123"; + public static final String NON_MANO_FILES_RULE = "r146092"; public static final String OPERATION_STATUS_FAILED = "FAILED"; public static final String OPERATION_STATUS_PASS = "PASS"; diff --git a/csarvalidation/src/test/java/org/onap/functional/PnfValidationFunctionalTest.java b/csarvalidation/src/test/java/org/onap/functional/PnfValidationFunctionalTest.java index 576f763..2038eca 100644 --- a/csarvalidation/src/test/java/org/onap/functional/PnfValidationFunctionalTest.java +++ b/csarvalidation/src/test/java/org/onap/functional/PnfValidationFunctionalTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2020 Nokia * <p> * Licensed under the Apache License, Version 2.0 (the "License"); @@ -27,6 +27,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.onap.cvc.csar.cc.sol004.IntegrationTestUtils.absoluteFilePath; import static org.onap.functional.CsarValidationUtility.CERTIFICATION_RULE; import static org.onap.functional.CsarValidationUtility.MANIFEST_FILE_RULE; +import static org.onap.functional.CsarValidationUtility.NON_MANO_FILES_RULE; import static org.onap.functional.CsarValidationUtility.OPERATION_STATUS_FAILED; import static org.onap.functional.CsarValidationUtility.OPERATION_STATUS_PASS; import static org.onap.functional.CsarValidationUtility.PM_DICTIONARY_YAML_RULE; @@ -86,7 +87,7 @@ public class PnfValidationFunctionalTest { List<OnapCliValidationResponseWrapper.ValidationResultWrapper.ValidationErrorWrapper> expectedErrors = List.of( createExpectedError(CERTIFICATION_RULE, "0x4007", - "File has invalid signature!"), + "Manifest file has invalid signature!"), createExpectedError(CERTIFICATION_RULE, "0x4004", "Source 'Files/pnf-sw-information/pnf-sw-information.yaml' has wrong hash!"), createExpectedError(CERTIFICATION_RULE, "0x4011", @@ -123,7 +124,7 @@ public class PnfValidationFunctionalTest { List<OnapCliValidationResponseWrapper.ValidationResultWrapper.ValidationErrorWrapper> expectedErrors = List.of( createExpectedError(CERTIFICATION_RULE, "0x4007", - "File has invalid signature!"), + "Manifest file has invalid signature!"), createExpectedError(CERTIFICATION_RULE, "0x4004", "Source 'Files/pnf-sw-information/pnf-sw-information.yaml' has wrong hash!"), createExpectedError(CERTIFICATION_RULE, "0x4011", @@ -189,7 +190,7 @@ public class PnfValidationFunctionalTest { List<OnapCliValidationResponseWrapper.ValidationResultWrapper.ValidationErrorWrapper> expectedErrors = List.of( createExpectedError(CERTIFICATION_RULE, "0x4007", - "File has invalid signature!"), + "Manifest file has invalid signature!"), createExpectedError(CERTIFICATION_RULE, "0x4004", "Source 'Files/pnf-sw-information/pnf-sw-information.yaml' has wrong hash!"), createExpectedError(CERTIFICATION_RULE, "0x4011", @@ -231,14 +232,14 @@ public class PnfValidationFunctionalTest { List<OnapCliValidationResponseWrapper.ValidationResultWrapper.ValidationErrorWrapper> expectedCertificationErrors = List.of( createExpectedError(CERTIFICATION_RULE, "0x4020", - "Source 'Files/ChangeLog.txt' has incorrect signature!"), + "Source 'Files/Scripts/my_script.sh' has incorrect signature!"), createExpectedError(CERTIFICATION_RULE, "0x4007", - "File has invalid signature!") + "Manifest file has invalid signature!") ); List<OnapCliValidationResponseWrapper.ValidationResultWrapper.ValidationErrorWrapper> expectedManifestErrors = List.of( createExpectedError(MANIFEST_FILE_RULE, "0x1001", - "file(s): [Files/pnf-sw-information/pnf-sw-information.cert, Files/pnf-sw-information/pnf-sw-information.sig.cms] available in CSAR, but cannot be found in Manifest as Source", + "file(s): [Files/Scripts/my_script.cert, Files/Scripts/my_script.sig.cms] available in CSAR, but cannot be found in Manifest as Source", "TOSCA-Metadata" ) ); @@ -268,6 +269,97 @@ public class PnfValidationFunctionalTest { verifyThatOperationFinishedWithoutAnyError(cli); } + @Test + public void shouldReportThatIndividualArtifactsHaveMultipleIncorrectCertificatesAndSignatures() throws URISyntaxException { + // given + List<OnapCliValidationResponseWrapper.ValidationResultWrapper.ValidationErrorWrapper> expectedCertificationErrors = + List.of( + createExpectedError(CERTIFICATION_RULE, "0x4018", + "Source 'Artifacts/Deployment/Measurements/PM_Dictionary.yml' has 'signature' tag, pointing to non existing file!. Pointed file 'Artifacts/Deployment/Measurements/PM_Dictionary.sig.cms'"), + createExpectedError(CERTIFICATION_RULE, "0x4023", + "Source 'Artifacts/Deployment/Yang_module/yang-module1.yang' has 'signature' file with wrong name, signature name: 'yang-module.sig.cms'.Signature should have same name as source file!"), + createExpectedError(CERTIFICATION_RULE, "0x4023", + "Source 'Artifacts/Deployment/Yang_module/yang-module1.yang' has 'certificate' file with wrong name, signature name: 'yang-module.cert'.Signature should have same name as source file!"), + createExpectedError(CERTIFICATION_RULE, "0x4020", + "Source 'Artifacts/Other/my_script.csh' has incorrect signature!"), + createExpectedError(CERTIFICATION_RULE, "0x4022", + "Source 'Artifacts/Informational/user_guide.txt' has 'signature' file located in wrong directory, directory: 'Artifacts/user_guide.sig.cms'.Signature should be in same directory as source file!"), + createExpectedError(CERTIFICATION_RULE, "0x4022", + "Source 'Artifacts/Informational/user_guide.txt' has 'certificate' file located in wrong directory, directory: 'Artifacts/user_guide.cert'.Signature should be in same directory as source file!"), + createExpectedError(CERTIFICATION_RULE, "0x4007", + "Manifest file has invalid signature!") + ); + List<OnapCliValidationResponseWrapper.ValidationResultWrapper.ValidationErrorWrapper> expectedManifestErrors = + List.of( + createExpectedError(MANIFEST_FILE_RULE, "0x1001", + "file(s): [TOSCA-Metadata/TOSCA.meta, Definitions/MainServiceTemplate.yaml, Artifacts/Deployment/Yang_module/yang-module2.yang, Artifacts/Deployment/Yang_module/yang-module.cert, Artifacts/Deployment/Yang_module/yang-module.sig.cms, Artifacts/ChangeLog.txt, Artifacts/sample-pnf.cert] available in CSAR, but cannot be found in Manifest as Source", + "TOSCA-Metadata" + ) + ); + List<OnapCliValidationResponseWrapper.ValidationResultWrapper.ValidationErrorWrapper> expectedPnfDictionaryErrors = + List.of( + createExpectedError(PM_DICTIONARY_YAML_RULE, "0x2000", + "Fail to load PM_Dictionary With error: PM_Dictionary YAML file is empty", + "Artifacts/Deployment/Measurements/PM_Dictionary.yml" + ) + ); + List<OnapCliValidationResponseWrapper.ValidationResultWrapper.ValidationErrorWrapper> expectedNonManoFilesErrors = + List.of( + createExpectedError(NON_MANO_FILES_RULE, "0x2002", + "Missing. Entry [Source under onap_ves_events]", + "MainServiceTemplate.mf" + ), + createExpectedError(NON_MANO_FILES_RULE, "0x2002", + "Missing. Entry [onap_yang_module]", + "MainServiceTemplate.mf" + ), + createExpectedError(NON_MANO_FILES_RULE, "0x2002", + "Missing. Entry [Source under onap_others]]", + "MainServiceTemplate.mf" + ), + createExpectedError(NON_MANO_FILES_RULE, "0x2002", + "Missing. Entry [Source under onap_pm_dictionary]", + "MainServiceTemplate.mf" + ) + ); + OnapCliWrapper cli = new OnapCliWrapper(createPnfValidationRequestInfo( + "pnf/r130206/csar-cert-in-tosca-multiple-individual-signature.csar" + )); + + // when + cli.handle(); + + // then + final OnapCliValidationResponseWrapper result = getCliCommandValidationResult(cli); + + assertThat(result.criteria).isEqualTo(OPERATION_STATUS_FAILED); + result.results.forEach((ruleValidationResult)->{ + assertThat(ruleValidationResult.warnings).isEmpty(); + switch (ruleValidationResult.vnfreqName) { + case CERTIFICATION_RULE: + assertThat(ruleValidationResult.errors) + .containsAll(expectedCertificationErrors); + break; + case MANIFEST_FILE_RULE: + assertThat(ruleValidationResult.errors) + .containsAll(expectedManifestErrors); + break; + case PM_DICTIONARY_YAML_RULE: + assertThat(ruleValidationResult.errors) + .containsAll(expectedPnfDictionaryErrors); + break; + case NON_MANO_FILES_RULE: + assertThat(ruleValidationResult.errors) + .containsAll(expectedNonManoFilesErrors); + break; + default: + assertThat(ruleValidationResult.errors).isEmpty(); + break; + } + }); + verifyThatOperationFinishedWithoutAnyError(cli); + } + private String[] createPnfValidationRequestInfo(String csarPath) throws URISyntaxException { return new String[]{ "--product", "onap-dublin", |