diff options
author | Bogumil Zebek <bogumil.zebek@nokia.com> | 2021-01-20 14:53:39 +0100 |
---|---|---|
committer | Zebek Bogumil <bogumil.zebek@nokia.com> | 2021-01-20 14:53:39 +0100 |
commit | 398dcd3e75651e047e307a3207fb2b8dc1207ab0 (patch) | |
tree | 14b0e7fbf8445b2a207d094fc3525efe2b0e82db /csarvalidation/src/test | |
parent | 59010375b15438297c5e25e6864fd88b76c80760 (diff) |
Add release parameter to rules
- All vnf/pnf rules where updated. Release parameter was added into the info->metadata section.
- VNFSDK validation logic supports optional release parameter. Parameter defines which rules should be used during validation process.
By default: all rules are used during validation process.
--release parameter defines which rules (parent with ancestors) should be used.
For example: if user run validation with --release=dublin, then amsterdam, casablanca and dublin rules will be used during validation.
Rules order is defined in the vnfreqs.properties file.
Change-Id: I3e9dc1e7a899fa51c266808cbcb73e04a2e252cc
Issue-ID: VNFSDK-731
Signed-off-by: Zebek Bogumil <bogumil.zebek@nokia.com>
Diffstat (limited to 'csarvalidation/src/test')
4 files changed, 498 insertions, 159 deletions
diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/CsarValidatorTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/CsarValidatorTest.java new file mode 100644 index 0000000..d4f2891 --- /dev/null +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/CsarValidatorTest.java @@ -0,0 +1,212 @@ +/* + * Copyright 2021 Nokia + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.cvc.csar; + +import org.apache.commons.lang3.tuple.Pair; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.cli.fw.error.OnapCommandException; +import org.onap.cvc.csar.oclip.Command; +import org.onap.cvc.csar.oclip.CommandFactory; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + +@RunWith(MockitoJUnitRunner.class) +public class CsarValidatorTest { + + private static final String PATH_TO_CSAR_FILE = "pathToCsarFile"; + private static final String PRODUCT = "onap-vtp"; + private static final boolean IS_PNF = true; + private static final String AMSTERDAM_RULE = "rAmsterdam"; + private static final String CASABLANCA_RULE = "rCasablanca"; + private static final String DUBLIN_RULE = "rDublin"; + private static final String FRANKFURT_RULE = "rFrankfurt"; + private static final String GUILIN_RULE = "rGuilin"; + private static final String HONOLULU_RULE = "rHonolulu"; + private static final String AMSTERDAM_RELEASE = "amsterdam"; + private static final String CASABLANCA_RELEASE = "casablanca"; + private static final String DUBLIN_RELEASE = "dublin"; + private static final String FRANKFURT_RELEASE = "frankfurt"; + private static final String GUILIN_RELEASE = "guilin"; + private static final String HONOLULU_RELEASE = "honolulu"; + @Mock + private CommandFactory commandFactory; + private final ReleasesResolver releasesResolver = ReleasesResolver.create("amsterdam,casablanca,dublin,frankfurt,guilin,honolulu"); + private final RulesToValidate rulesToValidate = new RulesToValidate(""); + private final List<String> activeRules = List.of(AMSTERDAM_RULE, CASABLANCA_RULE, DUBLIN_RULE, FRANKFURT_RULE, GUILIN_RULE, HONOLULU_RULE); + + private final List<String> ignoreCodes = List.of(); + + private CsarValidator csarValidator; + + + @Before + public void setUp() { + this.csarValidator = new CsarValidator(commandFactory, ignoreCodes, activeRules, releasesResolver, rulesToValidate); + } + + @Test + public void shouldReportAnErrorWhenReleaseIsNotRecognized() throws OnapCommandException { + + // given + Command cmdAmsterdam = givenCmdFor(AMSTERDAM_RULE, AMSTERDAM_RELEASE); + Command cmdCasablanca = givenCmdFor(CASABLANCA_RULE, CASABLANCA_RELEASE); + Command cmdDublin = givenCmdFor(DUBLIN_RULE, DUBLIN_RELEASE); + Command cmdFrankfurt = givenCmdFor(FRANKFURT_RULE, FRANKFURT_RELEASE); + Command cmdGuilin = givenCmdFor(GUILIN_RULE, GUILIN_RELEASE); + Command cmdHonolulu = givenCmdFor(HONOLULU_RULE, HONOLULU_RELEASE); + + // when + final Pair<Boolean, List<VTPValidateCSAR.CSARValidation.Result>> validationResult = csarValidator.validate(new CsarValidator.ValidationContext(PATH_TO_CSAR_FILE, PRODUCT, "validationResult", IS_PNF)); + + // then + assertThat(validationResult.getLeft()).isFalse(); + verify(cmdAmsterdam, never()).run(); + verify(cmdCasablanca, never()).run(); + verify(cmdDublin, never()).run(); + verify(cmdFrankfurt, never()).run(); + verify(cmdGuilin, never()).run(); + verify(cmdHonolulu, never()).run(); + } + + @Test + public void shouldValidateCsarUsingAllRulesWhenReleaseIsLatest() throws OnapCommandException { + + // given + Command cmdAmsterdam = givenCmdFor(AMSTERDAM_RULE, AMSTERDAM_RELEASE); + Command cmdCasablanca = givenCmdFor(CASABLANCA_RULE, CASABLANCA_RELEASE); + Command cmdDublin = givenCmdFor(DUBLIN_RULE, DUBLIN_RELEASE); + Command cmdFrankfurt = givenCmdFor(FRANKFURT_RULE, FRANKFURT_RELEASE); + Command cmdGuilin = givenCmdFor(GUILIN_RULE, GUILIN_RELEASE); + Command cmdHonolulu = givenCmdFor(HONOLULU_RULE, HONOLULU_RELEASE); + + // when + csarValidator.validate(new CsarValidator.ValidationContext(PATH_TO_CSAR_FILE, PRODUCT, "latest", IS_PNF)); + + // then + verify(cmdAmsterdam).run(); + verify(cmdCasablanca).run(); + verify(cmdDublin).run(); + verify(cmdFrankfurt).run(); + verify(cmdGuilin).run(); + verify(cmdHonolulu).run(); + } + + @Test + public void shouldValidateCsarUsingOnlyAmsterdamRulesWhenReleaseIsAmsterdam() throws OnapCommandException { + // given + Command cmdAmsterdam = givenCmdFor(AMSTERDAM_RULE, AMSTERDAM_RELEASE); + Command cmdCasablanca = givenCmdFor(CASABLANCA_RULE, CASABLANCA_RELEASE); + Command cmdDublin = givenCmdFor(DUBLIN_RULE, DUBLIN_RELEASE); + Command cmdFrankfurt = givenCmdFor(FRANKFURT_RULE, FRANKFURT_RELEASE); + Command cmdGuilin = givenCmdFor(GUILIN_RULE, GUILIN_RELEASE); + Command cmdHonolulu = givenCmdFor(HONOLULU_RULE, HONOLULU_RELEASE); + + // when + csarValidator.validate(new CsarValidator.ValidationContext(PATH_TO_CSAR_FILE, PRODUCT, AMSTERDAM_RELEASE, IS_PNF)); + + // then + verify(cmdAmsterdam).run(); + verify(cmdCasablanca, never()).run(); + verify(cmdDublin, never()).run(); + verify(cmdFrankfurt, never()).run(); + verify(cmdGuilin, never()).run(); + verify(cmdHonolulu, never()).run(); + } + + @Test + public void shouldValidateCsarUsingCasablancaWithAncestorRulesWhenReleaseIsCasablanca() throws OnapCommandException { + // given + Command cmdAmsterdam = givenCmdFor(AMSTERDAM_RULE, AMSTERDAM_RELEASE); + Command cmdCasablanca = givenCmdFor(CASABLANCA_RULE, CASABLANCA_RELEASE); + Command cmdDublin = givenCmdFor(DUBLIN_RULE, DUBLIN_RELEASE); + Command cmdFrankfurt = givenCmdFor(FRANKFURT_RULE, FRANKFURT_RELEASE); + Command cmdGuilin = givenCmdFor(GUILIN_RULE, GUILIN_RELEASE); + Command cmdHonolulu = givenCmdFor(HONOLULU_RULE, HONOLULU_RELEASE); + + // when + csarValidator.validate(new CsarValidator.ValidationContext(PATH_TO_CSAR_FILE, PRODUCT, CASABLANCA_RELEASE, IS_PNF)); + + // then + verify(cmdAmsterdam).run(); + verify(cmdCasablanca).run(); + verify(cmdDublin, never()).run(); + verify(cmdFrankfurt, never()).run(); + verify(cmdGuilin, never()).run(); + verify(cmdHonolulu, never()).run(); + } + + @Test + public void shouldValidateCsarUsingDublinWithAncestorRulesWhenReleaseIsDublin() throws OnapCommandException { + // given + Command cmdAmsterdam = givenCmdFor(AMSTERDAM_RULE, AMSTERDAM_RELEASE); + Command cmdCasablanca = givenCmdFor(CASABLANCA_RULE, CASABLANCA_RELEASE); + Command cmdDublin = givenCmdFor(DUBLIN_RULE, DUBLIN_RELEASE); + Command cmdFrankfurt = givenCmdFor(FRANKFURT_RULE, FRANKFURT_RELEASE); + Command cmdGuilin = givenCmdFor(GUILIN_RULE, GUILIN_RELEASE); + Command cmdHonolulu = givenCmdFor(HONOLULU_RULE, HONOLULU_RELEASE); + + // when + csarValidator.validate(new CsarValidator.ValidationContext(PATH_TO_CSAR_FILE, PRODUCT, DUBLIN_RELEASE, IS_PNF)); + + // then + verify(cmdAmsterdam).run(); + verify(cmdCasablanca).run(); + verify(cmdDublin).run(); + verify(cmdFrankfurt, never()).run(); + verify(cmdGuilin, never()).run(); + verify(cmdHonolulu, never()).run(); + } + + @Test + public void shouldValidateCsarUsingHonoluluWithAncestorRulesWhenReleaseIsHonolulu() throws OnapCommandException { + // given + Command cmdAmsterdam = givenCmdFor(AMSTERDAM_RULE, AMSTERDAM_RELEASE); + Command cmdCasablanca = givenCmdFor(CASABLANCA_RULE, CASABLANCA_RELEASE); + Command cmdDublin = givenCmdFor(DUBLIN_RULE, DUBLIN_RELEASE); + Command cmdFrankfurt = givenCmdFor(FRANKFURT_RULE, FRANKFURT_RELEASE); + Command cmdGuilin = givenCmdFor(GUILIN_RULE, GUILIN_RELEASE); + Command cmdHonolulu = givenCmdFor(HONOLULU_RULE, HONOLULU_RELEASE); + + // when + csarValidator.validate(new CsarValidator.ValidationContext(PATH_TO_CSAR_FILE, PRODUCT, HONOLULU_RELEASE, IS_PNF)); + + // then + verify(cmdAmsterdam).run(); + verify(cmdCasablanca).run(); + verify(cmdDublin).run(); + verify(cmdFrankfurt).run(); + verify(cmdGuilin).run(); + verify(cmdHonolulu).run(); + } + + private Command givenCmdFor(String rule, String release) throws OnapCommandException { + Command cmd = Mockito.mock(Command.class); + Mockito.when(commandFactory.createForPnf(rule, PATH_TO_CSAR_FILE, PRODUCT)).thenReturn(cmd); + Mockito.when(cmd.getRelease()).thenReturn(release); + Mockito.when(cmd.run()).thenReturn(List.of()); + + return cmd; + } +} diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/ReleaseResolverTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/ReleaseResolverTest.java new file mode 100644 index 0000000..a3ad6e7 --- /dev/null +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/ReleaseResolverTest.java @@ -0,0 +1,85 @@ +/* + * Copyright 2021 Nokia + * <p> + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.cvc.csar; + + +import org.junit.Test; + +import java.io.IOException; +import java.util.Properties; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class ReleaseResolverTest { + + private static final Properties APP_CONFIGURATION = new Properties(); + + static { + try { + APP_CONFIGURATION.load(VTPValidateCSAR.class.getResourceAsStream("/vnfreqs.properties")); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private ReleasesResolver releaseResolver = ReleasesResolver.create(APP_CONFIGURATION.getProperty("releases.order")); + + @Test + public void shouldResolveReleasesForAmsterdam() { + assertThat(releaseResolver.resolveWithAncestors("amsterdam")) + .containsExactlyInAnyOrder("amsterdam"); + } + + @Test + public void shouldResolveReleasesForCasablanca() { + assertThat(releaseResolver.resolveWithAncestors("casablanca")) + .containsExactlyInAnyOrder("amsterdam", "casablanca"); + + } + + @Test + public void shouldResolveReleasesForDublin() { + assertThat(releaseResolver.resolveWithAncestors("dublin")) + .containsExactlyInAnyOrder("amsterdam", "casablanca", "dublin"); + } + + @Test + public void shouldResolveReleasesForGuilin() { + assertThat(releaseResolver.resolveWithAncestors("guilin")) + .containsExactlyInAnyOrder("amsterdam", "casablanca", "dublin", "frankfurt", "guilin"); + } + + @Test + public void shouldResolveReleasesForHonolulu() { + assertThat(releaseResolver.resolveWithAncestors("honolulu")) + .containsExactlyInAnyOrder("amsterdam", "casablanca", "dublin", "frankfurt", "guilin", "honolulu"); + } + + @Test + public void shouldResolveReleasesForLatest() { + assertThat(releaseResolver.resolveWithAncestors("latest")) + .containsExactlyInAnyOrder("amsterdam", "casablanca", "dublin", "frankfurt", "guilin", "honolulu"); + } + + @Test + public void shouldReportAnErrorWhenReleaseIsUnknown() { + assertThatThrownBy(() -> + releaseResolver.resolveWithAncestors("unknown") + ).isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("Release 'unknown' is not defined at the releases.order list in a vnfreqs.properties file!"); + } +} diff --git a/csarvalidation/src/test/java/org/onap/functional/PnfValidationFunctionalTest.java b/csarvalidation/src/test/java/org/onap/functional/PnfValidationFunctionalTest.java index 2477377..3e3877e 100644 --- a/csarvalidation/src/test/java/org/onap/functional/PnfValidationFunctionalTest.java +++ b/csarvalidation/src/test/java/org/onap/functional/PnfValidationFunctionalTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 Nokia + * Copyright 2021 Nokia * <p> * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,10 +42,10 @@ public class PnfValidationFunctionalTest { public void shouldReportOnlyWarningWhenCsarDoNotHaveCertificateAndHashesInManifest() throws URISyntaxException { // given OnapCliValidationResponseWrapper.ValidationResultWrapper.ValidationErrorWrapper expectedWarning = - createExpectedError(CERTIFICATION_RULE, "0x1006", - "Warning. Consider adding package integrity and authenticity assurance according to ETSI NFV-SOL 004 Security Option 1"); + createExpectedError(CERTIFICATION_RULE, "0x1006", + "Warning. Consider adding package integrity and authenticity assurance according to ETSI NFV-SOL 004 Security Option 1"); - OnapCliWrapper cli = new OnapCliWrapper(createPnfValidationRequestInfo( "pnf/validFile.csar")); + OnapCliWrapper cli = new OnapCliWrapper(createPnfValidationRequestInfo("pnf/validFile.csar")); // when cli.handle(); @@ -54,11 +54,11 @@ public class PnfValidationFunctionalTest { final OnapCliValidationResponseWrapper result = getCliCommandValidationResult(cli); assertThat(result.criteria).isEqualTo(OPERATION_STATUS_PASS); - result.results.forEach((ruleValidationResult)->{ + result.results.forEach((ruleValidationResult) -> { assertThat(ruleValidationResult.errors).isEmpty(); if (ruleValidationResult.vnfreqName.equals(CERTIFICATION_RULE)) { assertThat(ruleValidationResult.warnings) - .containsExactlyInAnyOrder(expectedWarning); + .containsExactlyInAnyOrder(expectedWarning); } else { assertThat(ruleValidationResult.warnings).isEmpty(); } @@ -69,7 +69,22 @@ public class PnfValidationFunctionalTest { @Test public void shouldNotReportThatPnfValidationFailedWhenZipDoNotHaveCertificatesAndHashesInManifest() throws URISyntaxException { // given - OnapCliWrapper cli = new OnapCliWrapper(createPnfValidationRequestInfo( "pnf/signed-package-valid-signature.zip")); + OnapCliWrapper cli = new OnapCliWrapper(createPnfValidationRequestInfo("pnf/signed-package-valid-signature.zip")); + + // when + cli.handle(); + + // then + final OnapCliValidationResponseWrapper result = getCliCommandValidationResult(cli); + + assertThat(result.criteria).isEqualTo(OPERATION_STATUS_PASS); + verifyThatOperationFinishedWithoutAnyError(cli); + } + + @Test + public void shouldPassForCasablancaWithAncestorRuleSet() throws URISyntaxException { + // given + OnapCliWrapper cli = new OnapCliWrapper(createPnfValidationRequestInfoForSelectedRelease("pnf/signed-package-valid-signature.zip", "casablanca")); // when cli.handle(); @@ -85,19 +100,19 @@ public class PnfValidationFunctionalTest { public void shouldReportThatPnfValidationFailedWhenCsarContainsCertificateInCmsAndInToscaAndInRootAndHashIsIncorrect_allOtherRulesShouldPass() throws URISyntaxException { // given List<OnapCliValidationResponseWrapper.ValidationResultWrapper.ValidationErrorWrapper> expectedErrors = - List.of( - createExpectedError(CERTIFICATION_RULE, "0x4007", - "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", - "ETSI-Entry-Certificate entry in Tosca.meta is defined despite the certificate is included in the signature container"), - createExpectedError(CERTIFICATION_RULE, "0x4012", - "ETSI-Entry-Certificate certificate present despite the certificate is included in the signature container"), - createExpectedError(CERTIFICATION_RULE, "0x4013", - "Certificate present in root catalog despite the certificate is included in the signature container") - ); - OnapCliWrapper cli = new OnapCliWrapper(createPnfValidationRequestInfo( "pnf/r130206/cert-in-cms-and-root-and-tosca-incorrect-hash.csar")); + List.of( + createExpectedError(CERTIFICATION_RULE, "0x4007", + "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", + "ETSI-Entry-Certificate entry in Tosca.meta is defined despite the certificate is included in the signature container"), + createExpectedError(CERTIFICATION_RULE, "0x4012", + "ETSI-Entry-Certificate certificate present despite the certificate is included in the signature container"), + createExpectedError(CERTIFICATION_RULE, "0x4013", + "Certificate present in root catalog despite the certificate is included in the signature container") + ); + OnapCliWrapper cli = new OnapCliWrapper(createPnfValidationRequestInfo("pnf/r130206/cert-in-cms-and-root-and-tosca-incorrect-hash.csar")); // when cli.handle(); @@ -106,11 +121,11 @@ public class PnfValidationFunctionalTest { final OnapCliValidationResponseWrapper result = getCliCommandValidationResult(cli); assertThat(result.criteria).isEqualTo(OPERATION_STATUS_FAILED); - result.results.forEach((ruleValidationResult)->{ + result.results.forEach((ruleValidationResult) -> { assertThat(ruleValidationResult.warnings).isEmpty(); if (ruleValidationResult.vnfreqName.equals(CERTIFICATION_RULE)) { assertThat(ruleValidationResult.errors) - .containsExactlyInAnyOrderElementsOf(expectedErrors); + .containsExactlyInAnyOrderElementsOf(expectedErrors); } else { assertThat(ruleValidationResult.errors).isEmpty(); } @@ -122,23 +137,23 @@ public class PnfValidationFunctionalTest { public void shouldReportThatPnfCertificationRuleValidationFailedWhenCsarContainsCertificateInCmsAndInToscaAndInRootAndHashIsIncorrect() throws URISyntaxException { // given List<OnapCliValidationResponseWrapper.ValidationResultWrapper.ValidationErrorWrapper> expectedErrors = - List.of( - createExpectedError(CERTIFICATION_RULE, "0x4007", - "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", - "ETSI-Entry-Certificate entry in Tosca.meta is defined despite the certificate is included in the signature container"), - createExpectedError(CERTIFICATION_RULE, "0x4012", - "ETSI-Entry-Certificate certificate present despite the certificate is included in the signature container"), - createExpectedError(CERTIFICATION_RULE, "0x4013", - "Certificate present in root catalog despite the certificate is included in the signature container") - ); + List.of( + createExpectedError(CERTIFICATION_RULE, "0x4007", + "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", + "ETSI-Entry-Certificate entry in Tosca.meta is defined despite the certificate is included in the signature container"), + createExpectedError(CERTIFICATION_RULE, "0x4012", + "ETSI-Entry-Certificate certificate present despite the certificate is included in the signature container"), + createExpectedError(CERTIFICATION_RULE, "0x4013", + "Certificate present in root catalog despite the certificate is included in the signature container") + ); OnapCliWrapper cli = new OnapCliWrapper( - createPnfValidationSelectedRulesRequestInfo( - "pnf/r130206/cert-in-cms-and-root-and-tosca-incorrect-hash.csar", - CERTIFICATION_RULE - )); + createPnfValidationRequestInfoForSelectedRules( + "pnf/r130206/cert-in-cms-and-root-and-tosca-incorrect-hash.csar", + CERTIFICATION_RULE + )); // when cli.handle(); @@ -148,11 +163,11 @@ public class PnfValidationFunctionalTest { assertThat(result.criteria).isEqualTo(OPERATION_STATUS_FAILED); assertThat(result.results).hasSize(2); - result.results.forEach((ruleValidationResult)->{ + result.results.forEach((ruleValidationResult) -> { assertThat(ruleValidationResult.warnings).isEmpty(); if (ruleValidationResult.vnfreqName.equals(CERTIFICATION_RULE)) { assertThat(ruleValidationResult.errors) - .containsExactlyInAnyOrderElementsOf(expectedErrors); + .containsExactlyInAnyOrderElementsOf(expectedErrors); } else { assertThat(ruleValidationResult.errors).isEmpty(); } @@ -164,10 +179,10 @@ public class PnfValidationFunctionalTest { public void shouldReportThatPnfPmDictionaryYamlRuleValidationSuccessWhenCsarContainsCertificateInCmsAndInToscaAndInRootAndHashIsIncorrect() throws URISyntaxException { // given OnapCliWrapper cli = new OnapCliWrapper( - createPnfValidationSelectedRulesRequestInfo( - "pnf/r130206/cert-in-cms-and-root-and-tosca-incorrect-hash.csar", - PM_DICTIONARY_YAML_RULE - )); + createPnfValidationRequestInfoForSelectedRules( + "pnf/r130206/cert-in-cms-and-root-and-tosca-incorrect-hash.csar", + PM_DICTIONARY_YAML_RULE + )); // when cli.handle(); @@ -177,7 +192,7 @@ public class PnfValidationFunctionalTest { assertThat(result.criteria).isEqualTo(OPERATION_STATUS_PASS); assertThat(result.results).hasSize(2); - result.results.forEach((ruleValidationResult)->{ + result.results.forEach((ruleValidationResult) -> { assertThat(ruleValidationResult.warnings).isEmpty(); assertThat(ruleValidationResult.errors).isEmpty(); }); @@ -188,23 +203,23 @@ public class PnfValidationFunctionalTest { public void shouldReportThatPnfCertificationRuleAndPnfPmDictionaryYamlRuleValidationFailedWhenCsarContainsCertificateInCmsAndInToscaAndInRootAndHashIsIncorrect() throws URISyntaxException { // given List<OnapCliValidationResponseWrapper.ValidationResultWrapper.ValidationErrorWrapper> expectedErrors = - List.of( - createExpectedError(CERTIFICATION_RULE, "0x4007", - "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", - "ETSI-Entry-Certificate entry in Tosca.meta is defined despite the certificate is included in the signature container"), - createExpectedError(CERTIFICATION_RULE, "0x4012", - "ETSI-Entry-Certificate certificate present despite the certificate is included in the signature container"), - createExpectedError(CERTIFICATION_RULE, "0x4013", - "Certificate present in root catalog despite the certificate is included in the signature container") - ); + List.of( + createExpectedError(CERTIFICATION_RULE, "0x4007", + "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", + "ETSI-Entry-Certificate entry in Tosca.meta is defined despite the certificate is included in the signature container"), + createExpectedError(CERTIFICATION_RULE, "0x4012", + "ETSI-Entry-Certificate certificate present despite the certificate is included in the signature container"), + createExpectedError(CERTIFICATION_RULE, "0x4013", + "Certificate present in root catalog despite the certificate is included in the signature container") + ); OnapCliWrapper cli = new OnapCliWrapper( - createPnfValidationSelectedRulesRequestInfo( - "pnf/r130206/cert-in-cms-and-root-and-tosca-incorrect-hash.csar", - CERTIFICATION_RULE+","+PM_DICTIONARY_YAML_RULE - )); + createPnfValidationRequestInfoForSelectedRules( + "pnf/r130206/cert-in-cms-and-root-and-tosca-incorrect-hash.csar", + CERTIFICATION_RULE + "," + PM_DICTIONARY_YAML_RULE + )); // when cli.handle(); @@ -214,11 +229,11 @@ public class PnfValidationFunctionalTest { assertThat(result.criteria).isEqualTo(OPERATION_STATUS_FAILED); assertThat(result.results).hasSize(3); - result.results.forEach((ruleValidationResult)->{ + result.results.forEach((ruleValidationResult) -> { assertThat(ruleValidationResult.warnings).isEmpty(); if (ruleValidationResult.vnfreqName.equals(CERTIFICATION_RULE)) { assertThat(ruleValidationResult.errors) - .containsExactlyInAnyOrderElementsOf(expectedErrors); + .containsExactlyInAnyOrderElementsOf(expectedErrors); } else { assertThat(ruleValidationResult.errors).isEmpty(); } @@ -230,21 +245,21 @@ public class PnfValidationFunctionalTest { public void shouldReportThatIndividualArtifactHaveIncorrectCertificateAndCertificateAndSignatureAreNotPresentAsSources() throws URISyntaxException { // given List<OnapCliValidationResponseWrapper.ValidationResultWrapper.ValidationErrorWrapper> expectedCertificationErrors = - List.of( - createExpectedError(CERTIFICATION_RULE, "0x4020", - "Source 'Files/Scripts/my_script.sh' has incorrect signature!"), - createExpectedError(CERTIFICATION_RULE, "0x4007", - "Manifest file has invalid signature!") - ); + List.of( + createExpectedError(CERTIFICATION_RULE, "0x4020", + "Source 'Files/Scripts/my_script.sh' has incorrect signature!"), + createExpectedError(CERTIFICATION_RULE, "0x4007", + "Manifest file has invalid signature!") + ); List<OnapCliValidationResponseWrapper.ValidationResultWrapper.ValidationErrorWrapper> expectedManifestErrors = - List.of( - createExpectedError(MANIFEST_FILE_RULE, "0x1001", - "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" - ) - ); + List.of( + createExpectedError(MANIFEST_FILE_RULE, "0x1001", + "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" + ) + ); OnapCliWrapper cli = new OnapCliWrapper(createPnfValidationRequestInfo( - "pnf/r130206/csar-cert-in-cms-valid-with-incorrect-signature-of-individual-artifact.csar" + "pnf/r130206/csar-cert-in-cms-valid-with-incorrect-signature-of-individual-artifact.csar" )); // when @@ -254,14 +269,14 @@ public class PnfValidationFunctionalTest { final OnapCliValidationResponseWrapper result = getCliCommandValidationResult(cli); assertThat(result.criteria).isEqualTo(OPERATION_STATUS_FAILED); - result.results.forEach((ruleValidationResult)->{ + result.results.forEach((ruleValidationResult) -> { assertThat(ruleValidationResult.warnings).isEmpty(); if (ruleValidationResult.vnfreqName.equals(CERTIFICATION_RULE)) { assertThat(ruleValidationResult.errors) - .containsExactlyInAnyOrderElementsOf(expectedCertificationErrors); + .containsExactlyInAnyOrderElementsOf(expectedCertificationErrors); } else if (ruleValidationResult.vnfreqName.equals(MANIFEST_FILE_RULE)) { assertThat(ruleValidationResult.errors) - .containsExactlyInAnyOrderElementsOf(expectedManifestErrors); + .containsExactlyInAnyOrderElementsOf(expectedManifestErrors); } else { assertThat(ruleValidationResult.errors).isEmpty(); } @@ -273,61 +288,61 @@ public class PnfValidationFunctionalTest { public void shouldReportThatIndividualArtifactsHaveMultipleIncorrectCertificatesAndSignatures() throws URISyntaxException { // given List<OnapCliValidationResponseWrapper.ValidationResultWrapper.ValidationErrorWrapper> expectedCertificationErrors = - List.of( - createExpectedError(CERTIFICATION_RULE, "0x4004", + List.of( + createExpectedError(CERTIFICATION_RULE, "0x4004", "Source 'Artifacts/Deployment/Events/RadioNode_Pnf_v1.yaml' has wrong hash!"), createExpectedError(CERTIFICATION_RULE, "0x4020", "Source 'Artifacts/Deployment/Events/RadioNode_Pnf_v2.yaml' has incorrect signature!"), 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!") - ); + "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.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.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" - ) - ); + 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" + "pnf/r130206/csar-cert-in-tosca-multiple-individual-signature.csar" )); // when @@ -337,24 +352,24 @@ public class PnfValidationFunctionalTest { final OnapCliValidationResponseWrapper result = getCliCommandValidationResult(cli); assertThat(result.criteria).isEqualTo(OPERATION_STATUS_FAILED); - result.results.forEach((ruleValidationResult)->{ + result.results.forEach((ruleValidationResult) -> { assertThat(ruleValidationResult.warnings).isEmpty(); switch (ruleValidationResult.vnfreqName) { case CERTIFICATION_RULE: assertThat(ruleValidationResult.errors) - .containsExactlyInAnyOrderElementsOf(expectedCertificationErrors); + .containsExactlyInAnyOrderElementsOf(expectedCertificationErrors); break; case MANIFEST_FILE_RULE: assertThat(ruleValidationResult.errors) - .containsExactlyInAnyOrderElementsOf(expectedManifestErrors); + .containsExactlyInAnyOrderElementsOf(expectedManifestErrors); break; case PM_DICTIONARY_YAML_RULE: assertThat(ruleValidationResult.errors) - .containsExactlyInAnyOrderElementsOf(expectedPnfDictionaryErrors); + .containsExactlyInAnyOrderElementsOf(expectedPnfDictionaryErrors); break; case NON_MANO_FILES_RULE: assertThat(ruleValidationResult.errors) - .containsExactlyInAnyOrderElementsOf(expectedNonManoFilesErrors); + .containsExactlyInAnyOrderElementsOf(expectedNonManoFilesErrors); break; default: assertThat(ruleValidationResult.errors).isEmpty(); @@ -366,22 +381,33 @@ public class PnfValidationFunctionalTest { private String[] createPnfValidationRequestInfo(String csarPath) throws URISyntaxException { return new String[]{ - "--product", "onap-dublin", - "csar-validate", - "--format", "json", - "--pnf", - "--csar", absoluteFilePath(csarPath) + "--product", "onap-vtp", + "csar-validate", + "--format", "json", + "--pnf", + "--csar", absoluteFilePath(csarPath) + }; + } + + private String[] createPnfValidationRequestInfoForSelectedRelease(String csarPath, String release) throws URISyntaxException { + return new String[]{ + "--product", "onap-vtp", + "csar-validate", + "--release", release, + "--format", "json", + "--pnf", + "--csar", absoluteFilePath(csarPath) }; } - private String[] createPnfValidationSelectedRulesRequestInfo(String csarPath, String rulesToValidate) throws URISyntaxException { + private String[] createPnfValidationRequestInfoForSelectedRules(String csarPath, String rulesToValidate) throws URISyntaxException { return new String[]{ - "--product", "onap-dublin", - "csar-validate", - "--format", "json", - "--rules", rulesToValidate, - "--pnf", - "--csar", absoluteFilePath(csarPath) + "--product", "onap-vtp", + "csar-validate", + "--format", "json", + "--rules", rulesToValidate, + "--pnf", + "--csar", absoluteFilePath(csarPath) }; } } diff --git a/csarvalidation/src/test/java/org/onap/functional/VnfValidationFunctionalTest.java b/csarvalidation/src/test/java/org/onap/functional/VnfValidationFunctionalTest.java index adaea59..e93c51f 100644 --- a/csarvalidation/src/test/java/org/onap/functional/VnfValidationFunctionalTest.java +++ b/csarvalidation/src/test/java/org/onap/functional/VnfValidationFunctionalTest.java @@ -1,6 +1,6 @@ -/** +/* * Copyright 2017 Huawei Technologies Co., Ltd. - * Copyright 2020 Nokia + * Copyright 2021 Nokia * <p> * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,7 @@ import java.net.URISyntaxException; import static org.assertj.core.api.Assertions.assertThat; import static org.onap.cvc.csar.cc.sol004.IntegrationTestUtils.absoluteFilePath; import static org.onap.functional.CsarValidationUtility.OPERATION_STATUS_FAILED; +import static org.onap.functional.CsarValidationUtility.OPERATION_STATUS_PASS; import static org.onap.functional.CsarValidationUtility.getCliCommandValidationResult; import static org.onap.functional.CsarValidationUtility.ruleHaveOneOfCodes; import static org.onap.functional.CsarValidationUtility.verifyThatOperationFinishedWithoutAnyError; @@ -36,7 +37,7 @@ public class VnfValidationFunctionalTest { @Test public void shouldReportThanVnfValidationFailed() throws URISyntaxException { // given - OnapCliWrapper cli = new OnapCliWrapper(createVnfValidationRequestInfo("VoLTE.csar")); + OnapCliWrapper cli = new OnapCliWrapper(createVnfValidationRequestInfo("VoLTE.csar","latest")); // when cli.handle(); @@ -44,17 +45,17 @@ public class VnfValidationFunctionalTest { // then final OnapCliValidationResponseWrapper result = getCliCommandValidationResult(cli); assertThat(result.criteria).isEqualTo(OPERATION_STATUS_FAILED); - result.results.forEach((ruleValidationResult)->{ - if ( ruleHaveOneOfCodes(ruleValidationResult.vnfreqName, - "r01123", "r09467") + result.results.forEach((ruleValidationResult) -> { + if (ruleHaveOneOfCodes(ruleValidationResult.vnfreqName, + "r01123", "r09467") ) { assertThat(ruleValidationResult.errors) - .hasSize(2); - } else if ( ruleHaveOneOfCodes(ruleValidationResult.vnfreqName, - "r21322","r26885","r43958" ,"r66070","r130206") + .hasSize(2); + } else if (ruleHaveOneOfCodes(ruleValidationResult.vnfreqName, + "r21322", "r26885", "r43958", "r66070", "r130206") ) { assertThat(ruleValidationResult.errors) - .hasSize(1); + .hasSize(1); } else { assertThat(ruleValidationResult.errors).hasSize(0); } @@ -63,13 +64,28 @@ public class VnfValidationFunctionalTest { verifyThatOperationFinishedWithoutAnyError(cli); } - private String[] createVnfValidationRequestInfo(String csarPath) throws URISyntaxException { + @Test + public void shouldPassForAmsterdamWithAncestorRuleSet() throws URISyntaxException { + // given + OnapCliWrapper cli = new OnapCliWrapper(createVnfValidationRequestInfo("VoLTE.csar","amsterdam")); + + // when + cli.handle(); + + // then + final OnapCliValidationResponseWrapper result = getCliCommandValidationResult(cli); + assertThat(result.criteria).isEqualTo(OPERATION_STATUS_PASS); + + verifyThatOperationFinishedWithoutAnyError(cli); + } + + private String[] createVnfValidationRequestInfo(String csarPath, String release) throws URISyntaxException { return new String[]{ - "--product", "onap-dublin", - "csar-validate", - "--format", "json", - "--csar", absoluteFilePath(csarPath) + "--product", "onap-vtp", + "csar-validate", + "--release", release, + "--format", "json", + "--csar", absoluteFilePath(csarPath) }; } - } |