summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBartosz Gardziejewski <bartosz.gardziejewski@nokia.com>2020-10-29 14:03:41 +0100
committerBartosz Gardziejewski <bartosz.gardziejewski@nokia.com>2020-10-29 13:24:52 +0000
commit625cc87fc112891fc5945d2f2f0669f3bf75f089 (patch)
tree11fa285d637747acdf2f797f681bfc03ebd48153
parent413368b561b8f81cb7c36b982190e636d2d3f4ff (diff)
Add rules parameter for selected rules validation
This commit will add extra, optional parameter for csar-validation command. New parameter is named "rules", and it allows to specify rules that will be validated. Using this parameter allows to use refrepo/marketplace to validate selected rules and at the same time guarantee that response format will be exactly the same as for validating all rules, this is in contrast for validating one rule using csar-validate-<rule>, that returns json significantly different then csar-validate. Signed-off-by: Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com> Change-Id: I6eb228d360354c0e249032d013e6a23d1f2713ff Issue-ID: VNFSDK-700
-rw-r--r--csarvalidation/src/main/java/org/onap/cvc/csar/VTPValidateCSAR.java32
-rw-r--r--csarvalidation/src/main/resources/open-cli-schema/vtp-validate-csar.yaml9
-rw-r--r--csarvalidation/src/test/java/org/onap/functional/CsarValidationUtility.java1
-rw-r--r--csarvalidation/src/test/java/org/onap/functional/PnfValidationFunctionalTest.java122
4 files changed, 153 insertions, 11 deletions
diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/VTPValidateCSAR.java b/csarvalidation/src/main/java/org/onap/cvc/csar/VTPValidateCSAR.java
index 74697f1..637a454 100644
--- a/csarvalidation/src/main/java/org/onap/cvc/csar/VTPValidateCSAR.java
+++ b/csarvalidation/src/main/java/org/onap/cvc/csar/VTPValidateCSAR.java
@@ -42,7 +42,10 @@ public class VTPValidateCSAR extends OnapCommand {
private static Gson gson = new Gson();
private static final Logger LOG = LoggerFactory.getLogger(VTPValidateCSAR.class);
- public static final String PNF_ATTRIBUTE_NAME = "pnf";
+ private static final String RULES_ATTRIBUTE_SEPARATOR = ",";
+ private static final String PNF_ATTRIBUTE_NAME = "pnf";
+ private static final String CSAR_ATTRIBUTE_NAME = "csar";
+ private static final String RULES_ATTRIBUTE_NAME = "rules";
public static class CSARValidation {
@@ -216,8 +219,9 @@ public class VTPValidateCSAR extends OnapCommand {
@Override
protected void run() throws OnapCommandException {
//Read the input arguments
- String path = (String) getParametersMap().get("csar").getValue();
+ String path = (String) getParametersMap().get(CSAR_ATTRIBUTE_NAME).getValue();
boolean isPnf = (boolean) getParametersMap().get(PNF_ATTRIBUTE_NAME).getValue();
+ String rulesToValidate = (String) getParametersMap().get(RULES_ATTRIBUTE_NAME).getValue();
boolean overallPass = true;
try (CSARArchive csar = isPnf ? new PnfCSARArchive() : new CSARArchive()) {
@@ -244,13 +248,25 @@ public class VTPValidateCSAR extends OnapCommand {
validation.getResults().add(resultSOL004);
- //Run thru the vnfreqs requirement checks
String keyReqs = isPnf ? "pnfreqs.enabled" : "vnfreqs.enabled";
- for (String vnfreq : this.getPropertiesList(keyReqs)) {
- CSARValidation.Result result = new CSARValidation.Result();
- result.setVnfreqName(vnfreq);
-
- overallPass = validateVnfOrPnf(path, validation, ignoreCodes, vnfreq, result, isPnf, overallPass);
+ List<String> activeRules = this.getPropertiesList(keyReqs);
+ if(rulesToValidate.isEmpty()) {
+ // Run thru the vnfreqs requirement checks
+ for (String vnfreq : activeRules) {
+ CSARValidation.Result result = new CSARValidation.Result();
+ result.setVnfreqName(vnfreq);
+ overallPass = validateVnfOrPnf(path, validation, ignoreCodes, vnfreq, result, isPnf, overallPass);
+ }
+ } else {
+ // Validate selected rules
+ String[] listOfRulesToValidate = rulesToValidate.split(RULES_ATTRIBUTE_SEPARATOR);
+ for (String rule : listOfRulesToValidate) {
+ if(activeRules.contains(rule)) {
+ CSARValidation.Result result = new CSARValidation.Result();
+ result.setVnfreqName(rule);
+ overallPass = validateVnfOrPnf(path, validation, ignoreCodes, rule, result, isPnf, overallPass);
+ }
+ }
}
validation.setDate(new Date().toString());
diff --git a/csarvalidation/src/main/resources/open-cli-schema/vtp-validate-csar.yaml b/csarvalidation/src/main/resources/open-cli-schema/vtp-validate-csar.yaml
index cefdb2b..b77dfa2 100644
--- a/csarvalidation/src/main/resources/open-cli-schema/vtp-validate-csar.yaml
+++ b/csarvalidation/src/main/resources/open-cli-schema/vtp-validate-csar.yaml
@@ -38,6 +38,13 @@ parameters:
type: bool
is_optional: true
default_value: false
+ - name: rules
+ description: Rule that should be validate, if left empty all rules will be validated
+ long_option: rules
+ short_option: r
+ type: binary
+ is_optional: true
+ default_value: ""
results:
direction: portrait
@@ -67,4 +74,4 @@ results:
- name: results
description: All test cases results
scope: short
- type: json \ No newline at end of file
+ type: json
diff --git a/csarvalidation/src/test/java/org/onap/functional/CsarValidationUtility.java b/csarvalidation/src/test/java/org/onap/functional/CsarValidationUtility.java
index 24ef778..efeeb5d 100644
--- a/csarvalidation/src/test/java/org/onap/functional/CsarValidationUtility.java
+++ b/csarvalidation/src/test/java/org/onap/functional/CsarValidationUtility.java
@@ -34,6 +34,7 @@ public final class CsarValidationUtility {
private CsarValidationUtility(){}
public static final String CERTIFICATION_RULE = "r130206";
+ public static final String PM_DICTIONARY_YAML_RULE = "r816745";
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 903691e..4dec242 100644
--- a/csarvalidation/src/test/java/org/onap/functional/PnfValidationFunctionalTest.java
+++ b/csarvalidation/src/test/java/org/onap/functional/PnfValidationFunctionalTest.java
@@ -28,6 +28,7 @@ import static org.onap.cvc.csar.cc.sol004.IntegrationTestUtils.absoluteFilePath;
import static org.onap.functional.CsarValidationUtility.CERTIFICATION_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;
import static org.onap.functional.CsarValidationUtility.createExpectedError;
import static org.onap.functional.CsarValidationUtility.getCliCommandValidationResult;
import static org.onap.functional.CsarValidationUtility.verifyThatOperationFinishedWithoutAnyError;
@@ -82,7 +83,6 @@ public class PnfValidationFunctionalTest {
@Test
public void shouldReportThatPnfValidationFailedWhenCsarContainsCertificateInCmsAndInToscaAndInRootAndHashIsIncorrect_allOtherRulesShouldPass() throws URISyntaxException {
// given
-
List<OnapCliValidationResponseWrapper.ValidationResultWrapper.ValidationErrorWrapper> expectedErrors =
List.of(
createExpectedError(CERTIFICATION_RULE, "0x4007",
@@ -118,6 +118,115 @@ public class PnfValidationFunctionalTest {
verifyThatOperationFinishedWithoutAnyError(cli);
}
+ @Test
+ public void shouldReportThatPnfCertificationRuleValidationFailedWhenCsarContainsCertificateInCmsAndInToscaAndInRootAndHashIsIncorrect() throws URISyntaxException {
+ // given
+ List<OnapCliValidationResponseWrapper.ValidationResultWrapper.ValidationErrorWrapper> expectedErrors =
+ List.of(
+ createExpectedError(CERTIFICATION_RULE, "0x4007",
+ "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
+ ));
+
+ // when
+ cli.handle();
+
+ // then
+ final OnapCliValidationResponseWrapper result = getCliCommandValidationResult(cli);
+
+ assertThat(result.criteria).isEqualTo(OPERATION_STATUS_FAILED);
+ assertThat(result.results).hasSize(2);
+ result.results.forEach((ruleValidationResult)->{
+ assertThat(ruleValidationResult.warnings).isEmpty();
+ if (ruleValidationResult.vnfreqName.equals(CERTIFICATION_RULE)) {
+ assertThat(ruleValidationResult.errors)
+ .hasSize(5)
+ .containsAll(expectedErrors);
+ } else {
+ assertThat(ruleValidationResult.errors).isEmpty();
+ }
+ });
+ verifyThatOperationFinishedWithoutAnyError(cli);
+ }
+
+ @Test
+ 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
+ ));
+
+ // when
+ cli.handle();
+
+ // then
+ final OnapCliValidationResponseWrapper result = getCliCommandValidationResult(cli);
+
+ assertThat(result.criteria).isEqualTo(OPERATION_STATUS_PASS);
+ assertThat(result.results).hasSize(2);
+ result.results.forEach((ruleValidationResult)->{
+ assertThat(ruleValidationResult.warnings).isEmpty();
+ assertThat(ruleValidationResult.errors).isEmpty();
+ });
+ verifyThatOperationFinishedWithoutAnyError(cli);
+ }
+
+ @Test
+ public void shouldReportThatPnfCertificationRuleAndPnfPmDictionaryYamlRuleValidationFailedWhenCsarContainsCertificateInCmsAndInToscaAndInRootAndHashIsIncorrect() throws URISyntaxException {
+ // given
+ List<OnapCliValidationResponseWrapper.ValidationResultWrapper.ValidationErrorWrapper> expectedErrors =
+ List.of(
+ createExpectedError(CERTIFICATION_RULE, "0x4007",
+ "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
+ ));
+
+ // when
+ cli.handle();
+
+ // then
+ final OnapCliValidationResponseWrapper result = getCliCommandValidationResult(cli);
+
+ assertThat(result.criteria).isEqualTo(OPERATION_STATUS_FAILED);
+ assertThat(result.results).hasSize(3);
+ result.results.forEach((ruleValidationResult)->{
+ assertThat(ruleValidationResult.warnings).isEmpty();
+ if (ruleValidationResult.vnfreqName.equals(CERTIFICATION_RULE)) {
+ assertThat(ruleValidationResult.errors)
+ .hasSize(5)
+ .containsAll(expectedErrors);
+ } else {
+ assertThat(ruleValidationResult.errors).isEmpty();
+ }
+ });
+ verifyThatOperationFinishedWithoutAnyError(cli);
+ }
private String[] createPnfValidationRequestInfo(String csarPath) throws URISyntaxException {
return new String[]{
"--product", "onap-dublin",
@@ -128,5 +237,14 @@ public class PnfValidationFunctionalTest {
};
}
-
+ private String[] createPnfValidationSelectedRulesRequestInfo(String csarPath, String rulesToValidate) throws URISyntaxException {
+ return new String[]{
+ "--product", "onap-dublin",
+ "csar-validate",
+ "--format", "json",
+ "--rules", rulesToValidate,
+ "--pnf",
+ "--csar", absoluteFilePath(csarPath)
+ };
+ }
}