From c8c96daccd09dd3eed7dd70e12defc05af787db3 Mon Sep 17 00:00:00 2001 From: Peter Nied Date: Tue, 12 Dec 2023 02:26:16 +0000 Subject: [PATCH] Fix broken tests with url path changes Signed-off-by: Peter Nied --- .../security/DefaultConfigurationTests.java | 2 +- .../security/PointInTimeOperationTest.java | 4 ++-- .../security/SecurityConfigurationTests.java | 10 +++++----- .../java/org/opensearch/security/SslOnlyTests.java | 2 +- .../http/CommonProxyAuthenticationTests.java | 2 +- .../http/ExtendedProxyAuthenticationTest.java | 4 ++-- .../test/framework/cluster/TestRestClient.java | 13 ------------- 7 files changed, 12 insertions(+), 25 deletions(-) diff --git a/src/integrationTest/java/org/opensearch/security/DefaultConfigurationTests.java b/src/integrationTest/java/org/opensearch/security/DefaultConfigurationTests.java index 043d3908e9..8bb5b96145 100644 --- a/src/integrationTest/java/org/opensearch/security/DefaultConfigurationTests.java +++ b/src/integrationTest/java/org/opensearch/security/DefaultConfigurationTests.java @@ -69,7 +69,7 @@ public void shouldLoadDefaultConfiguration() { } try (TestRestClient client = cluster.getRestClient(ADMIN_USER_NAME, DEFAULT_PASSWORD)) { client.confirmCorrectCredentials(ADMIN_USER_NAME); - HttpResponse response = client.get("/_plugins/_security/api/internalusers"); + 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_NAME), hasKey(NEW_USER), hasKey(LIMITED_USER))); diff --git a/src/integrationTest/java/org/opensearch/security/PointInTimeOperationTest.java b/src/integrationTest/java/org/opensearch/security/PointInTimeOperationTest.java index 3d634c4a5d..ce934a8e16 100644 --- a/src/integrationTest/java/org/opensearch/security/PointInTimeOperationTest.java +++ b/src/integrationTest/java/org/opensearch/security/PointInTimeOperationTest.java @@ -381,7 +381,7 @@ public void listPitSegmentsCreatedWithIndexAlias_negative() throws IOException { @Test public void listAllPitSegments_positive() { try (TestRestClient restClient = cluster.getRestClient(POINT_IN_TIME_USER)) { - HttpResponse response = restClient.get("/_cat/pit_segments/_all"); + HttpResponse response = restClient.get("_cat/pit_segments/_all"); response.assertStatusCode(OK.getStatus()); } @@ -390,7 +390,7 @@ public void listAllPitSegments_positive() { @Test public void listAllPitSegments_negative() { try (TestRestClient restClient = cluster.getRestClient(LIMITED_POINT_IN_TIME_USER)) { - HttpResponse response = restClient.get("/_cat/pit_segments/_all"); + HttpResponse response = restClient.get("_cat/pit_segments/_all"); response.assertStatusCode(FORBIDDEN.getStatus()); } diff --git a/src/integrationTest/java/org/opensearch/security/SecurityConfigurationTests.java b/src/integrationTest/java/org/opensearch/security/SecurityConfigurationTests.java index cc95f191f7..76ea02494e 100644 --- a/src/integrationTest/java/org/opensearch/security/SecurityConfigurationTests.java +++ b/src/integrationTest/java/org/opensearch/security/SecurityConfigurationTests.java @@ -119,7 +119,7 @@ public void shouldCreateUserViaRestApi_failure() { @Test public void shouldAuthenticateAsAdminWithCertificate_positive() { try (TestRestClient client = cluster.getRestClient(cluster.getAdminCertificate())) { - HttpResponse httpResponse = client.get("/_plugins/_security/whoami"); + HttpResponse httpResponse = client.get("_plugins/_security/whoami"); httpResponse.assertStatusCode(200); assertThat(httpResponse.getTextFromJsonBody("/is_admin"), equalTo("true")); @@ -130,7 +130,7 @@ public void shouldAuthenticateAsAdminWithCertificate_positive() { public void shouldAuthenticateAsAdminWithCertificate_negativeSelfSignedCertificate() { TestCertificates testCertificates = cluster.getTestCertificates(); try (TestRestClient client = cluster.getRestClient(testCertificates.createSelfSignedCertificate("CN=bond"))) { - HttpResponse httpResponse = client.get("/_plugins/_security/whoami"); + HttpResponse httpResponse = client.get("_plugins/_security/whoami"); httpResponse.assertStatusCode(200); assertThat(httpResponse.getTextFromJsonBody("/is_admin"), equalTo("false")); @@ -141,7 +141,7 @@ public void shouldAuthenticateAsAdminWithCertificate_negativeSelfSignedCertifica public void shouldAuthenticateAsAdminWithCertificate_negativeIncorrectDn() { TestCertificates testCertificates = cluster.getTestCertificates(); try (TestRestClient client = cluster.getRestClient(testCertificates.createAdminCertificate("CN=non_admin"))) { - HttpResponse httpResponse = client.get("/_plugins/_security/whoami"); + HttpResponse httpResponse = client.get("_plugins/_security/whoami"); httpResponse.assertStatusCode(200); assertThat(httpResponse.getTextFromJsonBody("/is_admin"), equalTo("false")); @@ -199,7 +199,7 @@ public void shouldStillWorkAfterUpdateOfSecurityConfig() { @Test public void shouldAccessIndexWithPlaceholder_positive() { try (TestRestClient client = cluster.getRestClient(LIMITED_USER)) { - HttpResponse httpResponse = client.get("/" + LIMITED_USER_INDEX + "/_doc/" + ID_1); + HttpResponse httpResponse = client.get(LIMITED_USER_INDEX + "/_doc/" + ID_1); httpResponse.assertStatusCode(200); } @@ -208,7 +208,7 @@ public void shouldAccessIndexWithPlaceholder_positive() { @Test public void shouldAccessIndexWithPlaceholder_negative() { try (TestRestClient client = cluster.getRestClient(LIMITED_USER)) { - HttpResponse httpResponse = client.get("/" + PROHIBITED_INDEX + "/_doc/" + ID_2); + HttpResponse httpResponse = client.get(PROHIBITED_INDEX + "/_doc/" + ID_2); httpResponse.assertStatusCode(403); } diff --git a/src/integrationTest/java/org/opensearch/security/SslOnlyTests.java b/src/integrationTest/java/org/opensearch/security/SslOnlyTests.java index 25feffb2b4..2ea5b4c0b2 100644 --- a/src/integrationTest/java/org/opensearch/security/SslOnlyTests.java +++ b/src/integrationTest/java/org/opensearch/security/SslOnlyTests.java @@ -59,7 +59,7 @@ public void shouldGetIndicesWithoutAuthentication() { try (TestRestClient client = cluster.getRestClient()) { // request does not contains credential - HttpResponse response = client.get("/_cat/indices"); + HttpResponse response = client.get("_cat/indices"); // successful response is returned because the security plugin in SSL only mode // does not perform authentication and authorization diff --git a/src/integrationTest/java/org/opensearch/security/http/CommonProxyAuthenticationTests.java b/src/integrationTest/java/org/opensearch/security/http/CommonProxyAuthenticationTests.java index 49ded4f2a9..d98acf8895 100644 --- a/src/integrationTest/java/org/opensearch/security/http/CommonProxyAuthenticationTests.java +++ b/src/integrationTest/java/org/opensearch/security/http/CommonProxyAuthenticationTests.java @@ -31,7 +31,7 @@ */ abstract class CommonProxyAuthenticationTests { - protected static final String RESOURCE_AUTH_INFO = "/_opendistro/_security/authinfo"; + protected static final String RESOURCE_AUTH_INFO = "_opendistro/_security/authinfo"; protected static final TestSecurityConfig.User USER_ADMIN = new TestSecurityConfig.User("admin").roles(ALL_ACCESS); protected static final String ATTRIBUTE_DEPARTMENT = "department"; diff --git a/src/integrationTest/java/org/opensearch/security/http/ExtendedProxyAuthenticationTest.java b/src/integrationTest/java/org/opensearch/security/http/ExtendedProxyAuthenticationTest.java index 6fcc7eac83..7c361828d6 100644 --- a/src/integrationTest/java/org/opensearch/security/http/ExtendedProxyAuthenticationTest.java +++ b/src/integrationTest/java/org/opensearch/security/http/ExtendedProxyAuthenticationTest.java @@ -230,7 +230,7 @@ public void shouldRetrieveUserRolesAndAttributesSoThatAccessToPersonalIndexIsPos .header(HEADER_DEPARTMENT, DEPARTMENT_BRIDGE); try (TestRestClient client = cluster.createGenericClientRestClient(testRestClientConfiguration)) { - HttpResponse response = client.get("/" + PERSONAL_INDEX_NAME_SPOCK + "/_search"); + HttpResponse response = client.get(PERSONAL_INDEX_NAME_SPOCK + "/_search"); response.assertStatusCode(200); assertThat(response.getLongFromJsonBody(POINTER_TOTAL_HITS), equalTo(1L)); @@ -251,7 +251,7 @@ public void shouldRetrieveUserRolesAndAttributesSoThatAccessToPersonalIndexIsPos .header(HEADER_DEPARTMENT, DEPARTMENT_BRIDGE); try (TestRestClient client = cluster.createGenericClientRestClient(testRestClientConfiguration)) { - HttpResponse response = client.get("/" + PERSONAL_INDEX_NAME_KIRK + "/_search"); + HttpResponse response = client.get(PERSONAL_INDEX_NAME_KIRK + "/_search"); response.assertStatusCode(403); } diff --git a/src/integrationTest/java/org/opensearch/test/framework/cluster/TestRestClient.java b/src/integrationTest/java/org/opensearch/test/framework/cluster/TestRestClient.java index a3d0c09d11..c2e01bb338 100644 --- a/src/integrationTest/java/org/opensearch/test/framework/cluster/TestRestClient.java +++ b/src/integrationTest/java/org/opensearch/test/framework/cluster/TestRestClient.java @@ -31,8 +31,6 @@ import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; -import java.net.URI; -import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; @@ -61,10 +59,8 @@ import org.apache.hc.client5.http.routing.HttpRoutePlanner; import org.apache.hc.core5.http.Header; import org.apache.hc.core5.http.HttpEntity; -import org.apache.hc.core5.http.NameValuePair; import org.apache.hc.core5.http.io.entity.StringEntity; import org.apache.hc.core5.http.message.BasicHeader; -import org.apache.hc.core5.net.URIBuilder; import org.apache.http.HttpHeaders; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -109,15 +105,6 @@ public TestRestClient(InetSocketAddress nodeHttpAddress, List
headers, S this.sourceInetAddress = sourceInetAddress; } - public HttpResponse get(String path, List queryParameters, Header... headers) { - try { - URI uri = new URIBuilder(getHttpServerUri()).setPath(path).addParameters(queryParameters).build(); - return executeRequest(new HttpGet(uri), headers); - } catch (URISyntaxException ex) { - throw new RuntimeException("Incorrect URI syntax", ex); - } - } - public HttpResponse get(String path, Header... headers) { return executeRequest(new HttpGet(getHttpServerUri() + "/" + path), headers); }