1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package org.onap.aaf.cadi;
\r
25 import static org.junit.Assert.*;
\r
27 import org.junit.Test;
\r
29 import static org.junit.Assert.*;
\r
30 import static org.mockito.Matchers.isA;
\r
31 import static org.mockito.Mockito.when;
\r
33 import java.security.Principal;
\r
34 import java.util.List;
\r
36 import javax.servlet.http.HttpServletRequest;
\r
38 import org.junit.Before;
\r
39 import org.junit.Test;
\r
40 import org.mockito.Mock;
\r
41 import org.mockito.Mockito;
\r
42 import org.mockito.MockitoAnnotations;
\r
43 import org.onap.aaf.cadi.CachedPrincipal.Resp;
\r
44 import org.onap.aaf.cadi.filter.MapPermConverter;
\r
45 import org.onap.aaf.cadi.lur.EpiLur;
\r
46 import org.onap.aaf.cadi.taf.TafResp;
\r
48 public class JU_CadiWrapTest {
\r
51 private HttpServletRequest request;
\r
54 private TafResp tafResp;
\r
57 private Principal principle;
\r
63 public void setUp() throws Exception {
\r
64 MockitoAnnotations.initMocks(this);
\r
68 public void testInstantiate() throws CadiException {
\r
69 Access a = new PropAccess();
\r
70 when(tafResp.getAccess()).thenReturn(a);
\r
72 lur.fishAll(isA(Principal.class), isA(List.class));
\r
74 EpiLur lur1 = new EpiLur(lur);
\r
76 CadiWrap wrap = new CadiWrap(request, tafResp, lur1);
\r
78 assertNull(wrap.getUserPrincipal());
\r
79 assertNull(wrap.getRemoteUser());
\r
80 assertNull(wrap.getUser());
\r
81 assertEquals(wrap.getPermissions(principle).size(), 0);
\r
83 byte[] arr = {'1','2'};
\r
86 assertEquals(arr, wrap.getCred());
\r
88 wrap.setUser("User1");
\r
89 assertEquals("User1", wrap.getUser());
\r
91 wrap.invalidate("1");
\r
93 assertFalse(wrap.isUserInRole(null));
\r
95 wrap.set(tafResp, lur);
\r
97 wrap.invalidate("2");
\r
99 wrap.isUserInRole("User1");
\r
103 public void testInstantiateWithPermConverter() throws CadiException {
\r
104 Access a = new PropAccess();
\r
105 when(tafResp.getAccess()).thenReturn(a);
\r
106 when(tafResp.getPrincipal()).thenReturn(principle);
\r
109 CachingLur<Permission> lur1 = new CachingLur<Permission>() {
\r
112 public Permission createPerm(String p) {
\r
113 // TODO Auto-generated method stub
\r
118 public boolean fish(Principal bait, Permission pond) {
\r
119 // TODO Auto-generated method stub
\r
124 public void fishAll(Principal bait, List<Permission> permissions) {
\r
125 // TODO Auto-generated method stub
\r
130 public void destroy() {
\r
131 // TODO Auto-generated method stub
\r
136 public boolean handlesExclusively(Permission pond) {
\r
137 // TODO Auto-generated method stub
\r
142 public boolean supports(String userName) {
\r
143 // TODO Auto-generated method stub
\r
148 public void remove(String user) {
\r
149 // TODO Auto-generated method stub
\r
154 public Resp reload(User<Permission> user) {
\r
155 // TODO Auto-generated method stub
\r
160 public void setDebug(String commaDelimIDsOrNull) {
\r
161 // TODO Auto-generated method stub
\r
166 public void clear(Principal p, StringBuilder sb) {
\r
167 // TODO Auto-generated method stub
\r
172 MapPermConverter pc = new MapPermConverter();
\r
174 CadiWrap wrap = new CadiWrap(request, tafResp, lur1, pc);
\r
176 assertNotNull(wrap.getUserPrincipal());
\r
177 assertNull(wrap.getRemoteUser());
\r
178 assertNull(wrap.getUser());
\r
180 byte[] arr = {'1','2'};
\r
183 assertEquals(arr, wrap.getCred());
\r
185 wrap.setUser("User1");
\r
186 assertEquals("User1", wrap.getUser());
\r
188 wrap.invalidate("1");
\r
189 wrap.setPermConverter(new MapPermConverter());
\r
191 assertTrue(wrap.getLur() instanceof CachingLur);
\r
192 assertTrue(wrap.isUserInRole("User1"));
\r
194 wrap.set(tafResp, lur);
\r
195 assertFalse(wrap.isUserInRole("Perm1"));
\r