Skip to content

Commit

Permalink
Adds a quick fix to flaky test and corrects run-time error (#5029)
Browse files Browse the repository at this point in the history
Signed-off-by: Darshit Chanpura <[email protected]>
(cherry picked from commit 36f67f0)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] committed Jan 17, 2025
1 parent 5969ca9 commit db5f176
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -463,8 +464,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<String> indexes = new BufferedReader(new InputStreamReader(getIndicesResponse.getEntity().getContent())).lines()
.collect(Collectors.toList());
List<String> 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"));
Expand All @@ -477,8 +479,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<String> aliases = new BufferedReader(new InputStreamReader(getAliasesResponse.getEntity().getContent())).lines()
.collect(Collectors.toList());
List<String> 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));
Expand All @@ -491,8 +494,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<String> aliases = new BufferedReader(new InputStreamReader(getAliasesResponse.getEntity().getContent())).lines()
.collect(Collectors.toList());
List<String> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,6 +36,11 @@

public class SafeSerializationUtilsTest {

@After
public void clearCache() {
SafeSerializationUtils.safeClassCache.clear();
}

@Test
public void testSafeClasses() {
assertTrue(SafeSerializationUtils.isSafeClass(String.class));
Expand Down

0 comments on commit db5f176

Please sign in to comment.