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.Date;
45 import javax.security.auth.x500.X500Principal;
46 import javax.servlet.http.HttpServletRequest;
48 import org.junit.BeforeClass;
49 import org.junit.Test;
50 import org.junit.runner.RunWith;
51 import org.mockito.Mock;
52 import org.mockito.Mockito;
53 import org.mockito.runners.MockitoJUnitRunner;
54 import org.onap.aaf.auth.cm.cert.CSRMeta;
55 import org.onap.aaf.auth.dao.cached.CachedCertDAO;
56 import org.onap.aaf.cadi.cm.CertException;
57 import org.onap.aaf.misc.env.Trans;
59 //TODO: Gabe [JUnit] Missing class
60 @RunWith(MockitoJUnitRunner.class)
61 public class JU_DevlCA {
64 private static CachedCertDAO certDAO;
67 private static HttpServletRequest req;
70 private static CSRMeta csrMeta;
74 static X509andChain cert1;
75 static byte [] name = {1,23,4,54,6,56};
77 private static CA devICA;
80 public static void setUp() throws CertificateException, CertException, IOException {
81 String str = "core java api";
82 byte[] b = str.getBytes();
83 Principal prc = new X500Principal("CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US");
84 req = mock(HttpServletRequest.class);
85 devICA = mock(CA.class);
86 X509Certificate cert = new X509Certificate() {
89 public boolean hasUnsupportedCriticalExtension() {
94 public Set<String> getNonCriticalExtensionOIDs() {
100 public byte[] getExtensionValue(String oid) {
106 public Set<String> getCriticalExtensionOIDs() {
112 public void verify(PublicKey key, String sigProvider) throws CertificateException, NoSuchAlgorithmException,
113 InvalidKeyException, NoSuchProviderException, SignatureException {
119 public void verify(PublicKey key) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException,
120 NoSuchProviderException, SignatureException {
126 public String toString() {
132 public PublicKey getPublicKey() {
138 public byte[] getEncoded() throws CertificateEncodingException {
144 public int getVersion() {
150 public byte[] getTBSCertificate() throws CertificateEncodingException {
156 public boolean[] getSubjectUniqueID() {
162 public Principal getSubjectDN() {
168 public byte[] getSignature() {
174 public byte[] getSigAlgParams() {
180 public String getSigAlgOID() {
186 public String getSigAlgName() {
192 public BigInteger getSerialNumber() {
198 public Date getNotBefore() {
204 public Date getNotAfter() {
210 public boolean[] getKeyUsage() {
216 public boolean[] getIssuerUniqueID() {
222 public Principal getIssuerDN() {
228 public int getBasicConstraints() {
234 public void checkValidity(Date date) throws CertificateExpiredException, CertificateNotYetValidException {
240 public void checkValidity() throws CertificateExpiredException, CertificateNotYetValidException {
244 when(devICA.sign(Mockito.any(Trans.class), Mockito.any(CSRMeta.class))).thenReturn(cert1);
245 certDAO = mock(CachedCertDAO.class, CALLS_REAL_METHODS);
249 public void identity_True() throws CertificateException, IOException, CertException {
250 assertNotNull(devICA.sign(trans, csrMeta));
255 public void identityNull() throws CertificateException {
257 assertNotNull(devICA.sign(null, csrMeta));
258 } catch (IOException e) {
261 } catch (CertException e) {
268 public void identityBothNull() throws CertificateException {
270 assertNotNull(devICA.sign(null, null));
271 } catch (IOException e) {
274 } catch (CertException e) {