diff options
Diffstat (limited to 'tests/test_ftp.cpp')
| -rw-r--r-- | tests/test_ftp.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/test_ftp.cpp b/tests/test_ftp.cpp new file mode 100644 index 0000000..0015f42 --- /dev/null +++ b/tests/test_ftp.cpp @@ -0,0 +1,51 @@ +#include <doctest/doctest.h> + +#include <vector> + +#include "packeteer/l7/ftp.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_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"); +} |