DBService implements RolesProvider { @Override public List<Role> getRolesByDomain(String domain) { AthenzDomain athenzDomain = getAthenzDomain(domain, false); return athenzDomain.getRoles(); } 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 testGetRolesByDomain() { ObjectStore saveStore = zms.dbService.store; AthenzDomain athenzDomain = new AthenzDomain("test1"); Domain domain = new Domain().setName("test1").setMemberExpiryDays(100).setModified(Timestamp.fromCurrentTime()); athenzDomain.setDomain(domain); Role testRole = new Role(); testRole.setName("admin"); List<Role> roles = new ArrayList<>(); roles.add(testRole); athenzDomain.setRoles(roles); Mockito.when(mockObjStore.getConnection(true, false)).thenReturn(mockJdbcConn); Mockito.when(mockJdbcConn.getDomain(eq("test1"))).thenReturn(domain); Mockito.when(mockJdbcConn.getAthenzDomain(eq("test1"))).thenReturn(athenzDomain); zms.dbService.store = mockObjStore; List<Role> rolesFetched = zms.dbService.getRolesByDomain("test1"); assertEquals(1, rolesFetched.size()); assertEquals("admin", rolesFetched.get(0).getName()); zms.dbService.store = saveStore; }
@Test public void testGetRolesByDomainUnknown() { Mockito.when(mockObjStore.getConnection(true, false)).thenReturn(mockJdbcConn); try { zms.dbService.getRolesByDomain("unknownDomain"); fail(); } catch (Exception ignored) { } }