#include #include #include "packeteer/l7/smtp.hpp" using namespace packeteer::net; namespace { std::vector to_bytes(const std::string& s) { return std::vector(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:\r\n")); REQUIRE(msg.has_value()); CHECK_FALSE(msg->is_response); CHECK(msg->command_or_code == "MAIL"); CHECK(msg->argument == "FROM:"); } 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"); }