Skip to content

Commit 5190a31

Browse files
committed
Add more tests
1 parent 697ba98 commit 5190a31

1 file changed

Lines changed: 53 additions & 2 deletions

File tree

Tests/Packet++Test/Tests/MySqlTests.cpp

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
#include "../Utils/TestUtils.h"
33
#include "Packet.h"
44
#include "MySqlLayer.h"
5-
#include "NullLoopbackLayer.h"
65
#include "TcpLayer.h"
76

8-
#include <algorithm>
97
#include <memory>
108
#include <sstream>
119
#include <vector>
@@ -49,6 +47,10 @@ PTF_TEST_CASE(MySqlLayerParsingTest)
4947
}
5048

5149
PTF_ASSERT_EQUAL(mySqlLayer->toString(), "MySQL Server Layer, 10 message(s)");
50+
51+
auto eofMessage = mySqlLayer->getMySqlMessage(pcpp::MySqlMessageType::Server_EOF);
52+
PTF_ASSERT_EQUAL(eofMessage->getMessageType(), pcpp::MySqlMessageType::Server_EOF, enum);
53+
PTF_ASSERT_NULL(mySqlLayer->getMySqlMessage(pcpp::MySqlMessageType::Server_Error));
5254
}
5355

5456
// Client message
@@ -575,6 +577,23 @@ PTF_TEST_CASE(MySqlMessageParsingTest)
575577
"COM_SET_OPTION");
576578
}
577579

580+
// Client - COM_STMT_FETCH (0x1C)
581+
{
582+
std::vector<uint8_t> stmtFetchData = {
583+
0x09, 0x00, 0x00, // Packet length (9)
584+
0x00, // Packet number (0)
585+
0x1C, // COM_STMT_FETCH type
586+
0x01, 0x00, 0x00, 0x00, // Statement ID (1)
587+
0x64, 0x00, 0x00, 0x00 // Cursor rows (100)
588+
};
589+
auto message = pcpp::MySqlMessage::parseMySqlMessage(stmtFetchData.data(), stmtFetchData.size(),
590+
pcpp::MySqlMessageOrigin::Client);
591+
ASSERT_MYSQL_MESSAGE(message, pcpp::MySqlMessageType::Client_StmtFetch, pcpp::MySqlMessageOrigin::Client,
592+
"COM_STMT_FETCH");
593+
PTF_ASSERT_EQUAL(message->getMessageLength(), 8);
594+
PTF_ASSERT_EQUAL(message->getTotalMessageLength(), 13);
595+
}
596+
578597
// Client - COM_DAEMON (0x1D)
579598
{
580599
std::vector<uint8_t> daemonData = {
@@ -626,6 +645,38 @@ PTF_TEST_CASE(MySqlMessageParsingTest)
626645
ASSERT_MYSQL_MESSAGE(message, pcpp::MySqlMessageType::Client_Clone, pcpp::MySqlMessageOrigin::Client,
627646
"COM_CLONE");
628647
}
648+
649+
// Client - HandshakeResponse (packet number = 1)
650+
{
651+
std::vector<uint8_t> handshakeResponseData = {
652+
0xb4, 0x00, 0x00, // Packet length (180)
653+
0x01, // Packet number (1) - indicates handshake response
654+
0x85, 0xa6, // Capability flags
655+
0xff, 0x19, // Extended client capabilities
656+
0x00, 0x00, 0x00, 0x01, // MAX packet (16777216)
657+
0xff, // Collation
658+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Unused
659+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x72,
660+
0x6f, 0x6f, 0x74, 0x00, // Username ("root")
661+
0x01, 0x00, 0x63, 0x61, 0x63, 0x68, 0x69, 0x6e, // Client auth plugin ("caching_sha2_password")
662+
0x67, 0x5f, 0x73, 0x68, 0x61, 0x32, 0x5f, 0x70, // Connection attributes
663+
0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x00, 0x76, 0x03, 0x5f, 0x6f, 0x73, 0x09, 0x6d, 0x61,
664+
0x63, 0x6f, 0x73, 0x31, 0x34, 0x2e, 0x38, 0x09, 0x5f, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72,
665+
0x6d, 0x06, 0x78, 0x38, 0x36, 0x5f, 0x36, 0x34, 0x0f, 0x5f, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74,
666+
0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x05, 0x39, 0x2e, 0x36, 0x2e, 0x30, 0x0c, 0x5f,
667+
0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x08, 0x6c, 0x69, 0x62, 0x6d,
668+
0x79, 0x73, 0x71, 0x6c, 0x04, 0x5f, 0x70, 0x69, 0x64, 0x05, 0x36, 0x38, 0x32, 0x32, 0x36, 0x07,
669+
0x6f, 0x73, 0x5f, 0x75, 0x73, 0x65, 0x72, 0x04, 0x65, 0x6c, 0x61, 0x64, 0x0c, 0x70, 0x72, 0x6f,
670+
0x67, 0x72, 0x61, 0x6d, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x05, 0x6d, 0x79, 0x73, 0x71, 0x6c
671+
};
672+
auto message = pcpp::MySqlMessage::parseMySqlMessage(handshakeResponseData.data(), handshakeResponseData.size(),
673+
pcpp::MySqlMessageOrigin::Client);
674+
ASSERT_MYSQL_MESSAGE(message, pcpp::MySqlMessageType::Client_HandshakeResponse,
675+
pcpp::MySqlMessageOrigin::Client, "HandshakeResponse");
676+
PTF_ASSERT_EQUAL(message->getMessageLength(), 180);
677+
PTF_ASSERT_EQUAL(message->getTotalMessageLength(), 184);
678+
PTF_ASSERT_EQUAL(message->getPacketNumber(), 1);
679+
}
629680
}
630681

631682
PTF_TEST_CASE(MySqlInvalidDataTest)

0 commit comments

Comments
 (0)