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