DataStore implements DataCacheProvider, RolesProvider { void processDomainPolicies(DomainData domainData, DataCache domainCache) { com.yahoo.athenz.zms.SignedPolicies signedPolicies = domainData.getPolicies(); if (signedPolicies == null) { return; } com.yahoo.athenz.zms.DomainPolicies domainPolicies = signedPolicies.getContents(); if (domainPolicies == null) { return; } List<com.yahoo.athenz.zms.Policy> policies = domainPolicies.getPolicies(); if (policies == null) { return; } List<Role> roles = domainData.getRoles(); HashMap<String, Role> roleMap = new HashMap<>(); for (Role role : roles) { roleMap.put(role.getName(), role); } for (com.yahoo.athenz.zms.Policy policy : policies) { domainCache.processPolicy(domainData.getName(), policy, roleMap); } } DataStore(ChangeLogStore clogStore, CloudStore cloudStore); JWKList getZtsJWKList(Boolean rfc); void init(); boolean processDomain(SignedDomain signedDomain, boolean saveInStore); boolean processDomainDeletes(); void processDomainChecks(); boolean processDomainUpdates(); DomainData getDomainData(String name); void addDomainToCache(String name, DataCache dataCache); @Override DataCache getDataCache(String domainName); List<GroupMember> getGroupMembers(final String groupName); void getAccessibleRoles(DataCache data, String domainName, String identity,
            String[] requestedRoleList, Set<String> accessibleRoles, boolean keepFullName); String getPublicKey(String domain, String service, String keyId); HostServices getHostServices(String host); CloudStore getCloudStore(); void setCloudStore(CloudStore cloudStore); Cache<String, DataCache> getCacheStore(); Map<String, String> getPublicKeyCache(); @Override List<Role> getRolesByDomain(String domain);  }
@Test public void testProcessDomainPolicies() { ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0"); DataStore store = new DataStore(clogStore, null); List<com.yahoo.athenz.zms.Policy> policies = new ArrayList<>(); com.yahoo.athenz.zms.Policy policy = new com.yahoo.athenz.zms.Policy(); com.yahoo.athenz.zms.Assertion assertion = new com.yahoo.athenz.zms.Assertion(); assertion.setResource("sports:role.readers"); assertion.setAction("assume_role"); assertion.setRole("coretech:role.readers"); List<com.yahoo.athenz.zms.Assertion> assertions = new ArrayList<>(); assertions.add(assertion); policy.setAssertions(assertions); policies.add(policy); List<Role> roles = new ArrayList<>(); Role role = new Role(); role.setName("coretech:role.admin"); List<RoleMember> members = new ArrayList<>(); members.add(new RoleMember().setMemberName("user_domain.user")); role.setRoleMembers(members); roles.add(role); role = new Role(); role.setName("coretech:role.readers"); members = new ArrayList<>(); members.add(new RoleMember().setMemberName("user_domain.user")); role.setRoleMembers(members); roles.add(role); com.yahoo.athenz.zms.DomainPolicies domainPolicies = new com.yahoo.athenz.zms.DomainPolicies(); domainPolicies.setDomain("coretech"); domainPolicies.setPolicies(policies); com.yahoo.athenz.zms.SignedPolicies signedPolicies = new com.yahoo.athenz.zms.SignedPolicies(); signedPolicies.setContents(domainPolicies); signedPolicies.setSignature(Crypto.sign(SignUtils.asCanonicalString(domainPolicies), pkey)); signedPolicies.setKeyId("0"); DomainData domainData = new DomainData(); domainData.setName("coretech"); domainData.setPolicies(signedPolicies); domainData.setRoles(roles); DataCache dataCache = new DataCache(); dataCache.setDomainData(domainData); store.processDomainRoles(domainData, dataCache); assertEquals(dataCache.getMemberRoleSet("user_domain.user").size(), 2); assertTrue(dataCache.getMemberRoleSet("user_domain.user") .contains(new MemberRole("coretech:role.admin", 0))); assertTrue(dataCache.getMemberRoleSet("user_domain.user") .contains(new MemberRole("coretech:role.readers", 0))); }
@Test public void testProcessDomainPoliciesNullPolicies() { ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0"); DataStore store = new DataStore(clogStore, null); DomainData domainData = new DomainData(); domainData.setName("coretech"); DataCache dataCache = new DataCache(); dataCache.setDomainData(domainData); store.processDomainPolicies(domainData, dataCache); assertEquals(dataCache.getMemberCount(), 0); SignedPolicies signedPolicies = new SignedPolicies(); domainData.setPolicies(signedPolicies); store.processDomainPolicies(domainData, dataCache); assertEquals(dataCache.getMemberCount(), 0); DomainPolicies domainPolicies = new DomainPolicies(); signedPolicies.setContents(domainPolicies); store.processDomainPolicies(domainData, dataCache); assertEquals(dataCache.getMemberCount(), 0); }