use of org.cloudfoundry.credhub.util.PasswordKeyProxyFactoryTestImpl in project credhub by cloudfoundry-incubator.
the class LunaKeyProxyTest method isMatchingCanary_whenDecryptThrowsRelevantIllegalBlockSizeException_returnsFalse.
@Test
public void isMatchingCanary_whenDecryptThrowsRelevantIllegalBlockSizeException_returnsFalse() throws Exception {
subject = new LunaKeyProxy(encryptionKey, new InternalEncryptionService(new PasswordKeyProxyFactoryTestImpl()) {
@Override
public String decrypt(Key key, byte[] encryptedValue, byte[] nonce) throws Exception {
throw new IllegalBlockSizeException("returns 0x40");
}
});
assertThat(subject.matchesCanary(mock(EncryptionKeyCanary.class)), equalTo(false));
}
use of org.cloudfoundry.credhub.util.PasswordKeyProxyFactoryTestImpl in project credhub by cloudfoundry-incubator.
the class LunaKeyProxyTest method isMatchingCanary_whenDecryptThrowsOtherException_throwsIncorrectKeyException.
@Test(expected = IncorrectKeyException.class)
public void isMatchingCanary_whenDecryptThrowsOtherException_throwsIncorrectKeyException() throws Exception {
subject = new LunaKeyProxy(encryptionKey, new InternalEncryptionService(new PasswordKeyProxyFactoryTestImpl()) {
@Override
public String decrypt(Key key, byte[] encryptedValue, byte[] nonce) throws Exception {
throw new Exception("");
}
});
subject.matchesCanary(mock(EncryptionKeyCanary.class));
}
use of org.cloudfoundry.credhub.util.PasswordKeyProxyFactoryTestImpl in project credhub by cloudfoundry-incubator.
the class LunaKeyProxyTest method isMatchingCanary_whenCanaryMatches_returnsTrue.
@Test
public void isMatchingCanary_whenCanaryMatches_returnsTrue() throws Exception {
subject = new LunaKeyProxy(encryptionKey, new InternalEncryptionService(new PasswordKeyProxyFactoryTestImpl()));
assertThat(subject.matchesCanary(canary), equalTo(true));
}
use of org.cloudfoundry.credhub.util.PasswordKeyProxyFactoryTestImpl in project credhub by cloudfoundry-incubator.
the class LunaKeyProxyTest method isMatchingCanary_whenDecryptThrowsIllegalBlockSizeException_throwsIncorrectKeyException.
@Test(expected = IncorrectKeyException.class)
public void isMatchingCanary_whenDecryptThrowsIllegalBlockSizeException_throwsIncorrectKeyException() throws Exception {
subject = new LunaKeyProxy(encryptionKey, new InternalEncryptionService(new PasswordKeyProxyFactoryTestImpl()) {
@Override
public String decrypt(Key key, byte[] encryptedValue, byte[] nonce) throws Exception {
throw new IllegalBlockSizeException("");
}
});
subject.matchesCanary(mock(EncryptionKeyCanary.class));
}
use of org.cloudfoundry.credhub.util.PasswordKeyProxyFactoryTestImpl in project credhub by cloudfoundry-incubator.
the class LunaKeyProxyTest method beforeEach.
@Before
public void beforeEach() throws Exception {
final InternalEncryptionService encryptionService = new InternalEncryptionService(new PasswordKeyProxyFactoryTestImpl());
EncryptionKeyMetadata keyMetadata = new EncryptionKeyMetadata();
keyMetadata.setEncryptionPassword("p@ssword");
encryptionKey = encryptionService.createKeyProxy(keyMetadata).getKey();
canary = new EncryptionKeyCanary();
EncryptedValue encryptionData = encryptionService.encrypt(null, encryptionKey, CANARY_VALUE);
canary.setEncryptedCanaryValue(encryptionData.getEncryptedValue());
canary.setNonce(encryptionData.getNonce());
deprecatedCanary = new EncryptionKeyCanary();
EncryptedValue deprecatedEncryptionData = encryptionService.encrypt(null, encryptionKey, DEPRECATED_CANARY_VALUE);
deprecatedCanary.setEncryptedCanaryValue(deprecatedEncryptionData.getEncryptedValue());
deprecatedCanary.setNonce(deprecatedEncryptionData.getNonce());
}
Aggregations