Merge "Fix sql injection vulnerability"
[portal.git] / ecomp-portal-BE-common / src / test / java / org / onap / portalapp / portal / service / AdminRolesServiceImplTest.java
index d9beb4d..f14d3fd 100644 (file)
@@ -4,6 +4,8 @@
  * ===================================================================
  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
  * ===================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ===================================================================
  *
  * Unless otherwise specified, all software contained herein is licensed
  * under the Apache License, Version 2.0 (the "License");
@@ -33,7 +35,7 @@
  *
  * ============LICENSE_END============================================
  *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * 
  */
 package org.onap.portalapp.portal.service;
 
@@ -93,6 +95,9 @@ public class AdminRolesServiceImplTest {
        @Mock
        DataAccessService dataAccessService = new DataAccessServiceImpl();
 
+    @Mock
+    ExternalAccessRolesService externalAccessRolesService;
+
        @Mock
        EPAppCommonServiceImpl epAppCommonServiceImpl = new EPAppCommonServiceImpl();
 
@@ -188,6 +193,21 @@ public class AdminRolesServiceImplTest {
                AppsListWithAdminRole  actual = adminRolesServiceImpl.getAppsWithAdminRoleStateForUser(user.getOrgUserId());
                assertNotNull(actual);
        }
+       
+       @Test
+       public void getAppsWithAdminRoleStateForUserTestWithException() {
+               EPUser user = mockUser.mockEPUser();
+               EPApp app = mockApp();
+               app.setId(1l);
+               List<EPUser> users = new ArrayList<>();
+               users.add(user);
+               Map<String, String> userParams = new HashMap<>();
+               userParams.put("org_user_id", user.getOrgUserId());
+               Mockito.when(dataAccessService.executeNamedQuery("getEPUserByOrgUserId", userParams, null)).thenReturn(users);
+               AppsListWithAdminRole  actual = adminRolesServiceImpl.getAppsWithAdminRoleStateForUser(user.getOrgUserId());
+
+               
+       }
 
        @SuppressWarnings({ "deprecation", "unchecked" })
        @Test
@@ -355,6 +375,25 @@ public class AdminRolesServiceImplTest {
                assertFalse(actual);
        }
 
+    @Test
+    public void isAccountAdminUserNull() {
+        boolean actual = adminRolesServiceImpl.isAccountAdmin(null);
+        assertFalse(actual);
+    }
+
+    @Test
+    public void isRoleAdminTest() {
+        EPUser user = mockUser.mockEPUser();
+        List<String> roles = new ArrayList<>();
+        roles.add("approver\\|");
+        Mockito.when(dataAccessService.executeNamedQuery(
+            Matchers.eq("getRoleFunctionsOfUserforAlltheApplications"), Matchers.any(), Matchers.any()))
+                .thenReturn(roles);
+        Mockito.when(externalAccessRolesService.getFunctionCodeType(Matchers.anyString())).thenReturn("approver");
+        boolean actual = adminRolesServiceImpl.isRoleAdmin(user);
+        assertTrue(actual);
+    }
+
        @Test
        public void isUserTest() {
                EPUser user = mockUser.mockEPUser();
@@ -417,8 +456,11 @@ public class AdminRolesServiceImplTest {
                epUserApp.setUserId(1l);
                userApps.add(epUserApp);
                user.setUserApps(userApps);
-               Mockito.when((EPUser) dataAccessService.getDomainObject(Matchers.any(), Matchers.anyLong(), Matchers.anyMap()))
-                               .thenReturn(user);
+               List<Integer> userAdminApps =  new ArrayList<>();
+               userAdminApps.add(1);
+               userAdminApps.add(2);
+               Mockito.when(dataAccessService.executeNamedQuery(Matchers.anyString(), Matchers.anyMap(), Matchers.anyMap()))
+                               .thenReturn(userAdminApps);
                boolean actual = adminRolesServiceImpl.isAccountAdminOfApplication(user, app);
                assertTrue(actual);
        }