Merge "Fix sql injection vulnerability"
[portal.git] / ecomp-portal-BE-common / src / test / java / org / onap / portalapp / portal / service / UserRolesCommonServiceImplTest.java
index adf205b..d3ac4b9 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START==========================================
  * ONAP Portal
  * ===================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
  * ===================================================================
  *
  * Unless otherwise specified, all software contained herein is licensed
@@ -446,8 +446,13 @@ public class UserRolesCommonServiceImplTest {
                Mockito.when(applicationsRestClientService.get(EcompRole[].class, mockApp.getId(), "/roles"))
                                .thenReturn(mockEcompRoleArray);
                // syncAppRolesTest
-               Mockito.when(session.createQuery("from " + EPRole.class.getName() + " where appId=" + mockApp.getId()))
+
+               Mockito.when(session.createQuery("from :name where appId = :appId"))
                                .thenReturn(epRoleQuery);
+
+               Mockito.when(epRoleQuery.setParameter("name",EPRole.class.getName())).thenReturn(epRoleQuery);
+               Mockito.when(epRoleQuery.setParameter("appId",mockApp.getId())).thenReturn(epRoleQuery);
+
                Mockito.doReturn(mockEPRoleList).when(epRoleQuery).list();
                Mockito.when(session.createQuery(
                                "from " + EPUserApp.class.getName() + " where app.id=" + mockApp.getId() + " and role_id=" + 15l))
@@ -1336,7 +1341,7 @@ public class UserRolesCommonServiceImplTest {
                EPUserAppRolesRequest mockEpAppRolesRequestData = new EPUserAppRolesRequest();
                Mockito.doNothing().when(dataAccessService).saveDomainObject(mockEpAppRolesRequestData, null);
                final Map<String, Long> params = new HashMap<>();
-               params.put("appId", appWithRolesForUser.appId);
+               params.put("appId", appWithRolesForUser.getAppId());
                params.put("appRoleId", roleInAppForUser.roleId);
                Mockito.when((List<EPUserAppRoles>) dataAccessService.executeNamedQuery("appRoles", params, null))
                                .thenReturn(epUserAppRolesList);