srdusr
aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_smtp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_smtp.cpp')
-rw-r--r--tests/test_smtp.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/test_smtp.cpp b/tests/test_smtp.cpp
new file mode 100644
index 0000000..610ed4e
--- /dev/null
+++ b/tests/test_smtp.cpp
@@ -0,0 +1,51 @@
+#include <doctest/doctest.h>
+
+#include <vector>
+
+#include "packeteer/l7/smtp.hpp"
+
+using namespace packeteer::net;
+
+namespace {
+
+std::vector<unsigned char> to_bytes(const std::string& s) {
+ return std::vector<unsigned char>(s.begin(), s.end());
+}
+
+} // namespace
+
+TEST_CASE("parse_smtp decodes a greeting response") {
+ auto msg = parse_smtp(to_bytes("220 mail.example.com ESMTP\r\n"));
+ REQUIRE(msg.has_value());
+ CHECK(msg->is_response);
+ CHECK(msg->command_or_code == "220");
+ CHECK(msg->argument == "mail.example.com ESMTP");
+}
+
+TEST_CASE("parse_smtp decodes a MAIL FROM command") {
+ auto msg = parse_smtp(to_bytes("MAIL FROM:<[email protected]>\r\n"));
+ REQUIRE(msg.has_value());
+ CHECK_FALSE(msg->is_response);
+ CHECK(msg->command_or_code == "MAIL");
+ CHECK(msg->argument == "FROM:<[email protected]>");
+}
+
+TEST_CASE("parse_smtp decodes a multi-line response's first line, dash included") {
+ auto msg = parse_smtp(to_bytes("250-mail.example.com Hello\r\n250-PIPELINING\r\n"));
+ REQUIRE(msg.has_value());
+ CHECK(msg->command_or_code == "250");
+ CHECK(msg->argument == "mail.example.com Hello");
+}
+
+TEST_CASE("parse_smtp rejects an unrecognized command word") {
+ CHECK_FALSE(parse_smtp(to_bytes("BOGUS foo\r\n")).has_value());
+}
+
+TEST_CASE("SmtpDissector claims port 25") {
+ SmtpDissector dissector;
+ CHECK(dissector.port() == kSmtpPort);
+
+ auto summary = dissector.summarize(to_bytes("EHLO client.example.com\r\n"));
+ REQUIRE(summary.has_value());
+ CHECK(*summary == "SMTP EHLO client.example.com");
+}