From 3f78fa7f650a9147c4a445daad484ccdc63dc9ed Mon Sep 17 00:00:00 2001 From: Darshit Chanpura Date: Tue, 14 Jan 2025 23:05:03 -0500 Subject: [PATCH 1/2] Adds a quick fix to flaky test and corrects run-time error Signed-off-by: Darshit Chanpura --- .../security/DoNotFailOnForbiddenTests.java | 15 +++++++++------ .../support/SafeSerializationUtilsTest.java | 6 ++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/integrationTest/java/org/opensearch/security/DoNotFailOnForbiddenTests.java b/src/integrationTest/java/org/opensearch/security/DoNotFailOnForbiddenTests.java index 456d1ebada..59c44de332 100644 --- a/src/integrationTest/java/org/opensearch/security/DoNotFailOnForbiddenTests.java +++ b/src/integrationTest/java/org/opensearch/security/DoNotFailOnForbiddenTests.java @@ -462,8 +462,9 @@ public void shouldPerformCatIndices_positive() throws IOException { Request getIndicesRequest = new Request("GET", "/_cat/indices"); // High level client doesn't support _cat/_indices API Response getIndicesResponse = restHighLevelClient.getLowLevelClient().performRequest(getIndicesRequest); - List indexes = new BufferedReader(new InputStreamReader(getIndicesResponse.getEntity().getContent())).lines() - .collect(Collectors.toList()); + List indexes = new BufferedReader( + new InputStreamReader(getIndicesResponse.getEntity().getContent(), StandardCharsets.UTF_8) + ).lines().collect(Collectors.toList()); assertThat(indexes.size(), equalTo(1)); assertThat(indexes.get(0), containsString("marvelous_songs")); @@ -476,8 +477,9 @@ public void shouldPerformCatAliases_positive() throws IOException { try (RestHighLevelClient restHighLevelClient = cluster.getRestHighLevelClient(LIMITED_USER)) { Request getAliasesRequest = new Request("GET", "/_cat/aliases"); Response getAliasesResponse = restHighLevelClient.getLowLevelClient().performRequest(getAliasesRequest); - List aliases = new BufferedReader(new InputStreamReader(getAliasesResponse.getEntity().getContent())).lines() - .collect(Collectors.toList()); + List aliases = new BufferedReader( + new InputStreamReader(getAliasesResponse.getEntity().getContent(), StandardCharsets.UTF_8) + ).lines().collect(Collectors.toList()); // Does not fail on forbidden, but alias response only contains index which user has access to assertThat(getAliasesResponse.getStatusLine().getStatusCode(), equalTo(200)); @@ -490,8 +492,9 @@ public void shouldPerformCatAliases_positive() throws IOException { try (RestHighLevelClient restHighLevelClient = cluster.getRestHighLevelClient(ADMIN_USER)) { Request getAliasesRequest = new Request("GET", "/_cat/aliases"); Response getAliasesResponse = restHighLevelClient.getLowLevelClient().performRequest(getAliasesRequest); - List aliases = new BufferedReader(new InputStreamReader(getAliasesResponse.getEntity().getContent())).lines() - .collect(Collectors.toList()); + List aliases = new BufferedReader( + new InputStreamReader(getAliasesResponse.getEntity().getContent(), StandardCharsets.UTF_8) + ).lines().collect(Collectors.toList()); // Admin has access to all assertThat(getAliasesResponse.getStatusLine().getStatusCode(), equalTo(200)); diff --git a/src/test/java/org/opensearch/security/support/SafeSerializationUtilsTest.java b/src/test/java/org/opensearch/security/support/SafeSerializationUtilsTest.java index f69d4e0291..187fd8b372 100644 --- a/src/test/java/org/opensearch/security/support/SafeSerializationUtilsTest.java +++ b/src/test/java/org/opensearch/security/support/SafeSerializationUtilsTest.java @@ -17,6 +17,7 @@ import java.util.HashMap; import java.util.regex.Pattern; +import org.junit.After; import org.junit.Test; import org.opensearch.security.auth.UserInjector; @@ -35,6 +36,11 @@ public class SafeSerializationUtilsTest { + @After + public void clearCache() { + SafeSerializationUtils.safeClassCache.clear(); + } + @Test public void testSafeClasses() { assertTrue(SafeSerializationUtils.isSafeClass(String.class)); From f19a0a724c1fc16f472f878e58595cbc3c37e17d Mon Sep 17 00:00:00 2001 From: Darshit Chanpura Date: Thu, 16 Jan 2025 13:49:44 -0500 Subject: [PATCH 2/2] Updates import statement Signed-off-by: Darshit Chanpura --- .../java/org/opensearch/security/DoNotFailOnForbiddenTests.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/integrationTest/java/org/opensearch/security/DoNotFailOnForbiddenTests.java b/src/integrationTest/java/org/opensearch/security/DoNotFailOnForbiddenTests.java index 59c44de332..4aa6005beb 100644 --- a/src/integrationTest/java/org/opensearch/security/DoNotFailOnForbiddenTests.java +++ b/src/integrationTest/java/org/opensearch/security/DoNotFailOnForbiddenTests.java @@ -12,6 +12,7 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.util.List; import java.util.stream.Collectors;