use of org.elasticsearch.rest.AbstractRestChannel in project elasticsearch by elastic.
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;
}
use of org.elasticsearch.rest.AbstractRestChannel 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();
}
}
Aggregations