Skip to content

Commit

Permalink
Add test files (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
egecetin committed Sep 21, 2023
1 parent 4145366 commit 982a656
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 2 deletions.
1 change: 1 addition & 0 deletions Common++/header/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ namespace pcpp
PacketLogModuleSomeIpLayer, ///< SomeIpLayer module (Packet++)
PacketLogModuleSomeIpSdLayer, ///< SomeIpSdLayer module (Packet++)
PacketLogModuleWakeOnLanLayer, ///< WakeOnLanLayer module (Packet++)
PacketLogModuleSmtpLayer, ///< SmtpLayer module (Packet++)
PcapLogModuleWinPcapLiveDevice, ///< WinPcapLiveDevice module (Pcap++)
PcapLogModuleRemoteDevice, ///< WinPcapRemoteDevice module (Pcap++)
PcapLogModuleLiveDevice, ///< PcapLiveDevice module (Pcap++)
Expand Down
22 changes: 21 additions & 1 deletion Packet++/header/SmtpLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,27 @@ namespace pcpp
/// Send mail to terminal or to mailbox
SOML = ('S') | ('O' << 8) | ('M' << 16) | ('L' << 24),
/// Send mail to terminal and mailbox
SAML = ('S') | ('A' << 8) | ('M' << 16) | ('L' << 24)
SAML = ('S') | ('A' << 8) | ('M' << 16) | ('L' << 24),
///
TLS = ('T' << 8) | ('L' << 16) | ('S' << 24),
/// Start TLS handshake
STLS = ('S') | ('T' << 8) | ('L' << 16) | ('S' << 24),
/// Authenticate client and server
AUTH = ('A') | ('U' << 8) | ('T' << 16) | ('H' << 24),
/// Reverse the role of sender and receiver
ATRN = ('A') | ('T' << 8) | ('R' << 16) | ('N' << 24),
/// Submit mail contents
BDAT = ('B') | ('D' << 8) | ('A' << 16) | ('T' << 24),
/// Request to start SMTP queue processing
ETRN = ('E') | ('T' << 8) | ('R' << 16) | ('N' << 24),
/// Release status of the channel
XADR = ('X') | ('A' << 8) | ('D' << 16) | ('R' << 24),
/// Release status of the circuit checking facility
XCIR = ('X') | ('C' << 8) | ('I' << 16) | ('R' << 24),
/// Release status of the number of messages in channel queues
XSTA = ('X') | ('S' << 8) | ('T' << 16) | ('A' << 24),
/// Release status of whether a compiled configuration and character set are in use
XGEN = ('X') | ('G' << 8) | ('E' << 16) | ('N' << 24),
};

/** A constructor that creates the layer from an existing packet raw data
Expand Down
5 changes: 5 additions & 0 deletions Packet++/src/TcpLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "TpktLayer.h"
#include "FtpLayer.h"
#include "SomeIpLayer.h"
#include "SmtpLayer.h"
#include "PacketUtils.h"
#include "Logger.h"
#include <string.h>
Expand Down Expand Up @@ -380,6 +381,10 @@ void TcpLayer::parseNextLayer()
m_NextLayer = SomeIpLayer::parseSomeIpLayer(payload, payloadLen, this, m_Packet);
else if (TpktLayer::isDataValid(payload, payloadLen) && TpktLayer::isTpktPort(portSrc, portDst))
m_NextLayer = new TpktLayer(payload, payloadLen, this, m_Packet);
else if (SmtpLayer::isSmtpPort(portSrc) && SmtpLayer::isDataValid(payload, payloadLen))
m_NextLayer = new SmtpResponseLayer(payload, payloadLen, this, m_Packet);
else if (SmtpLayer::isSmtpPort(portDst) && SmtpLayer::isDataValid(payload, payloadLen))
m_NextLayer = new SmtpRequestLayer(payload, payloadLen, this, m_Packet);
else
m_NextLayer = new PayloadLayer(payload, payloadLen, this, m_Packet);
}
Expand Down
Binary file added Tests/Packet++Test/PacketExamples/Smtp.pcap
Binary file not shown.
1 change: 1 addition & 0 deletions Tests/Packet++Test/PacketExamples/smtpCommand.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
001f33d9816000e01c3c17c2080045000034252440008006f3c30a0a01044a358c9905be00197ec453baaeec62ee5018fec18968000041555448204c4f47494e0d0a
1 change: 1 addition & 0 deletions Tests/Packet++Test/PacketExamples/smtpIpv6.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
68a3c4f949f65475d0c90b8186dd60000000004706382607f8b0400c0c03000000000000001a20010470e5bfdead49572174e82c48870019f9c79563979d03a0883150180150e6870000323230206d782e676f6f676c652e636f6d2045534d5450206d313773693130353135393376636b2e32202d2067736d74700d0a
1 change: 1 addition & 0 deletions Tests/Packet++Test/PacketExamples/smtpMultiLine.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
00e01c3c17c2001f33d981600800456000dd21e24000320643fd4a358c990a0a0104001905beaeec61b07ec453b1501816d08a4400003232302d786339302e7765627369746577656c636f6d652e636f6d2045534d5450204578696d20342e3639202331204d6f6e2c203035204f637420323030392030313a30353a3534202d30353030200d0a3232302d576520646f206e6f7420617574686f72697a652074686520757365206f6620746869732073797374656d20746f207472616e73706f727420756e736f6c6963697465642c200d0a32323020616e642f6f722062756c6b20652d6d61696c2e0d0a
1 change: 1 addition & 0 deletions Tests/Packet++Test/PacketExamples/smtpResponse.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
00e01c3c17c2001f33d9816008004560003a21e540003206449d4a358c990a0a0104001905beaeec62ee7ec453c6501816d0634c00003333342056584e6c636d3568625755360d0a
7 changes: 6 additions & 1 deletion Tests/Packet++Test/TestDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,5 +241,10 @@ PTF_TEST_CASE(TpktLayerTest);
PTF_TEST_CASE(VrrpParsingTest);
PTF_TEST_CASE(VrrpCreateAndEditTest);

//Implemented in CotpTests.cpp
// Implemented in CotpTests.cpp
PTF_TEST_CASE(CotpLayerTest);

// Implemented in SmtpTests.cpp
PTF_TEST_CASE(SmtpParsingTests);
PTF_TEST_CASE(SmtpCreationTests);
PTF_TEST_CASE(SmtpEditTests);
54 changes: 54 additions & 0 deletions Tests/Packet++Test/Tests/SmtpTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,70 @@ PTF_TEST_CASE(SmtpParsingTests)
{
timeval time;
gettimeofday(&time, nullptr);

// Command
READ_FILE_AND_CREATE_PACKET(1, "PacketExamples/smtpCommand.dat");

pcpp::Packet smtpPacket1(&rawPacket1);
pcpp::SmtpRequestLayer *smtpLayer1 = smtpPacket1.getLayerOfType<pcpp::SmtpRequestLayer>();

PTF_ASSERT_NOT_NULL(smtpLayer1);
PTF_ASSERT_EQUAL(int(smtpLayer1->getCommand()), int(pcpp::SmtpRequestLayer::SmtpCommand::AUTH));
PTF_ASSERT_EQUAL(smtpLayer1->getCommandString(), "AUTH");
PTF_ASSERT_EQUAL(smtpLayer1->getCommandOption(), "LOGIN");
PTF_ASSERT_EQUAL(smtpLayer1->toString(), "SMTP Request: AUTH");
PTF_ASSERT_FALSE(smtpLayer1->isMultiLine());

// PTF_ASSERT_EQUAL(pcpp::SmtpRequestLayer::getCommandInfo(pcpp::SmtpRequestLayer::SmtpCommand::AUTH),
// "Authenticate client and server");
PTF_ASSERT_EQUAL(pcpp::SmtpRequestLayer::getCommandAsString(pcpp::SmtpRequestLayer::SmtpCommand::AUTH), "AUTH");

// Response packet
READ_FILE_AND_CREATE_PACKET(2, "PacketExamples/smtpResponse.dat");

pcpp::Packet smtpPacket2(&rawPacket2);
pcpp::SmtpResponseLayer *smtpLayer2 = smtpPacket2.getLayerOfType<pcpp::SmtpResponseLayer>();

PTF_ASSERT_NOT_NULL(smtpLayer2);
PTF_ASSERT_EQUAL(int(smtpLayer2->getStatusCode()), int(pcpp::SmtpResponseLayer::SmtpStatusCode::SERVER_CHALLENGE));
PTF_ASSERT_EQUAL(smtpLayer2->getStatusCodeString(), "334");
PTF_ASSERT_EQUAL(smtpLayer2->getStatusOption(), "VXNlcm5hbWU6");
PTF_ASSERT_EQUAL(smtpLayer2->toString(), "SMTP Response: 334");
PTF_ASSERT_FALSE(smtpLayer2->isMultiLine());

PTF_ASSERT_EQUAL(
pcpp::SmtpResponseLayer::getStatusCodeAsString(pcpp::SmtpResponseLayer::SmtpStatusCode::SERVER_CHALLENGE),
"Server challenge");

// Multiline

// IPv6
}

PTF_TEST_CASE(SmtpCreationTests)
{
timeval time;
gettimeofday(&time, nullptr);

// Request

// Response packet

// Multiline

// IPv6
}

PTF_TEST_CASE(SmtpEditTests)
{
timeval time;
gettimeofday(&time, nullptr);

// Request

// Response packet

// Multiline

// IPv6
}
4 changes: 4 additions & 0 deletions Tests/Packet++Test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,5 +316,9 @@ int main(int argc, char* argv[])

PTF_RUN_TEST(CotpLayerTest, "cotp");

PTF_RUN_TEST(SmtpParsingTests, "smtp");
PTF_RUN_TEST(SmtpCreationTests, "smtp");
PTF_RUN_TEST(SmtpEditTests, "smtp");

PTF_END_RUNNING_TESTS;
}

0 comments on commit 982a656

Please sign in to comment.