diff options
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src')
5 files changed, 31 insertions, 20 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/onboarding/OnboardingPackageProcessor.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/onboarding/OnboardingPackageProcessor.java index 640a15735f..0446103491 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/onboarding/OnboardingPackageProcessor.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/onboarding/OnboardingPackageProcessor.java @@ -75,10 +75,11 @@ public class OnboardingPackageProcessor { private final CnfPackageValidator cnfPackageValidator; private FileContentHandler packageContent; - public OnboardingPackageProcessor(final String packageFileName, final byte[] packageFileContent) { + public OnboardingPackageProcessor(final String packageFileName, final byte[] packageFileContent, + final CnfPackageValidator cnfPackageValidator) { this.packageFileName = packageFileName; this.packageFileContent = packageFileContent; - this.cnfPackageValidator = new CnfPackageValidator(); + this.cnfPackageValidator = cnfPackageValidator; onboardPackageInfo = processPackage(); } @@ -87,11 +88,13 @@ public class OnboardingPackageProcessor { } public boolean hasErrors() { - return !errorMessages.isEmpty(); + return errorMessages.stream() + .anyMatch(error -> error.getLevel() == ErrorLevel.ERROR); } public boolean hasNoErrors() { - return errorMessages.isEmpty(); + return errorMessages.stream() + .noneMatch(error -> error.getLevel() == ErrorLevel.ERROR); } public Set<ErrorMessage> getErrorMessages() { diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/onboarding/validation/CnfPackageValidator.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/onboarding/validation/CnfPackageValidator.java index 50f1fd8d06..6c886f8e74 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/onboarding/validation/CnfPackageValidator.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/onboarding/validation/CnfPackageValidator.java @@ -42,7 +42,7 @@ public class CnfPackageValidator { Stats stats = new Stats(); for (FileData mod : modules) { if (mod.getBase() == null) { - stats.without++; + stats.withoutBase++; } else if (mod.getBase()) { stats.base++; } @@ -50,14 +50,14 @@ public class CnfPackageValidator { return stats; } - private List<String> createErrorMessages(Stats stats) { + private List<String> createErrorMessages(Stats result) { List<String> messages = new ArrayList<>(); - if (stats.without > 0) { - messages.add(MANIFEST_VALIDATION_HELM_IS_BASE_MISSING.formatMessage(stats.without)); + if (result.withoutBase > 0) { + messages.add(MANIFEST_VALIDATION_HELM_IS_BASE_MISSING.formatMessage(result.withoutBase)); } - if (stats.base == 0) { + if (result.base == 0) { messages.add(MANIFEST_VALIDATION_HELM_IS_BASE_NOT_SET.getErrorMessage()); - } else if (stats.base > 1) { + } else if (result.base > 1) { messages.add(MANIFEST_VALIDATION_HELM_IS_BASE_NOT_UNIQUE.getErrorMessage()); } return messages; @@ -66,6 +66,7 @@ public class CnfPackageValidator { private static class Stats { private int base = 0; - private int without = 0; + private int withoutBase = 0; } + } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/onboarding/OnboardingPackageProcessorTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/onboarding/OnboardingPackageProcessorTest.java index d6327866f4..6c847a713e 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/onboarding/OnboardingPackageProcessorTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/onboarding/OnboardingPackageProcessorTest.java @@ -49,6 +49,7 @@ import org.junit.runners.Parameterized.Parameters; import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.datatypes.error.ErrorLevel; import org.openecomp.sdc.datatypes.error.ErrorMessage; +import org.openecomp.sdc.vendorsoftwareproduct.impl.onboarding.validation.CnfPackageValidator; import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackageInfo; @RunWith(Parameterized.class) @@ -59,6 +60,7 @@ public class OnboardingPackageProcessorTest { private final byte[] packageBytes; private final Set<ErrorMessage> expectedErrorSet; private final OnboardingTypesEnum expectedPackageType; + private final CnfPackageValidator cnfPackageValidator; public OnboardingPackageProcessorTest(final String packageName, final byte[] packageBytes, final Set<ErrorMessage> expectedErrorSet, @@ -67,6 +69,7 @@ public class OnboardingPackageProcessorTest { this.packageBytes = packageBytes; this.expectedErrorSet = expectedErrorSet; this.expectedPackageType = expectedPackageType; + this.cnfPackageValidator = new CnfPackageValidator(); } @Parameters(name = "Run {index} for {0}") @@ -115,7 +118,7 @@ public class OnboardingPackageProcessorTest { @Test public void processPackage() { final OnboardingPackageProcessor onboardingPackageProcessor = new OnboardingPackageProcessor(packageName, - packageBytes); + packageBytes, cnfPackageValidator); assertThat("Should contains errors", onboardingPackageProcessor.hasErrors(), is(!expectedErrorSet.isEmpty())); assertThat("Should have the same number of errors", onboardingPackageProcessor.getErrorMessages().size(), equalTo(expectedErrorSet.size())); diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/onboarding/OnboardingPackageProcessorUnitTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/onboarding/OnboardingPackageProcessorUnitTest.java index a97a0f639a..795da7780f 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/onboarding/OnboardingPackageProcessorUnitTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/onboarding/OnboardingPackageProcessorUnitTest.java @@ -19,6 +19,9 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl.onboarding; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; + import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -26,14 +29,13 @@ import org.junit.Test; import org.openecomp.sdc.heat.datatypes.manifest.FileData; import org.openecomp.sdc.heat.datatypes.manifest.FileData.Type; import org.openecomp.sdc.heat.datatypes.manifest.ManifestContent; - -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; +import org.openecomp.sdc.vendorsoftwareproduct.impl.onboarding.validation.CnfPackageValidator; public class OnboardingPackageProcessorUnitTest { - private OnboardingPackageProcessor processor = new OnboardingPackageProcessor("unitTestPackage", null); + private OnboardingPackageProcessor processor = new OnboardingPackageProcessor("unitTestPackage", + null, new CnfPackageValidator()); @Test public void shouldValidateZipPackage_helmWithoutHeat() { diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/CsarSecurityValidatorTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/CsarSecurityValidatorTest.java index 0fce606052..27d80412bf 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/CsarSecurityValidatorTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/CsarSecurityValidatorTest.java @@ -34,6 +34,7 @@ import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.openecomp.sdc.vendorsoftwareproduct.impl.onboarding.OnboardingPackageProcessor; +import org.openecomp.sdc.vendorsoftwareproduct.impl.onboarding.validation.CnfPackageValidator; import org.openecomp.sdc.vendorsoftwareproduct.security.SecurityManager; import org.openecomp.sdc.vendorsoftwareproduct.security.SecurityManagerException; import org.openecomp.sdc.vendorsoftwareproduct.types.OnboardPackageInfo; @@ -56,7 +57,7 @@ public class CsarSecurityValidatorTest { public void isSignatureValidTestCorrectStructureAndValidSignatureExists() throws SecurityManagerException { final byte[] packageBytes = getFileBytesOrFail("signing/signed-package.zip"); final OnboardSignedPackage onboardSignedPackage = loadSignedPackage("signed-package.zip", - packageBytes); + packageBytes, null); when(securityManager.verifySignedData(any(), any(), any())).thenReturn(true); final boolean isSignatureValid = csarSecurityValidator.verifyPackageSignature(onboardSignedPackage); assertThat("Signature should be valid", isSignatureValid, is(true)); @@ -66,7 +67,7 @@ public class CsarSecurityValidatorTest { public void isSignatureValidTestCorrectStructureAndNotValidSignatureExists() throws SecurityManagerException { final byte[] packageBytes = getFileBytesOrFail("signing/signed-package-tampered-data.zip"); final OnboardSignedPackage onboardSignedPackage = loadSignedPackage("signed-package-tampered-data.zip", - packageBytes); + packageBytes, null); //no mocked securityManager csarSecurityValidator = new CsarSecurityValidator(); csarSecurityValidator.verifyPackageSignature(onboardSignedPackage); @@ -86,9 +87,10 @@ public class CsarSecurityValidatorTest { CsarSecurityValidatorTest.class.getResource(BASE_DIR + path).toURI())); } - private OnboardSignedPackage loadSignedPackage(final String packageName, final byte[] packageBytes) { + private OnboardSignedPackage loadSignedPackage(final String packageName, final byte[] packageBytes, + CnfPackageValidator cnfPackageValidator) { final OnboardingPackageProcessor onboardingPackageProcessor = - new OnboardingPackageProcessor(packageName, packageBytes); + new OnboardingPackageProcessor(packageName, packageBytes, cnfPackageValidator); final OnboardPackageInfo onboardPackageInfo = onboardingPackageProcessor.getOnboardPackageInfo().orElse(null); if (onboardPackageInfo == null) { fail("Unexpected error. Could not load original package"); |