DataStore implements DataCacheProvider, RolesProvider { void addPublicKeys(Map<String, String> publicKeyMap) { if (publicKeyMap == null || publicKeyMap.isEmpty()) { return; } for (Map.Entry<String, String> entry : publicKeyMap.entrySet()) { publicKeyCache.put(entry.getKey(), entry.getValue()); } } 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 testAddPublicKeys() { ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0"); DataStore store = new DataStore(clogStore, null); store.publicKeyCache.put("coretech.storage_0", "PublicKey0"); store.publicKeyCache.put("sports.storage_0", "PublicKey0"); store.publicKeyCache.put("sports.storage_1", "PublicKey1"); Map<String, String> addKeys = new HashMap<>(); addKeys.put("sports.storage_1", "PublicKey1"); addKeys.put("sports.storage_2", "PublicKey2"); store.addPublicKeys(addKeys); assertEquals(store.publicKeyCache.size(), 4); assertTrue(store.publicKeyCache.containsKey("coretech.storage_0")); assertTrue(store.publicKeyCache.containsKey("sports.storage_0")); assertTrue(store.publicKeyCache.containsKey("sports.storage_1")); assertTrue(store.publicKeyCache.containsKey("sports.storage_2")); }
@Test public void testAddPublicKeysUpdateValue() { ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0"); DataStore store = new DataStore(clogStore, null); store.publicKeyCache.put("coretech.storage_0", "PublicKey0"); store.publicKeyCache.put("sports.storage_0", "PublicKey0"); store.publicKeyCache.put("sports.storage_1", "PublicKey1"); Map<String, String> addKeys = new HashMap<>(); addKeys.put("coretech.storage_0", "PublicKey0"); addKeys.put("sports.storage_0", "PublicKey100"); addKeys.put("sports.storage_1", "PublicKey101"); store.addPublicKeys(addKeys); assertEquals(store.publicKeyCache.size(), 3); String value = store.publicKeyCache.get("coretech.storage_0"); assertEquals(value, "PublicKey0"); value = store.publicKeyCache.get("sports.storage_0"); assertEquals(value, "PublicKey100"); value = store.publicKeyCache.get("sports.storage_1"); assertEquals(value, "PublicKey101"); }
@Test public void testAddPublicKeysEmpty() { ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0"); DataStore store = new DataStore(clogStore, null); store.publicKeyCache.put("coretech.storage_0", "PublicKey0"); Map<String, String> addKeys = new HashMap<>(); store.addPublicKeys(addKeys); assertEquals(store.publicKeyCache.size(), 1); assertTrue(store.publicKeyCache.containsKey("coretech.storage_0")); }
@Test public void testAddPublicKeysNull() { ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0"); DataStore store = new DataStore(clogStore, null); store.publicKeyCache.put("coretech.storage_0", "PublicKey0"); store.addPublicKeys(null); assertEquals(store.publicKeyCache.size(), 1); assertTrue(store.publicKeyCache.containsKey("coretech.storage_0")); }