1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
/*******************************************************************************
* ============LICENSE_START====================================================
* * org.onap.aaf
* * ===========================================================================
* * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
* * ===========================================================================
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* * ============LICENSE_END====================================================
* *
* * ECOMP is a trademark and service mark of AT&T Intellectual Property.
* *
******************************************************************************/
package org.onap.aaf.cadi;
import static org.junit.Assert.*;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.mockito.Matchers.isA;
import static org.mockito.Mockito.when;
import java.security.Principal;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.onap.aaf.cadi.CachedPrincipal.Resp;
import org.onap.aaf.cadi.filter.MapPermConverter;
import org.onap.aaf.cadi.lur.EpiLur;
import org.onap.aaf.cadi.taf.TafResp;
public class JU_CadiWrapTest {
@Mock
private HttpServletRequest request;
@Mock
private TafResp tafResp;
@Mock
private Principal principle;
@Mock
private Lur lur;
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
}
@Test
public void testInstantiate() throws CadiException {
Access a = new PropAccess();
when(tafResp.getAccess()).thenReturn(a);
lur.fishAll(isA(Principal.class), isA(List.class));
EpiLur lur1 = new EpiLur(lur);
CadiWrap wrap = new CadiWrap(request, tafResp, lur1);
assertNull(wrap.getUserPrincipal());
assertNull(wrap.getRemoteUser());
assertNull(wrap.getUser());
assertEquals(wrap.getPermissions(principle).size(), 0);
byte[] arr = {'1','2'};
wrap.setCred(arr);
assertEquals(arr, wrap.getCred());
wrap.setUser("User1");
assertEquals("User1", wrap.getUser());
wrap.invalidate("1");
assertFalse(wrap.isUserInRole(null));
wrap.set(tafResp, lur);
wrap.invalidate("2");
wrap.isUserInRole("User1");
}
@Test
public void testInstantiateWithPermConverter() throws CadiException {
Access a = new PropAccess();
when(tafResp.getAccess()).thenReturn(a);
when(tafResp.getPrincipal()).thenReturn(principle);
CachingLur<Permission> lur1 = new CachingLur<Permission>() {
@Override
public Permission createPerm(String p) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean fish(Principal bait, Permission pond) {
// TODO Auto-generated method stub
return true;
}
@Override
public void fishAll(Principal bait, List<Permission> permissions) {
// TODO Auto-generated method stub
}
@Override
public void destroy() {
// TODO Auto-generated method stub
}
@Override
public boolean handlesExclusively(Permission pond) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean supports(String userName) {
// TODO Auto-generated method stub
return false;
}
@Override
public void remove(String user) {
// TODO Auto-generated method stub
}
@Override
public Resp reload(User<Permission> user) {
// TODO Auto-generated method stub
return null;
}
@Override
public void setDebug(String commaDelimIDsOrNull) {
// TODO Auto-generated method stub
}
@Override
public void clear(Principal p, StringBuilder sb) {
// TODO Auto-generated method stub
}
};
MapPermConverter pc = new MapPermConverter();
CadiWrap wrap = new CadiWrap(request, tafResp, lur1, pc);
assertNotNull(wrap.getUserPrincipal());
assertNull(wrap.getRemoteUser());
assertNull(wrap.getUser());
byte[] arr = {'1','2'};
wrap.setCred(arr);
assertEquals(arr, wrap.getCred());
wrap.setUser("User1");
assertEquals("User1", wrap.getUser());
wrap.invalidate("1");
wrap.setPermConverter(new MapPermConverter());
assertTrue(wrap.getLur() instanceof CachingLur);
assertTrue(wrap.isUserInRole("User1"));
wrap.set(tafResp, lur);
assertFalse(wrap.isUserInRole("Perm1"));
}
}
|