[TEST] add a lot of forgotten try with resources to wrap ElasticsearchResponses
Original commit: elastic/x-pack-elasticsearch@e4634ea599
This commit is contained in:
parent
4e2766df11
commit
ad9a64e854
|
@ -39,11 +39,12 @@ public class IndexAuditIT extends ESIntegTestCase {
|
||||||
|
|
||||||
public void testShieldIndexAuditTrailWorking() throws Exception {
|
public void testShieldIndexAuditTrailWorking() throws Exception {
|
||||||
try (RestClient restClient = restClient()) {
|
try (RestClient restClient = restClient()) {
|
||||||
ElasticsearchResponse response = restClient.performRequest("GET", "/_cluster/health", Collections.emptyMap(), null,
|
try (ElasticsearchResponse response = restClient.performRequest("GET", "/_cluster/health", Collections.emptyMap(), null,
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final AtomicReference<ClusterState> lastClusterState = new AtomicReference<>();
|
final AtomicReference<ClusterState> lastClusterState = new AtomicReference<>();
|
||||||
final AtomicBoolean indexExists = new AtomicBoolean(false);
|
final AtomicBoolean indexExists = new AtomicBoolean(false);
|
||||||
|
|
|
@ -59,12 +59,13 @@ public class CustomRealmIT extends ESIntegTestCase {
|
||||||
|
|
||||||
public void testHttpAuthentication() throws Exception {
|
public void testHttpAuthentication() throws Exception {
|
||||||
try (RestClient restClient = restClient()) {
|
try (RestClient restClient = restClient()) {
|
||||||
ElasticsearchResponse response = restClient.performRequest("GET", "/", Collections.emptyMap(), null,
|
try (ElasticsearchResponse response = restClient.performRequest("GET", "/", Collections.emptyMap(), null,
|
||||||
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void testTransportClient() throws Exception {
|
public void testTransportClient() throws Exception {
|
||||||
NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().get();
|
NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().get();
|
||||||
|
|
|
@ -54,7 +54,8 @@ public class MarvelSettingsFilterTests extends MarvelIntegTestCase {
|
||||||
} else {
|
} else {
|
||||||
headers = new Header[0];
|
headers = new Header[0];
|
||||||
}
|
}
|
||||||
ElasticsearchResponse response = restClient.performRequest("GET", "/_nodes/settings", Collections.emptyMap(), null, headers);
|
try (ElasticsearchResponse response = restClient.performRequest("GET", "/_nodes/settings",
|
||||||
|
Collections.emptyMap(), null, headers)) {
|
||||||
Map<String, Object> responseMap = JsonXContent.jsonXContent.createParser(response.getEntity().getContent()).map();
|
Map<String, Object> responseMap = JsonXContent.jsonXContent.createParser(response.getEntity().getContent()).map();
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Map<String, Object> nodes = (Map<String, Object>) responseMap.get("nodes");
|
Map<String, Object> nodes = (Map<String, Object>) responseMap.get("nodes");
|
||||||
|
@ -71,6 +72,7 @@ public class MarvelSettingsFilterTests extends MarvelIntegTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void assertNullSetting(Map<String, Object> settings, String setting) {
|
private void assertNullSetting(Map<String, Object> settings, String setting) {
|
||||||
assertThat(extractValue(setting, settings), nullValue());
|
assertThat(extractValue(setting, settings), nullValue());
|
||||||
|
|
|
@ -37,15 +37,16 @@ public abstract class AbstractPrivilegeTestCase extends ShieldIntegTestCase {
|
||||||
protected void assertAccessIsAllowed(String user, String method, String uri, String body,
|
protected void assertAccessIsAllowed(String user, String method, String uri, String body,
|
||||||
Map<String, String> params) throws IOException {
|
Map<String, String> params) throws IOException {
|
||||||
try (RestClient restClient = restClient()) {
|
try (RestClient restClient = restClient()) {
|
||||||
ElasticsearchResponse response = restClient.performRequest(method, uri, params, entityOrNull(body),
|
try (ElasticsearchResponse response = restClient.performRequest(method, uri, params, entityOrNull(body),
|
||||||
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
||||||
UsernamePasswordToken.basicAuthHeaderValue(user, new SecuredString("passwd".toCharArray()))));
|
UsernamePasswordToken.basicAuthHeaderValue(user, new SecuredString("passwd".toCharArray()))))) {
|
||||||
StatusLine statusLine = response.getStatusLine();
|
StatusLine statusLine = response.getStatusLine();
|
||||||
String message = String.format(Locale.ROOT, "%s %s: Expected no error got %s %s with body %s", method, uri,
|
String message = String.format(Locale.ROOT, "%s %s: Expected no error got %s %s with body %s", method, uri,
|
||||||
statusLine.getStatusCode(), statusLine.getReasonPhrase(), EntityUtils.toString(response.getEntity()));
|
statusLine.getStatusCode(), statusLine.getReasonPhrase(), EntityUtils.toString(response.getEntity()));
|
||||||
assertThat(message, statusLine.getStatusCode(), is(not(greaterThanOrEqualTo(400))));
|
assertThat(message, statusLine.getStatusCode(), is(not(greaterThanOrEqualTo(400))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void assertAccessIsAllowed(String user, String method, String uri, String body) throws IOException {
|
protected void assertAccessIsAllowed(String user, String method, String uri, String body) throws IOException {
|
||||||
assertAccessIsAllowed(user, method, uri, body, new HashMap<>());
|
assertAccessIsAllowed(user, method, uri, body, new HashMap<>());
|
||||||
|
|
|
@ -81,12 +81,15 @@ public class BulkUpdateTests extends ShieldIntegTestCase {
|
||||||
|
|
||||||
try (RestClient restClient = restClient()) {
|
try (RestClient restClient = restClient()) {
|
||||||
StringEntity body = new StringEntity("{\"test\":\"test\"}", RestClient.JSON_CONTENT_TYPE);
|
StringEntity body = new StringEntity("{\"test\":\"test\"}", RestClient.JSON_CONTENT_TYPE);
|
||||||
ElasticsearchResponse response = restClient.performRequest("PUT", path, Collections.emptyMap(), body, basicAuthHeader);
|
try (ElasticsearchResponse response = restClient.performRequest("PUT", path, Collections.emptyMap(), body, basicAuthHeader)) {
|
||||||
assertThat(response.getStatusLine().getStatusCode(), equalTo(201));
|
assertThat(response.getStatusLine().getStatusCode(), equalTo(201));
|
||||||
|
}
|
||||||
|
|
||||||
response = restClient.performRequest("GET", path, Collections.emptyMap(), null, basicAuthHeader);
|
try (ElasticsearchResponse response = restClient.performRequest("GET", path, Collections.emptyMap(), null, 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\""));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
flushAndRefresh();
|
flushAndRefresh();
|
||||||
|
@ -94,14 +97,17 @@ public class BulkUpdateTests extends ShieldIntegTestCase {
|
||||||
|
|
||||||
//update with new field
|
//update with new field
|
||||||
body = new StringEntity("{\"doc\": {\"not test\": \"not test\"}}", RestClient.JSON_CONTENT_TYPE);
|
body = new StringEntity("{\"doc\": {\"not test\": \"not test\"}}", RestClient.JSON_CONTENT_TYPE);
|
||||||
response = restClient.performRequest("POST", path + "/_update", Collections.emptyMap(), body, basicAuthHeader);
|
try (ElasticsearchResponse response = restClient.performRequest("POST", path + "/_update",
|
||||||
|
Collections.emptyMap(), body, basicAuthHeader)) {
|
||||||
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
|
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
|
||||||
|
}
|
||||||
|
|
||||||
response = restClient.performRequest("GET", path, Collections.emptyMap(), null, basicAuthHeader);
|
try (ElasticsearchResponse response = restClient.performRequest("GET", path, Collections.emptyMap(), null, 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\""));
|
||||||
assertThat(responseBody, containsString("\"not test\":\"not test\""));
|
assertThat(responseBody, containsString("\"not test\":\"not test\""));
|
||||||
|
}
|
||||||
|
|
||||||
// this part is important. Without this, the document may be read from the translog which would bypass the bug where
|
// this part is important. Without this, the document may be read from the translog which would bypass the bug where
|
||||||
// FLS kicks in because the request can't be found and only returns meta fields
|
// FLS kicks in because the request can't be found and only returns meta fields
|
||||||
|
@ -109,14 +115,17 @@ public class BulkUpdateTests extends ShieldIntegTestCase {
|
||||||
|
|
||||||
body = new StringEntity("{\"update\": {\"_index\": \"index1\", \"_type\": \"type\", \"_id\": \"1\"}}\n" +
|
body = new StringEntity("{\"update\": {\"_index\": \"index1\", \"_type\": \"type\", \"_id\": \"1\"}}\n" +
|
||||||
"{\"doc\": {\"bulk updated\":\"bulk updated\"}}\n", RestClient.JSON_CONTENT_TYPE);
|
"{\"doc\": {\"bulk updated\":\"bulk updated\"}}\n", RestClient.JSON_CONTENT_TYPE);
|
||||||
response = restClient.performRequest("POST", "/_bulk", Collections.emptyMap(), body, basicAuthHeader);
|
try (ElasticsearchResponse response = restClient.performRequest("POST", "/_bulk",
|
||||||
|
Collections.emptyMap(), body, basicAuthHeader)) {
|
||||||
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
|
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
|
||||||
|
}
|
||||||
|
|
||||||
response = restClient.performRequest("GET", path, Collections.emptyMap(), null, basicAuthHeader);
|
try (ElasticsearchResponse response = restClient.performRequest("GET", path, Collections.emptyMap(), null, basicAuthHeader)) {
|
||||||
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\""));
|
||||||
assertThat(responseBody, containsString("\"bulk updated\":\"bulk updated\""));
|
assertThat(responseBody, containsString("\"bulk updated\":\"bulk updated\""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -167,15 +167,16 @@ public class ClearRealmsCacheTests extends ShieldIntegTestCase {
|
||||||
|
|
||||||
static void executeHttpRequest(String path, Map<String, String> params) throws Exception {
|
static void executeHttpRequest(String path, Map<String, String> params) throws Exception {
|
||||||
try (RestClient restClient = restClient()) {
|
try (RestClient restClient = restClient()) {
|
||||||
ElasticsearchResponse response = restClient.performRequest("POST", path, params, null,
|
try (ElasticsearchResponse response = restClient.performRequest("POST", path, params, null,
|
||||||
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
||||||
UsernamePasswordToken.basicAuthHeaderValue(ShieldSettingsSource.DEFAULT_USER_NAME,
|
UsernamePasswordToken.basicAuthHeaderValue(ShieldSettingsSource.DEFAULT_USER_NAME,
|
||||||
new SecuredString(ShieldSettingsSource.DEFAULT_PASSWORD.toCharArray()))));
|
new SecuredString(ShieldSettingsSource.DEFAULT_PASSWORD.toCharArray()))))) {
|
||||||
assertNotNull(response.getEntity());
|
assertNotNull(response.getEntity());
|
||||||
assertTrue(EntityUtils.toString(response.getEntity()).contains("cluster_name"));
|
assertTrue(EntityUtils.toString(response.getEntity()).contains("cluster_name"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Settings nodeSettings(int nodeOrdinal) {
|
public Settings nodeSettings(int nodeOrdinal) {
|
||||||
|
|
|
@ -138,12 +138,13 @@ public class ClearRolesCacheTests extends NativeRealmIntegTestCase {
|
||||||
path = "/_xpack/security/role/" + Strings.arrayToCommaDelimitedString(rolesToClear) + "/_clear_cache";
|
path = "/_xpack/security/role/" + Strings.arrayToCommaDelimitedString(rolesToClear) + "/_clear_cache";
|
||||||
}
|
}
|
||||||
try (RestClient restClient = restClient()) {
|
try (RestClient restClient = restClient()) {
|
||||||
ElasticsearchResponse response = restClient.performRequest("POST", path, Collections.emptyMap(), null,
|
try (ElasticsearchResponse response = restClient.performRequest("POST", path, Collections.emptyMap(), null,
|
||||||
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
||||||
UsernamePasswordToken.basicAuthHeaderValue(ShieldSettingsSource.DEFAULT_USER_NAME,
|
UsernamePasswordToken.basicAuthHeaderValue(ShieldSettingsSource.DEFAULT_USER_NAME,
|
||||||
new SecuredString(ShieldSettingsSource.DEFAULT_PASSWORD.toCharArray()))));
|
new SecuredString(ShieldSettingsSource.DEFAULT_PASSWORD.toCharArray()))))) {
|
||||||
assertThat(response.getStatusLine().getStatusCode(), is(RestStatus.OK.getStatus()));
|
assertThat(response.getStatusLine().getStatusCode(), is(RestStatus.OK.getStatus()));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
securityClient.prepareClearRolesCache().names(rolesToClear).get();
|
securityClient.prepareClearRolesCache().names(rolesToClear).get();
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,9 +198,10 @@ public class LicensingTests extends ShieldIntegTestCase {
|
||||||
|
|
||||||
public void testRestAuthenticationByLicenseType() throws Exception {
|
public void testRestAuthenticationByLicenseType() throws Exception {
|
||||||
try (RestClient restClient = restClient()) {
|
try (RestClient restClient = restClient()) {
|
||||||
ElasticsearchResponse response = restClient.performRequest("GET", "/", Collections.emptyMap(), null);
|
try (ElasticsearchResponse response = restClient.performRequest("GET", "/", Collections.emptyMap(), null)) {
|
||||||
// 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));
|
||||||
|
}
|
||||||
|
|
||||||
// generate a new license with a mode that enables auth
|
// generate a new license with a mode that enables auth
|
||||||
OperationMode mode = randomFrom(OperationMode.GOLD, OperationMode.TRIAL, OperationMode.PLATINUM, OperationMode.STANDARD);
|
OperationMode mode = randomFrom(OperationMode.GOLD, OperationMode.TRIAL, OperationMode.PLATINUM, OperationMode.STANDARD);
|
||||||
|
|
|
@ -44,11 +44,12 @@ public class ShieldPluginTests extends ShieldIntegTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("executing authorized request to /_xpack infos");
|
logger.info("executing authorized request to /_xpack infos");
|
||||||
ElasticsearchResponse response = restClient.performRequest("GET", "/_xpack", Collections.emptyMap(), null,
|
try (ElasticsearchResponse response = restClient.performRequest("GET", "/_xpack", Collections.emptyMap(), null,
|
||||||
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
||||||
basicAuthHeaderValue(ShieldSettingsSource.DEFAULT_USER_NAME,
|
basicAuthHeaderValue(ShieldSettingsSource.DEFAULT_USER_NAME,
|
||||||
new SecuredString(ShieldSettingsSource.DEFAULT_PASSWORD.toCharArray()))));
|
new SecuredString(ShieldSettingsSource.DEFAULT_PASSWORD.toCharArray()))))) {
|
||||||
assertThat(response.getStatusLine().getStatusCode(), is(OK.getStatus()));
|
assertThat(response.getStatusLine().getStatusCode(), is(OK.getStatus()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -142,14 +142,15 @@ public class RunAsIntegTests extends ShieldIntegTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
// but when running as a different user it should work
|
// but when running as a different user it should work
|
||||||
ElasticsearchResponse response = restClient.performRequest("GET", "/_nodes", Collections.emptyMap(), null,
|
try (ElasticsearchResponse response = restClient.performRequest("GET", "/_nodes", Collections.emptyMap(), null,
|
||||||
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
||||||
UsernamePasswordToken.basicAuthHeaderValue(RUN_AS_USER,
|
UsernamePasswordToken.basicAuthHeaderValue(RUN_AS_USER,
|
||||||
SecuredStringTests.build(ShieldSettingsSource.DEFAULT_PASSWORD))),
|
SecuredStringTests.build(ShieldSettingsSource.DEFAULT_PASSWORD))),
|
||||||
new BasicHeader(InternalAuthenticationService.RUN_AS_USER_HEADER, ShieldSettingsSource.DEFAULT_USER_NAME));
|
new BasicHeader(InternalAuthenticationService.RUN_AS_USER_HEADER, ShieldSettingsSource.DEFAULT_USER_NAME))) {
|
||||||
assertThat(response.getStatusLine().getStatusCode(), is(200));
|
assertThat(response.getStatusLine().getStatusCode(), is(200));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void testEmptyUserImpersonationHeader() throws Exception {
|
public void testEmptyUserImpersonationHeader() throws Exception {
|
||||||
try (TransportClient client = getTransportClient(Settings.builder()
|
try (TransportClient client = getTransportClient(Settings.builder()
|
||||||
|
|
|
@ -89,13 +89,14 @@ public class PkiOptionalClientAuthTests extends ShieldIntegTestCase {
|
||||||
assertThat(e.getElasticsearchResponse().getStatusLine().getStatusCode(), is(401));
|
assertThat(e.getElasticsearchResponse().getStatusLine().getStatusCode(), is(401));
|
||||||
}
|
}
|
||||||
|
|
||||||
ElasticsearchResponse response = restClient.performRequest("GET", "_nodes", Collections.emptyMap(), null,
|
try (ElasticsearchResponse response = restClient.performRequest("GET", "_nodes", Collections.emptyMap(), null,
|
||||||
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
||||||
UsernamePasswordToken.basicAuthHeaderValue(ShieldSettingsSource.DEFAULT_USER_NAME,
|
UsernamePasswordToken.basicAuthHeaderValue(ShieldSettingsSource.DEFAULT_USER_NAME,
|
||||||
new SecuredString(ShieldSettingsSource.DEFAULT_PASSWORD.toCharArray()))));
|
new SecuredString(ShieldSettingsSource.DEFAULT_PASSWORD.toCharArray()))))) {
|
||||||
assertThat(response.getStatusLine().getStatusCode(), is(200));
|
assertThat(response.getStatusLine().getStatusCode(), is(200));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void testTransportClientWithoutClientCertificate() {
|
public void testTransportClientWithoutClientCertificate() {
|
||||||
Transport transport = internalCluster().getDataNodeInstance(Transport.class);
|
Transport transport = internalCluster().getDataNodeInstance(Transport.class);
|
||||||
|
|
|
@ -81,11 +81,12 @@ public class PkiWithoutClientAuthenticationTests extends ShieldIntegTestCase {
|
||||||
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 = restClient(httpClient, "https")) {
|
try (RestClient restClient = restClient(httpClient, "https")) {
|
||||||
ElasticsearchResponse response = restClient.performRequest("GET", "/_nodes", Collections.emptyMap(), null,
|
try (ElasticsearchResponse response = restClient.performRequest("GET", "/_nodes", Collections.emptyMap(), null,
|
||||||
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
||||||
UsernamePasswordToken.basicAuthHeaderValue(ShieldSettingsSource.DEFAULT_USER_NAME,
|
UsernamePasswordToken.basicAuthHeaderValue(ShieldSettingsSource.DEFAULT_USER_NAME,
|
||||||
new SecuredString(ShieldSettingsSource.DEFAULT_PASSWORD.toCharArray()))));
|
new SecuredString(ShieldSettingsSource.DEFAULT_PASSWORD.toCharArray()))))) {
|
||||||
assertThat(response.getStatusLine().getStatusCode(), is(200));
|
assertThat(response.getStatusLine().getStatusCode(), is(200));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -45,11 +45,12 @@ public class PkiWithoutSSLTests extends ShieldIntegTestCase {
|
||||||
|
|
||||||
public void testThatHttpWorks() throws Exception {
|
public void testThatHttpWorks() throws Exception {
|
||||||
try (RestClient restClient = restClient()) {
|
try (RestClient restClient = restClient()) {
|
||||||
ElasticsearchResponse response = restClient.performRequest("GET", "/_nodes", Collections.emptyMap(), null,
|
try (ElasticsearchResponse response = restClient.performRequest("GET", "/_nodes", Collections.emptyMap(), null,
|
||||||
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
new BasicHeader(UsernamePasswordToken.BASIC_AUTH_HEADER,
|
||||||
UsernamePasswordToken.basicAuthHeaderValue(ShieldSettingsSource.DEFAULT_USER_NAME,
|
UsernamePasswordToken.basicAuthHeaderValue(ShieldSettingsSource.DEFAULT_USER_NAME,
|
||||||
new SecuredString(ShieldSettingsSource.DEFAULT_PASSWORD.toCharArray()))));
|
new SecuredString(ShieldSettingsSource.DEFAULT_PASSWORD.toCharArray()))))) {
|
||||||
assertThat(response.getStatusLine().getStatusCode(), is(200));
|
assertThat(response.getStatusLine().getStatusCode(), is(200));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -53,9 +53,9 @@ public class RestAuthenticateActionTests extends ShieldIntegTestCase {
|
||||||
|
|
||||||
public void testAuthenticateApi() throws Exception {
|
public void testAuthenticateApi() throws Exception {
|
||||||
try (RestClient restClient = restClient()) {
|
try (RestClient restClient = restClient()) {
|
||||||
ElasticsearchResponse response = restClient.performRequest("GET", "/_xpack/security/_authenticate", Collections.emptyMap(),
|
try (ElasticsearchResponse response = restClient.performRequest("GET", "/_xpack/security/_authenticate", Collections.emptyMap(),
|
||||||
null, new BasicHeader("Authorization", basicAuthHeaderValue(ShieldSettingsSource.DEFAULT_USER_NAME,
|
null, new BasicHeader("Authorization", basicAuthHeaderValue(ShieldSettingsSource.DEFAULT_USER_NAME,
|
||||||
new SecuredString(ShieldSettingsSource.DEFAULT_PASSWORD.toCharArray()))));
|
new SecuredString(ShieldSettingsSource.DEFAULT_PASSWORD.toCharArray()))))) {
|
||||||
assertThat(response.getStatusLine().getStatusCode(), is(200));
|
assertThat(response.getStatusLine().getStatusCode(), is(200));
|
||||||
JsonPath jsonPath = new JsonPath(EntityUtils.toString(response.getEntity()));
|
JsonPath jsonPath = new JsonPath(EntityUtils.toString(response.getEntity()));
|
||||||
assertThat(jsonPath.evaluate("username").toString(), equalTo(ShieldSettingsSource.DEFAULT_USER_NAME));
|
assertThat(jsonPath.evaluate("username").toString(), equalTo(ShieldSettingsSource.DEFAULT_USER_NAME));
|
||||||
|
@ -65,11 +65,12 @@ public class RestAuthenticateActionTests extends ShieldIntegTestCase {
|
||||||
assertThat(roles, contains(ShieldSettingsSource.DEFAULT_ROLE));
|
assertThat(roles, contains(ShieldSettingsSource.DEFAULT_ROLE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void testAuthenticateApiWithoutAuthentication() throws Exception {
|
public void testAuthenticateApiWithoutAuthentication() throws Exception {
|
||||||
try (RestClient restClient = restClient()) {
|
try (RestClient restClient = restClient()) {
|
||||||
ElasticsearchResponse response = restClient.performRequest("GET", "/_xpack/security/_authenticate",
|
try (ElasticsearchResponse response = restClient.performRequest("GET", "/_xpack/security/_authenticate",
|
||||||
Collections.emptyMap(), null);
|
Collections.emptyMap(), null)) {
|
||||||
if (anonymousEnabled) {
|
if (anonymousEnabled) {
|
||||||
assertThat(response.getStatusLine().getStatusCode(), is(200));
|
assertThat(response.getStatusLine().getStatusCode(), is(200));
|
||||||
JsonPath jsonPath = new JsonPath(EntityUtils.toString(response.getEntity()));
|
JsonPath jsonPath = new JsonPath(EntityUtils.toString(response.getEntity()));
|
||||||
|
@ -90,3 +91,4 @@ public class RestAuthenticateActionTests extends ShieldIntegTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -83,12 +83,13 @@ public class SslClientAuthTests extends ShieldIntegTestCase {
|
||||||
CloseableHttpClient client = HttpClients.custom().setSSLSocketFactory(socketFactory).build();
|
CloseableHttpClient client = HttpClients.custom().setSSLSocketFactory(socketFactory).build();
|
||||||
|
|
||||||
try (RestClient restClient = restClient(client, "https")) {
|
try (RestClient restClient = restClient(client, "https")) {
|
||||||
ElasticsearchResponse response = restClient.performRequest("GET", "/", Collections.emptyMap(), null,
|
try (ElasticsearchResponse response = restClient.performRequest("GET", "/", Collections.emptyMap(), null,
|
||||||
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"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void testThatTransportWorksWithoutSslClientAuth() throws Exception {
|
public void testThatTransportWorksWithoutSslClientAuth() throws Exception {
|
||||||
// specify an arbitrary keystore, that does not include the certs needed to connect to the transport protocol
|
// specify an arbitrary keystore, that does not include the certs needed to connect to the transport protocol
|
||||||
|
|
|
@ -63,7 +63,8 @@ public class WatcherSettingsFilterTests extends AbstractWatcherIntegrationTestCa
|
||||||
} else {
|
} else {
|
||||||
headers = new Header[0];
|
headers = new Header[0];
|
||||||
}
|
}
|
||||||
ElasticsearchResponse response = restClient.performRequest("GET", "/_nodes/settings", Collections.emptyMap(), null, headers);
|
try (ElasticsearchResponse response = restClient.performRequest("GET", "/_nodes/settings",
|
||||||
|
Collections.emptyMap(), null, headers)) {
|
||||||
Map<String, Object> responseMap = JsonXContent.jsonXContent.createParser(response.getEntity().getContent()).map();
|
Map<String, Object> responseMap = JsonXContent.jsonXContent.createParser(response.getEntity().getContent()).map();
|
||||||
Map<String, Object> nodes = (Map<String, Object>) responseMap.get("nodes");
|
Map<String, Object> nodes = (Map<String, Object>) responseMap.get("nodes");
|
||||||
for (Object node : nodes.values()) {
|
for (Object node : nodes.values()) {
|
||||||
|
@ -76,3 +77,4 @@ public class WatcherSettingsFilterTests extends AbstractWatcherIntegrationTestCa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue