From 7366c95994ef71137d0e8d8481af87cf64e3bb76 Mon Sep 17 00:00:00 2001 From: jaymode Date: Thu, 30 Apr 2015 13:11:15 -0400 Subject: [PATCH] [Test] fix bug where random byte may be the same as the byte being changed Original commit: elastic/x-pack-elasticsearch@657d38fbca8d32b82e2f697dbf4cd4f23ee7fc93 --- .../shield/crypto/InternalCryptoServiceTests.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/elasticsearch/shield/crypto/InternalCryptoServiceTests.java b/src/test/java/org/elasticsearch/shield/crypto/InternalCryptoServiceTests.java index 3939e314a34..3c184e89bf0 100644 --- a/src/test/java/org/elasticsearch/shield/crypto/InternalCryptoServiceTests.java +++ b/src/test/java/org/elasticsearch/shield/crypto/InternalCryptoServiceTests.java @@ -223,7 +223,12 @@ public class InternalCryptoServiceTests extends ElasticsearchTestCase { assertThat(Arrays.equals(encrypted, bytes), is(false)); int tamperedIndex = randomIntBetween(0, encrypted.length - 1); - encrypted[tamperedIndex] = randomByte(); + final byte untamperedByte = encrypted[tamperedIndex]; + byte tamperedByte = randomByte(); + while (tamperedByte == untamperedByte) { + tamperedByte = randomByte(); + } + encrypted[tamperedIndex] = tamperedByte; final byte[] decrypted = service.decrypt(encrypted); assertThat(Arrays.equals(bytes, decrypted), is(false)); }