use of org.c02e.jpgpj.Decryptor in project keywhiz by square.
the class BackupResourceTest method backupSuccess.
@Test
public void backupSuccess() throws Exception {
Response httpResponse = backup("test", "Blackops");
assertThat(httpResponse.code()).isEqualTo(200);
InputStream ciphertext = httpResponse.body().byteStream();
ByteArrayOutputStream plaintext = new ByteArrayOutputStream();
Key key = new Key(TEST_EXPORT_KEY_PRIVATE, "password");
// Decrypt and make sure we have expected data in the encrypted backup
Decryptor decryptor = new Decryptor(key);
decryptor.setVerificationRequired(false);
decryptor.decrypt(ciphertext, plaintext);
List<SecretDeliveryResponse> output = mapper.readValue(plaintext.toByteArray(), new TypeReference<List<SecretDeliveryResponse>>() {
});
assertThat(output).extracting(SecretDeliveryResponse::getName).containsExactlyInAnyOrder("Hacking_Password", "General_Password");
assertThat(output).extracting(SecretDeliveryResponse::getSecret).allMatch(s -> !Strings.isNullOrEmpty(s));
}
Aggregations