summaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java
diff options
context:
space:
mode:
authorkooper <sergey.sachkov@est.tech>2019-03-22 10:28:46 +0000
committerOren Kleks <orenkle@amdocs.com>2019-03-24 07:14:19 +0000
commitc5927b27b83286c6f4aef7ae5be19a16398c23ce (patch)
tree3d9ab610b97f27c4d1c32062d3ce1a334210ff1f /openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java
parentb8cef3d6fe5ee531bcb13ec13f2e8a5b23b383ea (diff)
Retrieve issuer certificate
Change-Id: I22b9ed99d9b19ed300b5671826bd5cd369417f06 Issue-ID: SDC-2162 Signed-off-by: kooper <sergey.sachkov@est.tech>
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java')
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/security/SecurityManagerTest.java84
1 files changed, 84 insertions, 0 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/security/SecurityManagerTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/security/SecurityManagerTest.java
new file mode 100644
index 0000000000..c693015791
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/security/SecurityManagerTest.java
@@ -0,0 +1,84 @@
+package org.openecomp.sdc.vendorsoftwareproduct.security;
+
+import org.apache.commons.io.FileUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import java.io.File;
+import java.io.IOException;
+
+import static junit.framework.TestCase.assertEquals;
+import static junit.framework.TestCase.assertTrue;
+import static org.mockito.ArgumentMatchers.eq;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(SecurityManager.class)
+public class SecurityManagerTest {
+ File certDir;
+
+ @Before
+ public void setUp(){
+ certDir = new File("/tmp/cert");
+ certDir.mkdirs();
+ PowerMockito.mockStatic(System.class);
+ PowerMockito.when(System.getenv(eq("SDC_CERT_DIR"))).thenReturn(certDir.getPath());
+ }
+
+ @After
+ public void tearDown(){
+ certDir.delete();
+ }
+
+ @Test
+ public void testGetCertificates() throws IOException {
+ File origFile = new File("src/test/resources/cert/root-certificate.pem");
+ File newFile = new File("/tmp/cert/root-certificate.pem");
+ newFile.createNewFile();
+ FileUtils.copyFile(origFile, newFile);
+ SecurityManager securityManager = new SecurityManager();
+ assertEquals(1, securityManager.getCertificates().size());
+ newFile.delete();
+ assertEquals(0, securityManager.getCertificates().size());
+ }
+
+ @Test
+ public void testGetCertificatesNoDirectory() throws IOException {
+ certDir.delete();
+ SecurityManager securityManager = new SecurityManager();
+ assertEquals(0, securityManager.getCertificates().size());
+ }
+
+ @Test(expected = SecurityManagerException.class)
+ public void testGetCertificatesException() throws IOException {
+ File newFile = new File("/tmp/cert/root-certificate.pem");
+ newFile.createNewFile();
+ SecurityManager securityManager = new SecurityManager();
+ assertEquals(1, securityManager.getCertificates().size());
+ newFile.delete();
+ assertEquals(0, securityManager.getCertificates().size());
+ }
+
+ @Test
+ public void testGetCertificatesUpdated() throws IOException {
+ File origFile = new File("src/test/resources/cert/root-certificate.pem");
+ File newFile = new File("/tmp/cert/root-certificate.pem");
+ newFile.createNewFile();
+ FileUtils.copyFile(origFile, newFile);
+ SecurityManager securityManager = new SecurityManager();
+ assertTrue(securityManager.getCertificates().size() == 1);
+ File otherOrigFile = new File("src/test/resources/cert/package-certificate.pem");
+ File otherNewFile = new File("/tmp/cert/package-certificate.pem");
+ newFile.createNewFile();
+ FileUtils.copyFile(otherOrigFile, otherNewFile);
+ assertEquals(2, securityManager.getCertificates().size());
+ otherNewFile.delete();
+ assertEquals(1, securityManager.getCertificates().size());
+ newFile.delete();
+ assertEquals(0, securityManager.getCertificates().size());
+ }
+}