Search in sources :

Example 51 with RestResponse

use of org.elasticsearch.rest.RestResponse in project elasticsearch by elastic.

the class DedicatedClusterSnapshotRestoreIT method testThatSensitiveRepositorySettingsAreNotExposed.

public void testThatSensitiveRepositorySettingsAreNotExposed() throws Exception {
    Settings nodeSettings = Settings.builder().put().build();
    logger.info("--> start two nodes");
    internalCluster().startNodes(2, nodeSettings);
    // Register mock repositories
    client().admin().cluster().preparePutRepository("test-repo").setType("mock").setSettings(Settings.builder().put("location", randomRepoPath()).put(MockRepository.Plugin.USERNAME_SETTING.getKey(), "notsecretusername").put(MockRepository.Plugin.PASSWORD_SETTING.getKey(), "verysecretpassword")).get();
    NodeClient nodeClient = internalCluster().getInstance(NodeClient.class);
    RestGetRepositoriesAction getRepoAction = new RestGetRepositoriesAction(nodeSettings, mock(RestController.class), internalCluster().getInstance(SettingsFilter.class));
    RestRequest getRepoRequest = new FakeRestRequest();
    getRepoRequest.params().put("repository", "test-repo");
    final CountDownLatch getRepoLatch = new CountDownLatch(1);
    final AtomicReference<AssertionError> getRepoError = new AtomicReference<>();
    getRepoAction.handleRequest(getRepoRequest, new AbstractRestChannel(getRepoRequest, true) {

        @Override
        public void sendResponse(RestResponse response) {
            try {
                assertThat(response.content().utf8ToString(), containsString("notsecretusername"));
                assertThat(response.content().utf8ToString(), not(containsString("verysecretpassword")));
            } catch (AssertionError ex) {
                getRepoError.set(ex);
            }
            getRepoLatch.countDown();
        }
    }, nodeClient);
    assertTrue(getRepoLatch.await(1, TimeUnit.SECONDS));
    if (getRepoError.get() != null) {
        throw getRepoError.get();
    }
    RestClusterStateAction clusterStateAction = new RestClusterStateAction(nodeSettings, mock(RestController.class), internalCluster().getInstance(SettingsFilter.class));
    RestRequest clusterStateRequest = new FakeRestRequest();
    final CountDownLatch clusterStateLatch = new CountDownLatch(1);
    final AtomicReference<AssertionError> clusterStateError = new AtomicReference<>();
    clusterStateAction.handleRequest(clusterStateRequest, new AbstractRestChannel(clusterStateRequest, true) {

        @Override
        public void sendResponse(RestResponse response) {
            try {
                assertThat(response.content().utf8ToString(), containsString("notsecretusername"));
                assertThat(response.content().utf8ToString(), not(containsString("verysecretpassword")));
            } catch (AssertionError ex) {
                clusterStateError.set(ex);
            }
            clusterStateLatch.countDown();
        }
    }, nodeClient);
    assertTrue(clusterStateLatch.await(1, TimeUnit.SECONDS));
    if (clusterStateError.get() != null) {
        throw clusterStateError.get();
    }
}
Also used : NodeClient(org.elasticsearch.client.node.NodeClient) RestClusterStateAction(org.elasticsearch.rest.action.admin.cluster.RestClusterStateAction) RestResponse(org.elasticsearch.rest.RestResponse) RestGetRepositoriesAction(org.elasticsearch.rest.action.admin.cluster.RestGetRepositoriesAction) RestController(org.elasticsearch.rest.RestController) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest) SettingsFilter(org.elasticsearch.common.settings.SettingsFilter) RestRequest(org.elasticsearch.rest.RestRequest) FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest) AbstractRestChannel(org.elasticsearch.rest.AbstractRestChannel) Settings(org.elasticsearch.common.settings.Settings)

Aggregations

RestResponse (org.elasticsearch.rest.RestResponse)51 NodeClient (org.elasticsearch.client.node.NodeClient)48 Settings (org.elasticsearch.common.settings.Settings)48 RestController (org.elasticsearch.rest.RestController)48 RestRequest (org.elasticsearch.rest.RestRequest)48 GET (org.elasticsearch.rest.RestRequest.Method.GET)40 Strings (org.elasticsearch.common.Strings)33 IOException (java.io.IOException)31 BytesRestResponse (org.elasticsearch.rest.BytesRestResponse)31 BaseRestHandler (org.elasticsearch.rest.BaseRestHandler)30 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)27 RestBuilderListener (org.elasticsearch.rest.action.RestBuilderListener)25 IndicesOptions (org.elasticsearch.action.support.IndicesOptions)23 OK (org.elasticsearch.rest.RestStatus.OK)20 RestResponseListener (org.elasticsearch.rest.action.RestResponseListener)20 Table (org.elasticsearch.common.Table)17 ClusterStateRequest (org.elasticsearch.action.admin.cluster.state.ClusterStateRequest)12 ClusterStateResponse (org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)12 RestActions.buildBroadcastShardsHeader (org.elasticsearch.rest.action.RestActions.buildBroadcastShardsHeader)11 RestStatus (org.elasticsearch.rest.RestStatus)10