Search in sources :

Example 1 with AbstractRestChannel

use of org.opensearch.rest.AbstractRestChannel in project OpenSearch by opensearch-project.

the class RestTableTests method assertResponseContentType.

private RestResponse assertResponseContentType(Map<String, List<String>> headers, String mediaType) throws Exception {
    FakeRestRequest requestWithAcceptHeader = new FakeRestRequest.Builder(xContentRegistry()).withHeaders(headers).build();
    table.startRow();
    table.addCell("foo");
    table.addCell("foo");
    table.addCell("foo");
    table.addCell("foo");
    table.addCell("foo");
    table.addCell("foo");
    table.addCell("foo");
    table.addCell("foo");
    table.endRow();
    RestResponse response = buildResponse(table, new AbstractRestChannel(requestWithAcceptHeader, true) {

        @Override
        public void sendResponse(RestResponse response) {
        }
    });
    assertThat(response.contentType(), equalTo(mediaType));
    return response;
}
Also used : RestResponse(org.opensearch.rest.RestResponse) FakeRestRequest(org.opensearch.test.rest.FakeRestRequest) AbstractRestChannel(org.opensearch.rest.AbstractRestChannel)

Example 2 with AbstractRestChannel

use of org.opensearch.rest.AbstractRestChannel in project OpenSearch by opensearch-project.

the class RepositoryCredentialsTests method testInsecureRepositoryCredentials.

public void testInsecureRepositoryCredentials() throws Exception {
    final String repositoryName = "repo-insecure-creds";
    createRepository(repositoryName, Settings.builder().put(S3Repository.ACCESS_KEY_SETTING.getKey(), "insecure_aws_key").put(S3Repository.SECRET_KEY_SETTING.getKey(), "insecure_aws_secret").build());
    final RestRequest fakeRestRequest = new FakeRestRequest();
    fakeRestRequest.params().put("repository", repositoryName);
    final RestGetRepositoriesAction action = new RestGetRepositoriesAction(getInstanceFromNode(SettingsFilter.class));
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicReference<AssertionError> error = new AtomicReference<>();
    action.handleRequest(fakeRestRequest, new AbstractRestChannel(fakeRestRequest, true) {

        @Override
        public void sendResponse(RestResponse response) {
            try {
                String responseAsString = response.content().utf8ToString();
                assertThat(responseAsString, containsString(repositoryName));
                assertThat(responseAsString, not(containsString("insecure_")));
            } catch (final AssertionError ex) {
                error.set(ex);
            }
            latch.countDown();
        }
    }, getInstanceFromNode(NodeClient.class));
    latch.await();
    if (error.get() != null) {
        throw error.get();
    }
    assertWarnings("Using s3 access/secret key from repository settings. Instead store these in named clients and" + " the opensearch keystore for secure settings.");
}
Also used : NodeClient(org.opensearch.client.node.NodeClient) RestResponse(org.opensearch.rest.RestResponse) RestGetRepositoriesAction(org.opensearch.rest.action.admin.cluster.RestGetRepositoriesAction) AtomicReference(java.util.concurrent.atomic.AtomicReference) Matchers.containsString(org.hamcrest.Matchers.containsString) CountDownLatch(java.util.concurrent.CountDownLatch) FakeRestRequest(org.opensearch.test.rest.FakeRestRequest) SettingsFilter(org.opensearch.common.settings.SettingsFilter) FakeRestRequest(org.opensearch.test.rest.FakeRestRequest) RestRequest(org.opensearch.rest.RestRequest) AbstractRestChannel(org.opensearch.rest.AbstractRestChannel)

Example 3 with AbstractRestChannel

use of org.opensearch.rest.AbstractRestChannel in project OpenSearch by opensearch-project.

the class DedicatedClusterSnapshotRestoreIT method testThatSensitiveRepositorySettingsAreNotExposed.

public void testThatSensitiveRepositorySettingsAreNotExposed() throws Exception {
    disableRepoConsistencyCheck("This test does not create any data in the repository");
    logger.info("--> start two nodes");
    internalCluster().startNodes(2);
    createRepository("test-repo", "mock", Settings.builder().put("location", randomRepoPath()).put(MockRepository.Plugin.USERNAME_SETTING.getKey(), "notsecretusername").put(MockRepository.Plugin.PASSWORD_SETTING.getKey(), "verysecretpassword"));
    NodeClient nodeClient = internalCluster().getInstance(NodeClient.class);
    RestGetRepositoriesAction getRepoAction = new RestGetRepositoriesAction(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(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.opensearch.client.node.NodeClient) RestClusterStateAction(org.opensearch.rest.action.admin.cluster.RestClusterStateAction) RestResponse(org.opensearch.rest.RestResponse) RestGetRepositoriesAction(org.opensearch.rest.action.admin.cluster.RestGetRepositoriesAction) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) FakeRestRequest(org.opensearch.test.rest.FakeRestRequest) SettingsFilter(org.opensearch.common.settings.SettingsFilter) FakeRestRequest(org.opensearch.test.rest.FakeRestRequest) RestRequest(org.opensearch.rest.RestRequest) AbstractRestChannel(org.opensearch.rest.AbstractRestChannel)

Aggregations

AbstractRestChannel (org.opensearch.rest.AbstractRestChannel)3 RestResponse (org.opensearch.rest.RestResponse)3 FakeRestRequest (org.opensearch.test.rest.FakeRestRequest)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 NodeClient (org.opensearch.client.node.NodeClient)2 SettingsFilter (org.opensearch.common.settings.SettingsFilter)2 RestRequest (org.opensearch.rest.RestRequest)2 RestGetRepositoriesAction (org.opensearch.rest.action.admin.cluster.RestGetRepositoriesAction)2 Matchers.containsString (org.hamcrest.Matchers.containsString)1 RestClusterStateAction (org.opensearch.rest.action.admin.cluster.RestClusterStateAction)1