adapt to ObjectPath changes to support binary formats

Original commit: elastic/x-pack-elasticsearch@11782418e9
This commit is contained in:
javanna 2017-02-18 10:27:35 +01:00 committed by Luca Cavanna
parent 212098fc7c
commit 33ccc3bd6c
2 changed files with 4 additions and 18 deletions

View File

@ -6,13 +6,10 @@
package org.elasticsearch.xpack.security.rest.action; package org.elasticsearch.xpack.security.rest.action;
import org.apache.http.message.BasicHeader; import org.apache.http.message.BasicHeader;
import org.apache.http.util.EntityUtils;
import org.elasticsearch.client.Response; import org.elasticsearch.client.Response;
import org.elasticsearch.client.ResponseException; import org.elasticsearch.client.ResponseException;
import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.network.NetworkModule;
import org.elasticsearch.common.settings.Settings; 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.SecurityIntegTestCase;
import org.elasticsearch.test.SecuritySettingsSource; import org.elasticsearch.test.SecuritySettingsSource;
import org.elasticsearch.test.rest.yaml.ObjectPath; 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 BasicHeader("Authorization", basicAuthHeaderValue(SecuritySettingsSource.DEFAULT_USER_NAME,
new SecuredString(SecuritySettingsSource.DEFAULT_PASSWORD.toCharArray())))); new SecuredString(SecuritySettingsSource.DEFAULT_PASSWORD.toCharArray()))));
assertThat(response.getStatusLine().getStatusCode(), is(200)); assertThat(response.getStatusLine().getStatusCode(), is(200));
ObjectPath objectPath = ObjectPath.createFromXContent(XContentFactory.xContent(XContentType.JSON), ObjectPath objectPath = ObjectPath.createFromResponse(response);
EntityUtils.toString(response.getEntity()));
assertThat(objectPath.evaluate("username").toString(), equalTo(SecuritySettingsSource.DEFAULT_USER_NAME)); assertThat(objectPath.evaluate("username").toString(), equalTo(SecuritySettingsSource.DEFAULT_USER_NAME));
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
List<String> roles = (List<String>) objectPath.evaluate("roles"); 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"); Response response = getRestClient().performRequest("GET", "/_xpack/security/_authenticate");
if (anonymousEnabled) { if (anonymousEnabled) {
assertThat(response.getStatusLine().getStatusCode(), is(200)); assertThat(response.getStatusLine().getStatusCode(), is(200));
ObjectPath objectPath = ObjectPath.createFromXContent(XContentFactory.xContent(XContentType.JSON), ObjectPath objectPath = ObjectPath.createFromResponse(response);
EntityUtils.toString(response.getEntity()));
assertThat(objectPath.evaluate("username").toString(), equalTo("anon")); assertThat(objectPath.evaluate("username").toString(), equalTo("anon"));
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
List<String> roles = (List<String>) objectPath.evaluate("roles"); List<String> roles = (List<String>) objectPath.evaluate("roles");

View File

@ -7,13 +7,11 @@ package org.elasticsearch.upgrades;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite; import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.apache.lucene.util.TimeUnits; import org.apache.lucene.util.TimeUnits;
import org.elasticsearch.client.Response; import org.elasticsearch.client.Response;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext; 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.ClientYamlTestCandidate;
import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase;
import org.elasticsearch.test.rest.yaml.ObjectPath; import org.elasticsearch.test.rest.yaml.ObjectPath;
@ -49,7 +47,7 @@ public class UpgradeClusterClientYamlTestSuiteIT extends ESClientYamlSuiteTestCa
assertBusy(() -> { assertBusy(() -> {
try { try {
Response nodeDetailsResponse = client().performRequest("GET", "/_nodes"); Response nodeDetailsResponse = client().performRequest("GET", "/_nodes");
ObjectPath path = objectPath(nodeDetailsResponse); ObjectPath path = ObjectPath.createFromResponse(nodeDetailsResponse);
Map<String, Object> nodes = path.evaluate("nodes"); Map<String, Object> nodes = path.evaluate("nodes");
assertThat(nodes.size(), greaterThanOrEqualTo(2)); assertThat(nodes.size(), greaterThanOrEqualTo(2));
String masterVersion = null; String masterVersion = null;
@ -64,7 +62,7 @@ public class UpgradeClusterClientYamlTestSuiteIT extends ESClientYamlSuiteTestCa
final String masterTemplateVersion = masterVersion; final String masterTemplateVersion = masterVersion;
Response response = client().performRequest("GET", "/_cluster/state/metadata"); 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"; final String mappingsPath = "metadata.templates." + SECURITY_TEMPLATE_NAME + ".mappings";
Map<String, Object> mappings = objectPath.evaluate(mappingsPath); Map<String, Object> mappings = objectPath.evaluate(mappingsPath);
assertNotNull(mappings); 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 @Override
protected boolean preserveIndicesUponCompletion() { protected boolean preserveIndicesUponCompletion() {
return true; return true;