Search in sources :

Example 1 with NettyBootstrap

use of io.crate.netty.NettyBootstrap in project crate by crate.

the class PostgresNettyPublishPortTest method testPublishAddressOverride.

@Test
public void testPublishAddressOverride() {
    // Check override for network.publish_host
    Settings settingsWithCustomPublish = Settings.builder().put("network.publish_host", "cantbindtothis").build();
    NetworkService networkService = new NetworkService(Collections.emptyList());
    StubUserManager userManager = new StubUserManager();
    PostgresNetty psql = new PostgresNetty(settingsWithCustomPublish, mock(SQLOperations.class), userManager, networkService, new AlwaysOKAuthentication(userName -> User.CRATE_USER), new NettyBootstrap(), mock(SslContextProvider.class));
    try {
        psql.doStart();
        fail("Should have failed due to custom hostname");
    } catch (BindTransportException e) {
        // that's what we want
        assertThat(e.getCause(), instanceOf(UnknownHostException.class));
    } finally {
        psql.doStop();
        psql.close();
    }
}
Also used : PostgresNetty.resolvePublishPort(io.crate.protocols.postgres.PostgresNetty.resolvePublishPort) User(io.crate.user.User) BindTransportException(org.elasticsearch.transport.BindTransportException) Test(org.junit.Test) BindHttpException(org.elasticsearch.http.BindHttpException) UnknownHostException(java.net.UnknownHostException) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) NetworkService(org.elasticsearch.common.network.NetworkService) InetAddress.getByName(java.net.InetAddress.getByName) Settings(org.elasticsearch.common.settings.Settings) TransportAddress(org.elasticsearch.common.transport.TransportAddress) Arrays.asList(java.util.Arrays.asList) NettyBootstrap(io.crate.netty.NettyBootstrap) Matchers.equalTo(org.hamcrest.Matchers.equalTo) SslContextProvider(io.crate.protocols.ssl.SslContextProvider) ESTestCase(org.elasticsearch.test.ESTestCase) AlwaysOKAuthentication(io.crate.auth.AlwaysOKAuthentication) SQLOperations(io.crate.action.sql.SQLOperations) StubUserManager(io.crate.user.StubUserManager) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) AlwaysOKAuthentication(io.crate.auth.AlwaysOKAuthentication) NetworkService(org.elasticsearch.common.network.NetworkService) BindTransportException(org.elasticsearch.transport.BindTransportException) SslContextProvider(io.crate.protocols.ssl.SslContextProvider) SQLOperations(io.crate.action.sql.SQLOperations) Settings(org.elasticsearch.common.settings.Settings) StubUserManager(io.crate.user.StubUserManager) NettyBootstrap(io.crate.netty.NettyBootstrap) Test(org.junit.Test)

Example 2 with NettyBootstrap

use of io.crate.netty.NettyBootstrap in project crate by crate.

the class PostgresNettyPublishPortTest method testBindAddressOverrideSetting.

@Test
public void testBindAddressOverrideSetting() {
    // Check override for network.bind_host
    Settings settingsWithCustomBind = Settings.builder().put("network.bind_host", "cantbindtothis").build();
    NetworkService networkService = new NetworkService(Collections.emptyList());
    StubUserManager userManager = new StubUserManager();
    PostgresNetty psql = new PostgresNetty(settingsWithCustomBind, mock(SQLOperations.class), userManager, networkService, new AlwaysOKAuthentication(userManager), new NettyBootstrap(), mock(SslContextProvider.class));
    try {
        psql.doStart();
        fail("Should have failed due to custom hostname");
    } catch (BindPostgresException e) {
        // that's what we want
        assertThat(e.getCause(), instanceOf(UnknownHostException.class));
    } finally {
        psql.doStop();
        psql.close();
    }
}
Also used : AlwaysOKAuthentication(io.crate.auth.AlwaysOKAuthentication) NetworkService(org.elasticsearch.common.network.NetworkService) SslContextProvider(io.crate.protocols.ssl.SslContextProvider) SQLOperations(io.crate.action.sql.SQLOperations) Settings(org.elasticsearch.common.settings.Settings) StubUserManager(io.crate.user.StubUserManager) NettyBootstrap(io.crate.netty.NettyBootstrap) Test(org.junit.Test)

Example 3 with NettyBootstrap

use of io.crate.netty.NettyBootstrap in project crate by crate.

the class PostgresNettyPublishPortTest method testBindAndPublishAddressDefault.

@Test
public void testBindAndPublishAddressDefault() {
    // First check if binding to a local works
    NetworkService networkService = new NetworkService(Collections.emptyList());
    StubUserManager userManager = new StubUserManager();
    PostgresNetty psql = new PostgresNetty(Settings.EMPTY, mock(SQLOperations.class), userManager, networkService, new AlwaysOKAuthentication(userManager), new NettyBootstrap(), mock(SslContextProvider.class));
    try {
        psql.doStart();
    } finally {
        psql.doStop();
        psql.close();
    }
}
Also used : AlwaysOKAuthentication(io.crate.auth.AlwaysOKAuthentication) NetworkService(org.elasticsearch.common.network.NetworkService) SslContextProvider(io.crate.protocols.ssl.SslContextProvider) SQLOperations(io.crate.action.sql.SQLOperations) StubUserManager(io.crate.user.StubUserManager) NettyBootstrap(io.crate.netty.NettyBootstrap) Test(org.junit.Test)

Example 4 with NettyBootstrap

use of io.crate.netty.NettyBootstrap in project crate by crate.

the class CrateHttpsTransportTest method testPipelineConfiguration.

@Test
public void testPipelineConfiguration() throws Exception {
    Settings settings = Settings.builder().put(PATH_HOME_SETTING.getKey(), "/tmp").put(SslSettings.SSL_HTTP_ENABLED.getKey(), true).put(SslSettings.SSL_TRUSTSTORE_FILEPATH.getKey(), trustStoreFile.getAbsolutePath()).put(SslSettings.SSL_TRUSTSTORE_PASSWORD.getKey(), "keystorePassword").put(SslSettings.SSL_KEYSTORE_FILEPATH.getKey(), keyStoreFile.getAbsolutePath()).put(SslSettings.SSL_KEYSTORE_PASSWORD.getKey(), "keystorePassword").put(SslSettings.SSL_KEYSTORE_KEY_PASSWORD.getKey(), "keystorePassword").build();
    NetworkService networkService = new NetworkService(Collections.singletonList(new NetworkService.CustomNameResolver() {

        @Override
        public InetAddress[] resolveDefault() {
            return new InetAddress[] { InetAddresses.forString("127.0.0.1") };
        }

        @Override
        public InetAddress[] resolveIfPossible(String value) throws IOException {
            return new InetAddress[] { InetAddresses.forString("127.0.0.1") };
        }
    }));
    PipelineRegistry pipelineRegistry = new PipelineRegistry(settings);
    pipelineRegistry.setSslContextProvider(new SslContextProvider(settings));
    Netty4HttpServerTransport transport = new Netty4HttpServerTransport(settings, networkService, BigArrays.NON_RECYCLING_INSTANCE, mock(ThreadPool.class), NamedXContentRegistry.EMPTY, pipelineRegistry, new NettyBootstrap(), mock(NodeClient.class));
    EmbeddedChannel channel = new EmbeddedChannel();
    try {
        transport.start();
        Netty4HttpServerTransport.HttpChannelHandler httpChannelHandler = (Netty4HttpServerTransport.HttpChannelHandler) transport.configureServerChannelHandler();
        httpChannelHandler.initChannel(channel);
        assertThat(channel.pipeline().first(), instanceOf(SslHandler.class));
    } finally {
        transport.stop();
        transport.close();
        channel.releaseInbound();
        channel.close().awaitUninterruptibly();
    }
}
Also used : NodeClient(org.elasticsearch.client.node.NodeClient) ThreadPool(org.elasticsearch.threadpool.ThreadPool) Netty4HttpServerTransport(org.elasticsearch.http.netty4.Netty4HttpServerTransport) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) PipelineRegistry(io.crate.netty.channel.PipelineRegistry) SslHandler(io.netty.handler.ssl.SslHandler) NetworkService(org.elasticsearch.common.network.NetworkService) SslContextProvider(io.crate.protocols.ssl.SslContextProvider) InetAddress(java.net.InetAddress) Settings(org.elasticsearch.common.settings.Settings) SslSettings(io.crate.protocols.ssl.SslSettings) NettyBootstrap(io.crate.netty.NettyBootstrap) Test(org.junit.Test)

Example 5 with NettyBootstrap

use of io.crate.netty.NettyBootstrap in project crate by crate.

the class PostgresNettyPublishPortTest method testGeneralBindAndPublishAddressOverrideSetting.

@Test
public void testGeneralBindAndPublishAddressOverrideSetting() {
    // Check override for network.host
    Settings settingsWithCustomHost = Settings.builder().put("network.host", "cantbindtothis").build();
    NetworkService networkService = new NetworkService(Collections.emptyList());
    StubUserManager userManager = new StubUserManager();
    PostgresNetty psql = new PostgresNetty(settingsWithCustomHost, mock(SQLOperations.class), userManager, networkService, new AlwaysOKAuthentication(userManager), new NettyBootstrap(), mock(SslContextProvider.class));
    try {
        psql.doStart();
        fail("Should have failed due to custom hostname");
    } catch (BindPostgresException e) {
        // that's what we want
        assertThat(e.getCause(), instanceOf(UnknownHostException.class));
    } finally {
        psql.doStop();
        psql.close();
    }
}
Also used : AlwaysOKAuthentication(io.crate.auth.AlwaysOKAuthentication) NetworkService(org.elasticsearch.common.network.NetworkService) SslContextProvider(io.crate.protocols.ssl.SslContextProvider) SQLOperations(io.crate.action.sql.SQLOperations) Settings(org.elasticsearch.common.settings.Settings) StubUserManager(io.crate.user.StubUserManager) NettyBootstrap(io.crate.netty.NettyBootstrap) Test(org.junit.Test)

Aggregations

NettyBootstrap (io.crate.netty.NettyBootstrap)7 SslContextProvider (io.crate.protocols.ssl.SslContextProvider)7 NetworkService (org.elasticsearch.common.network.NetworkService)7 AlwaysOKAuthentication (io.crate.auth.AlwaysOKAuthentication)6 Settings (org.elasticsearch.common.settings.Settings)6 Test (org.junit.Test)6 SQLOperations (io.crate.action.sql.SQLOperations)4 StubUserManager (io.crate.user.StubUserManager)4 User (io.crate.user.User)3 ESTestCase (org.elasticsearch.test.ESTestCase)3 ThreadPool (org.elasticsearch.threadpool.ThreadPool)3 IOException (java.io.IOException)2 Collections (java.util.Collections)2 List (java.util.List)2 TimeUnit (java.util.concurrent.TimeUnit)2 Version (org.elasticsearch.Version)2 ActionListener (org.elasticsearch.action.ActionListener)2 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)2 NamedWriteableRegistry (org.elasticsearch.common.io.stream.NamedWriteableRegistry)2 PageCacheRecycler (org.elasticsearch.common.util.PageCacheRecycler)2