@Test public void shouldGenerateDifferentCipherTextEveryTime() throws NoSuchAlgorithmException { ProductionIVProvider ivProvider = new ProductionIVProvider(); byte[] iv1 = ivProvider.createIV(); byte[] iv2 = ivProvider.createIV(); assertThat(iv1).isNotEqualTo(iv2); }
assertThat(v1).isNotEqualTo(v1Simple); assertThat(v1.hashCode()).isNotEqualTo(v1Simple.hashCode()); assertThat(v1Adapter.encode(v1)).isNotEqualTo(v1Adapter.encode(v1Simple));
@Test public void verify_compression_helper_methods_work_as_expected() { // given String orig = UUID.randomUUID().toString(); // when byte[] gzipped = gzipPayload(orig); String ungzipped = ungzipPayload(gzipped); byte[] deflated = deflatePayload(orig); String inflated = inflatePayload(deflated); // then assertThat(gzipped).isNotEqualTo(orig.getBytes(UTF_8)); assertThat(deflated).isNotEqualTo(orig.getBytes(UTF_8)); assertThat(ungzipped).isEqualTo(orig); assertThat(inflated).isEqualTo(orig); assertThat(gzipped).isNotEqualTo(deflated); }
@Test void aesCodecShouldEncryptPayloadContentWhenWriting() throws Exception { Payload payload = codec().write(expected()); byte[] bytes = IOUtils.toByteArray(payload.openStream()); // authenticated encryption uses a random salt for the authentication // header all we can say for sure is that the output is not the same as // the input. assertThat(bytes).isNotEqualTo(SOME_BYTES); }
@Test void encryptionWithCustomPayloadCodeCannotBeReadFromUnencryptedDAO() throws Exception { ObjectStorageBlobsDAO encryptedDao = ObjectStorageBlobsDAO .builder(testConfig) .container(containerName) .blobIdFactory(blobIdFactory()) .payloadCodec(new AESPayloadCodec(CRYPTO_CONFIG)) .build(); byte[] bytes = "James is the best!".getBytes(StandardCharsets.UTF_8); BlobId blobId = encryptedDao.save(bytes).join(); InputStream encryptedIs = testee.read(blobId); assertThat(encryptedIs).isNotNull(); byte[] encryptedBytes = IOUtils.toByteArray(encryptedIs); assertThat(encryptedBytes).isNotEqualTo(bytes); InputStream clearTextIs = encryptedDao.read(blobId); assertThat(clearTextIs).hasSameContentAs(new ByteArrayInputStream(bytes)); } }