adapt to ObjectPath changes to support binary formats
Original commit: elastic/x-pack-elasticsearch@11782418e9
This commit is contained in:
parent
212098fc7c
commit
33ccc3bd6c
|
@ -6,13 +6,10 @@
|
|||
package org.elasticsearch.xpack.security.rest.action;
|
||||
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.elasticsearch.client.Response;
|
||||
import org.elasticsearch.client.ResponseException;
|
||||
import org.elasticsearch.common.network.NetworkModule;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.test.SecurityIntegTestCase;
|
||||
import org.elasticsearch.test.SecuritySettingsSource;
|
||||
import org.elasticsearch.test.rest.yaml.ObjectPath;
|
||||
|
@ -56,8 +53,7 @@ public class RestAuthenticateActionTests extends SecurityIntegTestCase {
|
|||
new BasicHeader("Authorization", basicAuthHeaderValue(SecuritySettingsSource.DEFAULT_USER_NAME,
|
||||
new SecuredString(SecuritySettingsSource.DEFAULT_PASSWORD.toCharArray()))));
|
||||
assertThat(response.getStatusLine().getStatusCode(), is(200));
|
||||
ObjectPath objectPath = ObjectPath.createFromXContent(XContentFactory.xContent(XContentType.JSON),
|
||||
EntityUtils.toString(response.getEntity()));
|
||||
ObjectPath objectPath = ObjectPath.createFromResponse(response);
|
||||
assertThat(objectPath.evaluate("username").toString(), equalTo(SecuritySettingsSource.DEFAULT_USER_NAME));
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> roles = (List<String>) objectPath.evaluate("roles");
|
||||
|
@ -70,8 +66,7 @@ public class RestAuthenticateActionTests extends SecurityIntegTestCase {
|
|||
Response response = getRestClient().performRequest("GET", "/_xpack/security/_authenticate");
|
||||
if (anonymousEnabled) {
|
||||
assertThat(response.getStatusLine().getStatusCode(), is(200));
|
||||
ObjectPath objectPath = ObjectPath.createFromXContent(XContentFactory.xContent(XContentType.JSON),
|
||||
EntityUtils.toString(response.getEntity()));
|
||||
ObjectPath objectPath = ObjectPath.createFromResponse(response);
|
||||
assertThat(objectPath.evaluate("username").toString(), equalTo("anon"));
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> roles = (List<String>) objectPath.evaluate("roles");
|
||||
|
|
|
@ -7,13 +7,11 @@ package org.elasticsearch.upgrades;
|
|||
|
||||
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
|
||||
import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite;
|
||||
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.apache.lucene.util.TimeUnits;
|
||||
import org.elasticsearch.client.Response;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
|
||||
import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase;
|
||||
import org.elasticsearch.test.rest.yaml.ObjectPath;
|
||||
|
@ -49,7 +47,7 @@ public class UpgradeClusterClientYamlTestSuiteIT extends ESClientYamlSuiteTestCa
|
|||
assertBusy(() -> {
|
||||
try {
|
||||
Response nodeDetailsResponse = client().performRequest("GET", "/_nodes");
|
||||
ObjectPath path = objectPath(nodeDetailsResponse);
|
||||
ObjectPath path = ObjectPath.createFromResponse(nodeDetailsResponse);
|
||||
Map<String, Object> nodes = path.evaluate("nodes");
|
||||
assertThat(nodes.size(), greaterThanOrEqualTo(2));
|
||||
String masterVersion = null;
|
||||
|
@ -64,7 +62,7 @@ public class UpgradeClusterClientYamlTestSuiteIT extends ESClientYamlSuiteTestCa
|
|||
final String masterTemplateVersion = masterVersion;
|
||||
|
||||
Response response = client().performRequest("GET", "/_cluster/state/metadata");
|
||||
ObjectPath objectPath = objectPath(response);
|
||||
ObjectPath objectPath = ObjectPath.createFromResponse(response);
|
||||
final String mappingsPath = "metadata.templates." + SECURITY_TEMPLATE_NAME + ".mappings";
|
||||
Map<String, Object> mappings = objectPath.evaluate(mappingsPath);
|
||||
assertNotNull(mappings);
|
||||
|
@ -79,13 +77,6 @@ public class UpgradeClusterClientYamlTestSuiteIT extends ESClientYamlSuiteTestCa
|
|||
});
|
||||
}
|
||||
|
||||
private ObjectPath objectPath(Response response) throws IOException {
|
||||
String body = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
|
||||
String contentType = response.getHeader("Content-Type");
|
||||
XContentType xContentType = XContentType.fromMediaTypeOrFormat(contentType);
|
||||
return ObjectPath.createFromXContent(xContentType.xContent(), body);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean preserveIndicesUponCompletion() {
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue