+++ /dev/null
-/*******************************************************************************\r
- * ============LICENSE_START====================================================\r
- * * org.onap.aaf\r
- * * ===========================================================================\r
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * * ===========================================================================\r
- * * Licensed under the Apache License, Version 2.0 (the "License");\r
- * * you may not use this file except in compliance with the License.\r
- * * You may obtain a copy of the License at\r
- * * \r
- * * http://www.apache.org/licenses/LICENSE-2.0\r
- * * \r
- * * Unless required by applicable law or agreed to in writing, software\r
- * * distributed under the License is distributed on an "AS IS" BASIS,\r
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * * See the License for the specific language governing permissions and\r
- * * limitations under the License.\r
- * * ============LICENSE_END====================================================\r
- * *\r
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
- * *\r
- ******************************************************************************/\r
-package org.onap.aaf.cadi;\r
-\r
-import static org.junit.Assert.*;\r
-\r
-import org.junit.Test;\r
-\r
-import static org.junit.Assert.*;\r
-import static org.mockito.Matchers.isA;\r
-import static org.mockito.Mockito.when;\r
-\r
-import java.security.Principal;\r
-import java.util.List;\r
-\r
-import javax.servlet.http.HttpServletRequest;\r
-\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import org.mockito.Mock;\r
-import org.mockito.Mockito;\r
-import org.mockito.MockitoAnnotations;\r
-import org.onap.aaf.cadi.CachedPrincipal.Resp;\r
-import org.onap.aaf.cadi.filter.MapPermConverter;\r
-import org.onap.aaf.cadi.lur.EpiLur;\r
-import org.onap.aaf.cadi.taf.TafResp;\r
-\r
-public class JU_CadiWrapTest {\r
- \r
- @Mock\r
- private HttpServletRequest request;\r
- \r
- @Mock\r
- private TafResp tafResp;\r
- \r
- @Mock\r
- private Principal principle;\r
-\r
- @Mock\r
- private Lur lur;\r
-\r
- @Before\r
- public void setUp() throws Exception {\r
- MockitoAnnotations.initMocks(this);\r
- }\r
-\r
- @Test\r
- public void testInstantiate() throws CadiException {\r
- Access a = new PropAccess();\r
- when(tafResp.getAccess()).thenReturn(a);\r
- \r
- lur.fishAll(isA(Principal.class), isA(List.class));\r
- \r
- EpiLur lur1 = new EpiLur(lur);\r
- \r
- CadiWrap wrap = new CadiWrap(request, tafResp, lur1);\r
- \r
- assertNull(wrap.getUserPrincipal());\r
- assertNull(wrap.getRemoteUser());\r
- assertNull(wrap.getUser());\r
- assertEquals(wrap.getPermissions(principle).size(), 0);\r
- \r
- byte[] arr = {'1','2'};\r
- wrap.setCred(arr);\r
- \r
- assertEquals(arr, wrap.getCred());\r
- \r
- wrap.setUser("User1");\r
- assertEquals("User1", wrap.getUser());\r
- \r
- wrap.invalidate("1");\r
-\r
- assertFalse(wrap.isUserInRole(null));\r
- \r
- wrap.set(tafResp, lur);\r
- \r
- wrap.invalidate("2");\r
- \r
- wrap.isUserInRole("User1");\r
- }\r
-\r
- @Test\r
- public void testInstantiateWithPermConverter() throws CadiException {\r
- Access a = new PropAccess();\r
- when(tafResp.getAccess()).thenReturn(a);\r
- when(tafResp.getPrincipal()).thenReturn(principle);\r
- \r
- \r
- CachingLur<Permission> lur1 = new CachingLur<Permission>() {\r
-\r
- @Override\r
- public Permission createPerm(String p) {\r
- // TODO Auto-generated method stub\r
- return null;\r
- }\r
-\r
- @Override\r
- public boolean fish(Principal bait, Permission pond) {\r
- // TODO Auto-generated method stub\r
- return true;\r
- }\r
-\r
- @Override\r
- public void fishAll(Principal bait, List<Permission> permissions) {\r
- // TODO Auto-generated method stub\r
- \r
- }\r
-\r
- @Override\r
- public void destroy() {\r
- // TODO Auto-generated method stub\r
- \r
- }\r
-\r
- @Override\r
- public boolean handlesExclusively(Permission pond) {\r
- // TODO Auto-generated method stub\r
- return false;\r
- }\r
-\r
- @Override\r
- public boolean supports(String userName) {\r
- // TODO Auto-generated method stub\r
- return false;\r
- }\r
-\r
- @Override\r
- public void remove(String user) {\r
- // TODO Auto-generated method stub\r
- \r
- }\r
-\r
- @Override\r
- public Resp reload(User<Permission> user) {\r
- // TODO Auto-generated method stub\r
- return null;\r
- }\r
-\r
- @Override\r
- public void setDebug(String commaDelimIDsOrNull) {\r
- // TODO Auto-generated method stub\r
- \r
- }\r
-\r
- @Override\r
- public void clear(Principal p, StringBuilder sb) {\r
- // TODO Auto-generated method stub\r
- \r
- }\r
- };\r
- \r
- MapPermConverter pc = new MapPermConverter();\r
- \r
- CadiWrap wrap = new CadiWrap(request, tafResp, lur1, pc);\r
- \r
- assertNotNull(wrap.getUserPrincipal());\r
- assertNull(wrap.getRemoteUser());\r
- assertNull(wrap.getUser());\r
- \r
- byte[] arr = {'1','2'};\r
- wrap.setCred(arr);\r
- \r
- assertEquals(arr, wrap.getCred());\r
- \r
- wrap.setUser("User1");\r
- assertEquals("User1", wrap.getUser());\r
- \r
- wrap.invalidate("1");\r
- wrap.setPermConverter(new MapPermConverter());\r
- \r
- assertTrue(wrap.getLur() instanceof CachingLur);\r
- assertTrue(wrap.isUserInRole("User1"));\r
- \r
- wrap.set(tafResp, lur);\r
- assertFalse(wrap.isUserInRole("Perm1"));\r
- }\r
-}\r