summaryrefslogtreecommitdiffstats
path: root/auth/auth-certman/src
diff options
context:
space:
mode:
authorSai Gandham <sg481n@att.com>2018-10-29 10:33:45 -0500
committerSai Gandham <sg481n@att.com>2018-10-29 10:34:03 -0500
commit7d6102863c924000d6e1b23f0c232f49e1f611a1 (patch)
treece7a54d7210996e6cd9fa3a72d8ac6240db7e709 /auth/auth-certman/src
parentd87c0e6b78cfe091eb9ee2312d10f7bb41b567db (diff)
Add more junits for batch & cm
Issue-ID: AAF-111 Change-Id: Id0c5d966fdd19b5f9e6c42448110409bf288fcbf Signed-off-by: Sai Gandham <sg481n@att.com>
Diffstat (limited to 'auth/auth-certman/src')
-rw-r--r--auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/ca/JU_X509ChainTest.java72
-rw-r--r--auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/ca/JU_X509ChainWithIssuerTest.java74
-rw-r--r--auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/data/JU_CertReqTest.java62
-rw-r--r--auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/data/JU_CertRespTest.java140
4 files changed, 348 insertions, 0 deletions
diff --git a/auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/ca/JU_X509ChainTest.java b/auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/ca/JU_X509ChainTest.java
new file mode 100644
index 00000000..06ea9e6e
--- /dev/null
+++ b/auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/ca/JU_X509ChainTest.java
@@ -0,0 +1,72 @@
+/**
+ * ============LICENSE_START====================================================
+ * org.onap.aaf
+ * ===========================================================================
+ * Copyright (c) 2018 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.onap.aaf.auth.cm.ca;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.security.Principal;
+import java.security.cert.Certificate;
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.onap.aaf.cadi.configure.CertException;
+
+public class JU_X509ChainTest {
+
+ @Mock
+ X509Certificate x509;
+
+ @Mock
+ X509ChainWithIssuer orig;
+ @Mock
+ Principal subject;
+ @Mock
+ Reader reader;
+ @Mock
+ X509Certificate cert;
+
+ @Before
+ public void setUp() throws Exception {
+ initMocks(this);
+ // when(subject.get)
+ // when(x509.getSubjectDN()).thenReturn(subject);
+ when(cert.getEncoded()).thenReturn("x509".getBytes());
+ }
+
+ @Test
+ public void test() throws IOException, CertException {
+ Certificate[] certs = { x509 };
+ X509andChain x509Chain = new X509andChain(cert, new ArrayList<String>());
+ x509Chain.addTrustChainEntry(cert);
+
+ assertNotNull(x509Chain.getX509());
+ assertEquals(2, x509Chain.getTrustChain().length);
+ }
+
+}
diff --git a/auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/ca/JU_X509ChainWithIssuerTest.java b/auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/ca/JU_X509ChainWithIssuerTest.java
new file mode 100644
index 00000000..7b6afce7
--- /dev/null
+++ b/auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/ca/JU_X509ChainWithIssuerTest.java
@@ -0,0 +1,74 @@
+/**
+ * ============LICENSE_START====================================================
+ * org.onap.aaf
+ * ===========================================================================
+ * Copyright (c) 2018 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.onap.aaf.auth.cm.ca;
+
+import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.security.Principal;
+import java.security.cert.Certificate;
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.onap.aaf.cadi.configure.CertException;
+
+public class JU_X509ChainWithIssuerTest {
+
+ @Mock
+ X509Certificate x509;
+
+ @Mock
+ X509ChainWithIssuer orig;
+ @Mock
+ Principal subject;
+ @Mock
+ Reader reader;
+
+ @Before
+ public void setUp() throws Exception {
+ initMocks(this);
+ // when(subject.get)
+ when(x509.getSubjectDN()).thenReturn(subject);
+ when(x509.getEncoded()).thenReturn("x509".getBytes());
+ }
+
+ @Test
+ public void test() throws IOException, CertException {
+ X509ChainWithIssuer x509Chain = new X509ChainWithIssuer(orig, x509);
+
+ assertNull(x509Chain.getIssuerDN());
+ Certificate[] certs = { x509 };
+ // Certificate cert = ;
+ x509Chain = new X509ChainWithIssuer(certs);
+ List<Reader> rdrs = new ArrayList<Reader>();
+ rdrs.add(null);
+
+ x509Chain = new X509ChainWithIssuer(rdrs);
+ }
+
+}
diff --git a/auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/data/JU_CertReqTest.java b/auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/data/JU_CertReqTest.java
new file mode 100644
index 00000000..1ab26531
--- /dev/null
+++ b/auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/data/JU_CertReqTest.java
@@ -0,0 +1,62 @@
+/**
+ * ============LICENSE_START====================================================
+ * org.onap.aaf
+ * ===========================================================================
+ * Copyright (c) 2018 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.onap.aaf.auth.cm.data;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import java.io.IOException;
+import java.security.GeneralSecurityException;
+import java.util.ArrayList;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.onap.aaf.auth.cm.ca.CA;
+import org.onap.aaf.auth.cm.cert.CSRMeta;
+import org.onap.aaf.cadi.configure.CertException;
+
+public class JU_CertReqTest {
+
+ @Mock
+ CA ca;
+
+ @Mock
+ CSRMeta csr;
+
+ @Before
+ public void setUp() throws Exception {
+ initMocks(this);
+ when(ca.newCSRMeta()).thenReturn(csr);
+ when(csr.cn()).thenReturn("cn123");
+ when(csr.mechID()).thenReturn("mechId");
+ }
+
+ @Test
+ public void testCertResp() throws IOException, GeneralSecurityException, CertException {
+ CertReq req = new CertReq();
+ req.certAuthority = ca;
+ req.fqdns = new ArrayList<String>();
+
+ assertEquals(csr, req.getCSRMeta());
+ }
+}
diff --git a/auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/data/JU_CertRespTest.java b/auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/data/JU_CertRespTest.java
new file mode 100644
index 00000000..1366e706
--- /dev/null
+++ b/auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/data/JU_CertRespTest.java
@@ -0,0 +1,140 @@
+/**
+ * ============LICENSE_START====================================================
+ * org.onap.aaf
+ * ===========================================================================
+ * Copyright (c) 2018 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.onap.aaf.auth.cm.data;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import java.io.IOException;
+import java.security.GeneralSecurityException;
+import java.security.KeyPair;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.cert.X509Certificate;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.onap.aaf.auth.cm.ca.CA;
+import org.onap.aaf.auth.cm.cert.CSRMeta;
+import org.onap.aaf.cadi.configure.CertException;
+import org.onap.aaf.misc.env.Trans;
+
+public class JU_CertRespTest {
+
+ @Mock
+ CSRMeta csrMeta;
+
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ Trans trans;
+
+ @Mock
+ X509Certificate x509;
+
+ @Mock
+ CA ca;
+
+ @Before
+ public void setUp() throws Exception {
+ initMocks(this);
+ CertDrop drop = new CertDrop();
+ CertRenew renew = new CertRenew();
+
+ PublicKey publicKey = new PublicKey() {
+
+ @Override
+ public String getFormat() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public byte[] getEncoded() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getAlgorithm() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ };
+ PrivateKey privateKey = new PrivateKey() {
+
+ @Override
+ public String getFormat() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public byte[] getEncoded() {
+ // TODO Auto-generated method stub
+ return "privatekey".getBytes();
+ }
+
+ @Override
+ public String getAlgorithm() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ };
+ KeyPair keypair = new KeyPair(publicKey, privateKey);
+
+ when(csrMeta.keypair(trans)).thenReturn(keypair);
+ when(csrMeta.challenge()).thenReturn("challenge");
+ when(x509.getSubjectDN()).thenReturn(null);
+ when(x509.getEncoded()).thenReturn("x509Certificate".getBytes());
+
+ }
+
+ @Test
+ public void testCertResp() throws IOException, GeneralSecurityException, CertException {
+ CertResp resp = new CertResp("CERT");
+
+ assertEquals("CERT", resp.asCertString());
+ assertEquals("", resp.challenge());
+
+ String[] trustChain = { "trustChain" };
+ String[] notes = { "notes" };
+
+ String[] caIssureDNs = { "caIssuer" };
+ String[] trustedCAs = { "trustedCAs" };
+
+ when(ca.getCaIssuerDNs()).thenReturn(caIssureDNs);
+ when(ca.getEnv()).thenReturn("Env");
+ when(ca.getTrustedCAs()).thenReturn(trustedCAs);
+
+ resp = new CertResp(trans, ca, x509, csrMeta, trustChain, notes);
+
+ assertNotNull(resp.privateString());
+ assertEquals("challenge", resp.challenge());
+ assertEquals("notes", resp.notes()[0]);
+ assertEquals("trustChain", resp.trustChain()[0]);
+ assertEquals("caIssuer", resp.caIssuerDNs()[0]);
+ assertEquals("trustedCAs", resp.trustCAs()[0]);
+ assertEquals("Env", resp.env());
+ }
+}