/*
 * 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 java.util.Collection;
import java.util.Map;
import java.util.stream.Collectors;

import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.SecurityIntegTestCase;
import org.elasticsearch.xpack.core.XPackSettings;
import org.elasticsearch.xpack.security.transport.SecurityServerTransportInterceptor;

// this class sits in org.elasticsearch.transport so that TransportService.requestHandlers is visible
public class SecurityServerTransportServiceTests extends SecurityIntegTestCase {
    @Override
    protected Settings transportClientSettings() {
        return Settings.builder()
                .put(super.transportClientSettings())
                .put(XPackSettings.SECURITY_ENABLED.getKey(), true)
                .build();
    }

    @Override
    protected Collection<Class<? extends Plugin>> getMockPlugins() {
        Collection<Class<? extends Plugin>> mockPlugins = super.getMockPlugins();
        // no handler wrapping here we check the requestHandlers below and this plugin wraps it
        return mockPlugins.stream().filter(p -> p != AssertingTransportInterceptor.TestPlugin.class).collect(Collectors.toList());
    }

    public void testSecurityServerTransportServiceWrapsAllHandlers() {
        for (TransportService transportService : internalCluster().getInstances(TransportService.class)) {
            for (Map.Entry<String, RequestHandlerRegistry> entry : transportService.requestHandlers.entrySet()) {
                RequestHandlerRegistry handler = entry.getValue();
                assertEquals(
                        "handler not wrapped by " + SecurityServerTransportInterceptor.ProfileSecuredRequestHandler.class +
                                "; do all the handler registration methods have overrides?",
                        handler.toString(),
                        "ProfileSecuredRequestHandler{action='" + handler.getAction() + "', executorName='" + handler.getExecutor()
                                + "', forceExecution=" + handler.isForceExecution() + "}");
            }
        }
    }
}

@@ -294,76 +294,11 @@
 til.
-Collection;%0Aimport java.util.Map;%0Aimport java.util.stream.Collectors
+Map
 ;%0A%0Ai
@@ -351,49 +351,8 @@
 gs;%0A
-import org.elasticsearch.plugins.Plugin;%0A
 impo
@@ -979,407 +979,8 @@
  %7D%0A%0A
-    @Override%0A    protected Collection%3CClass%3C? extends Plugin%3E%3E getMockPlugins() %7B%0A        Collection%3CClass%3C? extends Plugin%3E%3E mockPlugins = super.getMockPlugins();%0A        // no handler wrapping here we check the requestHandlers below and this plugin wraps it%0A        return mockPlugins.stream().filter(p -%3E p != AssertingTransportInterceptor.TestPlugin.class).collect(Collectors.toList());%0A    %7D%0A%0A
     

remove Streamable serde assertions (elastic/x-pack-elasticsearch#4261)