ZMSFileChangeLogStoreFactory implements ChangeLogStoreFactory { @Override public ChangeLogStore create(String ztsHomeDir, PrivateKey privateKey, String privateKeyId) { final String rootDirectory = ztsHomeDir + File.separator + ZTS_DATA_STORE; ChangeLogStore store = mtlsClientChangeLogStore(rootDirectory); if (store == null) { LOGGER.info("mtls client change log store not available"); store = new ZMSFileChangeLogStore(rootDirectory, privateKey, privateKeyId); } return store; }  @Override void setPrivateKeyStore(PrivateKeyStore privateKeyStore); @Override ChangeLogStore create(String ztsHomeDir, PrivateKey privateKey, String privateKeyId);  }
@Test public void testCreateStore() { File privKeyFile = new File("src/test/resources/unit_test_zts_private.pem"); String privKey = Crypto.encodedFile(privKeyFile); PrivateKey pkey = Crypto.loadPrivateKey(Crypto.ybase64DecodeString(privKey)); ZMSFileChangeLogStoreFactory factory = new ZMSFileChangeLogStoreFactory(); ChangeLogStore store = factory.create(ZTS_DATA_STORE_PATH, pkey, "0"); assertNotNull(store); }
@Test public void testCreateMTLSClientStore() { setupMTLSSettings(); ZMSFileChangeLogStoreFactory factory = new ZMSFileChangeLogStoreFactory(); ChangeLogStore store = factory.create(ZTS_DATA_STORE_PATH, null, null); assertNotNull(store); assertTrue(store instanceof ZMSFileMTLSChangeLogStore); clearMTLSSettings(); }
@Test public void testCreateMTLSClientStoreInvalidUrl() { setupMTLSSettings(); System.clearProperty(PROP_ATHENZ_CONF); ZMSFileChangeLogStoreFactory factory = new ZMSFileChangeLogStoreFactory(); try { factory.create(ZTS_DATA_STORE_PATH, null, null); fail(); } catch (Exception ex) { assertTrue(ex instanceof IllegalArgumentException); } clearMTLSSettings(); }
@Test public void testCreateMTLSClientStoreInvalidTrustStorePassword() { setupMTLSSettings(); System.clearProperty("athenz.common.server.clog.zts_server_trust_store_password_name"); ZMSFileChangeLogStoreFactory factory = new ZMSFileChangeLogStoreFactory(); try { factory.create(ZTS_DATA_STORE_PATH, null, null); fail(); } catch (Exception ex) { assertTrue(ex instanceof IllegalArgumentException); } clearMTLSSettings(); }