#include #include #include "packeteer/l7/ftp.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_ftp decodes a greeting response") { auto msg = parse_ftp(to_bytes("220 (vsFTPd 3.0.5)\r\n")); REQUIRE(msg.has_value()); CHECK(msg->is_response); CHECK(msg->command_or_code == "220"); CHECK(msg->argument == "(vsFTPd 3.0.5)"); } TEST_CASE("parse_ftp decodes a USER command") { auto msg = parse_ftp(to_bytes("USER anonymous\r\n")); REQUIRE(msg.has_value()); CHECK_FALSE(msg->is_response); CHECK(msg->command_or_code == "USER"); CHECK(msg->argument == "anonymous"); } TEST_CASE("parse_ftp decodes a command with no argument") { auto msg = parse_ftp(to_bytes("PASV\r\n")); REQUIRE(msg.has_value()); CHECK(msg->command_or_code == "PASV"); CHECK(msg->argument.empty()); } TEST_CASE("parse_ftp rejects an unrecognized command word") { CHECK_FALSE(parse_ftp(to_bytes("BOGUS foo\r\n")).has_value()); } TEST_CASE("FtpDissector claims port 21 and formats command and argument together") { FtpDissector dissector; CHECK(dissector.port() == kFtpPort); auto summary = dissector.summarize(to_bytes("RETR file.txt\r\n")); REQUIRE(summary.has_value()); CHECK(*summary == "FTP RETR file.txt"); }