diff options
author | andre.schmid <andre.schmid@est.tech> | 2019-09-19 16:14:01 +0100 |
---|---|---|
committer | Ofir Sonsino <ofir.sonsino@intl.att.com> | 2019-11-03 15:41:37 +0000 |
commit | 433947b5ab5e28fc29aee447de934de89a707419 (patch) | |
tree | a485b95b2ae7716ced4825fb7b9eb2b6eeb3433b /openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/data/PackageArchiveTest.java | |
parent | ee64a64fb0705422c18608304e63a505d10d8ba1 (diff) |
Centralize onboarding package validation
Change-Id: I3cc58cf15f62008e83cfc7ddb095d07ab216b82a
Issue-ID: SDC-2583
Signed-off-by: andre.schmid <andre.schmid@est.tech>
Diffstat (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/data/PackageArchiveTest.java')
-rw-r--r-- | openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/data/PackageArchiveTest.java | 119 |
1 files changed, 0 insertions, 119 deletions
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/data/PackageArchiveTest.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/data/PackageArchiveTest.java deleted file mode 100644 index 91a20bd57f..0000000000 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/data/PackageArchiveTest.java +++ /dev/null @@ -1,119 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdcrests.vsp.rest.data; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.openecomp.sdc.vendorsoftwareproduct.security.SecurityManager; -import org.openecomp.sdc.vendorsoftwareproduct.security.SecurityManagerException; -import org.powermock.reflect.Whitebox; - -import java.io.IOException; -import java.net.URISyntaxException; -import java.nio.file.Files; -import java.nio.file.Paths; - -import static junit.framework.TestCase.assertTrue; -import static org.junit.Assert.assertFalse; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.MockitoAnnotations.initMocks; -import static org.powermock.api.mockito.PowerMockito.when; - -public class PackageArchiveTest { - private static final String BASE_DIR = "/vspmanager.csar/"; - - @Mock - SecurityManager manager; - - @Before - public void setUp(){ - initMocks(this); - } - - - @Test - public void isSignedTestCheckingWrongFile() throws IOException, - URISyntaxException { - PackageArchive packageArchive = getArchive("notCsar.txt"); - assertFalse("2 or 3 files expected for signed package present or signature valid for " + - "empty file", packageArchive.isSigned()); - } - - @Test - public void isSignedTestWrongPackageStructure2EmptyDirInRoot() throws IOException, - URISyntaxException { - PackageArchive packageArchive = getArchive("signing/2-empty-directories-in-root.zip"); - assertFalse(packageArchive.isSigned()); - } - - @Test - public void isSignedTestWrongPackageStructure2EmptyFilesAndEmptyDirInRoot() throws IOException, - URISyntaxException { - PackageArchive packageArchive = getArchive("signing/2-empty-files-1-empty-directory-in-root.zip"); - assertFalse(packageArchive.isSigned()); - } - - @Test - public void isSignedTestWrongPackageStructure2EmptyFilesAndDirWithContentInRoot() throws IOException, - URISyntaxException { - PackageArchive packageArchive = getArchive("signing/2-empty-files-1-directory-with-contents-in-root.zip"); - assertFalse(packageArchive.isSigned()); - } - - @Test - public void isSignedTestCorrectStructureNoSignature() throws IOException, - URISyntaxException { - PackageArchive packageArchive = getArchive("signing/2-files-in-root.zip"); - assertFalse(packageArchive.isSigned()); - } - - @Test - public void isSignedTestCorrectStructureAndSignatureExists() throws IOException, - URISyntaxException { - PackageArchive packageArchive = getArchive("signing/csar-and-cms-in-root.zip"); - assertTrue(packageArchive.isSigned()); - } - - @Test - public void isSignatureValidTestCorrectStructureAndValidSignatureExists() throws IOException, - URISyntaxException, SecurityManagerException { - PackageArchive packageArchive = getArchive("signing/signed-package.zip"); - Whitebox.setInternalState(packageArchive, "securityManager", manager); - when(manager.verifySignedData(any(), any(), any())).thenReturn(true); - assertTrue("Signature invalid for signed package", - packageArchive.isSignatureValid()); - } - - @Test(expected = SecurityManagerException.class) - public void isSignatureValidTestCorrectStructureAndNotValidSignatureExists() throws IOException, - URISyntaxException, SecurityManagerException { - PackageArchive packageArchive = getArchive("signing/signed-package-tampered-data.zip"); - Whitebox.setInternalState(packageArchive, "securityManager", manager); - when(manager.verifySignedData(any(), any(), any())).thenThrow(new SecurityManagerException("error!")); - packageArchive.isSignatureValid(); - } - - private PackageArchive getArchive(String path) throws URISyntaxException, IOException { - return new PackageArchive(Files.readAllBytes(Paths.get( - PackageArchiveTest.class.getResource(BASE_DIR + path).toURI()))); - } -} |