summaryrefslogtreecommitdiffstats
path: root/authz-certman/src/test/java/com/att/authz/cm/cert
diff options
context:
space:
mode:
authorsg481n <sg481n@att.com>2017-08-03 17:27:34 -0400
committersg481n <sg481n@att.com>2017-08-03 17:27:34 -0400
commit43854a9e3310ff7a92257d16c4fc0a8321eaec68 (patch)
tree46af936c5da4f9c60d7d63dade5c61a8fd5ef9f4 /authz-certman/src/test/java/com/att/authz/cm/cert
parentf691a8b8dfc9eea4c6b3bfa45ea60f07ad347e69 (diff)
 [AAF-21] Initial code import
Change-Id: I63d7d499bbd46f500b5f5a4db966166f613f327a Signed-off-by: sg481n <sg481n@att.com>
Diffstat (limited to 'authz-certman/src/test/java/com/att/authz/cm/cert')
-rw-r--r--authz-certman/src/test/java/com/att/authz/cm/cert/JU_BCFactory.java132
-rw-r--r--authz-certman/src/test/java/com/att/authz/cm/cert/JU_CSRMeta.java96
2 files changed, 228 insertions, 0 deletions
diff --git a/authz-certman/src/test/java/com/att/authz/cm/cert/JU_BCFactory.java b/authz-certman/src/test/java/com/att/authz/cm/cert/JU_BCFactory.java
new file mode 100644
index 00000000..b504f6a8
--- /dev/null
+++ b/authz-certman/src/test/java/com/att/authz/cm/cert/JU_BCFactory.java
@@ -0,0 +1,132 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * 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====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+package com.att.authz.cm.cert;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.security.Key;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+
+import org.bouncycastle.operator.OperatorCreationException;
+import org.bouncycastle.pkcs.PKCS10CertificationRequest;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import com.att.cadi.cm.CertException;
+import com.att.inno.env.TimeTaken;
+import com.att.inno.env.Trans;
+
+@RunWith(MockitoJUnitRunner.class)
+public class JU_BCFactory {
+
+ private static BCFactory bcFactory = new BCFactory();
+
+ private static BCFactory bcFact;
+
+ private static PrivateKey pk;
+
+
+ private static Trans trans;
+
+
+ private static PKCS10CertificationRequest req;
+
+ @BeforeClass
+ public static void setUp() throws IOException {
+ pk = new XYZKey();
+ trans = mock(Trans.class);
+ req = mock(PKCS10CertificationRequest.class);
+ when(req.getEncoded()).thenReturn(new byte[1]);
+ when(trans.start(Mockito.anyString(), Mockito.anyInt())).thenReturn(new TimeTaken(null, 0) {
+
+ @Override
+ public void output(StringBuilder sb) {
+ // TODO Auto-generated method stub
+
+ }
+ });
+ bcFact = mock(BCFactory.class);
+ }
+
+ @Test
+ public void toStrin() throws OperatorCreationException, IOException, CertException {
+ assertNotNull(bcFactory.toString(trans, req));
+ }
+
+ @Test
+ public void toStrinMoc() throws OperatorCreationException, IOException, CertException {
+ assertNotNull(bcFact.toString(trans, req));
+ }
+
+ @Rule
+ public ExpectedException thrown= ExpectedException.none();
+
+ @Test
+ public void toCSR() {
+ try {
+ assertNotNull(bcFactory.toCSR(trans, new File("/random/path")));
+ thrown.expect(FileNotFoundException.class);
+ } catch (IOException e) {
+
+ e.printStackTrace();
+ }
+ }
+
+}
+
+class XYZKey implements Key, PublicKey, PrivateKey {
+
+ int rotValue;
+ public XYZKey() {
+ rotValue = 1200213;
+ }
+ public String getAlgorithm() {
+ return "XYZ";
+ }
+
+ public String getFormat() {
+ return "XYZ Special Format";
+ }
+
+ public byte[] getEncoded() {
+ byte b[] = new byte[4];
+ b[3] = (byte) ((rotValue << 24) & 0xff);
+ b[2] = (byte) ((rotValue << 16) & 0xff);
+ b[1] = (byte) ((rotValue << 8) & 0xff);
+ b[0] = (byte) ((rotValue << 0) & 0xff);
+ return b;
+ }
+}
diff --git a/authz-certman/src/test/java/com/att/authz/cm/cert/JU_CSRMeta.java b/authz-certman/src/test/java/com/att/authz/cm/cert/JU_CSRMeta.java
new file mode 100644
index 00000000..541d5fb7
--- /dev/null
+++ b/authz-certman/src/test/java/com/att/authz/cm/cert/JU_CSRMeta.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * ============LICENSE_START====================================================
+ * * org.onap.aai
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * Copyright © 2017 Amdocs
+ * * ===========================================================================
+ * * 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====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+package com.att.authz.cm.cert;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.mock;
+
+import java.io.IOException;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+
+import org.bouncycastle.asn1.x500.X500Name;
+import org.bouncycastle.operator.OperatorCreationException;
+import org.bouncycastle.pkcs.PKCS10CertificationRequest;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import com.att.cadi.cm.CertException;
+import com.att.inno.env.Trans;
+
+@RunWith(MockitoJUnitRunner.class)
+public class JU_CSRMeta {
+
+ private static CSRMeta csrmeta;
+ private static Trans trans;
+ private static PKCS10CertificationRequest req;
+
+ @BeforeClass
+ public static void setUp() {
+ trans = mock(Trans.class);
+ csrmeta = new CSRMeta();
+ csrmeta.cn("CN");
+ csrmeta.email("pupleti@ht.com");
+ csrmeta.mechID("HAKJH787");
+ csrmeta.o("O");
+ csrmeta.l("L");
+ csrmeta.st("ST");
+ csrmeta.c("C");
+ csrmeta.challenge("Challenge");
+ csrmeta.san("CA");
+ }
+
+ @Test
+ public void x500Name() throws IOException {
+
+ X500Name x500 = csrmeta.x500Name();
+ assertEquals(x500.toString(),"CN=CN,E=pupleti@ht.com,OU=HAKJH787,O=O,L=L,ST=ST,C=C");
+ }
+
+ @Test
+ public void initialConversationCert() throws CertificateException, OperatorCreationException, IOException {
+ X509Certificate cert = csrmeta.initialConversationCert(trans);
+ assertEquals(cert.getBasicConstraints(),-1);
+ }
+
+ @Test
+ public void generateCSR() throws IOException, CertException {
+ req = csrmeta.generateCSR(trans);
+ assertNotNull(req);
+ }
+
+ @Rule
+ public ExpectedException thrown= ExpectedException.none();
+
+ @Test
+ public void dump() throws IOException, CertException {
+ req = csrmeta.generateCSR(trans);
+ csrmeta.dump(req);
+ }
+
+}