Search in sources :

Example 6 with EndpointContext

use of com.couchbase.client.core.endpoint.EndpointContext in project couchbase-jvm-clients by couchbase.

the class PasswordAuthenticatorTest method ldapCompatibleOnlyEnablesPlain.

@Test
void ldapCompatibleOnlyEnablesPlain() {
    PasswordAuthenticator authenticator = PasswordAuthenticator.ldapCompatible("user", "pass");
    EndpointContext ctx = mock(EndpointContext.class);
    when(ctx.environment()).thenReturn(ENV);
    EmbeddedChannel channel = new EmbeddedChannel();
    authenticator.authKeyValueConnection(ctx, channel.pipeline());
    SaslAuthenticationHandler handler = channel.pipeline().get(SaslAuthenticationHandler.class);
    assertEquals(EnumSet.of(SaslMechanism.PLAIN), handler.allowedMechanisms());
}
Also used : SaslAuthenticationHandler(com.couchbase.client.core.io.netty.kv.SaslAuthenticationHandler) EndpointContext(com.couchbase.client.core.endpoint.EndpointContext) EmbeddedChannel(com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.jupiter.api.Test)

Example 7 with EndpointContext

use of com.couchbase.client.core.endpoint.EndpointContext in project couchbase-jvm-clients by couchbase.

the class PasswordAuthenticatorTest method allowsToEnablePlainInAddition.

@Test
void allowsToEnablePlainInAddition() {
    PasswordAuthenticator authenticator = PasswordAuthenticator.builder().username("user").password("pass").enablePlainSaslMechanism().build();
    EndpointContext ctx = mock(EndpointContext.class);
    when(ctx.environment()).thenReturn(ENV);
    EmbeddedChannel channel = new EmbeddedChannel();
    authenticator.authKeyValueConnection(ctx, channel.pipeline());
    SaslAuthenticationHandler handler = channel.pipeline().get(SaslAuthenticationHandler.class);
    assertEquals(EnumSet.allOf(SaslMechanism.class), handler.allowedMechanisms());
}
Also used : SaslAuthenticationHandler(com.couchbase.client.core.io.netty.kv.SaslAuthenticationHandler) EndpointContext(com.couchbase.client.core.endpoint.EndpointContext) EmbeddedChannel(com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.jupiter.api.Test)

Example 8 with EndpointContext

use of com.couchbase.client.core.endpoint.EndpointContext in project couchbase-jvm-clients by couchbase.

the class PasswordAuthenticatorTest method shouldOnlyNegotiatePlainWhenTlsEnabled.

/**
 * Regression test for JVMCBC-890.
 */
@Test
void shouldOnlyNegotiatePlainWhenTlsEnabled() {
    PasswordAuthenticator authenticator = PasswordAuthenticator.create("user", "pass");
    CoreEnvironment tlsEnvironment = CoreEnvironment.builder().securityConfig(SecurityConfig.enableTls(true).trustManagerFactory(InsecureTrustManagerFactory.INSTANCE)).build();
    try {
        EndpointContext ctx = mock(EndpointContext.class);
        when(ctx.environment()).thenReturn(tlsEnvironment);
        EmbeddedChannel channel = new EmbeddedChannel();
        authenticator.authKeyValueConnection(ctx, channel.pipeline());
        SaslAuthenticationHandler handler = channel.pipeline().get(SaslAuthenticationHandler.class);
        assertEquals(EnumSet.of(SaslMechanism.PLAIN), handler.allowedMechanisms());
    } finally {
        tlsEnvironment.shutdown();
    }
}
Also used : SaslAuthenticationHandler(com.couchbase.client.core.io.netty.kv.SaslAuthenticationHandler) EndpointContext(com.couchbase.client.core.endpoint.EndpointContext) EmbeddedChannel(com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.jupiter.api.Test)

Example 9 with EndpointContext

use of com.couchbase.client.core.endpoint.EndpointContext in project couchbase-jvm-clients by couchbase.

the class KeyValueChannelIntegrationTest method beforeAll.

@BeforeAll
static void beforeAll() {
    TestNodeConfig node = config().nodes().get(0);
    env = environment().eventBus(eventBus).build();
    Core core = Core.create(env, authenticator(), seedNodes());
    endpointContext = new EndpointContext(core.context(), new HostAndPort(node.hostname(), node.ports().get(Services.KV)), null, ServiceType.KV, Optional.empty(), Optional.of(config().bucketname()), Optional.empty());
    eventLoopGroup = new NioEventLoopGroup(1);
}
Also used : HostAndPort(com.couchbase.client.core.util.HostAndPort) EndpointContext(com.couchbase.client.core.endpoint.EndpointContext) TestNodeConfig(com.couchbase.client.test.TestNodeConfig) NioEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.nio.NioEventLoopGroup) Core(com.couchbase.client.core.Core) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 10 with EndpointContext

use of com.couchbase.client.core.endpoint.EndpointContext in project couchbase-jvm-clients by couchbase.

the class MemcacheProtocolVerificationHandlerTest method shouldVerifyCorrectResponses.

/**
 * Verifies good responses are passed through.
 *
 * @param inputHolder the good input packets.
 */
@ParameterizedTest(name = "{0}")
@MethodSource
void shouldVerifyCorrectResponses(final InputHolder inputHolder) {
    EndpointContext ctx = mock(EndpointContext.class);
    final EmbeddedChannel channel = new EmbeddedChannel(new MemcacheProtocolVerificationHandler(ctx));
    try {
        channel.writeInbound(inputHolder.input);
        ByteBuf written = channel.readInbound();
        assertEquals(inputHolder.input, written);
    } finally {
        channel.finishAndReleaseAll();
    }
}
Also used : EndpointContext(com.couchbase.client.core.endpoint.EndpointContext) EmbeddedChannel(com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel) ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

EndpointContext (com.couchbase.client.core.endpoint.EndpointContext)23 EmbeddedChannel (com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel)15 Core (com.couchbase.client.core.Core)13 CoreContext (com.couchbase.client.core.CoreContext)12 CoreEnvironment (com.couchbase.client.core.env.CoreEnvironment)11 HostAndPort (com.couchbase.client.core.util.HostAndPort)11 Test (org.junit.jupiter.api.Test)10 BaseEndpoint (com.couchbase.client.core.endpoint.BaseEndpoint)6 BeforeAll (org.junit.jupiter.api.BeforeAll)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 SimpleEventBus (com.couchbase.client.core.cnc.SimpleEventBus)5 ByteBuf (com.couchbase.client.core.deps.io.netty.buffer.ByteBuf)5 DefaultHttpResponse (com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultHttpResponse)5 DefaultLastHttpContent (com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultLastHttpContent)5 HttpResponse (com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpResponse)5 Authenticator (com.couchbase.client.core.env.Authenticator)5 TimeoutConfig (com.couchbase.client.core.env.TimeoutConfig)5 DefaultHttpContent (com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultHttpContent)4 HttpContent (com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpContent)4 Unpooled (com.couchbase.client.core.deps.io.netty.buffer.Unpooled)3