[Test] fix bug where random byte may be the same as the byte being changed

Original commit: elastic/x-pack-elasticsearch@657d38fbca
This commit is contained in:
jaymode 2015-04-30 13:11:15 -04:00
parent 03a00201ab
commit 7366c95994
1 changed files with 6 additions and 1 deletions

View File

@ -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));
}