1 /*******************************************************************************
2 * ============LICENSE_START====================================================
4 * * ===========================================================================
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * * ===========================================================================
7 * * Licensed under the Apache License, Version 2.0 (the "License");
8 * * you may not use this file except in compliance with the License.
9 * * You may obtain a copy of the License at
11 * * http://www.apache.org/licenses/LICENSE-2.0
13 * * Unless required by applicable law or agreed to in writing, software
14 * * distributed under the License is distributed on an "AS IS" BASIS,
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * * See the License for the specific language governing permissions and
17 * * limitations under the License.
18 * * ============LICENSE_END====================================================
21 ******************************************************************************/
22 package org.onap.aaf.auth.cm.ca;
24 import static org.junit.Assert.assertNotNull;
25 import static org.mockito.Mockito.CALLS_REAL_METHODS;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.when;
29 import java.io.IOException;
30 import java.math.BigInteger;
31 import java.security.InvalidKeyException;
32 import java.security.NoSuchAlgorithmException;
33 import java.security.NoSuchProviderException;
34 import java.security.Principal;
35 import java.security.PublicKey;
36 import java.security.SignatureException;
37 import java.security.cert.CertificateEncodingException;
38 import java.security.cert.CertificateException;
39 import java.security.cert.CertificateExpiredException;
40 import java.security.cert.CertificateNotYetValidException;
41 import java.security.cert.X509Certificate;
42 import java.util.ArrayList;
43 import java.util.Date;
46 import javax.security.auth.x500.X500Principal;
47 import javax.servlet.http.HttpServletRequest;
49 import org.junit.BeforeClass;
50 import org.junit.Test;
51 import org.junit.runner.RunWith;
52 import org.mockito.Mock;
53 import org.mockito.Mockito;
54 import org.mockito.runners.MockitoJUnitRunner;
55 import org.onap.aaf.auth.cm.ca.CA;
56 import org.onap.aaf.auth.cm.cert.CSRMeta;
57 import org.onap.aaf.auth.dao.cached.CachedCertDAO;
58 import org.onap.aaf.cadi.cm.CertException;
59 import org.onap.aaf.misc.env.Trans;
61 //TODO: Gabe [JUnit] Import does not exist
62 @RunWith(MockitoJUnitRunner.class)
63 public class JU_AppCA {
66 private static CachedCertDAO certDAO;
69 private static HttpServletRequest req;
72 private static CSRMeta csrMeta;
76 static X509andChain cert1;
77 static byte [] name = {1,23,4,54,6,56};
79 private static LocalCA localCA;
82 public static void setUp() throws CertificateException, CertException, IOException {
83 String str = "core java api";
84 byte[] b = str.getBytes();
85 Principal prc = new X500Principal("CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US");
86 req = mock(HttpServletRequest.class);
87 localCA = mock(LocalCA.class);
88 X509Certificate cert = new X509Certificate() {
91 public boolean hasUnsupportedCriticalExtension() {
96 public Set<String> getNonCriticalExtensionOIDs() {
102 public byte[] getExtensionValue(String oid) {
108 public Set<String> getCriticalExtensionOIDs() {
114 public void verify(PublicKey key, String sigProvider) throws CertificateException, NoSuchAlgorithmException,
115 InvalidKeyException, NoSuchProviderException, SignatureException {
121 public void verify(PublicKey key) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException,
122 NoSuchProviderException, SignatureException {
128 public String toString() {
134 public PublicKey getPublicKey() {
140 public byte[] getEncoded() throws CertificateEncodingException {
146 public int getVersion() {
152 public byte[] getTBSCertificate() throws CertificateEncodingException {
158 public boolean[] getSubjectUniqueID() {
164 public Principal getSubjectDN() {
170 public byte[] getSignature() {
176 public byte[] getSigAlgParams() {
182 public String getSigAlgOID() {
188 public String getSigAlgName() {
194 public BigInteger getSerialNumber() {
200 public Date getNotBefore() {
206 public Date getNotAfter() {
212 public boolean[] getKeyUsage() {
218 public boolean[] getIssuerUniqueID() {
224 public Principal getIssuerDN() {
230 public int getBasicConstraints() {
236 public void checkValidity(Date date) throws CertificateExpiredException, CertificateNotYetValidException {
242 public void checkValidity() throws CertificateExpiredException, CertificateNotYetValidException {
246 X509andChain xac = new X509andChain(cert, new ArrayList<String>());
247 when(localCA.sign(Mockito.any(Trans.class), Mockito.any(CSRMeta.class))).thenReturn(xac);
248 certDAO = mock(CachedCertDAO.class, CALLS_REAL_METHODS);
252 public void identity_True() throws CertificateException, IOException, CertException {
253 assertNotNull(localCA.sign(trans, csrMeta));
258 public void identityNull() throws CertificateException {
260 assertNotNull(localCA.sign(null, csrMeta));
261 } catch (IOException e) {
264 } catch (CertException e) {
271 public void identityBothNull() throws CertificateException {
273 assertNotNull(localCA.sign(null, null));
274 } catch (IOException e) {
277 } catch (CertException e) {