Rest Client: use short performRequest methods when possible
Original commit: elastic/x-pack-elasticsearch@088d6c7ad8
This commit is contained in:
parent
f67b758b47
commit
86d1805d40
|
@ -37,7 +37,7 @@ public class IndexAuditIT extends ESIntegTestCase {
|
||||||
private static final String PASS = "changeme";
|
private static final String PASS = "changeme";
|
||||||
|
|
||||||
public void testShieldIndexAuditTrailWorking() throws Exception {
|
public void testShieldIndexAuditTrailWorking() throws Exception {
|
||||||
try (Response response = getRestClient().performRequest("GET", "/", Collections.emptyMap(), null,
|
try (Response response = getRestClient().performRequest("GET", "/",
|
||||||
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
||||||
UsernamePasswordToken.basicAuthHeaderValue(USER, new SecuredString(PASS.toCharArray()))))) {
|
UsernamePasswordToken.basicAuthHeaderValue(USER, new SecuredString(PASS.toCharArray()))))) {
|
||||||
assertThat(response.getStatusLine().getStatusCode(), is(200));
|
assertThat(response.getStatusLine().getStatusCode(), is(200));
|
||||||
|
|
|
@ -47,7 +47,7 @@ public class CustomRealmIT extends ESIntegTestCase {
|
||||||
|
|
||||||
public void testHttpConnectionWithNoAuthentication() throws Exception {
|
public void testHttpConnectionWithNoAuthentication() throws Exception {
|
||||||
try {
|
try {
|
||||||
getRestClient().performRequest("GET", "/", Collections.emptyMap(), null);
|
getRestClient().performRequest("GET", "/");
|
||||||
fail("request should have failed");
|
fail("request should have failed");
|
||||||
} catch(ResponseException e) {
|
} catch(ResponseException e) {
|
||||||
Response response = e.getResponse();
|
Response response = e.getResponse();
|
||||||
|
@ -58,7 +58,7 @@ public class CustomRealmIT extends ESIntegTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testHttpAuthentication() throws Exception {
|
public void testHttpAuthentication() throws Exception {
|
||||||
try (Response response = getRestClient().performRequest("GET", "/", Collections.emptyMap(), null,
|
try (Response response = getRestClient().performRequest("GET", "/",
|
||||||
new BasicHeader(CustomRealm.USER_HEADER, CustomRealm.KNOWN_USER),
|
new BasicHeader(CustomRealm.USER_HEADER, CustomRealm.KNOWN_USER),
|
||||||
new BasicHeader(CustomRealm.PW_HEADER, CustomRealm.KNOWN_PW))) {
|
new BasicHeader(CustomRealm.PW_HEADER, CustomRealm.KNOWN_PW))) {
|
||||||
assertThat(response.getStatusLine().getStatusCode(), is(200));
|
assertThat(response.getStatusLine().getStatusCode(), is(200));
|
||||||
|
|
|
@ -84,7 +84,7 @@ public class BulkUpdateTests extends SecurityIntegTestCase {
|
||||||
assertThat(response.getStatusLine().getStatusCode(), equalTo(201));
|
assertThat(response.getStatusLine().getStatusCode(), equalTo(201));
|
||||||
}
|
}
|
||||||
|
|
||||||
try (Response response = getRestClient().performRequest("GET", path, Collections.emptyMap(), null, basicAuthHeader)) {
|
try (Response response = getRestClient().performRequest("GET", path, basicAuthHeader)) {
|
||||||
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
|
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
|
||||||
assertThat(EntityUtils.toString(response.getEntity()), containsString("\"test\":\"test\""));
|
assertThat(EntityUtils.toString(response.getEntity()), containsString("\"test\":\"test\""));
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ public class BulkUpdateTests extends SecurityIntegTestCase {
|
||||||
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
|
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
|
||||||
}
|
}
|
||||||
|
|
||||||
try (Response response = getRestClient().performRequest("GET", path, Collections.emptyMap(), null, basicAuthHeader)) {
|
try (Response response = getRestClient().performRequest("GET", path, basicAuthHeader)) {
|
||||||
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
|
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
|
||||||
String responseBody = EntityUtils.toString(response.getEntity());
|
String responseBody = EntityUtils.toString(response.getEntity());
|
||||||
assertThat(responseBody, containsString("\"test\":\"test\""));
|
assertThat(responseBody, containsString("\"test\":\"test\""));
|
||||||
|
@ -118,7 +118,7 @@ public class BulkUpdateTests extends SecurityIntegTestCase {
|
||||||
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
|
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
|
||||||
}
|
}
|
||||||
|
|
||||||
try (Response response = getRestClient().performRequest("GET", path, Collections.emptyMap(), null, basicAuthHeader)) {
|
try (Response response = getRestClient().performRequest("GET", path, basicAuthHeader)) {
|
||||||
String responseBody = EntityUtils.toString(response.getEntity());
|
String responseBody = EntityUtils.toString(response.getEntity());
|
||||||
assertThat(responseBody, containsString("\"test\":\"test\""));
|
assertThat(responseBody, containsString("\"test\":\"test\""));
|
||||||
assertThat(responseBody, containsString("\"not test\":\"not test\""));
|
assertThat(responseBody, containsString("\"not test\":\"not test\""));
|
||||||
|
|
|
@ -162,7 +162,7 @@ public class ClearRealmsCacheTests extends SecurityIntegTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void executeHttpRequest(String path, Map<String, String> params) throws Exception {
|
static void executeHttpRequest(String path, Map<String, String> params) throws Exception {
|
||||||
try (Response response = getRestClient().performRequest("POST", path, params, null,
|
try (Response response = getRestClient().performRequest("POST", path, params,
|
||||||
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
||||||
UsernamePasswordToken.basicAuthHeaderValue(SecuritySettingsSource.DEFAULT_USER_NAME,
|
UsernamePasswordToken.basicAuthHeaderValue(SecuritySettingsSource.DEFAULT_USER_NAME,
|
||||||
new SecuredString(SecuritySettingsSource.DEFAULT_PASSWORD.toCharArray()))))) {
|
new SecuredString(SecuritySettingsSource.DEFAULT_PASSWORD.toCharArray()))))) {
|
||||||
|
|
|
@ -15,6 +15,8 @@ import org.elasticsearch.common.network.NetworkModule;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.unit.TimeValue;
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.rest.RestStatus;
|
import org.elasticsearch.rest.RestStatus;
|
||||||
|
import org.elasticsearch.test.NativeRealmIntegTestCase;
|
||||||
|
import org.elasticsearch.test.SecuritySettingsSource;
|
||||||
import org.elasticsearch.xpack.security.SecurityTemplateService;
|
import org.elasticsearch.xpack.security.SecurityTemplateService;
|
||||||
import org.elasticsearch.xpack.security.action.role.GetRolesResponse;
|
import org.elasticsearch.xpack.security.action.role.GetRolesResponse;
|
||||||
import org.elasticsearch.xpack.security.action.role.PutRoleResponse;
|
import org.elasticsearch.xpack.security.action.role.PutRoleResponse;
|
||||||
|
@ -23,13 +25,10 @@ import org.elasticsearch.xpack.security.authc.support.UsernamePasswordToken;
|
||||||
import org.elasticsearch.xpack.security.authz.RoleDescriptor;
|
import org.elasticsearch.xpack.security.authz.RoleDescriptor;
|
||||||
import org.elasticsearch.xpack.security.authz.store.NativeRolesStore;
|
import org.elasticsearch.xpack.security.authz.store.NativeRolesStore;
|
||||||
import org.elasticsearch.xpack.security.client.SecurityClient;
|
import org.elasticsearch.xpack.security.client.SecurityClient;
|
||||||
import org.elasticsearch.test.NativeRealmIntegTestCase;
|
|
||||||
import org.elasticsearch.test.SecuritySettingsSource;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;
|
import static org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;
|
||||||
|
@ -138,7 +137,7 @@ public class ClearRolesCacheTests extends NativeRealmIntegTestCase {
|
||||||
} else {
|
} else {
|
||||||
path = "/_xpack/security/role/" + Strings.arrayToCommaDelimitedString(rolesToClear) + "/_clear_cache";
|
path = "/_xpack/security/role/" + Strings.arrayToCommaDelimitedString(rolesToClear) + "/_clear_cache";
|
||||||
}
|
}
|
||||||
try (Response response = getRestClient().performRequest("POST", path, Collections.emptyMap(), null,
|
try (Response response = getRestClient().performRequest("POST", path,
|
||||||
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
||||||
UsernamePasswordToken.basicAuthHeaderValue(SecuritySettingsSource.DEFAULT_USER_NAME,
|
UsernamePasswordToken.basicAuthHeaderValue(SecuritySettingsSource.DEFAULT_USER_NAME,
|
||||||
new SecuredString(SecuritySettingsSource.DEFAULT_PASSWORD.toCharArray()))))) {
|
new SecuredString(SecuritySettingsSource.DEFAULT_PASSWORD.toCharArray()))))) {
|
||||||
|
|
|
@ -305,7 +305,7 @@ public class IndexPrivilegeTests extends AbstractPrivilegeTestCase {
|
||||||
|
|
||||||
public void testThatUnknownUserIsRejectedProperly() throws Exception {
|
public void testThatUnknownUserIsRejectedProperly() throws Exception {
|
||||||
try {
|
try {
|
||||||
getRestClient().performRequest("GET", "/", Collections.emptyMap(), null,
|
getRestClient().performRequest("GET", "/",
|
||||||
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
||||||
UsernamePasswordToken.basicAuthHeaderValue("idonotexist", new SecuredString("passwd".toCharArray()))));
|
UsernamePasswordToken.basicAuthHeaderValue("idonotexist", new SecuredString("passwd".toCharArray()))));
|
||||||
fail("request should have failed");
|
fail("request should have failed");
|
||||||
|
|
|
@ -168,7 +168,7 @@ public class LicensingTests extends SecurityIntegTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRestAuthenticationByLicenseType() throws Exception {
|
public void testRestAuthenticationByLicenseType() throws Exception {
|
||||||
try (Response response = getRestClient().performRequest("GET", "/", Collections.emptyMap(), null)) {
|
try (Response response = getRestClient().performRequest("GET", "/")) {
|
||||||
// the default of the licensing tests is basic
|
// the default of the licensing tests is basic
|
||||||
assertThat(response.getStatusLine().getStatusCode(), is(200));
|
assertThat(response.getStatusLine().getStatusCode(), is(200));
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,7 @@ public class LicensingTests extends SecurityIntegTestCase {
|
||||||
OperationMode mode = randomFrom(OperationMode.GOLD, OperationMode.TRIAL, OperationMode.PLATINUM, OperationMode.STANDARD);
|
OperationMode mode = randomFrom(OperationMode.GOLD, OperationMode.TRIAL, OperationMode.PLATINUM, OperationMode.STANDARD);
|
||||||
enableLicensing(mode);
|
enableLicensing(mode);
|
||||||
try {
|
try {
|
||||||
getRestClient().performRequest("GET", "/", Collections.emptyMap(), null);
|
getRestClient().performRequest("GET", "/");
|
||||||
fail("request should have failed");
|
fail("request should have failed");
|
||||||
} catch(ResponseException e) {
|
} catch(ResponseException e) {
|
||||||
assertThat(e.getResponse().getStatusLine().getStatusCode(), is(401));
|
assertThat(e.getResponse().getStatusLine().getStatusCode(), is(401));
|
||||||
|
|
|
@ -9,13 +9,12 @@ import org.apache.http.message.BasicHeader;
|
||||||
import org.elasticsearch.client.Response;
|
import org.elasticsearch.client.Response;
|
||||||
import org.elasticsearch.client.ResponseException;
|
import org.elasticsearch.client.ResponseException;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.xpack.security.authc.support.SecuredString;
|
|
||||||
import org.elasticsearch.xpack.security.authc.support.UsernamePasswordToken;
|
|
||||||
import org.elasticsearch.test.SecurityIntegTestCase;
|
import org.elasticsearch.test.SecurityIntegTestCase;
|
||||||
import org.elasticsearch.test.SecuritySettingsSource;
|
import org.elasticsearch.test.SecuritySettingsSource;
|
||||||
|
import org.elasticsearch.xpack.security.authc.support.SecuredString;
|
||||||
|
import org.elasticsearch.xpack.security.authc.support.UsernamePasswordToken;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
import static org.elasticsearch.rest.RestStatus.OK;
|
import static org.elasticsearch.rest.RestStatus.OK;
|
||||||
import static org.elasticsearch.rest.RestStatus.UNAUTHORIZED;
|
import static org.elasticsearch.rest.RestStatus.UNAUTHORIZED;
|
||||||
|
@ -35,14 +34,14 @@ public class SecurityPluginTests extends SecurityIntegTestCase {
|
||||||
public void testThatPluginIsLoaded() throws IOException {
|
public void testThatPluginIsLoaded() throws IOException {
|
||||||
try {
|
try {
|
||||||
logger.info("executing unauthorized request to /_xpack info");
|
logger.info("executing unauthorized request to /_xpack info");
|
||||||
getRestClient().performRequest("GET", "/_xpack", Collections.emptyMap(), null);
|
getRestClient().performRequest("GET", "/_xpack");
|
||||||
fail("request should have failed");
|
fail("request should have failed");
|
||||||
} catch(ResponseException e) {
|
} catch(ResponseException e) {
|
||||||
assertThat(e.getResponse().getStatusLine().getStatusCode(), is(UNAUTHORIZED.getStatus()));
|
assertThat(e.getResponse().getStatusLine().getStatusCode(), is(UNAUTHORIZED.getStatus()));
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("executing authorized request to /_xpack infos");
|
logger.info("executing authorized request to /_xpack infos");
|
||||||
try (Response response = getRestClient().performRequest("GET", "/_xpack", Collections.emptyMap(), null,
|
try (Response response = getRestClient().performRequest("GET", "/_xpack",
|
||||||
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
||||||
basicAuthHeaderValue(SecuritySettingsSource.DEFAULT_USER_NAME,
|
basicAuthHeaderValue(SecuritySettingsSource.DEFAULT_USER_NAME,
|
||||||
new SecuredString(SecuritySettingsSource.DEFAULT_PASSWORD.toCharArray()))))) {
|
new SecuredString(SecuritySettingsSource.DEFAULT_PASSWORD.toCharArray()))))) {
|
||||||
|
|
|
@ -118,7 +118,7 @@ public class RunAsIntegTests extends SecurityIntegTestCase {
|
||||||
public void testUserImpersonationUsingHttp() throws Exception {
|
public void testUserImpersonationUsingHttp() throws Exception {
|
||||||
// use the transport client user and try to run as
|
// use the transport client user and try to run as
|
||||||
try {
|
try {
|
||||||
getRestClient().performRequest("GET", "/_nodes", Collections.emptyMap(), null,
|
getRestClient().performRequest("GET", "/_nodes",
|
||||||
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
||||||
UsernamePasswordToken.basicAuthHeaderValue(TRANSPORT_CLIENT_USER,
|
UsernamePasswordToken.basicAuthHeaderValue(TRANSPORT_CLIENT_USER,
|
||||||
SecuredStringTests.build(SecuritySettingsSource.DEFAULT_PASSWORD))),
|
SecuredStringTests.build(SecuritySettingsSource.DEFAULT_PASSWORD))),
|
||||||
|
@ -130,7 +130,7 @@ public class RunAsIntegTests extends SecurityIntegTestCase {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//the run as user shouldn't have access to the nodes api
|
//the run as user shouldn't have access to the nodes api
|
||||||
getRestClient().performRequest("GET", "/_nodes", Collections.emptyMap(), null,
|
getRestClient().performRequest("GET", "/_nodes",
|
||||||
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
||||||
UsernamePasswordToken.basicAuthHeaderValue(RUN_AS_USER,
|
UsernamePasswordToken.basicAuthHeaderValue(RUN_AS_USER,
|
||||||
SecuredStringTests.build(SecuritySettingsSource.DEFAULT_PASSWORD))));
|
SecuredStringTests.build(SecuritySettingsSource.DEFAULT_PASSWORD))));
|
||||||
|
@ -140,7 +140,7 @@ public class RunAsIntegTests extends SecurityIntegTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
// but when running as a different user it should work
|
// but when running as a different user it should work
|
||||||
try (Response response = getRestClient().performRequest("GET", "/_nodes", Collections.emptyMap(), null,
|
try (Response response = getRestClient().performRequest("GET", "/_nodes",
|
||||||
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
||||||
UsernamePasswordToken.basicAuthHeaderValue(RUN_AS_USER,
|
UsernamePasswordToken.basicAuthHeaderValue(RUN_AS_USER,
|
||||||
SecuredStringTests.build(SecuritySettingsSource.DEFAULT_PASSWORD))),
|
SecuredStringTests.build(SecuritySettingsSource.DEFAULT_PASSWORD))),
|
||||||
|
@ -173,7 +173,7 @@ public class RunAsIntegTests extends SecurityIntegTestCase {
|
||||||
|
|
||||||
public void testEmptyHeaderUsingHttp() throws Exception {
|
public void testEmptyHeaderUsingHttp() throws Exception {
|
||||||
try {
|
try {
|
||||||
getRestClient().performRequest("GET", "/_nodes", Collections.emptyMap(), null,
|
getRestClient().performRequest("GET", "/_nodes",
|
||||||
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
||||||
UsernamePasswordToken.basicAuthHeaderValue(RUN_AS_USER,
|
UsernamePasswordToken.basicAuthHeaderValue(RUN_AS_USER,
|
||||||
SecuredStringTests.build(SecuritySettingsSource.DEFAULT_PASSWORD))),
|
SecuredStringTests.build(SecuritySettingsSource.DEFAULT_PASSWORD))),
|
||||||
|
@ -208,7 +208,7 @@ public class RunAsIntegTests extends SecurityIntegTestCase {
|
||||||
|
|
||||||
public void testNonExistentRunAsUserUsingHttp() throws Exception {
|
public void testNonExistentRunAsUserUsingHttp() throws Exception {
|
||||||
try {
|
try {
|
||||||
getRestClient().performRequest("GET", "/_nodes", Collections.emptyMap(), null,
|
getRestClient().performRequest("GET", "/_nodes",
|
||||||
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
||||||
UsernamePasswordToken.basicAuthHeaderValue(RUN_AS_USER,
|
UsernamePasswordToken.basicAuthHeaderValue(RUN_AS_USER,
|
||||||
SecuredStringTests.build(SecuritySettingsSource.DEFAULT_PASSWORD))),
|
SecuredStringTests.build(SecuritySettingsSource.DEFAULT_PASSWORD))),
|
||||||
|
|
|
@ -35,7 +35,6 @@ import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.security.KeyStore;
|
import java.security.KeyStore;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
import static org.elasticsearch.test.SecuritySettingsSource.DEFAULT_PASSWORD;
|
import static org.elasticsearch.test.SecuritySettingsSource.DEFAULT_PASSWORD;
|
||||||
import static org.elasticsearch.test.SecuritySettingsSource.DEFAULT_USER_NAME;
|
import static org.elasticsearch.test.SecuritySettingsSource.DEFAULT_USER_NAME;
|
||||||
|
@ -83,13 +82,13 @@ public class PkiOptionalClientAuthTests extends SecurityIntegTestCase {
|
||||||
CloseableHttpClient httpClient = HttpClients.custom().setSSLContext(getSSLContext()).build();
|
CloseableHttpClient httpClient = HttpClients.custom().setSSLContext(getSSLContext()).build();
|
||||||
try (RestClient restClient = createRestClient(httpClient, "https")) {
|
try (RestClient restClient = createRestClient(httpClient, "https")) {
|
||||||
try {
|
try {
|
||||||
restClient.performRequest("GET", "_nodes", Collections.emptyMap(), null);
|
restClient.performRequest("GET", "_nodes");
|
||||||
fail("request should have failed");
|
fail("request should have failed");
|
||||||
} catch(ResponseException e) {
|
} catch(ResponseException e) {
|
||||||
assertThat(e.getResponse().getStatusLine().getStatusCode(), is(401));
|
assertThat(e.getResponse().getStatusLine().getStatusCode(), is(401));
|
||||||
}
|
}
|
||||||
|
|
||||||
try (Response response = restClient.performRequest("GET", "_nodes", Collections.emptyMap(), null,
|
try (Response response = restClient.performRequest("GET", "_nodes",
|
||||||
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
||||||
UsernamePasswordToken.basicAuthHeaderValue(SecuritySettingsSource.DEFAULT_USER_NAME,
|
UsernamePasswordToken.basicAuthHeaderValue(SecuritySettingsSource.DEFAULT_USER_NAME,
|
||||||
new SecuredString(SecuritySettingsSource.DEFAULT_PASSWORD.toCharArray()))))) {
|
new SecuredString(SecuritySettingsSource.DEFAULT_PASSWORD.toCharArray()))))) {
|
||||||
|
|
|
@ -28,7 +28,6 @@ import javax.net.ssl.TrustManager;
|
||||||
import javax.net.ssl.X509TrustManager;
|
import javax.net.ssl.X509TrustManager;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
|
@ -81,7 +80,7 @@ public class PkiWithoutClientAuthenticationTests extends SecurityIntegTestCase {
|
||||||
sc.init(null, trustAllCerts, new SecureRandom());
|
sc.init(null, trustAllCerts, new SecureRandom());
|
||||||
CloseableHttpClient httpClient = HttpClients.custom().setSSLContext(sc).build();
|
CloseableHttpClient httpClient = HttpClients.custom().setSSLContext(sc).build();
|
||||||
try (RestClient restClient = createRestClient(httpClient, "https")) {
|
try (RestClient restClient = createRestClient(httpClient, "https")) {
|
||||||
try (Response response = restClient.performRequest("GET", "/_nodes", Collections.emptyMap(), null,
|
try (Response response = restClient.performRequest("GET", "/_nodes",
|
||||||
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
||||||
UsernamePasswordToken.basicAuthHeaderValue(SecuritySettingsSource.DEFAULT_USER_NAME,
|
UsernamePasswordToken.basicAuthHeaderValue(SecuritySettingsSource.DEFAULT_USER_NAME,
|
||||||
new SecuredString(SecuritySettingsSource.DEFAULT_PASSWORD.toCharArray()))))) {
|
new SecuredString(SecuritySettingsSource.DEFAULT_PASSWORD.toCharArray()))))) {
|
||||||
|
|
|
@ -16,8 +16,6 @@ import org.elasticsearch.test.SecuritySettingsSource;
|
||||||
import org.elasticsearch.xpack.security.authc.support.SecuredString;
|
import org.elasticsearch.xpack.security.authc.support.SecuredString;
|
||||||
import org.elasticsearch.xpack.security.authc.support.UsernamePasswordToken;
|
import org.elasticsearch.xpack.security.authc.support.UsernamePasswordToken;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
|
|
||||||
@ClusterScope(numClientNodes = 0, supportsDedicatedMasters = false, numDataNodes = 1)
|
@ClusterScope(numClientNodes = 0, supportsDedicatedMasters = false, numDataNodes = 1)
|
||||||
|
@ -43,7 +41,7 @@ public class PkiWithoutSSLTests extends SecurityIntegTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testThatHttpWorks() throws Exception {
|
public void testThatHttpWorks() throws Exception {
|
||||||
try (Response response = getRestClient().performRequest("GET", "/_nodes", Collections.emptyMap(), null,
|
try (Response response = getRestClient().performRequest("GET", "/_nodes",
|
||||||
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
||||||
UsernamePasswordToken.basicAuthHeaderValue(SecuritySettingsSource.DEFAULT_USER_NAME,
|
UsernamePasswordToken.basicAuthHeaderValue(SecuritySettingsSource.DEFAULT_USER_NAME,
|
||||||
new SecuredString(SecuritySettingsSource.DEFAULT_PASSWORD.toCharArray()))))) {
|
new SecuredString(SecuritySettingsSource.DEFAULT_PASSWORD.toCharArray()))))) {
|
||||||
|
|
|
@ -13,15 +13,14 @@ 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.XContentFactory;
|
||||||
import org.elasticsearch.common.xcontent.XContentType;
|
import org.elasticsearch.common.xcontent.XContentType;
|
||||||
import org.elasticsearch.xpack.security.authc.support.SecuredString;
|
|
||||||
import org.elasticsearch.xpack.security.authz.InternalAuthorizationService;
|
|
||||||
import org.elasticsearch.xpack.security.user.AnonymousUser;
|
|
||||||
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.ObjectPath;
|
import org.elasticsearch.test.rest.ObjectPath;
|
||||||
|
import org.elasticsearch.xpack.security.authc.support.SecuredString;
|
||||||
|
import org.elasticsearch.xpack.security.authz.InternalAuthorizationService;
|
||||||
|
import org.elasticsearch.xpack.security.user.AnonymousUser;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.elasticsearch.xpack.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
|
import static org.elasticsearch.xpack.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
|
||||||
|
@ -54,7 +53,7 @@ public class RestAuthenticateActionTests extends SecurityIntegTestCase {
|
||||||
|
|
||||||
public void testAuthenticateApi() throws Exception {
|
public void testAuthenticateApi() throws Exception {
|
||||||
try (Response response = getRestClient().performRequest(
|
try (Response response = getRestClient().performRequest(
|
||||||
"GET", "/_xpack/security/_authenticate", Collections.emptyMap(), null,
|
"GET", "/_xpack/security/_authenticate",
|
||||||
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));
|
||||||
|
@ -69,8 +68,7 @@ public class RestAuthenticateActionTests extends SecurityIntegTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAuthenticateApiWithoutAuthentication() throws Exception {
|
public void testAuthenticateApiWithoutAuthentication() throws Exception {
|
||||||
try (Response response = getRestClient().performRequest("GET", "/_xpack/security/_authenticate",
|
try (Response response = getRestClient().performRequest("GET", "/_xpack/security/_authenticate")) {
|
||||||
Collections.emptyMap(), null)) {
|
|
||||||
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.createFromXContent(XContentFactory.xContent(XContentType.JSON),
|
||||||
|
|
|
@ -31,7 +31,6 @@ import javax.net.ssl.SSLHandshakeException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
import static org.elasticsearch.xpack.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
|
import static org.elasticsearch.xpack.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
|
||||||
import static org.elasticsearch.test.SecuritySettingsSource.getSSLSettingsForStore;
|
import static org.elasticsearch.test.SecuritySettingsSource.getSSLSettingsForStore;
|
||||||
|
@ -63,7 +62,7 @@ public class SslClientAuthTests extends SecurityIntegTestCase {
|
||||||
SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
|
SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
|
||||||
|
|
||||||
try (RestClient restClient = createRestClient(HttpClients.custom().setSSLSocketFactory(socketFactory).build(), "https")) {
|
try (RestClient restClient = createRestClient(HttpClients.custom().setSSLSocketFactory(socketFactory).build(), "https")) {
|
||||||
restClient.performRequest("GET", "/", Collections.emptyMap(), null);
|
restClient.performRequest("GET", "/");
|
||||||
fail("Expected SSLHandshakeException");
|
fail("Expected SSLHandshakeException");
|
||||||
} catch (SSLHandshakeException e) {
|
} catch (SSLHandshakeException e) {
|
||||||
assertThat(e.getMessage(), containsString("unable to find valid certification path to requested target"));
|
assertThat(e.getMessage(), containsString("unable to find valid certification path to requested target"));
|
||||||
|
@ -83,7 +82,7 @@ public class SslClientAuthTests extends SecurityIntegTestCase {
|
||||||
CloseableHttpClient client = HttpClients.custom().setSSLSocketFactory(socketFactory).build();
|
CloseableHttpClient client = HttpClients.custom().setSSLSocketFactory(socketFactory).build();
|
||||||
|
|
||||||
try (RestClient restClient = createRestClient(client, "https")) {
|
try (RestClient restClient = createRestClient(client, "https")) {
|
||||||
try (Response response = restClient.performRequest("GET", "/", Collections.emptyMap(), null,
|
try (Response response = restClient.performRequest("GET", "/",
|
||||||
new BasicHeader("Authorization", basicAuthHeaderValue(transportClientUsername(), transportClientPassword())))) {
|
new BasicHeader("Authorization", basicAuthHeaderValue(transportClientUsername(), transportClientPassword())))) {
|
||||||
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
|
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
|
||||||
assertThat(EntityUtils.toString(response.getEntity()), containsString("You Know, for Search"));
|
assertThat(EntityUtils.toString(response.getEntity()), containsString("You Know, for Search"));
|
||||||
|
|
|
@ -9,10 +9,8 @@ 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.xpack.security.authz.InternalAuthorizationService;
|
|
||||||
import org.elasticsearch.test.SecurityIntegTestCase;
|
import org.elasticsearch.test.SecurityIntegTestCase;
|
||||||
|
import org.elasticsearch.xpack.security.authz.InternalAuthorizationService;
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.containsString;
|
import static org.hamcrest.Matchers.containsString;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
|
@ -43,7 +41,7 @@ public class AnonymousUserIntegTests extends SecurityIntegTestCase {
|
||||||
|
|
||||||
public void testAnonymousViaHttp() throws Exception {
|
public void testAnonymousViaHttp() throws Exception {
|
||||||
try {
|
try {
|
||||||
getRestClient().performRequest("GET", "/_nodes", Collections.emptyMap(), null);
|
getRestClient().performRequest("GET", "/_nodes");
|
||||||
fail("request should have failed");
|
fail("request should have failed");
|
||||||
} catch(ResponseException e) {
|
} catch(ResponseException e) {
|
||||||
int statusCode = e.getResponse().getStatusLine().getStatusCode();
|
int statusCode = e.getResponse().getStatusLine().getStatusCode();
|
||||||
|
|
|
@ -68,7 +68,7 @@ public class WatcherPluginDisableTests extends ESIntegTestCase {
|
||||||
public void testRestEndpoints() throws Exception {
|
public void testRestEndpoints() throws Exception {
|
||||||
HttpServerTransport httpServerTransport = internalCluster().getDataNodeInstance(HttpServerTransport.class);
|
HttpServerTransport httpServerTransport = internalCluster().getDataNodeInstance(HttpServerTransport.class);
|
||||||
try {
|
try {
|
||||||
getRestClient().performRequest("GET", "/_xpack/watcher", Collections.emptyMap(), null);
|
getRestClient().performRequest("GET", "/_xpack/watcher");
|
||||||
fail("request should have failed");
|
fail("request should have failed");
|
||||||
} catch(ResponseException e) {
|
} catch(ResponseException e) {
|
||||||
assertThat(e.getResponse().getStatusLine().getStatusCode(), is(HttpStatus.SC_BAD_REQUEST));
|
assertThat(e.getResponse().getStatusLine().getStatusCode(), is(HttpStatus.SC_BAD_REQUEST));
|
||||||
|
|
Loading…
Reference in New Issue