2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 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 package org.onap.aai.aaf.auth;
23 import org.junit.BeforeClass;
24 import org.junit.Test;
26 import javax.servlet.http.HttpServletRequest;
28 import java.io.FileInputStream;
29 import java.io.IOException;
30 import java.util.List;
31 import java.util.Properties;
33 import static org.easymock.EasyMock.*;
34 import static org.junit.Assert.assertTrue;
37 * The Class CertUtilTest
39 public class CertUtilTest extends AAISetup {
42 public void testCadiCertIssuers() throws IOException {
43 String propFile = System.getProperty("BUNDLECONFIG_DIR") + "/aaf/cadi.properties";
44 Properties cadiProperties = new Properties();
45 cadiProperties.load(new FileInputStream(new File(propFile)));
47 List<String> issuersList = CertUtil.getCadiCertIssuers(cadiProperties);
48 assertTrue("issuersList isn't populated", !issuersList.isEmpty());
50 int x = issuersList.get(0).indexOf(" ");
51 assertTrue("issuer contains spaces", x < 0);
55 public void testAaiSslClientOuHeader() {
57 HttpServletRequest mockRequest = createMock(HttpServletRequest.class);
58 expect(mockRequest.getHeader(CertUtil.AAI_SSL_CLIENT_OU_HDR)).andReturn("m55555@org.onap.com:TEST").times(1, 4);
59 expect(mockRequest.getHeader(CertUtil.AAI_SSL_CLIENT_CN_HDR)).andReturn("CN").times(1, 2);
60 expect(mockRequest.getHeader(CertUtil.AAI_SSL_CLIENT_O_HDR)).andReturn("O").times(1, 2);
61 expect(mockRequest.getHeader(CertUtil.AAI_SSL_CLIENT_L_HDR)).andReturn("L").times(1, 2);
62 expect(mockRequest.getHeader(CertUtil.AAI_SSL_CLIENT_ST_HDR)).andReturn("ST").times(1, 2);
63 expect(mockRequest.getHeader(CertUtil.AAI_SSL_CLIENT_C_HDR)).andReturn("C").times(1, 2);
66 String ou = CertUtil.getAaiSslClientOuHeader(mockRequest);
67 assertTrue("OU Header value is not as expected", ou.equals("m55555@org.onap.com:TEST"));
69 assertTrue("Unexpected isHaProxy() return value", CertUtil.isHaProxy(mockRequest));
71 String mechId = CertUtil.getMechId(mockRequest);
72 assertTrue("mechid value is not as expected", mechId.equals("m55555@org.onap.com"));
77 public void testBuildUserChain() {
79 // aaf.userchain.pattern=<AAF-ID>:${aaf.userchain.service.reference}:${aaf.userchain.auth.type}:AS
80 String aafUserChainPattern = "<AAF-ID>:org.onap.haproxy:X509:AS";
81 String mechid = "m11111@onap.org";
82 String result = CertUtil.buildUserChainHeader(mechid, aafUserChainPattern);
84 assertTrue("user chain value is not as expected", "m11111@onap.org:org.onap.haproxy:X509:AS".equals(result));