FileStoreTlsKeyManagersProvider extends AbstractFileTlsKeyManagersProvider { @Override public KeyManager[] getKeyManagers() { try { return createKeyManagers(storePath, storeType, password); } catch (Exception e) { if (log.isWarnEnabled()) { log.warn(String.format("Unable to create KeyManagers from file %s", storePath.getAbsolutePath()), e); } return null; } } FileStoreTlsKeyManagersProvider(File storePath, String storeType, String password); @Override KeyManager[] getKeyManagers();  }
@Test public void paramsValid_createsKeyManager() { FileStoreTlsKeyManagersProvider provider = new FileStoreTlsKeyManagersProvider(clientKeyStore, CLIENT_STORE_TYPE, STORE_PASSWORD); assertThat(provider.getKeyManagers().length, equalTo(1)); }
@Test public void storeDoesNotExist_returnsNull() { FileStoreTlsKeyManagersProvider provider = new FileStoreTlsKeyManagersProvider(new File("does-not-exist"), CLIENT_STORE_TYPE, STORE_PASSWORD); assertThat(provider.getKeyManagers(), nullValue()); }
@Test public void invalidStoreType_returnsNull() { FileStoreTlsKeyManagersProvider provider = new FileStoreTlsKeyManagersProvider(clientKeyStore, "invalid", STORE_PASSWORD); assertThat(provider.getKeyManagers(), nullValue()); }
@Test public void passwordIncorrect_returnsNull() { FileStoreTlsKeyManagersProvider provider = new FileStoreTlsKeyManagersProvider(clientKeyStore, CLIENT_STORE_TYPE, "not correct password"); assertThat(provider.getKeyManagers(), nullValue()); }
@Test public void customKmfAlgorithmSetInProperty_usesAlgorithm() { FileStoreTlsKeyManagersProvider beforePropSetProvider = new FileStoreTlsKeyManagersProvider(clientKeyStore, CLIENT_STORE_TYPE, STORE_PASSWORD); assertThat(beforePropSetProvider.getKeyManagers(), notNullValue()); String property = "ssl.KeyManagerFactory.algorithm"; String previousValue = Security.getProperty(property); Security.setProperty(property, "some-bogus-value"); try { FileStoreTlsKeyManagersProvider afterPropSetProvider = new FileStoreTlsKeyManagersProvider( clientKeyStore, CLIENT_STORE_TYPE, STORE_PASSWORD); assertThat(afterPropSetProvider.getKeyManagers(), nullValue()); } finally { Security.setProperty(property, previousValue); } }