From 18cc44701523d3e6500c9e0bbcd0070e4e68b279 Mon Sep 17 00:00:00 2001 From: deniskovalchuk Date: Sat, 30 Mar 2024 19:49:36 +0300 Subject: [PATCH] test: add test for login without ssl support --- test/client.cpp | 24 ++++++++++++++++++++++-- test/test_server.hpp | 22 ++++++++++++++++++---- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/test/client.cpp b/test/client.cpp index 6d66d98..8072488 100644 --- a/test/client.cpp +++ b/test/client.cpp @@ -91,14 +91,15 @@ class test_cancel_callback : public ftp::transfer_callback } }; -class client : public testing::Test +template +class base_client : public testing::Test { protected: static void SetUpTestSuite() { try { - server_.start(server_root_dir_, 2121); + server_.start(server_root_dir_, server_port, server_use_ssl); } catch (const std::exception & ex) { @@ -141,6 +142,10 @@ class client : public testing::Test inline static ftp::test::server server_; }; +class client : public base_client<2121, false> +{ +}; + TEST_F(client, open_connection) { ftp::client client; @@ -1077,4 +1082,19 @@ TEST_P(client_with_transfer_mode, disable_rfc2428_support) check_reply(client.disconnect(), "221 Goodbye."); } +class ssl_client : public base_client<2142, true> +{ +}; + +TEST_F(ssl_client, login_without_ssl) +{ + ftp::client client; + + check_reply(client.connect("127.0.0.1", 2142), "220 FTP server is ready."); + + check_reply(client.login("user", "password"), CRLF("550 SSL/TLS required on the control channel.")); + + check_reply(client.disconnect(), "221 Goodbye."); +} + } // namespace diff --git a/test/test_server.hpp b/test/test_server.hpp index c831cd9..218ba5a 100644 --- a/test/test_server.hpp +++ b/test/test_server.hpp @@ -36,7 +36,7 @@ namespace ftp::test class server { public: - void start(const std::string & root_directory, std::uint16_t port) + void start(const std::string & root_directory, std::uint16_t port, bool use_ssl) { const char *server_path = std::getenv("LIBFTP_TEST_SERVER_PATH"); if (!server_path) @@ -56,9 +56,20 @@ class server std::filesystem::create_directory(root_directory); - /* Usage: python server.py root_directory port */ + const char *use_ssl_arg; + if (use_ssl) + { + use_ssl_arg = "--use-ssl=yes"; + } + else + { + use_ssl_arg = "--use-ssl=no"; + } + + /* Usage: python server.py root_directory port [--use-ssl {yes,no}] */ boost::process::ipstream output; - process_ = boost::process::child(python_path, server_path, root_directory, std::to_string(port), + process_ = boost::process::child(python_path, server_path, + root_directory, std::to_string(port), use_ssl_arg, boost::process::std_out > boost::process::null, boost::process::std_err > output); @@ -67,8 +78,11 @@ class server std::string line; std::getline(output, line); - if (line.find("starting FTP server") != std::string::npos) + if (line.find("starting FTP server") != std::string::npos || + line.find("starting FTP+SSL server") != std::string::npos) + { break; + } } }