Search in sources :

Example 11 with AuthenticationFailureException

use of com.couchbase.client.core.error.AuthenticationFailureException in project couchbase-jvm-clients by couchbase.

the class KeyValueChannelIntegrationTest method assertAuthenticationFailure.

/**
 * Helper method to assert authentication failure in different scenarios.
 */
private void assertAuthenticationFailure(final Bootstrap bootstrap, final String msg) throws Exception {
    CountDownLatch latch = new CountDownLatch(1);
    bootstrap.connect().addListener((ChannelFutureListener) future -> {
        try {
            assertFalse(future.isSuccess());
            Throwable ex = future.cause();
            assertTrue(ex instanceof AuthenticationFailureException);
            assertEquals(msg, ex.getMessage());
        } finally {
            latch.countDown();
        }
    });
    latch.await();
}
Also used : ChannelFutureListener(com.couchbase.client.core.deps.io.netty.channel.ChannelFutureListener) KeyValueEndpoint(com.couchbase.client.core.endpoint.KeyValueEndpoint) AuthenticationFailureException(com.couchbase.client.core.error.AuthenticationFailureException) ClusterType(com.couchbase.client.test.ClusterType) NoopRequest(com.couchbase.client.core.msg.kv.NoopRequest) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) AfterAll(org.junit.jupiter.api.AfterAll) PasswordAuthenticator(com.couchbase.client.core.env.PasswordAuthenticator) SocketChannel(com.couchbase.client.core.deps.io.netty.channel.socket.SocketChannel) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) BeforeAll(org.junit.jupiter.api.BeforeAll) ServiceType(com.couchbase.client.core.service.ServiceType) Duration(java.time.Duration) EndpointContext(com.couchbase.client.core.endpoint.EndpointContext) NioEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.nio.NioEventLoopGroup) Channel(com.couchbase.client.core.deps.io.netty.channel.Channel) ChannelInitializer(com.couchbase.client.core.deps.io.netty.channel.ChannelInitializer) Assert.assertTrue(org.junit.Assert.assertTrue) CoreEnvironment(com.couchbase.client.core.env.CoreEnvironment) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) Services(com.couchbase.client.test.Services) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) SimpleEventBus(com.couchbase.client.core.cnc.SimpleEventBus) CountDownLatch(java.util.concurrent.CountDownLatch) NioSocketChannel(com.couchbase.client.core.deps.io.netty.channel.socket.nio.NioSocketChannel) NoopResponse(com.couchbase.client.core.msg.kv.NoopResponse) Optional(java.util.Optional) CollectionIdentifier(com.couchbase.client.core.io.CollectionIdentifier) Core(com.couchbase.client.core.Core) TestNodeConfig(com.couchbase.client.test.TestNodeConfig) HostAndPort(com.couchbase.client.core.util.HostAndPort) Assert.assertEquals(org.junit.Assert.assertEquals) Bootstrap(com.couchbase.client.core.deps.io.netty.bootstrap.Bootstrap) AuthenticationFailureException(com.couchbase.client.core.error.AuthenticationFailureException) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 12 with AuthenticationFailureException

use of com.couchbase.client.core.error.AuthenticationFailureException in project couchbase-jvm-clients by couchbase.

the class SaslListMechanismsHandlerTest method failConnectIfStatusNotSuccess.

@Test
void failConnectIfStatusNotSuccess() {
    SaslListMechanismsHandler handler = new SaslListMechanismsHandler(endpointContext);
    channel.pipeline().addLast(handler);
    assertEquals(handler, channel.pipeline().get(SaslListMechanismsHandler.class));
    ChannelFuture connectFuture = channel.connect(new InetSocketAddress("1.2.3.4", 1234));
    assertFalse(connectFuture.isDone());
    channel.pipeline().fireChannelActive();
    channel.runPendingTasks();
    ByteBuf writtenRequest = channel.readOutbound();
    verifyRequest(writtenRequest, MemcacheProtocol.Opcode.SASL_LIST_MECHS.opcode(), false, false, false);
    assertNotNull(channel.pipeline().get(SaslListMechanismsHandler.class));
    ReferenceCountUtil.release(writtenRequest);
    ByteBuf response = decodeHexDump(readResource("error_sasl_list_mechs_response.txt", ErrorMapLoadingHandlerTest.class));
    channel.writeInbound(response);
    channel.runPendingTasks();
    assertFalse(connectFuture.isSuccess());
    AuthenticationFailureException cause = (AuthenticationFailureException) connectFuture.cause();
    assertTrue(cause.getMessage().contains("Received non-success status from server"));
}
Also used : ChannelFuture(com.couchbase.client.core.deps.io.netty.channel.ChannelFuture) InetSocketAddress(java.net.InetSocketAddress) AuthenticationFailureException(com.couchbase.client.core.error.AuthenticationFailureException) ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Aggregations

AuthenticationFailureException (com.couchbase.client.core.error.AuthenticationFailureException)12 CouchbaseException (com.couchbase.client.core.error.CouchbaseException)5 ByteBuf (com.couchbase.client.core.deps.io.netty.buffer.ByteBuf)4 Duration (java.time.Duration)4 IndexNotFoundException (com.couchbase.client.core.error.IndexNotFoundException)3 InternalServerFailureException (com.couchbase.client.core.error.InternalServerFailureException)3 KeyValueIoErrorContext (com.couchbase.client.core.error.context.KeyValueIoErrorContext)3 ChannelFuture (com.couchbase.client.core.deps.io.netty.channel.ChannelFuture)2 ErrorCodeAndMessage (com.couchbase.client.core.error.ErrorCodeAndMessage)2 IndexExistsException (com.couchbase.client.core.error.IndexExistsException)2 ParsingFailureException (com.couchbase.client.core.error.ParsingFailureException)2 QuotaLimitedException (com.couchbase.client.core.error.QuotaLimitedException)2 RateLimitedException (com.couchbase.client.core.error.RateLimitedException)2 UnambiguousTimeoutException (com.couchbase.client.core.error.UnambiguousTimeoutException)2 InetSocketAddress (java.net.InetSocketAddress)2 TimeoutException (java.util.concurrent.TimeoutException)2 Test (org.junit.jupiter.api.Test)2 Core (com.couchbase.client.core.Core)1 SimpleEventBus (com.couchbase.client.core.cnc.SimpleEventBus)1 SaslAuthenticationFailedEvent (com.couchbase.client.core.cnc.events.io.SaslAuthenticationFailedEvent)1