DataStore implements DataCacheProvider, RolesProvider { boolean roleMatchInSet(String role, Set<MemberRole> memberRoles) { String rolePattern; long currentTime = System.currentTimeMillis(); for (MemberRole memberRole : memberRoles) { long expiration = memberRole.getExpiration(); if (expiration != 0 && expiration < currentTime) { continue; } final String roleName = memberRole.getRole(); if (StringUtils.containsMatchCharacter(roleName)) { rolePattern = StringUtils.patternFromGlob(roleName); if (role.matches(rolePattern)) { return true; } } else { if (role.equals(roleName)) { return true; } } } return false; } 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 testRoleMatchInSetPlain() { ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0"); DataStore store = new DataStore(clogStore, null); Set<MemberRole> checkSet = new HashSet<>(); checkSet.add(new MemberRole("writers", 0)); checkSet.add(new MemberRole("readers", 0)); assertTrue(store.roleMatchInSet("writers", checkSet)); assertTrue(store.roleMatchInSet("readers", checkSet)); assertFalse(store.roleMatchInSet("admin", checkSet)); assertFalse(store.roleMatchInSet("testwriters", checkSet)); assertFalse(store.roleMatchInSet("writerstest", checkSet)); }
@Test public void testRoleMatchInSetExpiration() { ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0"); DataStore store = new DataStore(clogStore, null); Set<MemberRole> checkSet = new HashSet<>(); checkSet.add(new MemberRole("expired", System.currentTimeMillis() - 100000)); checkSet.add(new MemberRole("notexpired", System.currentTimeMillis() + 100000)); assertFalse(store.roleMatchInSet("expired", checkSet)); assertTrue(store.roleMatchInSet("notexpired", checkSet)); }
@Test public void testRoleMatchInSetRegex() { ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0"); DataStore store = new DataStore(clogStore, null); Set<MemberRole> checkSet = new HashSet<>(); checkSet.add(new MemberRole("coretech:role.readers", 0)); checkSet.add(new MemberRole("coretech:role.writers", 0)); checkSet.add(new MemberRole("*:role.update", 0)); checkSet.add(new MemberRole("weather:role.*", 0)); assertTrue(store.roleMatchInSet("coretech:role.readers", checkSet)); assertTrue(store.roleMatchInSet("coretech:role.writers", checkSet)); assertTrue(store.roleMatchInSet("sports:role.update", checkSet)); assertTrue(store.roleMatchInSet("weather:role.update", checkSet)); assertFalse(store.roleMatchInSet("coretech:role.admin", checkSet)); }