Search in sources :

Example 1 with ClientProtocolBuffer

use of com.hazelcast.client.impl.protocol.util.ClientProtocolBuffer in project hazelcast by hazelcast.

the class RawProtocolAuthenticationTest method testAuthenticateWithUsernameAndPassword.

@Test
public void testAuthenticateWithUsernameAndPassword() throws IOException, InterruptedException {
    final ByteBuffer initData = ByteBuffer.wrap("CB2".getBytes());
    channel.write(initData);
    String username = GroupConfig.DEFAULT_GROUP_NAME;
    String pass = GroupConfig.DEFAULT_GROUP_PASSWORD;
    final ClientMessage authMessage = ClientAuthenticationCodec.encodeRequest(username, pass, null, null, true, ClientTypes.JAVA, InternalSerializationService.VERSION_1, BuildInfoProvider.BUILD_INFO.getVersion());
    authMessage.setCorrelationId(1).addFlag(ClientMessage.BEGIN_AND_END_FLAGS);
    final ClientProtocolBuffer byteBuffer = authMessage.buffer();
    channel.write(ByteBuffer.wrap(byteBuffer.byteArray(), 0, authMessage.getFrameLength()));
    ClientMessage clientMessage = readMessageFromChannel();
    assertTrue(clientMessage.isComplete());
    ClientMessage cmResult = ClientMessage.createForDecode(clientMessage.buffer(), 0);
    ClientAuthenticationCodec.ResponseParameters resultParameters = ClientAuthenticationCodec.decodeResponse(cmResult);
    assertEquals(cmResult.getCorrelationId(), 1);
    assertEquals(resultParameters.status, 0);
    assertEquals(resultParameters.serializationVersion, 1);
    assertEquals(resultParameters.ownerUuid, server.getCluster().getLocalMember().getUuid());
    assertNotNull(UUID.fromString(resultParameters.uuid));
    assertEquals(server.getCluster().getLocalMember().getAddress(), resultParameters.address);
}
Also used : ClientProtocolBuffer(com.hazelcast.client.impl.protocol.util.ClientProtocolBuffer) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientAuthenticationCodec(com.hazelcast.client.impl.protocol.codec.ClientAuthenticationCodec) ByteBuffer(java.nio.ByteBuffer) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with ClientProtocolBuffer

use of com.hazelcast.client.impl.protocol.util.ClientProtocolBuffer in project hazelcast by hazelcast.

the class RawProtocolAuthenticationTest method testAuthenticateWithUsernameAndPassword_with_Invalid_SerializationVersion.

@Test
public void testAuthenticateWithUsernameAndPassword_with_Invalid_SerializationVersion() throws IOException, InterruptedException {
    final ByteBuffer initData = ByteBuffer.wrap("CB2".getBytes());
    channel.write(initData);
    String username = GroupConfig.DEFAULT_GROUP_NAME;
    String pass = GroupConfig.DEFAULT_GROUP_PASSWORD;
    final ClientMessage authMessage = ClientAuthenticationCodec.encodeRequest(username, pass, null, null, true, ClientTypes.JAVA, (byte) 0, BuildInfoProvider.BUILD_INFO.getVersion());
    authMessage.setCorrelationId(1).addFlag(ClientMessage.BEGIN_AND_END_FLAGS);
    final ClientProtocolBuffer byteBuffer = authMessage.buffer();
    channel.write(ByteBuffer.wrap(byteBuffer.byteArray(), 0, authMessage.getFrameLength()));
    ClientMessage clientMessage = readMessageFromChannel();
    assertTrue(clientMessage.isComplete());
    ClientMessage cmResult = ClientMessage.createForDecode(clientMessage.buffer(), 0);
    ClientAuthenticationCodec.ResponseParameters resultParameters = ClientAuthenticationCodec.decodeResponse(cmResult);
    assertEquals(cmResult.getCorrelationId(), 1);
    assertEquals(resultParameters.status, 2);
    assertEquals(resultParameters.serializationVersion, 1);
    assertNull(resultParameters.ownerUuid);
    assertNull(resultParameters.uuid);
    assertNull(resultParameters.address);
}
Also used : ClientProtocolBuffer(com.hazelcast.client.impl.protocol.util.ClientProtocolBuffer) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientAuthenticationCodec(com.hazelcast.client.impl.protocol.codec.ClientAuthenticationCodec) ByteBuffer(java.nio.ByteBuffer) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with ClientProtocolBuffer

use of com.hazelcast.client.impl.protocol.util.ClientProtocolBuffer in project hazelcast by hazelcast.

the class RawProtocolAuthenticationTest method testAuthenticateWithUsernameAndPassword_with_Invalid_MessageSize.

@Test
public void testAuthenticateWithUsernameAndPassword_with_Invalid_MessageSize() throws IOException, InterruptedException {
    final ByteBuffer initData = ByteBuffer.wrap("CB2".getBytes());
    channel.write(initData);
    String username = GroupConfig.DEFAULT_GROUP_NAME;
    String pass = GroupConfig.DEFAULT_GROUP_PASSWORD;
    final ClientMessage authMessage = ClientAuthenticationCodec.encodeRequest(username, pass, null, null, true, ClientTypes.JAVA, (byte) 0, BuildInfoProvider.BUILD_INFO.getVersion());
    authMessage.setCorrelationId(1).addFlag(ClientMessage.BEGIN_AND_END_FLAGS);
    //set invalid message size
    authMessage.setFrameLength(ClientMessage.HEADER_SIZE - 1);
    final ClientProtocolBuffer byteBuffer = authMessage.buffer();
    channel.write(ByteBuffer.wrap(byteBuffer.byteArray(), 0, authMessage.getFrameLength()));
    ClientMessage clientMessage = readMessageFromChannel();
    assertFalse(clientMessage.isComplete());
}
Also used : ClientProtocolBuffer(com.hazelcast.client.impl.protocol.util.ClientProtocolBuffer) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ByteBuffer(java.nio.ByteBuffer) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with ClientProtocolBuffer

use of com.hazelcast.client.impl.protocol.util.ClientProtocolBuffer in project hazelcast by hazelcast.

the class ClientMessageTest method testUnsignedFields.

@Test
public void testUnsignedFields() throws IOException {
    ClientProtocolBuffer buffer = new SafeBuffer(new byte[22]);
    ClientMessage cmEncode = ClientMessage.createForEncode(buffer, 0);
    cmEncode.setVersion((short) (Byte.MAX_VALUE + 10));
    cmEncode.setMessageType(Short.MAX_VALUE + 10);
    cmEncode.setDataOffset((int) Short.MAX_VALUE + 10);
    cmEncode.setCorrelationId(Integer.MAX_VALUE + 10);
    ClientMessage cmDecode = ClientMessage.createForDecode(buffer, 0);
    assertEquals(Byte.MAX_VALUE + 10, cmDecode.getVersion());
    assertEquals(Short.MAX_VALUE + 10, cmDecode.getMessageType());
    assertEquals((int) Short.MAX_VALUE + 10, cmDecode.getDataOffset());
}
Also used : ClientProtocolBuffer(com.hazelcast.client.impl.protocol.util.ClientProtocolBuffer) SafeBuffer(com.hazelcast.client.impl.protocol.util.SafeBuffer) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with ClientProtocolBuffer

use of com.hazelcast.client.impl.protocol.util.ClientProtocolBuffer in project hazelcast by hazelcast.

the class RawProtocolAuthenticationTest method testAuthenticateWithUsernameAndPassword_with_Invalid_Credentials.

@Test
public void testAuthenticateWithUsernameAndPassword_with_Invalid_Credentials() throws IOException, InterruptedException {
    final ByteBuffer initData = ByteBuffer.wrap("CB2".getBytes());
    channel.write(initData);
    String username = GroupConfig.DEFAULT_GROUP_NAME;
    String pass = "TheInvalidPassword";
    final ClientMessage authMessage = ClientAuthenticationCodec.encodeRequest(username, pass, null, null, true, ClientTypes.JAVA, InternalSerializationService.VERSION_1, BuildInfoProvider.BUILD_INFO.getVersion());
    authMessage.setCorrelationId(1).addFlag(ClientMessage.BEGIN_AND_END_FLAGS);
    final ClientProtocolBuffer byteBuffer = authMessage.buffer();
    channel.write(ByteBuffer.wrap(byteBuffer.byteArray(), 0, authMessage.getFrameLength()));
    ClientMessage clientMessage = readMessageFromChannel();
    assertTrue(clientMessage.isComplete());
    ClientMessage cmResult = ClientMessage.createForDecode(clientMessage.buffer(), 0);
    ClientAuthenticationCodec.ResponseParameters resultParameters = ClientAuthenticationCodec.decodeResponse(cmResult);
    assertEquals(cmResult.getCorrelationId(), 1);
    assertEquals(resultParameters.status, 1);
    assertEquals(resultParameters.serializationVersion, 1);
    assertNull(resultParameters.ownerUuid);
    assertNull(resultParameters.uuid);
    assertNull(resultParameters.address);
}
Also used : ClientProtocolBuffer(com.hazelcast.client.impl.protocol.util.ClientProtocolBuffer) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientAuthenticationCodec(com.hazelcast.client.impl.protocol.codec.ClientAuthenticationCodec) ByteBuffer(java.nio.ByteBuffer) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)5 ClientProtocolBuffer (com.hazelcast.client.impl.protocol.util.ClientProtocolBuffer)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 Test (org.junit.Test)5 ByteBuffer (java.nio.ByteBuffer)4 ClientAuthenticationCodec (com.hazelcast.client.impl.protocol.codec.ClientAuthenticationCodec)3 SafeBuffer (com.hazelcast.client.impl.protocol.util.SafeBuffer)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1