ConfigurationEntry entry = mock(ConfigurationEntry.class);
when(entry.getAttributes()).thenReturn(attributes);
when(entry.getId()).thenReturn(id);
KeyStoreRecoverer recoverer = new KeyStoreRecoverer();
final KeyStore keyStore = recoverer.create(null, entry, broker);
assertNotNull("Key store configured object is not created", keyStore);
assertEquals(id, keyStore.getId());
//verify we can retrieve the actual password using the method
Subject.doAs(SecurityManager.getSubjectWithAddedSystemRights(), new PrivilegedAction<Object>()
{
@Override
public Object run()
{
assertNotNull(keyStore.getPassword());
assertEquals(TestSSLConstants.BROKER_TRUSTSTORE_PASSWORD, keyStore.getPassword());
//verify that we haven't configured the key store with the actual dummy password value
assertFalse(AbstractKeyStoreAdapter.DUMMY_PASSWORD_MASK.equals(keyStore.getPassword()));
return null;
}
});
// Verify the remaining attributes, including that the password value returned
// via getAttribute is actually the dummy value and not the real password
attributesCopy.put(KeyStore.PASSWORD, AbstractKeyStoreAdapter.DUMMY_PASSWORD_MASK);
for (Map.Entry<String, Object> attribute : attributesCopy.entrySet())
{
Object attributeValue = keyStore.getAttribute(attribute.getKey());
assertEquals("Unexpected value of attribute '" + attribute.getKey() + "'", attribute.getValue(), attributeValue);
}
}