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);
}
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);
}
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());
}
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());
}
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);
}
Aggregations