DBService implements RolesProvider { boolean processGroup(ObjectStoreConnection con, Group originalGroup, final String domainName, final String groupName, Group group, final String admin, final String auditRef, StringBuilder auditDetails) { boolean requestSuccess; if (originalGroup == null) { group.setAuditEnabled(false); requestSuccess = con.insertGroup(domainName, group); } else { group.setAuditEnabled(originalGroup.getAuditEnabled()); requestSuccess = con.updateGroup(domainName, group); } if (!requestSuccess) { return false; } auditDetails.append("{\"name\": \"").append(groupName).append('\"'); List<GroupMember> groupMembers = group.getGroupMembers(); if (originalGroup == null) { for (GroupMember member : groupMembers) { if (!con.insertGroupMember(domainName, groupName, member, admin, auditRef)) { return false; } } auditLogGroupMembers(auditDetails, "added-members", groupMembers); } else { if (!processUpdateGroupMembers(con, originalGroup, groupMembers, domainName, groupName, admin, auditRef, auditDetails)) { return false; } } auditDetails.append('}'); return true; } DBService(ObjectStore store, AuditLogger auditLogger, ZMSConfig zmsConfig, AuditReferenceValidator auditReferenceValidator); DomainRoleMembers listOverdueReviewRoleMembers(String domainName); @Override List<Role> getRolesByDomain(String domain); ResourceAccessList getResourceAccessList(String principal, String action); AthenzDomain getAthenzDomain(final String domainName, boolean masterCopy); Quota getQuota(String domainName); void executePutRoleSystemMeta(ResourceContext ctx, final String domainName, final String roleName,
           RoleSystemMeta meta, final String attribute, final String auditRef, final String caller); void executePutGroupSystemMeta(ResourceContext ctx, final String domainName, final String groupName,
                                          GroupSystemMeta meta, final String attribute, final String auditRef); void executePutServiceIdentitySystemMeta(ResourceContext ctx, String domainName, String serviceName,
            ServiceIdentitySystemMeta meta, String attribute, String auditRef, String caller); void executePutRoleMeta(ResourceContext ctx, String domainName, String roleName, Role originalRole,
                                   RoleMeta meta, String auditRef, String caller); void executePutGroupMeta(ResourceContext ctx, final String domainName, final String groupName,
                                    GroupMeta meta, final String auditRef); Set<String> getPendingMembershipApproverRoles(int delayDays); Set<String> getPendingGroupMembershipApproverRoles(int delayDays); Map<String, DomainRoleMember> getRoleExpiryMembers(int delayDays); Map<String, DomainRoleMember> getRoleReviewMembers(int delayDays); Map<String, DomainGroupMember> getGroupExpiryMembers(int delayDays); void processExpiredPendingMembers(int pendingRoleMemberLifespan, final String monitorIdentity); void processExpiredPendingGroupMembers(int pendingGroupMemberLifespan, final String monitorIdentity); static int AUDIT_TYPE_ROLE; static int AUDIT_TYPE_POLICY; static int AUDIT_TYPE_SERVICE; static int AUDIT_TYPE_DOMAIN; static int AUDIT_TYPE_ENTITY; static int AUDIT_TYPE_TENANCY; static int AUDIT_TYPE_TEMPLATE; static int AUDIT_TYPE_GROUP; }
@Test public void testProcessGroupFailure() { final String domainName = "failure-group-domain"; Group group1 = new Group().setName("group1"); StringBuilder auditDetails = new StringBuilder("testAudit"); try { zms.dbService.processGroup(zms.dbService.store.getConnection(true, true), null, domainName, "group1", group1, adminUser, auditRef, auditDetails); fail(); } catch (ResourceException ex) { assertEquals(ex.getCode(), ResourceException.BAD_REQUEST); } group1 = new Group().setName(domainName + ":group.group1"); Mockito.when(mockObjStore.getConnection(true, true)).thenReturn(mockJdbcConn); Mockito.when(mockJdbcConn.insertGroup(anyString(), any(Group.class))) .thenReturn(false); assertFalse(zms.dbService.processGroup(mockJdbcConn, null, domainName, "group1", group1, adminUser, auditRef, auditDetails)); Mockito.when(mockJdbcConn.insertGroup(anyString(), any(Group.class))) .thenReturn(true); Mockito.when(mockJdbcConn.insertGroupMember(anyString(), anyString(), any(GroupMember.class), anyString(), anyString())).thenReturn(false); List<GroupMember> groupMembers = new ArrayList<>(); groupMembers.add(new GroupMember().setMemberName("user.user1")); group1.setGroupMembers(groupMembers); assertFalse(zms.dbService.processGroup(mockJdbcConn, null, domainName, "group1", group1, adminUser, auditRef, auditDetails)); }
@Test public void testProcessGroupMemberFailure() { final String domainName = "failure-group-mbr-domain"; final String groupName = "group1"; Group groupOriginal = createGroupObject(domainName, groupName, "user.user1", "user.user2"); Group groupUpdated = createGroupObject(domainName, groupName, "user.user2", "user.user3"); Mockito.when(mockObjStore.getConnection(true, true)).thenReturn(mockJdbcConn); Mockito.when(mockJdbcConn.updateGroup(anyString(), any(Group.class))) .thenReturn(true); StringBuilder auditDetails = new StringBuilder("testAudit"); Mockito.when(mockJdbcConn.deleteGroupMember(anyString(), anyString(), anyString(), anyString(), anyString())).thenReturn(false); assertFalse(zms.dbService.processGroup(mockJdbcConn, groupOriginal, domainName, groupName, groupUpdated, adminUser, auditRef, auditDetails)); Mockito.when(mockJdbcConn.deleteGroupMember(anyString(), anyString(), anyString(), anyString(), anyString())).thenReturn(true); Mockito.when(mockJdbcConn.insertGroupMember(anyString(), anyString(), any(GroupMember.class), anyString(), anyString())).thenReturn(false); Mockito.when(mockJdbcConn.insertGroup(anyString(), any(Group.class))) .thenReturn(true); assertFalse(zms.dbService.processGroup(mockJdbcConn, groupOriginal, domainName, groupName, groupUpdated, adminUser, auditRef, auditDetails)); }