Skip to content

Commit

Permalink
Fix broken tests with url path changes
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Nied <[email protected]>
  • Loading branch information
peternied committed Dec 12, 2023
1 parent 053e5b8 commit c8c96da
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> users = response.getBodyAs(Map.class);
assertThat(users, allOf(aMapWithSize(3), hasKey(ADMIN_USER_NAME), hasKey(NEW_USER), hasKey(LIMITED_USER)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand All @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand All @@ -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"));
Expand All @@ -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"));
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -109,15 +105,6 @@ public TestRestClient(InetSocketAddress nodeHttpAddress, List<Header> headers, S
this.sourceInetAddress = sourceInetAddress;
}

public HttpResponse get(String path, List<NameValuePair> 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);
}
Expand Down

0 comments on commit c8c96da

Please sign in to comment.