mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-03 04:52:10 +00:00
add gtest for MySQL Protocol handshake
This commit is contained in:
parent
f5a53dd270
commit
b9e2c0d72c
@ -517,11 +517,9 @@ public:
|
||||
buffer.ignore(10);
|
||||
if (capability_flags & MySQLProtocol::CLIENT_SECURE_CONNECTION)
|
||||
{
|
||||
UInt8 part2_length = (auth_plugin_data_length - AUTH_PLUGIN_DATA_PART_1_LENGTH) > 13
|
||||
? 13
|
||||
: (auth_plugin_data_length - AUTH_PLUGIN_DATA_PART_1_LENGTH);
|
||||
auth_plugin_data.resize(part2_length + AUTH_PLUGIN_DATA_PART_1_LENGTH - 1);
|
||||
buffer.readStrict(auth_plugin_data.data() + AUTH_PLUGIN_DATA_PART_1_LENGTH, part2_length - 1);
|
||||
UInt8 part2_length = (SCRAMBLE_LENGTH - AUTH_PLUGIN_DATA_PART_1_LENGTH);
|
||||
auth_plugin_data.resize(SCRAMBLE_LENGTH);
|
||||
buffer.readStrict(auth_plugin_data.data() + AUTH_PLUGIN_DATA_PART_1_LENGTH, part2_length);
|
||||
buffer.ignore(1);
|
||||
}
|
||||
|
||||
@ -958,7 +956,7 @@ public:
|
||||
packetType = PACKET_EOF;
|
||||
eof.readPayloadImpl(payload);
|
||||
break;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
ResponsePacketType getType() { return packetType; }
|
||||
|
31
src/Core/tests/gtest_MySQLProtocol.cpp
Normal file
31
src/Core/tests/gtest_MySQLProtocol.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
#include <string>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <Core/MySQLProtocol.h>
|
||||
#include <IO/ReadBufferFromString.h>
|
||||
#include <IO/WriteBufferFromString.h>
|
||||
|
||||
using namespace DB;
|
||||
using namespace MySQLProtocol;
|
||||
|
||||
TEST(MySQLProtocol, Handshake)
|
||||
{
|
||||
UInt32 server_capability_flags = CLIENT_PROTOCOL_41 | CLIENT_SECURE_CONNECTION | CLIENT_PLUGIN_AUTH
|
||||
| CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA | CLIENT_CONNECT_WITH_DB | CLIENT_DEPRECATE_EOF;
|
||||
|
||||
std::string s;
|
||||
WriteBufferFromString out(s);
|
||||
Handshake server_handshake(server_capability_flags, 0, "ClickHouse", "mysql_native_password", "aaaaaaaaaaaaaaaaaaaaa");
|
||||
server_handshake.writePayloadImpl(out);
|
||||
|
||||
ReadBufferFromString in(s);
|
||||
Handshake client_handshake;
|
||||
client_handshake.readPayloadImpl(in);
|
||||
|
||||
EXPECT_EQ(server_handshake.capability_flags, client_handshake.capability_flags);
|
||||
EXPECT_EQ(server_handshake.status_flags, client_handshake.status_flags);
|
||||
EXPECT_EQ(server_handshake.server_version, client_handshake.server_version);
|
||||
EXPECT_EQ(server_handshake.protocol_version, client_handshake.protocol_version);
|
||||
EXPECT_EQ(server_handshake.auth_plugin_data.substr(0, 20), client_handshake.auth_plugin_data);
|
||||
EXPECT_EQ(server_handshake.auth_plugin_name, client_handshake.auth_plugin_name);
|
||||
}
|
Loading…
Reference in New Issue
Block a user