Search in sources :

Example 16 with CommandError

use of org.apache.pulsar.common.api.proto.PulsarApi.CommandError in project incubator-pulsar by apache.

the class ServerCnxTest method testConnectCommandWithAuthenticationNegative.

@Test(timeOut = 30000)
public void testConnectCommandWithAuthenticationNegative() throws Exception {
    AuthenticationException e = new AuthenticationException();
    AuthenticationService authenticationService = mock(AuthenticationService.class);
    doReturn(authenticationService).when(brokerService).getAuthenticationService();
    doThrow(e).when(authenticationService).authenticate(new AuthenticationDataCommand(Mockito.anyString()), Mockito.anyString());
    doReturn(true).when(brokerService).isAuthenticationEnabled();
    resetChannel();
    assertTrue(channel.isActive());
    assertEquals(serverCnx.getState(), State.Start);
    // test server response to CONNECT
    ByteBuf clientCommand = Commands.newConnect("none", "", null);
    channel.writeInbound(clientCommand);
    assertEquals(serverCnx.getState(), State.Start);
    assertTrue(getResponse() instanceof CommandError);
    channel.finish();
}
Also used : AuthenticationDataCommand(org.apache.pulsar.broker.authentication.AuthenticationDataCommand) AuthenticationException(javax.naming.AuthenticationException) CommandError(org.apache.pulsar.common.api.proto.PulsarApi.CommandError) ByteBuf(io.netty.buffer.ByteBuf) AuthenticationService(org.apache.pulsar.broker.authentication.AuthenticationService) Test(org.testng.annotations.Test)

Aggregations

CommandError (org.apache.pulsar.common.api.proto.PulsarApi.CommandError)16 ByteBuf (io.netty.buffer.ByteBuf)15 Test (org.testng.annotations.Test)14 ByteString (com.google.protobuf.ByteString)7 Matchers.anyObject (org.mockito.Matchers.anyObject)7 PersistentTopic (org.apache.pulsar.broker.service.persistent.PersistentTopic)6 AuthorizationService (org.apache.pulsar.broker.authorization.AuthorizationService)4 CommandProducerSuccess (org.apache.pulsar.common.api.proto.PulsarApi.CommandProducerSuccess)3 Field (java.lang.reflect.Field)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 PulsarAuthorizationProvider (org.apache.pulsar.broker.authorization.PulsarAuthorizationProvider)2 CommandSuccess (org.apache.pulsar.common.api.proto.PulsarApi.CommandSuccess)2 TopicName (org.apache.pulsar.common.naming.TopicName)2 Policies (org.apache.pulsar.common.policies.data.Policies)2 AuthenticationException (javax.naming.AuthenticationException)1 AuthenticationDataCommand (org.apache.pulsar.broker.authentication.AuthenticationDataCommand)1 AuthenticationService (org.apache.pulsar.broker.authentication.AuthenticationService)1 ConfigurationCacheService (org.apache.pulsar.broker.cache.ConfigurationCacheService)1 AuthAction (org.apache.pulsar.common.policies.data.AuthAction)1