Mass removal of all Tabs (Style Warnings)
[aaf/authz.git] / auth / auth-certman / src / test / java / org / onap / aaf / auth / cm / ca / JU_AppCA.java
1 /*******************************************************************************
2  * ============LICENSE_START====================================================
3  * * org.onap.aaf
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
10  * * 
11  *  *      http://www.apache.org/licenses/LICENSE-2.0
12  * * 
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====================================================
19  * *
20  * *
21  ******************************************************************************/
22 package org.onap.aaf.auth.cm.ca;
23
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;
28
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;
44 import java.util.Set;
45
46 import javax.security.auth.x500.X500Principal;
47 import javax.servlet.http.HttpServletRequest;
48
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.cert.CSRMeta;
56 import org.onap.aaf.auth.dao.cached.CachedCertDAO;
57 import org.onap.aaf.cadi.configure.CertException;
58 import org.onap.aaf.misc.env.Trans;
59
60 //TODO: Gabe [JUnit] Import does not exist
61 @RunWith(MockitoJUnitRunner.class)
62 public class JU_AppCA {
63     
64     @Mock
65     private static CachedCertDAO certDAO;
66     
67     @Mock
68     private static HttpServletRequest req;
69     
70     @Mock
71     private static CSRMeta csrMeta;
72     
73     static Trans trans;
74     
75     static X509andChain cert1;
76     static byte [] name = {1,23,4,54,6,56};
77     
78     private static LocalCA localCA;
79     
80     @BeforeClass
81     public static void setUp() throws CertificateException, CertException, IOException {
82         String str = "core java api";
83         byte[] b = str.getBytes();
84         Principal prc = new X500Principal("CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US");
85         req = mock(HttpServletRequest.class);
86         localCA = mock(LocalCA.class);
87         X509Certificate cert = new X509Certificate() {
88             
89             @Override
90             public boolean hasUnsupportedCriticalExtension() {
91                 return false;
92             }
93             
94             @Override
95             public Set<String> getNonCriticalExtensionOIDs() {
96                  
97                 return null;
98             }
99             
100             @Override
101             public byte[] getExtensionValue(String oid) {
102                  
103                 return null;
104             }
105             
106             @Override
107             public Set<String> getCriticalExtensionOIDs() {
108                  
109                 return null;
110             }
111             
112             @Override
113             public void verify(PublicKey key, String sigProvider) throws CertificateException, NoSuchAlgorithmException,
114                     InvalidKeyException, NoSuchProviderException, SignatureException {
115                  
116                 
117             }
118             
119             @Override
120             public void verify(PublicKey key) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException,
121                     NoSuchProviderException, SignatureException {
122                  
123                 
124             }
125             
126             @Override
127             public String toString() {
128                  
129                 return null;
130             }
131             
132             @Override
133             public PublicKey getPublicKey() {
134                  
135                 return null;
136             }
137             
138             @Override
139             public byte[] getEncoded() throws CertificateEncodingException {
140                  
141                 return null;
142             }
143             
144             @Override
145             public int getVersion() {
146                  
147                 return 0;
148             }
149             
150             @Override
151             public byte[] getTBSCertificate() throws CertificateEncodingException {
152                  
153                 return null;
154             }
155             
156             @Override
157             public boolean[] getSubjectUniqueID() {
158                  
159                 return null;
160             }
161             
162             @Override
163             public Principal getSubjectDN() {
164                  
165                 return null;
166             }
167             
168             @Override
169             public byte[] getSignature() {
170                  
171                 return null;
172             }
173             
174             @Override
175             public byte[] getSigAlgParams() {
176                  
177                 return null;
178             }
179             
180             @Override
181             public String getSigAlgOID() {
182                  
183                 return null;
184             }
185             
186             @Override
187             public String getSigAlgName() {
188                  
189                 return null;
190             }
191             
192             @Override
193             public BigInteger getSerialNumber() {
194                  
195                 return null;
196             }
197             
198             @Override
199             public Date getNotBefore() {
200                  
201                 return null;
202             }
203             
204             @Override
205             public Date getNotAfter() {
206                  
207                 return null;
208             }
209             
210             @Override
211             public boolean[] getKeyUsage() {
212                  
213                 return null;
214             }
215             
216             @Override
217             public boolean[] getIssuerUniqueID() {
218                  
219                 return null;
220             }
221             
222             @Override
223             public Principal getIssuerDN() {
224                  
225                 return null;
226             }
227             
228             @Override
229             public int getBasicConstraints() {
230                  
231                 return 0;
232             }
233             
234             @Override
235             public void checkValidity(Date date) throws CertificateExpiredException, CertificateNotYetValidException {
236                  
237                 
238             }
239             
240             @Override
241             public void checkValidity() throws CertificateExpiredException, CertificateNotYetValidException {
242                 
243             }
244         };
245         X509andChain xac = new X509andChain(cert, new ArrayList<>());
246         when(localCA.sign(Mockito.any(Trans.class), Mockito.any(CSRMeta.class))).thenReturn(xac);
247         certDAO = mock(CachedCertDAO.class, CALLS_REAL_METHODS);
248     }
249     
250     @Test
251     public void identity_True() throws CertificateException, IOException, CertException {
252         assertNotNull(localCA.sign(trans, csrMeta));
253     }
254     
255     
256     @Test
257     public void identityNull() throws CertificateException {
258         try {
259             assertNotNull(localCA.sign(null, csrMeta));
260         } catch (IOException e) {
261         
262             e.printStackTrace();
263         } catch (CertException e) {
264             
265             e.printStackTrace();
266         }
267     }
268     
269     @Test
270     public void identityBothNull() throws CertificateException {
271         try {
272             assertNotNull(localCA.sign(null, null));
273         } catch (IOException e) {
274         
275             e.printStackTrace();
276         } catch (CertException e) {
277             
278             e.printStackTrace();
279         }
280     }
281
282 }