|
5 | 5 | */
|
6 | 6 | package org.elasticsearch.xpack.security;
|
7 | 7 |
|
| 8 | +import org.apache.http.HttpHost; |
8 | 9 | import org.apache.http.util.EntityUtils;
|
9 | 10 | import org.elasticsearch.client.Request;
|
10 | 11 | import org.elasticsearch.client.Response;
|
11 | 12 | import org.elasticsearch.client.ResponseException;
|
| 13 | +import org.elasticsearch.client.RestClient; |
| 14 | +import org.elasticsearch.client.RestClientBuilder; |
12 | 15 | import org.elasticsearch.common.Booleans;
|
13 | 16 | import org.elasticsearch.common.settings.SecureString;
|
14 | 17 | import org.elasticsearch.common.settings.Settings;
|
|
20 | 23 |
|
21 | 24 | import java.io.IOException;
|
22 | 25 | import java.util.Arrays;
|
| 26 | +import java.util.List; |
23 | 27 | import java.util.Locale;
|
24 | 28 | import java.util.Map;
|
25 | 29 |
|
@@ -55,6 +59,14 @@ protected Settings restClientSettings() {
|
55 | 59 | .build();
|
56 | 60 | }
|
57 | 61 |
|
| 62 | + @Override |
| 63 | + protected RestClient buildClient(Settings settings, HttpHost[] hosts) throws IOException { |
| 64 | + RestClientBuilder builder = RestClient.builder(hosts); |
| 65 | + configureClient(builder, settings); |
| 66 | + builder.setStrictDeprecationMode(false); |
| 67 | + return builder.build(); |
| 68 | + } |
| 69 | + |
58 | 70 | @Override
|
59 | 71 | protected boolean preserveClusterUponCompletion() {
|
60 | 72 | // If this is the first run (security not yet enabled), then don't clean up afterwards because we want to test restart with data
|
@@ -85,6 +97,21 @@ public void testSecuritySetup() throws Exception {
|
85 | 97 | }
|
86 | 98 | }
|
87 | 99 |
|
| 100 | + public void testSecurityDisabledWarning() throws Exception { |
| 101 | + final Request request = new Request("GET", "/_cat/indices"); |
| 102 | + Response response = client().performRequest(request); |
| 103 | + List<String> warningHeaders = response.getWarnings(); |
| 104 | + if (securityEnabled) { |
| 105 | + assertThat (warningHeaders.isEmpty(), equalTo(true)); |
| 106 | + } else { |
| 107 | + assertThat (warningHeaders.size(), equalTo(1)); |
| 108 | + assertThat (warningHeaders.get(0), |
| 109 | + containsString("Elasticsearch security features are not enabled, anyone can access your cluster without " + |
| 110 | + "authentication. Read https://www.elastic.co/guide/en/elasticsearch/reference/<autodetected version number>/" + |
| 111 | + "get-started-enable-security.html for more information.")); |
| 112 | + } |
| 113 | + } |
| 114 | + |
88 | 115 | private String getClusterInfo() throws IOException {
|
89 | 116 | Map<String, Object> info = getAsMap("/");
|
90 | 117 | assertThat(info, notNullValue());
|
|
0 commit comments