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 ******************************************************************************/
23 package org.onap.aaf.auth.direct.test;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertTrue;
28 import java.security.Principal;
29 import java.security.cert.CertificateException;
30 import java.security.cert.X509Certificate;
31 import java.util.ArrayList;
32 import java.util.List;
34 import javax.servlet.http.HttpServletRequest;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.junit.runner.RunWith;
39 import org.mockito.Mock;
40 import org.mockito.Mockito;
41 import org.onap.aaf.auth.dao.cached.CachedCertDAO;
42 import org.onap.aaf.auth.dao.cass.CertDAO;
43 import org.onap.aaf.auth.direct.DirectCertIdentity;
44 import org.onap.aaf.auth.env.AuthzTrans;
45 import org.onap.aaf.auth.layer.Result;
46 import org.powermock.modules.junit4.PowerMockRunner;
48 @RunWith(PowerMockRunner.class)
49 public class JU_DirectCertIdentity {
51 public DirectCertIdentity directCertIdentity;
55 directCertIdentity = new DirectCertIdentity();
59 HttpServletRequest req;
64 public void testidentity() {
67 Principal p = directCertIdentity.identity(req, cert, _certBytes);
68 assertEquals(((p) == null), true);
70 cert = Mockito.mock(X509Certificate.class);
71 Mockito.when(cert.getEncoded()).thenReturn(new byte[128]);
73 Result<List<CertDAO.Data>> rs = new Result<List<CertDAO.Data>>(null, 1, "test", new Object[0]);
75 CachedCertDAO cacheDao = Mockito.mock(CachedCertDAO.class);
76 Mockito.when(cacheDao.read(Mockito.any(AuthzTrans.class),Mockito.any(Object[].class))).thenReturn(rs);
77 DirectCertIdentity.set(cacheDao);
78 p = directCertIdentity.identity(req, cert, _certBytes);
80 _certBytes = new byte[128];
81 List<CertDAO.Data> dataAL = new ArrayList<>();
82 CertDAO.Data data = new CertDAO.Data();
84 rs = new Result<List<CertDAO.Data>>(dataAL, 0, "test", new Object[0]);
85 Mockito.when(cacheDao.read(Mockito.any(AuthzTrans.class),Mockito.any(Object[].class))).thenReturn(rs);
86 DirectCertIdentity.set(cacheDao);
87 p = directCertIdentity.identity(req, cert, _certBytes);
88 assertTrue(p.toString().contains("X509 Authentication for null"));
91 directCertIdentity.identity(req, cert, _certBytes);
92 } catch (CertificateException e) {
93 // TODO Auto-generated catch block