From d9437c157b6a60325f7c681ce3761c88e6473319 Mon Sep 17 00:00:00 2001 From: Peter Alfonsi Date: Wed, 26 Jun 2024 15:32:43 -0700 Subject: [PATCH 1/3] Fix testInvalidInput flakiness Signed-off-by: Peter Alfonsi --- .../serializer/ICacheKeySerializerTests.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/server/src/test/java/org/opensearch/common/cache/serializer/ICacheKeySerializerTests.java b/server/src/test/java/org/opensearch/common/cache/serializer/ICacheKeySerializerTests.java index 7713fdf1d0adc..e1d74a9644554 100644 --- a/server/src/test/java/org/opensearch/common/cache/serializer/ICacheKeySerializerTests.java +++ b/server/src/test/java/org/opensearch/common/cache/serializer/ICacheKeySerializerTests.java @@ -43,10 +43,17 @@ public void testInvalidInput() throws Exception { ICacheKeySerializer serializer = new ICacheKeySerializer<>(keySer); Random rand = Randomness.get(); - byte[] randomInput = new byte[1000]; - rand.nextBytes(randomInput); - - assertThrows(OpenSearchException.class, () -> serializer.deserialize(randomInput)); + // The first thing the serializer reads is a VInt for the number of dimensions. + // This is an invalid input for StreamInput.readVInt(), so we are guaranteed to have an exception + byte[] invalidVInt = { -1, -1, -1, -1, -1 }; + byte[] randomBytes = new byte[1000]; + rand.nextBytes(randomBytes); + // Concatenate the two byte[] into the invalid input + byte[] invalidInput = new byte[invalidVInt.length + randomBytes.length]; + System.arraycopy(invalidVInt, 0, invalidInput, 0, invalidVInt.length); + System.arraycopy(randomBytes, 0, invalidInput, invalidVInt.length, randomBytes.length); + + assertThrows(OpenSearchException.class, () -> serializer.deserialize(invalidInput)); } public void testDimNumbers() throws Exception { From ad2bd2fc4f5b1369c5405bf6602098c4d1853ddb Mon Sep 17 00:00:00 2001 From: Peter Alfonsi Date: Thu, 27 Jun 2024 13:44:56 -0700 Subject: [PATCH 2/3] Addressed andrross's comment Signed-off-by: Peter Alfonsi --- .../cache/serializer/ICacheKeySerializerTests.java | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/server/src/test/java/org/opensearch/common/cache/serializer/ICacheKeySerializerTests.java b/server/src/test/java/org/opensearch/common/cache/serializer/ICacheKeySerializerTests.java index e1d74a9644554..4b0fc3d2a7366 100644 --- a/server/src/test/java/org/opensearch/common/cache/serializer/ICacheKeySerializerTests.java +++ b/server/src/test/java/org/opensearch/common/cache/serializer/ICacheKeySerializerTests.java @@ -45,15 +45,7 @@ public void testInvalidInput() throws Exception { Random rand = Randomness.get(); // The first thing the serializer reads is a VInt for the number of dimensions. // This is an invalid input for StreamInput.readVInt(), so we are guaranteed to have an exception - byte[] invalidVInt = { -1, -1, -1, -1, -1 }; - byte[] randomBytes = new byte[1000]; - rand.nextBytes(randomBytes); - // Concatenate the two byte[] into the invalid input - byte[] invalidInput = new byte[invalidVInt.length + randomBytes.length]; - System.arraycopy(invalidVInt, 0, invalidInput, 0, invalidVInt.length); - System.arraycopy(randomBytes, 0, invalidInput, invalidVInt.length, randomBytes.length); - - assertThrows(OpenSearchException.class, () -> serializer.deserialize(invalidInput)); + assertThrows(OpenSearchException.class, () -> serializer.deserialize(new byte[] { -1, -1, -1, -1, -1 })); } public void testDimNumbers() throws Exception { From e86d7ac3530530f58ccb95ce695a56b3530e761c Mon Sep 17 00:00:00 2001 From: Peter Alfonsi Date: Fri, 28 Jun 2024 09:40:13 -0700 Subject: [PATCH 3/3] rerun security check Signed-off-by: Peter Alfonsi