|
40 | 40 | import com.cloud.user.UserVO; |
41 | 41 |
|
42 | 42 | import org.apache.cloudstack.acl.RolePermissionEntity.Permission; |
| 43 | +import org.apache.cloudstack.utils.cache.LazyCache; |
| 44 | +import com.cloud.utils.Pair; |
43 | 45 |
|
44 | 46 | import junit.framework.TestCase; |
45 | 47 |
|
@@ -234,6 +236,10 @@ public void testCheckAccessAccountUsesCachedPermissions() throws Exception { |
234 | 236 | cachePeriodField.setAccessible(true); |
235 | 237 | cachePeriodField.set(apiAccessCheckerSpy, 1); |
236 | 238 |
|
| 239 | + Field rpCacheField = DynamicRoleBasedAPIAccessChecker.class.getDeclaredField("rolePermissionsCache"); |
| 240 | + rpCacheField.setAccessible(true); |
| 241 | + rpCacheField.set(apiAccessCheckerSpy, new LazyCache<Long, Pair<Role, List<RolePermission>>>(32, 1, apiAccessCheckerSpy::getRolePermissions)); |
| 242 | + |
237 | 243 | final String allowedApiName = "someAllowedApi"; |
238 | 244 | final RolePermission permission = new RolePermissionVO(1L, allowedApiName, Permission.ALLOW, null); |
239 | 245 | Mockito.when(roleServiceMock.findAllPermissionsBy(Mockito.anyLong())).thenReturn(Collections.singletonList(permission)); |
@@ -301,6 +307,10 @@ public void testGetApisAllowedToAccountUsesCachedPermissions() { |
301 | 307 | cachePeriodField.setAccessible(true); |
302 | 308 | cachePeriodField.set(apiAccessCheckerSpy, 1); |
303 | 309 |
|
| 310 | + Field rpCacheField = DynamicRoleBasedAPIAccessChecker.class.getDeclaredField("rolePermissionsCache"); |
| 311 | + rpCacheField.setAccessible(true); |
| 312 | + rpCacheField.set(apiAccessCheckerSpy, new LazyCache<Long, Pair<Role, List<RolePermission>>>(32, 1, apiAccessCheckerSpy::getRolePermissions)); |
| 313 | + |
304 | 314 | final RolePermission permission = new RolePermissionVO(1L, "api1", Permission.ALLOW, null); |
305 | 315 | Mockito.when(roleServiceMock.findAllPermissionsBy(Mockito.anyLong())).thenReturn(Collections.singletonList(permission)); |
306 | 316 |
|
|
0 commit comments