Add test to ensure that ShieldServerTransportService wraps all handlers

This commit adds a test to ensure that all request handlers are wrapped
by ProfileSecuredRequestHandler.

Original commit: elastic/x-pack-elasticsearch@26473d0ddc
This commit is contained in:
Jason Tedor 2015-08-31 08:25:05 -04:00
parent fb11827f78
commit 36b5eaf09b
2 changed files with 40 additions and 1 deletions

View File

@ -111,7 +111,7 @@ public class ShieldServerTransportService extends TransportService {
return profileFilters.get(profile);
}
static class ProfileSecuredRequestHandler<T extends TransportRequest> implements TransportRequestHandler<T> {
public static class ProfileSecuredRequestHandler<T extends TransportRequest> implements TransportRequestHandler<T> {
protected final String action;
protected final TransportRequestHandler<T> handler;

View File

@ -0,0 +1,39 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.transport;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.shield.ShieldPlugin;
import org.elasticsearch.shield.transport.ShieldServerTransportService;
import org.elasticsearch.test.ShieldIntegTestCase;
import java.util.Map;
import static org.hamcrest.Matchers.instanceOf;
// this class sits in org.elasticsearch.transport so that TransportService.requestHandlers is visible
public class ShieldServerTransportServiceTests extends ShieldIntegTestCase {
@Override
protected Settings transportClientSettings() {
return Settings.settingsBuilder()
.put(super.transportClientSettings())
.put(ShieldPlugin.ENABLED_SETTING_NAME, true)
.build();
}
public void testShieldServerTransportServiceWrapsAllHandlers() {
for (TransportService transportService : internalTestCluster().getInstances(TransportService.class)) {
assertThat(transportService, instanceOf(ShieldServerTransportService.class));
for (Map.Entry<String, RequestHandlerRegistry> entry : transportService.requestHandlers.entrySet()) {
assertThat(
"handler not wrapped by " + ShieldServerTransportService.ProfileSecuredRequestHandler.class + "; do all the handler registration methods have overrides?",
entry.getValue().getHandler(),
instanceOf(ShieldServerTransportService.ProfileSecuredRequestHandler.class)
);
}
}
}
}