Skip to content

Commit

Permalink
test: add test for login without ssl support
Browse files Browse the repository at this point in the history
  • Loading branch information
deniskovalchuk committed Mar 30, 2024
1 parent e571cae commit 18cc447
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
24 changes: 22 additions & 2 deletions test/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,15 @@ class test_cancel_callback : public ftp::transfer_callback
}
};

class client : public testing::Test
template<std::uint16_t server_port, bool server_use_ssl>
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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
22 changes: 18 additions & 4 deletions test/test_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);

Expand All @@ -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;
}
}
}

Expand Down

0 comments on commit 18cc447

Please sign in to comment.