From f92c510fb3f386054dc498286c30862d1e011e9b Mon Sep 17 00:00:00 2001 From: Peter Nied Date: Thu, 7 Mar 2024 02:26:25 +0000 Subject: [PATCH] Clean up integration test Signed-off-by: Peter Nied --- .../security/DefaultConfigurationTests.java | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/integrationTest/java/org/opensearch/security/DefaultConfigurationTests.java b/src/integrationTest/java/org/opensearch/security/DefaultConfigurationTests.java index 73526db379..f5b000188a 100644 --- a/src/integrationTest/java/org/opensearch/security/DefaultConfigurationTests.java +++ b/src/integrationTest/java/org/opensearch/security/DefaultConfigurationTests.java @@ -27,9 +27,14 @@ import org.opensearch.test.framework.TestSecurityConfig.User; import org.opensearch.test.framework.cluster.ClusterManager; import org.opensearch.test.framework.cluster.LocalCluster; +import org.opensearch.test.framework.cluster.TestRestClient; +import org.opensearch.test.framework.cluster.TestRestClient.HttpResponse; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.aMapWithSize; +import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasKey; @RunWith(com.carrotsearch.randomizedtesting.RandomizedRunner.class) @ThreadLeakScope(ThreadLeakScope.Scope.NONE) @@ -59,19 +64,22 @@ public static void cleanConfigurationDirectory() throws IOException { FileUtils.deleteDirectory(configurationFolder.toFile()); } - // @Test - // public void shouldLoadDefaultConfiguration() { - // try (TestRestClient client = cluster.getRestClient(NEW_USER)) { - // Awaitility.await().alias("Load default configuration").until(() -> client.getAuthInfo().getStatusCode(), equalTo(200)); - // } - // try (TestRestClient client = cluster.getRestClient(ADMIN_USER)) { - // client.confirmCorrectCredentials(ADMIN_USER.getName()); - // HttpResponse response = client.get("_plugins/_security/api/internalusers"); - // response.assertStatusCode(200); - // Map users = response.getBodyAs(Map.class); - // assertThat(users, allOf(aMapWithSize(3), hasKey(ADMIN_USER.getName()), hasKey(NEW_USER.getName()), hasKey(LIMITED_USER.getName()))); - // } - // } + @Test + public void shouldLoadDefaultConfiguration() { + try (TestRestClient client = cluster.getRestClient(NEW_USER)) { + Awaitility.await().alias("Load default configuration").until(() -> client.getAuthInfo().getStatusCode(), equalTo(200)); + } + try (TestRestClient client = cluster.getRestClient(ADMIN_USER)) { + client.confirmCorrectCredentials(ADMIN_USER.getName()); + HttpResponse response = client.get("_plugins/_security/api/internalusers"); + response.assertStatusCode(200); + Map users = response.getBodyAs(Map.class); + assertThat( + users, + allOf(aMapWithSize(3), hasKey(ADMIN_USER.getName()), hasKey(NEW_USER.getName()), hasKey(LIMITED_USER.getName())) + ); + } + } @Test public void securityRolesUgrade() throws Exception { @@ -108,7 +116,7 @@ public void securityRolesUgrade() throws Exception { System.out.println("upgrade Response: " + upgradeResponse.getBody()); final var afterUpgradeRolesResponse = client.get("_plugins/_security/api/roles/"); - final var afterUpgradeRolesNames = extractFieldNames(defaultRolesResponse.getBodyAs(JsonNode.class)); + final var afterUpgradeRolesNames = extractFieldNames(afterUpgradeRolesResponse.getBodyAs(JsonNode.class)); assertThat(afterUpgradeRolesNames, equalTo(rolesNames)); } }