DBService implements RolesProvider { public AthenzDomain getAthenzDomain(final String domainName, boolean masterCopy) { try (ObjectStoreConnection con = store.getConnection(true, masterCopy)) { return getAthenzDomain(con, domainName); } } 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 testSetMembersInDomainNullRoles() { String domainName = "null-roles"; Domain domain = new Domain().setModified(Timestamp.fromCurrentTime()); AthenzDomain athenzDomain = new AthenzDomain(domainName); athenzDomain.setDomain(domain); athenzDomain.setRoles(null); Mockito.when(mockObjStore.getConnection(true, false)).thenReturn(mockJdbcConn); Mockito.when(mockJdbcConn.getAthenzDomain(domainName)).thenReturn(athenzDomain); ObjectStore saveStore = zms.dbService.store; zms.dbService.store = mockObjStore; AthenzDomain resAthenzDomain = zms.dbService.getAthenzDomain(domainName, false); assertNull(resAthenzDomain.getRoles()); zms.dbService.store = saveStore; }
@Test public void testSetMembersInDomainEmptyMembers() { String domainName = "no-role-members"; List<RoleMember> roleMembers = new ArrayList<>(); roleMembers.add(new RoleMember().setMemberName("user.admin")); Role role = new Role().setMembers(null).setRoleMembers(roleMembers); List<Role> roles = new ArrayList<>(); roles.add(role); Domain domain = new Domain().setModified(Timestamp.fromCurrentTime()); AthenzDomain athenzDomain = new AthenzDomain(domainName); athenzDomain.setDomain(domain); athenzDomain.setRoles(roles); Mockito.when(mockObjStore.getConnection(true, false)).thenReturn(mockJdbcConn); Mockito.when(mockJdbcConn.getAthenzDomain(domainName)).thenReturn(athenzDomain); ObjectStore saveStore = zms.dbService.store; zms.dbService.store = mockObjStore; AthenzDomain resAthenzDomain = zms.dbService.getAthenzDomain(domainName, false); assertNotNull(resAthenzDomain.getRoles()); List<String> members = resAthenzDomain.getRoles().get(0).getMembers(); assertEquals(members.size(), 1); assertEquals(members.get(0), "user.admin"); zms.dbService.store = saveStore; }