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
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END=========================================================
20 *******************************************************************************/
21 package org.onap.dmaap.commonauth.kafka.base.authorization;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertNull;
27 import static org.mockito.Mockito.when;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.mockito.Mock;
33 import org.mockito.MockitoAnnotations;
34 import org.onap.aaf.cadi.PropAccess;
35 import org.onap.aaf.cadi.aaf.AAFPermission;
36 import org.onap.aaf.cadi.aaf.v2_0.AAFAuthn;
37 import org.onap.aaf.cadi.aaf.v2_0.AAFConHttp;
38 import org.onap.aaf.cadi.aaf.v2_0.AbsAAFLur;
39 import org.powermock.core.classloader.annotations.PowerMockIgnore;
40 import org.powermock.modules.junit4.PowerMockRunner;
43 @RunWith(PowerMockRunner.class)
44 @PowerMockIgnore({"javax.net.ssl.*", "javax.security.auth.*"})
45 public class Cadi3AAFProviderTest {
47 public Cadi3AAFProvider cadi3AAFProvider;
50 private static AAFAuthn<?> aafAuthn;
53 private static AAFConHttp aafCon;
56 private static AbsAAFLur<AAFPermission> aafLur;
59 private static PropAccess access;
62 public void setUp() throws Exception {
63 MockitoAnnotations.initMocks(this);
64 System.setProperty("CADI_PROPERTIES", "src/test/resources/cadi.properties");
65 cadi3AAFProvider = new Cadi3AAFProvider();
69 public void testHasPermission() {
70 assertFalse(cadi3AAFProvider.hasPermission("userID", "permission", "instance", "action"));
74 public void testHasAdminPermission() {
75 assertEquals(cadi3AAFProvider.hasPermission("admin", "permission", "instance", "action"), true);
78 @Test(expected = NullPointerException.class)
79 public void tesAuthenticate() throws Exception {
80 when(aafAuthn.validate("userId", "password")).thenReturn("valid");
81 assertEquals(cadi3AAFProvider.authenticate("userId", "password"), "valid");
85 public void tesAuthenticateAdmin() throws Exception {
86 assertNull(cadi3AAFProvider.authenticate("kafkaUsername", "apiKey"));
90 public void tesAuthenticateAdminwtWrongCred() throws Exception {
91 assertNotNull(cadi3AAFProvider.authenticate("kafkaUsername", "api"));