From 7ca0d6eeda3be23506678eb7747b4bf0b7c62b41 Mon Sep 17 00:00:00 2001 From: Bartosz Gardziejewski Date: Tue, 19 Jan 2021 13:04:48 +0100 Subject: Add handling of individual artifact signature in manifest file. Signed-off-by: Bartosz Gardziejewski Issue-ID: SDC-3397 Change-Id: I0082571a874721998a07aef3ea845de76483d9c7 --- .../pmdictionary/CsarValidationTest.java | 44 ++++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) (limited to 'integration-tests/src/test/java/org') diff --git a/integration-tests/src/test/java/org/onap/sdc/backend/ci/tests/validation/pmdictionary/CsarValidationTest.java b/integration-tests/src/test/java/org/onap/sdc/backend/ci/tests/validation/pmdictionary/CsarValidationTest.java index e12e058d6c..2390de4780 100644 --- a/integration-tests/src/test/java/org/onap/sdc/backend/ci/tests/validation/pmdictionary/CsarValidationTest.java +++ b/integration-tests/src/test/java/org/onap/sdc/backend/ci/tests/validation/pmdictionary/CsarValidationTest.java @@ -3,6 +3,7 @@ * SDC * ================================================================================ * Copyright (C) 2020 Nokia. All rights reserved. + * Modification Copyright (C) 2021 Nokia. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +30,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validatio import java.io.IOException; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; @@ -59,12 +61,48 @@ class CsarValidationTest { //then assertThat(errorList, is(not(empty()))); - assertThat(getActualErrorMessage(errorList), is(equalTo(expectedErrorMessage))); + assertThat(getActualErrorMessages(errorList).get(0), is(equalTo(expectedErrorMessage))); assertThat(getActualErrorLevel(errorList), is(ErrorLevel.ERROR)); } - private String getActualErrorMessage(List errorList) { - return errorList.get(0).getMessage(); + @Test + void shouldNotReturnErrors_whenPnfCsarContainsIndividualSignatureInManifest() throws OnboardPackageException, IOException { + //given + FileContentHandler pnfFileContent = CsarLoader.load( + "validPnfWithIndividualSignatureCompliantWithSOL004.csar", + "/Files/PNFs/validation/individualSignature/validPnfWithIndividualSignatureCompliantWithSOL004.csar" + ); + + //when + Map> errorsMap = ValidatorFactory.getValidator(pnfFileContent).validateContent(pnfFileContent); + + //then + assertThat(errorsMap, is(anEmptyMap())); + } + + @Test + void shouldReturnErrors_whenPnfCsarContainsIndividualCertificateWithNoSignatureInManifest() throws OnboardPackageException, IOException { + //given + List expectedErrorMessage = List.of("Expected 'Signature' entry before 'Certificate' entry;\nAt line 9: 'Certificate: Definitions/pnf_main_descriptor.cert'."); + FileContentHandler pnfFileContent = CsarLoader.load( + "invalidPnfWithIndividualSignatureCompliantWithSOL004.csar", + "/Files/PNFs/validation/individualSignature/invalidPnfWithIndividualSignatureCompliantWithSOL004.csar" + ); + + //when + Map> errorsMap = ValidatorFactory.getValidator(pnfFileContent).validateContent(pnfFileContent); + List errorList = errorsMap.get("uploadFile"); + + //then + assertThat(getActualErrorMessages(errorList), containsInAnyOrder(expectedErrorMessage.toArray())); + assertThat(getActualErrorLevel(errorList), is(ErrorLevel.ERROR)); + } + + + private List getActualErrorMessages(List errorList) { + return errorList.stream() + .map((ErrorMessage::getMessage)) + .collect(Collectors.toUnmodifiableList()); } private ErrorLevel getActualErrorLevel(List errorList) { -- cgit 1.2.3-korg