summaryrefslogtreecommitdiffstats
path: root/authz-certman/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'authz-certman/src/test')
-rw-r--r--authz-certman/src/test/java/com/att/authz/cm/api/JU_API_Artifact.java109
-rw-r--r--authz-certman/src/test/java/com/att/authz/cm/api/JU_API_Cert.java109
-rw-r--r--authz-certman/src/test/java/com/att/authz/cm/ca/JU_AppCA.java287
-rw-r--r--authz-certman/src/test/java/com/att/authz/cm/ca/JU_DevlCA.java287
-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
-rw-r--r--authz-certman/src/test/java/com/att/authz/cm/data/JU_CertReq.java88
-rw-r--r--authz-certman/src/test/java/com/att/authz/cm/facade/JU_FacadeImpl.java195
-rw-r--r--authz-certman/src/test/java/com/att/authz/cm/validation/JU_Validator.java101
9 files changed, 1404 insertions, 0 deletions
diff --git a/authz-certman/src/test/java/com/att/authz/cm/api/JU_API_Artifact.java b/authz-certman/src/test/java/com/att/authz/cm/api/JU_API_Artifact.java
new file mode 100644
index 00000000..73e7160d
--- /dev/null
+++ b/authz-certman/src/test/java/com/att/authz/cm/api/JU_API_Artifact.java
@@ -0,0 +1,109 @@
+/*******************************************************************************
+ * ============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.api;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.mock;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+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.runners.MockitoJUnitRunner;
+
+import com.att.authz.cm.service.CertManAPI;
+import com.att.authz.env.AuthzTrans;
+;
+
+@RunWith(MockitoJUnitRunner.class)
+public class JU_API_Artifact {
+
+ @Mock
+ private static API_Artifact api;
+
+ @Mock
+ private static CertManAPI certManApi;
+
+ private static CertManAPI noMockAPI;
+ private static API_Artifact api_1;
+
+ private static HttpServletRequest req;
+ private static HttpServletResponse res;
+
+ @BeforeClass
+ public static void setUp() {
+ AuthzTrans trans = mock(AuthzTrans.class);
+ req = mock(HttpServletRequest.class);
+ trans.setProperty("testTag", "UserValue");
+ trans.set(req);
+ }
+
+ @Rule
+ public ExpectedException thrown= ExpectedException.none();
+
+ @Test
+ public void init_bothValued() {
+ try {
+ api.init(certManApi);
+ } catch (Exception e) {
+ thrown.expect(NullPointerException.class);
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void init_Null_() {
+ try {
+ api.init(null);
+ } catch (Exception e) {
+ //thrown.expect(Exception.class);
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void init_NMC_Null() {
+ try {
+ api_1.init(null);
+ } catch (Exception e) {
+ //thrown.expect(NullPointerException.class);
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void init_NMC() {
+ try {
+ api_1.init(noMockAPI);
+ } catch (Exception e) {
+ //thrown.expect(NullPointerException.class);
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/authz-certman/src/test/java/com/att/authz/cm/api/JU_API_Cert.java b/authz-certman/src/test/java/com/att/authz/cm/api/JU_API_Cert.java
new file mode 100644
index 00000000..31465a8b
--- /dev/null
+++ b/authz-certman/src/test/java/com/att/authz/cm/api/JU_API_Cert.java
@@ -0,0 +1,109 @@
+/*******************************************************************************
+ * ============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.api;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.mock;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+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.runners.MockitoJUnitRunner;
+
+import com.att.authz.cm.service.CertManAPI;
+import com.att.authz.env.AuthzTrans;
+;
+
+@RunWith(MockitoJUnitRunner.class)
+public class JU_API_Cert {
+
+ @Mock
+ private static API_Cert api;
+
+ @Mock
+ private static CertManAPI certManApi;
+
+ private static CertManAPI noMockAPI;
+ private static API_Cert api_1;
+
+ private static HttpServletRequest req;
+ private static HttpServletResponse res;
+
+ @BeforeClass
+ public static void setUp() {
+ AuthzTrans trans = mock(AuthzTrans.class);
+ req = mock(HttpServletRequest.class);
+ trans.setProperty("testTag", "UserValue");
+ trans.set(req);
+ }
+
+ @Rule
+ public ExpectedException thrown= ExpectedException.none();
+
+ @Test
+ public void init_bothValued() {
+ try {
+ api.init(certManApi);
+ } catch (Exception e) {
+ //thrown.expect(NullPointerException.class);
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void init_Null_() {
+ try {
+ api.init(null);
+ } catch (Exception e) {
+ //thrown.expect(Exception.class);
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void init_NMC_Null() {
+ try {
+ api_1.init(null);
+ } catch (Exception e) {
+ //thrown.expect(NullPointerException.class);
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void init_NMC() {
+ try {
+ api_1.init(noMockAPI);
+ } catch (Exception e) {
+ //thrown.expect(NullPointerException.class);
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/authz-certman/src/test/java/com/att/authz/cm/ca/JU_AppCA.java b/authz-certman/src/test/java/com/att/authz/cm/ca/JU_AppCA.java
new file mode 100644
index 00000000..898ddf65
--- /dev/null
+++ b/authz-certman/src/test/java/com/att/authz/cm/ca/JU_AppCA.java
@@ -0,0 +1,287 @@
+/*******************************************************************************
+ * ============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.ca;
+
+import static org.mockito.Mockito.CALLS_REAL_METHODS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.math.BigInteger;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.Principal;
+import java.security.PublicKey;
+import java.security.SignatureException;
+import java.security.cert.CertificateEncodingException;
+import java.security.cert.CertificateException;
+import java.security.cert.CertificateExpiredException;
+import java.security.cert.CertificateNotYetValidException;
+import java.security.cert.X509Certificate;
+import java.util.Date;
+import java.util.Set;
+
+import javax.security.auth.x500.X500Principal;
+import javax.servlet.http.HttpServletRequest;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import com.att.aft.dme2.api.http.HttpResponse;
+import com.att.aft.dme2.request.HttpRequest;
+import com.att.authz.cm.cert.CSRMeta;
+import com.att.cadi.cm.CertException;
+import com.att.dao.aaf.cached.CachedCertDAO;
+import com.att.dao.aaf.cass.CertDAO;
+import com.att.inno.env.Trans;
+
+
+@RunWith(MockitoJUnitRunner.class)
+public class JU_AppCA {
+
+ @Mock
+ private static CachedCertDAO certDAO;
+
+ @Mock
+ private static HttpServletRequest req;
+
+ @Mock
+ private static CSRMeta csrMeta;
+
+ static Trans trans;
+
+ static X509Certificate cert;
+ static byte [] name = {1,23,4,54,6,56};
+
+ private static AppCA appCA;
+
+ @BeforeClass
+ public static void setUp() throws CertificateException, CertException, IOException {
+ String str = "core java api";
+ byte[] b = str.getBytes();
+ Principal prc = new X500Principal("CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US");
+ req = mock(HttpServletRequest.class);
+ appCA = mock(AppCA.class);
+ X509Certificate cert = new X509Certificate() {
+
+ @Override
+ public boolean hasUnsupportedCriticalExtension() {
+ return false;
+ }
+
+ @Override
+ public Set<String> getNonCriticalExtensionOIDs() {
+
+ return null;
+ }
+
+ @Override
+ public byte[] getExtensionValue(String oid) {
+
+ return null;
+ }
+
+ @Override
+ public Set<String> getCriticalExtensionOIDs() {
+
+ return null;
+ }
+
+ @Override
+ public void verify(PublicKey key, String sigProvider) throws CertificateException, NoSuchAlgorithmException,
+ InvalidKeyException, NoSuchProviderException, SignatureException {
+
+
+ }
+
+ @Override
+ public void verify(PublicKey key) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException,
+ NoSuchProviderException, SignatureException {
+
+
+ }
+
+ @Override
+ public String toString() {
+
+ return null;
+ }
+
+ @Override
+ public PublicKey getPublicKey() {
+
+ return null;
+ }
+
+ @Override
+ public byte[] getEncoded() throws CertificateEncodingException {
+
+ return null;
+ }
+
+ @Override
+ public int getVersion() {
+
+ return 0;
+ }
+
+ @Override
+ public byte[] getTBSCertificate() throws CertificateEncodingException {
+
+ return null;
+ }
+
+ @Override
+ public boolean[] getSubjectUniqueID() {
+
+ return null;
+ }
+
+ @Override
+ public Principal getSubjectDN() {
+
+ return null;
+ }
+
+ @Override
+ public byte[] getSignature() {
+
+ return null;
+ }
+
+ @Override
+ public byte[] getSigAlgParams() {
+
+ return null;
+ }
+
+ @Override
+ public String getSigAlgOID() {
+
+ return null;
+ }
+
+ @Override
+ public String getSigAlgName() {
+
+ return null;
+ }
+
+ @Override
+ public BigInteger getSerialNumber() {
+
+ return null;
+ }
+
+ @Override
+ public Date getNotBefore() {
+
+ return null;
+ }
+
+ @Override
+ public Date getNotAfter() {
+
+ return null;
+ }
+
+ @Override
+ public boolean[] getKeyUsage() {
+
+ return null;
+ }
+
+ @Override
+ public boolean[] getIssuerUniqueID() {
+
+ return null;
+ }
+
+ @Override
+ public Principal getIssuerDN() {
+
+ return null;
+ }
+
+ @Override
+ public int getBasicConstraints() {
+
+ return 0;
+ }
+
+ @Override
+ public void checkValidity(Date date) throws CertificateExpiredException, CertificateNotYetValidException {
+
+
+ }
+
+ @Override
+ public void checkValidity() throws CertificateExpiredException, CertificateNotYetValidException {
+
+ }
+ };
+ when(appCA.sign(Mockito.any(Trans.class), Mockito.any(CSRMeta.class))).thenReturn(cert);
+ certDAO = mock(CachedCertDAO.class, CALLS_REAL_METHODS);
+ }
+
+ @Test
+ public void identity_True() throws CertificateException, IOException, CertException {
+ assertNotNull(appCA.sign(trans, csrMeta));
+ }
+
+
+ @Test
+ public void identityNull() throws CertificateException {
+ try {
+ assertNotNull(appCA.sign(null, csrMeta));
+ } catch (IOException e) {
+
+ e.printStackTrace();
+ } catch (CertException e) {
+
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void identityBothNull() throws CertificateException {
+ try {
+ assertNotNull(appCA.sign(null, null));
+ } catch (IOException e) {
+
+ e.printStackTrace();
+ } catch (CertException e) {
+
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/authz-certman/src/test/java/com/att/authz/cm/ca/JU_DevlCA.java b/authz-certman/src/test/java/com/att/authz/cm/ca/JU_DevlCA.java
new file mode 100644
index 00000000..c18afe5c
--- /dev/null
+++ b/authz-certman/src/test/java/com/att/authz/cm/ca/JU_DevlCA.java
@@ -0,0 +1,287 @@
+/*******************************************************************************
+ * ============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.ca;
+
+import static org.mockito.Mockito.CALLS_REAL_METHODS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.math.BigInteger;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.Principal;
+import java.security.PublicKey;
+import java.security.SignatureException;
+import java.security.cert.CertificateEncodingException;
+import java.security.cert.CertificateException;
+import java.security.cert.CertificateExpiredException;
+import java.security.cert.CertificateNotYetValidException;
+import java.security.cert.X509Certificate;
+import java.util.Date;
+import java.util.Set;
+
+import javax.security.auth.x500.X500Principal;
+import javax.servlet.http.HttpServletRequest;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import com.att.aft.dme2.api.http.HttpResponse;
+import com.att.aft.dme2.request.HttpRequest;
+import com.att.authz.cm.cert.CSRMeta;
+import com.att.cadi.cm.CertException;
+import com.att.dao.aaf.cached.CachedCertDAO;
+import com.att.dao.aaf.cass.CertDAO;
+import com.att.inno.env.Trans;
+
+
+@RunWith(MockitoJUnitRunner.class)
+public class JU_DevlCA {
+
+ @Mock
+ private static CachedCertDAO certDAO;
+
+ @Mock
+ private static HttpServletRequest req;
+
+ @Mock
+ private static CSRMeta csrMeta;
+
+ static Trans trans;
+
+ static X509Certificate cert;
+ static byte [] name = {1,23,4,54,6,56};
+
+ private static DevlCA devICA;
+
+ @BeforeClass
+ public static void setUp() throws CertificateException, CertException, IOException {
+ String str = "core java api";
+ byte[] b = str.getBytes();
+ Principal prc = new X500Principal("CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US");
+ req = mock(HttpServletRequest.class);
+ devICA = mock(DevlCA.class);
+ X509Certificate cert = new X509Certificate() {
+
+ @Override
+ public boolean hasUnsupportedCriticalExtension() {
+ return false;
+ }
+
+ @Override
+ public Set<String> getNonCriticalExtensionOIDs() {
+
+ return null;
+ }
+
+ @Override
+ public byte[] getExtensionValue(String oid) {
+
+ return null;
+ }
+
+ @Override
+ public Set<String> getCriticalExtensionOIDs() {
+
+ return null;
+ }
+
+ @Override
+ public void verify(PublicKey key, String sigProvider) throws CertificateException, NoSuchAlgorithmException,
+ InvalidKeyException, NoSuchProviderException, SignatureException {
+
+
+ }
+
+ @Override
+ public void verify(PublicKey key) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException,
+ NoSuchProviderException, SignatureException {
+
+
+ }
+
+ @Override
+ public String toString() {
+
+ return null;
+ }
+
+ @Override
+ public PublicKey getPublicKey() {
+
+ return null;
+ }
+
+ @Override
+ public byte[] getEncoded() throws CertificateEncodingException {
+
+ return null;
+ }
+
+ @Override
+ public int getVersion() {
+
+ return 0;
+ }
+
+ @Override
+ public byte[] getTBSCertificate() throws CertificateEncodingException {
+
+ return null;
+ }
+
+ @Override
+ public boolean[] getSubjectUniqueID() {
+
+ return null;
+ }
+
+ @Override
+ public Principal getSubjectDN() {
+
+ return null;
+ }
+
+ @Override
+ public byte[] getSignature() {
+
+ return null;
+ }
+
+ @Override
+ public byte[] getSigAlgParams() {
+
+ return null;
+ }
+
+ @Override
+ public String getSigAlgOID() {
+
+ return null;
+ }
+
+ @Override
+ public String getSigAlgName() {
+
+ return null;
+ }
+
+ @Override
+ public BigInteger getSerialNumber() {
+
+ return null;
+ }
+
+ @Override
+ public Date getNotBefore() {
+
+ return null;
+ }
+
+ @Override
+ public Date getNotAfter() {
+
+ return null;
+ }
+
+ @Override
+ public boolean[] getKeyUsage() {
+
+ return null;
+ }
+
+ @Override
+ public boolean[] getIssuerUniqueID() {
+
+ return null;
+ }
+
+ @Override
+ public Principal getIssuerDN() {
+
+ return null;
+ }
+
+ @Override
+ public int getBasicConstraints() {
+
+ return 0;
+ }
+
+ @Override
+ public void checkValidity(Date date) throws CertificateExpiredException, CertificateNotYetValidException {
+
+
+ }
+
+ @Override
+ public void checkValidity() throws CertificateExpiredException, CertificateNotYetValidException {
+
+ }
+ };
+ when(devICA.sign(Mockito.any(Trans.class), Mockito.any(CSRMeta.class))).thenReturn(cert);
+ certDAO = mock(CachedCertDAO.class, CALLS_REAL_METHODS);
+ }
+
+ @Test
+ public void identity_True() throws CertificateException, IOException, CertException {
+ assertNotNull(devICA.sign(trans, csrMeta));
+ }
+
+
+ @Test
+ public void identityNull() throws CertificateException {
+ try {
+ assertNotNull(devICA.sign(null, csrMeta));
+ } catch (IOException e) {
+
+ e.printStackTrace();
+ } catch (CertException e) {
+
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void identityBothNull() throws CertificateException {
+ try {
+ assertNotNull(devICA.sign(null, null));
+ } catch (IOException e) {
+
+ e.printStackTrace();
+ } catch (CertException e) {
+
+ e.printStackTrace();
+ }
+ }
+
+}
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);
+ }
+
+}
diff --git a/authz-certman/src/test/java/com/att/authz/cm/data/JU_CertReq.java b/authz-certman/src/test/java/com/att/authz/cm/data/JU_CertReq.java
new file mode 100644
index 00000000..f40268d9
--- /dev/null
+++ b/authz-certman/src/test/java/com/att/authz/cm/data/JU_CertReq.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * ============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.data;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import com.att.authz.cm.ca.CA;
+import com.att.authz.cm.cert.BCFactory;
+import com.att.authz.cm.cert.CSRMeta;
+import com.att.authz.cm.cert.StandardFields;
+import com.att.cadi.cm.CertException;
+import com.att.inno.env.Trans;
+
+@RunWith(MockitoJUnitRunner.class)
+public class JU_CertReq {
+
+ private static BCFactory bcFact;
+
+ private static CSRMeta value;
+
+ private static CertReq req;
+
+ @BeforeClass
+ public static void setUp() {
+ bcFact = mock(BCFactory.class);
+ value = mock(CSRMeta.class);
+ req = mock(CertReq.class);
+
+ }
+
+ @Test
+ public void getCSRMeta() throws CertException {
+ //req = new CertReq();
+ req.mechid = "1213";
+ List<String> fqdnsas = new ArrayList<String>();
+ fqdnsas.add("String1");
+ List<String> emails = new ArrayList<String>();
+ emails.add("pupleti@hotmail.com");
+ req.emails = emails;
+ req.fqdns = fqdnsas;
+ StandardFields sf = mock(StandardFields.class);
+ req.certAuthority = new CA("testName", sf, "ALL") {
+
+ @Override
+ public X509Certificate sign(Trans trans, CSRMeta csrmeta) throws IOException, CertException {
+
+ return null;
+ }
+ };
+ req.sponsor = "asa@df.co";
+ assertNull(req.getCSRMeta());
+ }
+}
diff --git a/authz-certman/src/test/java/com/att/authz/cm/facade/JU_FacadeImpl.java b/authz-certman/src/test/java/com/att/authz/cm/facade/JU_FacadeImpl.java
new file mode 100644
index 00000000..e613e594
--- /dev/null
+++ b/authz-certman/src/test/java/com/att/authz/cm/facade/JU_FacadeImpl.java
@@ -0,0 +1,195 @@
+/*******************************************************************************
+ * ============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.facade;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.CALLS_REAL_METHODS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.xml.namespace.QName;
+import javax.xml.validation.Schema;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import com.att.authz.cm.mapper.Mapper;
+import com.att.authz.cm.service.CMService;
+import com.att.authz.cm.service.CertManAPI;
+import com.att.authz.env.AuthzEnv;
+import com.att.authz.env.AuthzTrans;
+import com.att.cadi.aaf.AAFPermission;
+import com.att.authz.layer.Result;
+import com.att.cadi.aaf.v2_0.AAFLurPerm;
+import com.att.inno.env.APIException;
+import com.att.inno.env.Data;
+import com.att.inno.env.LogTarget;
+import com.att.inno.env.TimeTaken;
+import com.att.inno.env.Trans;
+import com.att.rosetta.env.RosettaDF;
+import com.att.rosetta.env.RosettaData;
+
+
+@RunWith(MockitoJUnitRunner.class)
+public class JU_FacadeImpl<REQ,CERT,ARTIFACTS,ERROR> {
+
+ private static AuthzTrans trans;
+ private static HttpServletResponse resp;
+ private static CertManAPI certman;
+ private static FacadeImpl hImpl;
+ private static CMService service;
+ private Mapper<REQ,CERT,ARTIFACTS,ERROR> mapper;
+ private Data.TYPE dataType;
+ private static AuthzEnv env;
+
+ private static FacadeImpl fImpl;
+ private static HttpServletRequest req;
+
+ @Before
+ public void setUp() throws APIException, IOException {
+ fImpl = mock(FacadeImpl.class);
+ env = mock(AuthzEnv.class);
+ resp = mock(HttpServletResponse.class);
+ req = mock(HttpServletRequest.class);
+ hImpl = mock(FacadeImpl.class, CALLS_REAL_METHODS);
+ Result<Void> rvd = (Result) mock(Result.class);
+ trans = mock(AuthzTrans.class);
+ when(trans.error()).thenReturn(new LogTarget() {
+
+ @Override
+ public void printf(String fmt, Object... vars) {}
+
+ @Override
+ public void log(Throwable e, Object... msgs) {
+ e.getMessage();
+ e.printStackTrace();
+ msgs.toString();
+
+ }
+
+ @Override
+ public void log(Object... msgs) {
+ }
+
+ @Override
+ public boolean isLoggable() {
+
+ return false;
+ }
+ });
+ when(trans.start(Mockito.anyString(), Mockito.anyInt())).thenReturn(new TimeTaken("Now", 1) {
+
+ @Override
+ public void output(StringBuilder sb) {
+
+ }
+ });
+ when(fImpl.check(Mockito.any(AuthzTrans.class), Mockito.any(HttpServletResponse.class), Mockito.anyString())).thenReturn(rvd);
+ when(resp.getOutputStream()).thenReturn(new ServletOutputStream() {
+
+ @Override
+ public void write(int b) throws IOException {
+
+
+ }
+ });
+
+ }
+
+ @Test
+ public void check() throws IOException {
+ AAFPermission ap = new AAFPermission("str1","str3","str2");
+ String perms = ap.getInstance();
+ assertNotNull(hImpl.check(trans, resp, perms));
+ }
+
+ @Test
+ public void checkNull() throws IOException {
+ AAFPermission ap = new AAFPermission(null,"Str3","str2");
+ String perms = ap.getInstance();
+ assertNotNull(hImpl.check(trans, resp, perms));
+ }
+
+ @Test
+ public void checkTwoNull() throws IOException {
+ AAFPermission ap = new AAFPermission(null,null,"str2");
+ String perms = ap.getInstance();
+ assertNotNull(fImpl.check(trans, resp, perms));
+ }
+
+ @Test
+ public void checkAllNull() throws IOException {
+ AAFPermission ap = new AAFPermission(null,null,null);
+ String perms = ap.getInstance();
+ assertNotNull(fImpl.check(trans, resp, perms));
+ }
+
+ @Test
+ public void checkTrans_null() throws IOException {
+ AAFPermission ap = new AAFPermission("str1","str3","str2");
+ String perms = ap.getInstance();
+ assertNotNull(hImpl.check(null, resp, perms));
+ }
+
+ @Test
+ public void checkRespNull() throws IOException {
+ AAFPermission ap = new AAFPermission("str1","str3","str2");
+ String perms = ap.getInstance();
+ assertNotNull(hImpl.check(trans, null, perms));
+ }
+
+ @Test
+ public void requestCert() {
+ assertNotNull(hImpl.requestCert(trans, req, resp, true));
+ }
+
+ @Test
+ public void renewCert() {
+ assertNotNull(hImpl.renewCert(trans, req, resp, true));
+ }
+
+ @Test
+ public void dropCert() {
+ assertNotNull(hImpl.renewCert(trans, req, resp, true));
+ }
+
+ @Test
+ public void createArtifacts() {
+ assertNotNull(hImpl.createArtifacts(trans, req, resp));
+ }
+
+ @Test
+ public void readArtifacts() {
+ assertNotNull(hImpl.readArtifacts(trans, req, resp));
+ }
+}
diff --git a/authz-certman/src/test/java/com/att/authz/cm/validation/JU_Validator.java b/authz-certman/src/test/java/com/att/authz/cm/validation/JU_Validator.java
new file mode 100644
index 00000000..e3a428aa
--- /dev/null
+++ b/authz-certman/src/test/java/com/att/authz/cm/validation/JU_Validator.java
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * ============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.validation;
+
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import com.att.dao.aaf.cass.ArtiDAO;
+
+@RunWith(MockitoJUnitRunner.class)
+public class JU_Validator {
+
+ private static Validator validator;
+
+ @BeforeClass
+ public static void setUp() {
+ validator = new Validator();
+ }
+
+ @Test
+ public void nullCheck() {
+ assertNotNull(validator.nullOrBlank("TestName", null).errs());
+ }
+
+ @Test
+ public void blankCheck() {
+ assertNotNull(validator.nullOrBlank("TestName", "").err());
+ }
+
+ @Test
+ public void notOK_null() {
+ assertNotNull(validator.notOK(null));
+ }
+
+ @Test
+ public void isNullCheck() {
+ assertNotNull(validator.isNull("TestName", null).errs());
+ }
+
+ @Test
+ public void nullBlankMin() {
+ assertNotNull(validator.nullBlankMin("TestName", null, 0));
+ }
+
+ @Test
+ public void artistsRequired() {
+ assertNotNull(validator.artisRequired(null, 0));
+ }
+
+ @Test
+ public void artistRequired() {
+ assertNotNull(validator.artisRequired(new ArrayList<ArtiDAO.Data>(), -1));
+ }
+
+ @Test
+ public void artistRequired_Null() {
+ assertNotNull(validator.artisRequired(null, -1));
+ }
+
+ @Test
+ public void artistkeys() {
+ assertNotNull(validator.artisKeys(new ArrayList<ArtiDAO.Data>(), -1));
+ }
+
+ @Test
+ public void artistKeys_Null() {
+ assertNotNull(validator.artisKeys(null, -1));
+ }
+
+ @Test
+ public void keys() {
+ assertNotNull(validator.keys(new ArtiDAO.Data()));
+ }
+}