DataStore implements DataCacheProvider, RolesProvider { void addRoleToList(String role, String rolePrefix, String[] requestedRoleList, Set<String> accessibleRoles, boolean keepFullName) { if (!role.startsWith(rolePrefix)) { return; } if (requestedRoleList != null) { boolean matchFound = false; for (String requestedRole : requestedRoleList) { if (role.endsWith(requestedRole)) { matchFound = true; break; } } if (!matchFound) { return; } } if (keepFullName) { accessibleRoles.add(role); } else { accessibleRoles.add(role.substring(rolePrefix.length())); } } 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 testAddRoleToListPrefixNoMatch() { ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0"); DataStore store = new DataStore(clogStore, null); Set<String> accessibleRoles = new HashSet<>(); store.addRoleToList("sports:role.admin", "coretech:role.", null, accessibleRoles, false); assertEquals(accessibleRoles.size(), 0); }
@Test public void testAddRoleToList() { ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0"); DataStore store = new DataStore(clogStore, null); Set<String> accessibleRoles = new HashSet<>(); store.addRoleToList("coretech:role.admin", "coretech:role.", null, accessibleRoles, false); assertEquals(accessibleRoles.size(), 1); assertTrue(accessibleRoles.contains("admin")); }
@Test public void testAddRoleToListSingleRoleSpecified() { ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0"); DataStore store = new DataStore(clogStore, null); Set<String> accessibleRoles = new HashSet<>(); String[] requestedRoleList = { "admin" }; store.addRoleToList("coretech:role.admin", "coretech:role.", requestedRoleList, accessibleRoles, false); assertEquals(accessibleRoles.size(), 1); assertTrue(accessibleRoles.contains("admin")); }
@Test public void testAddRoleToListSingleRoleSpecifiedNoMatch() { ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0"); DataStore store = new DataStore(clogStore, null); Set<String> accessibleRoles = new HashSet<>(); String[] requestedRoleList = { "admin2" }; store.addRoleToList("coretech:role.admin", "coretech:role.", requestedRoleList, accessibleRoles, false); assertEquals(accessibleRoles.size(), 0); }
@Test public void testAddRoleToListMultipleRoleSpecified() { ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0"); DataStore store = new DataStore(clogStore, null); Set<String> accessibleRoles = new HashSet<>(); String[] requestedRoleList = { "admin2", "admin3", "admin" }; store.addRoleToList("coretech:role.admin", "coretech:role.", requestedRoleList, accessibleRoles, false); assertEquals(accessibleRoles.size(), 1); assertTrue(accessibleRoles.contains("admin")); }
@Test public void testAddRoleToListMultipleRoleSpecifiedNoMatch() { ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0"); DataStore store = new DataStore(clogStore, null); Set<String> accessibleRoles = new HashSet<>(); String[] requestedRoleList = { "admin2", "admin3", "admin4" }; store.addRoleToList("coretech:role.admin", "coretech:role.", requestedRoleList, accessibleRoles, false); assertEquals(accessibleRoles.size(), 0); }