|
8 | 8 | import org.apache.http.util.EntityUtils;
|
9 | 9 | import org.elasticsearch.client.Request;
|
10 | 10 | import org.elasticsearch.client.Response;
|
| 11 | +import org.elasticsearch.client.ResponseException; |
11 | 12 | import org.elasticsearch.client.RestClient;
|
12 | 13 | import org.elasticsearch.common.Booleans;
|
13 | 14 | import org.elasticsearch.common.Strings;
|
|
18 | 19 | import org.elasticsearch.common.xcontent.XContentHelper;
|
19 | 20 | import org.elasticsearch.common.xcontent.json.JsonXContent;
|
20 | 21 | import org.elasticsearch.common.xcontent.support.XContentMapValues;
|
| 22 | +import org.elasticsearch.rest.RestStatus; |
21 | 23 | import org.elasticsearch.test.rest.ESRestTestCase;
|
22 | 24 |
|
23 | 25 | import java.io.IOException;
|
|
26 | 28 |
|
27 | 29 | import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
28 | 30 | import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
|
| 31 | +import static org.hamcrest.Matchers.containsString; |
29 | 32 | import static org.hamcrest.Matchers.equalTo;
|
| 33 | +import static org.hamcrest.Matchers.is; |
30 | 34 |
|
31 | 35 | public class FollowIndexSecurityIT extends ESRestTestCase {
|
32 | 36 |
|
@@ -96,16 +100,19 @@ public void testFollowIndex() throws Exception {
|
96 | 100 | assertThat(countCcrNodeTasks(), equalTo(0));
|
97 | 101 | });
|
98 | 102 |
|
99 |
| - createAndFollowIndex("leader_cluster:" + unallowedIndex, unallowedIndex); |
100 |
| - // Verify that nothing has been replicated and no node tasks are running |
101 |
| - // These node tasks should have been failed due to the fact that the user |
102 |
| - // has no sufficient priviledges. |
| 103 | + Exception e = expectThrows(ResponseException.class, |
| 104 | + () -> createAndFollowIndex("leader_cluster:" + unallowedIndex, unallowedIndex)); |
| 105 | + assertThat(e.getMessage(), |
| 106 | + containsString("action [indices:admin/xpack/ccr/create_and_follow_index] is unauthorized for user [test_ccr]")); |
| 107 | + // Verify that the follow index has not been created and no node tasks are running |
| 108 | + assertThat(indexExists(adminClient(), unallowedIndex), is(false)); |
103 | 109 | assertBusy(() -> assertThat(countCcrNodeTasks(), equalTo(0)));
|
104 |
| - verifyDocuments(adminClient(), unallowedIndex, 0); |
105 | 110 |
|
106 |
| - followIndex("leader_cluster:" + unallowedIndex, unallowedIndex); |
| 111 | + e = expectThrows(ResponseException.class, |
| 112 | + () -> followIndex("leader_cluster:" + unallowedIndex, unallowedIndex)); |
| 113 | + assertThat(e.getMessage(), containsString("follow index [" + unallowedIndex + "] does not exist")); |
| 114 | + assertThat(indexExists(adminClient(), unallowedIndex), is(false)); |
107 | 115 | assertBusy(() -> assertThat(countCcrNodeTasks(), equalTo(0)));
|
108 |
| - verifyDocuments(adminClient(), unallowedIndex, 0); |
109 | 116 | }
|
110 | 117 | }
|
111 | 118 |
|
@@ -191,4 +198,9 @@ protected static void createIndex(String name, Settings settings, String mapping
|
191 | 198 | assertOK(adminClient().performRequest(request));
|
192 | 199 | }
|
193 | 200 |
|
| 201 | + private static boolean indexExists(RestClient client, String index) throws IOException { |
| 202 | + Response response = client.performRequest(new Request("HEAD", "/" + index)); |
| 203 | + return RestStatus.OK.getStatus() == response.getStatusLine().getStatusCode(); |
| 204 | + } |
| 205 | + |
194 | 206 | }
|
0 commit comments