merge FTPSClientSession from develop-experimental

This commit is contained in:
Günter Obiltschnig
2020-01-23 11:57:28 +01:00
parent 958ce15bb5
commit 5d481ff493
13 changed files with 1416 additions and 37 deletions

View File

@@ -0,0 +1,260 @@
//
// DialogServer.cpp
//
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "DialogServer.h"
#include "Poco/Net/DialogSocket.h"
#include "Poco/Net/SocketAddress.h"
#include "Poco/Timespan.h"
#include <iostream>
#include "Poco/Net/SecureStreamSocket.h"
#include "Poco/Net/SSLManager.h"
#include "Poco/Net/Context.h"
#include "Poco/Net/SecureStreamSocketImpl.h"
using Poco::Net::Socket;
using Poco::Net::DialogSocket;
using Poco::Net::SocketAddress;
using Poco::FastMutex;
using Poco::Thread;
using Poco::Net::SecureStreamSocket;
using Poco::Net::SSLManager;
using Poco::Exception;
using Poco::Net::Context;
using Poco::Net::Session;
using Poco::Net::SecureStreamSocketImpl;
DialogServer::DialogServer(bool acceptCommands, bool ssl):
_socket(SocketAddress()),
_thread("DialogServer"),
_stop(false),
_acceptCommands(acceptCommands),
_log(false),
_ssl(ssl)
{
_thread.start(*this);
_ready.wait();
}
DialogServer::~DialogServer()
{
_stop = true;
_thread.join();
}
Poco::UInt16 DialogServer::port() const
{
return _socket.address().port();
}
void handleDataSSLrequest(DialogSocket& ds, bool ssl, Session::Ptr& sslSession)
{
if (ssl)
{
try
{
Context::Ptr cDefaultServerContext = SSLManager::instance().defaultServerContext();
SecureStreamSocket sss(SecureStreamSocket::attach(ds, cDefaultServerContext, sslSession));
sss.setLazyHandshake(true);
if (sss.completeHandshake() == 1)
{
ds = sss;
}
}
catch (Exception&) {
}
}
}
void handleSSLrequest(DialogSocket& ds, bool ssl, Session::Ptr& sslSession)
{
if (ssl)
{
try
{
Context::Ptr cDefaultServerContext = SSLManager::instance().defaultServerContext();
ds.sendMessage("200 OK");
SecureStreamSocket sss(SecureStreamSocket::attach(ds, cDefaultServerContext));
sss.setLazyHandshake(true);
if (sss.completeHandshake() == 1)
{
ds = sss;
SecureStreamSocketImpl* pSecure = dynamic_cast<SecureStreamSocketImpl*>(sss.impl());
if (pSecure != nullptr)
sslSession = pSecure->currentSession();
}
else
{
ds.sendMessage("501 Explicit TLS authentication not available");
}
}
catch (Exception&) {
ds.sendMessage("501 Explicit TLS authentication not available");
}
}
else
{
ds.sendMessage("501 Explicit TLS authentication not available");
}
}
void DialogServer::run()
{
_ready.set();
Poco::Timespan span(250000);
while (!_stop)
{
if (_socket.poll(span, Socket::SELECT_READ))
{
DialogSocket ds = _socket.acceptConnection();
if (!_SSLsession.isNull()) {
handleDataSSLrequest(ds, _ssl, _SSLsession);
}
{
FastMutex::ScopedLock lock(_mutex);
if (!_nextResponses.empty())
{
ds.sendMessage(_nextResponses.front());
_nextResponses.erase(_nextResponses.begin());
}
}
if (_acceptCommands)
{
try
{
std::string command;
while (ds.receiveMessage(command))
{
if ((command == "AUTH TLS") || (command == "AUTH SSL"))
{
handleSSLrequest(ds, _ssl, _SSLsession);
continue;
}
else if ((command == "PBSZ 0") || (command == "PROT P"))
{
ds.sendMessage("200 OK");
continue;
}
if (_log) std::cout << ">> " << command << std::endl;
{
FastMutex::ScopedLock lock(_mutex);
_lastCommands.push_back(command);
if (!_nextResponses.empty())
{
if (_log) std::cout << "<< " << _nextResponses.front() << std::endl;
ds.sendMessage(_nextResponses.front());
_nextResponses.erase(_nextResponses.begin());
}
}
}
}
catch (Poco::Exception& exc)
{
std::cerr << "DialogServer: " << exc.displayText() << std::endl;
}
}
}
}
}
const std::string& DialogServer::lastCommand() const
{
FastMutex::ScopedLock lock(_mutex);
static const std::string EMPTY;
if (_lastCommands.empty())
return EMPTY;
else
return _lastCommands.back();
}
const std::vector<std::string>& DialogServer::lastCommands() const
{
return _lastCommands;
}
std::string DialogServer::popCommand()
{
FastMutex::ScopedLock lock(_mutex);
std::string command;
if (!_lastCommands.empty())
{
command = _lastCommands.front();
_lastCommands.erase(_lastCommands.begin());
}
return command;
}
std::string DialogServer::popCommandWait()
{
std::string result(popCommand());
while (result.empty())
{
Thread::sleep(100);
result = popCommand();
}
return result;
}
void DialogServer::addResponse(const std::string& response)
{
FastMutex::ScopedLock lock(_mutex);
_nextResponses.push_back(response);
}
void DialogServer::clearCommands()
{
FastMutex::ScopedLock lock(_mutex);
_lastCommands.clear();
}
void DialogServer::clearResponses()
{
FastMutex::ScopedLock lock(_mutex);
_nextResponses.clear();
}
void DialogServer::log(bool flag)
{
_log = flag;
}
void DialogServer::setSslSession(Session::Ptr cSession)
{
_SSLsession = cSession;
}
Session::Ptr DialogServer::getSslSession()
{
return _SSLsession;
}

View File

@@ -0,0 +1,87 @@
//
// DialogServer.h
//
// Definition of the DialogServer class.
//
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef DialogServer_INCLUDED
#define DialogServer_INCLUDED
#include "Poco/Net/Net.h"
#include "Poco/Net/ServerSocket.h"
#include "Poco/Net/StreamSocket.h"
#include "Poco/Thread.h"
#include "Poco/Event.h"
#include "Poco/Mutex.h"
#include <vector>
#include "Poco/Net/Session.h"
class DialogServer: public Poco::Runnable
/// A server for testing FTPClientSession and friends.
{
public:
DialogServer(bool acceptCommands = true, bool ssl = false);
/// Creates the DialogServer.
~DialogServer();
/// Destroys the DialogServer.
Poco::UInt16 port() const;
/// Returns the port the echo server is
/// listening on.
void run();
/// Does the work.
const std::string& lastCommand() const;
/// Returns the last command received by the server.
std::string popCommand();
/// Pops the next command from the list of received commands.
std::string popCommandWait();
/// Pops the next command from the list of received commands.
/// Waits until a command is available.
const std::vector<std::string>& lastCommands() const;
/// Returns the last command received by the server.
void addResponse(const std::string& response);
/// Sets the next response returned by the server.
void clearCommands();
/// Clears all commands.
void clearResponses();
/// Clears all responses.
void log(bool flag);
/// Enables or disables logging to stdout.
Poco::Net::Session::Ptr getSslSession();
void setSslSession(Poco::Net::Session::Ptr cSession);
private:
Poco::Net::ServerSocket _socket;
Poco::Thread _thread;
Poco::Event _ready;
mutable Poco::FastMutex _mutex;
bool _stop;
std::vector<std::string> _nextResponses;
std::vector<std::string> _lastCommands;
bool _acceptCommands;
bool _log;
bool _ssl;
Poco::Net::Session::Ptr _SSLsession = nullptr;
};
#endif // DialogServer_INCLUDED

View File

@@ -0,0 +1,647 @@
//
// FTPSClientSessionTest.cpp
//
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "FTPSClientSessionTest.h"
#include "Poco/CppUnit/TestCaller.h"
#include "Poco/CppUnit/TestSuite.h"
#include "Poco/Net/FTPSClientSession.h"
#include "Poco/Net/DialogSocket.h"
#include "Poco/Net/SocketAddress.h"
#include "Poco/Net/NetException.h"
#include "Poco/Thread.h"
#include "Poco/ActiveMethod.h"
#include "Poco/StreamCopier.h"
#include "Poco/Net/Session.h"
#include "DialogServer.h"
#include <sstream>
using Poco::Net::FTPSClientSession;
using Poco::Net::DialogSocket;
using Poco::Net::SocketAddress;
using Poco::Net::FTPException;
using Poco::ActiveMethod;
using Poco::ActiveResult;
using Poco::StreamCopier;
using Poco::Thread;
using Poco::Net::Session;
namespace
{
class ActiveDownloader
{
public:
ActiveDownloader(FTPSClientSession& session):
download(this, &ActiveDownloader::downloadImp),
_session(session)
{
}
ActiveMethod<std::string, std::string, ActiveDownloader> download;
protected:
std::string downloadImp(const std::string& path)
{
std::istream& istr = _session.beginDownload(path);
std::ostringstream ostr;
StreamCopier::copyStream(istr, ostr);
_session.endDownload();
return ostr.str();
}
private:
FTPSClientSession& _session;
};
};
FTPSClientSessionTest::FTPSClientSessionTest(const std::string& name): CppUnit::TestCase(name)
{
}
FTPSClientSessionTest::~FTPSClientSessionTest()
{
}
void FTPSClientSessionTest::login(DialogServer& server, FTPSClientSession& session)
{
server.addResponse("331 Password required");
server.addResponse("230 Welcome");
server.addResponse("200 Type set to I");
session.login("user", "password");
std::string cmd = server.popCommand();
assertTrue (cmd == "USER user");
cmd = server.popCommand();
assertTrue (cmd == "PASS password");
cmd = server.popCommand();
assertTrue (cmd == "TYPE I");
assertTrue (session.getFileType() == FTPSClientSession::TYPE_BINARY);
}
void FTPSClientSessionTest::testLogin1()
{
DialogServer server;
server.addResponse("220 localhost FTP ready");
FTPSClientSession session("127.0.0.1", server.port());
assertTrue (session.isOpen());
assertTrue (!session.isLoggedIn());
login(server, session);
assertTrue (session.isOpen());
assertTrue (session.isLoggedIn());
server.addResponse("221 Good Bye");
session.logout();
assertTrue (session.isOpen());
assertTrue (!session.isLoggedIn());
server.clearCommands();
server.clearResponses();
session.tryFTPSmode(true);
login(server, session);
assertTrue (session.isOpen());
assertTrue (session.isLoggedIn());
server.addResponse("221 Good Bye");
session.close();
assertTrue (!session.isOpen());
assertTrue (!session.isLoggedIn());
}
void FTPSClientSessionTest::testLogin2()
{
DialogServer server;
server.addResponse("220 localhost FTP ready");
server.addResponse("331 Password required");
server.addResponse("230 Welcome");
server.addResponse("200 Type set to I");
Poco::UInt16 serverPort = server.port();
FTPSClientSession session("127.0.0.1", serverPort, "user", "password");
assertTrue (session.isOpen());
assertTrue (session.isLoggedIn());
server.addResponse("221 Good Bye");
session.close();
assertTrue (!session.isOpen());
assertTrue (!session.isLoggedIn());
server.clearCommands();
server.clearResponses();
server.addResponse("220 localhost FTP ready");
server.addResponse("331 Password required");
server.addResponse("230 Welcome");
server.addResponse("200 Type set to I");
session.tryFTPSmode(true);
session.open("127.0.0.1", serverPort, "user", "password");
assertTrue (session.isOpen());
assertTrue (session.isLoggedIn());
server.addResponse("221 Good Bye");
session.close();
assertTrue (!session.isOpen());
assertTrue (!session.isLoggedIn());
}
void FTPSClientSessionTest::testLogin3()
{
DialogServer server;
server.addResponse("220 localhost FTP ready");
server.addResponse("331 Password required");
server.addResponse("230 Welcome");
server.addResponse("200 Type set to I");
FTPSClientSession session;
assertTrue (!session.isOpen());
assertTrue (!session.isLoggedIn());
session.open("127.0.0.1", server.port(), "user", "password");
server.addResponse("221 Good Bye");
session.close();
assertTrue (!session.isOpen());
assertTrue (!session.isLoggedIn());
}
void FTPSClientSessionTest::testLoginFailed1()
{
DialogServer server;
server.addResponse("421 localhost FTP not ready");
FTPSClientSession session("127.0.0.1", server.port());
try
{
session.login("user", "password");
fail("server not ready - must throw");
}
catch (FTPException&)
{
}
server.addResponse("221 Good Bye");
session.close();
}
void FTPSClientSessionTest::testLoginFailed2()
{
DialogServer server;
server.addResponse("220 localhost FTP ready");
server.addResponse("331 Password required");
server.addResponse("530 Login incorrect");
FTPSClientSession session("127.0.0.1", server.port());
try
{
session.login("user", "password");
fail("login incorrect - must throw");
}
catch (FTPException&)
{
}
server.addResponse("221 Good Bye");
session.close();
}
void FTPSClientSessionTest::testCommands()
{
DialogServer server;
server.addResponse("220 localhost FTP ready");
server.addResponse("331 Password required");
server.addResponse("230 Welcome");
server.addResponse("200 Type set to I");
FTPSClientSession session("127.0.0.1", server.port());
session.login("user", "password");
std::string cmd = server.popCommand();
assertTrue (cmd == "USER user");
cmd = server.popCommand();
assertTrue (cmd == "PASS password");
cmd = server.popCommand();
assertTrue (cmd == "TYPE I");
// systemType
server.clearCommands();
server.addResponse("215 UNIX Type: L8 Version: dummyFTP 1.0");
std::string type = session.systemType();
cmd = server.popCommand();
assertTrue (cmd == "SYST");
assertTrue (type == "UNIX Type: L8 Version: dummyFTP 1.0");
// getWorkingDirectory
server.addResponse("257 \"/usr/test\" is current directory");
std::string cwd = session.getWorkingDirectory();
cmd = server.popCommand();
assertTrue (cmd == "PWD");
assertTrue (cwd == "/usr/test");
// getWorkingDirectory (quotes in filename)
server.addResponse("257 \"\"\"quote\"\"\" is current directory");
cwd = session.getWorkingDirectory();
cmd = server.popCommand();
assertTrue (cmd == "PWD");
assertTrue (cwd == "\"quote\"");
// setWorkingDirectory
server.addResponse("250 CWD OK");
session.setWorkingDirectory("test");
cmd = server.popCommand();
assertTrue (cmd == "CWD test");
server.addResponse("250 CDUP OK");
session.cdup();
cmd = server.popCommand();
assertTrue (cmd == "CDUP");
// rename
server.addResponse("350 File exists, send destination name");
server.addResponse("250 Rename OK");
session.rename("old.txt", "new.txt");
cmd = server.popCommand();
assertTrue (cmd == "RNFR old.txt");
cmd = server.popCommand();
assertTrue (cmd == "RNTO new.txt");
// rename (failing)
server.addResponse("550 not found");
try
{
session.rename("old.txt", "new.txt");
fail("not found - must throw");
}
catch (FTPException&)
{
}
server.clearCommands();
// remove
server.addResponse("250 delete ok");
session.remove("test.txt");
cmd = server.popCommand();
assertTrue (cmd == "DELE test.txt");
// remove (failing)
server.addResponse("550 not found");
try
{
session.remove("test.txt");
fail("not found - must throw");
}
catch (FTPException&)
{
}
server.clearCommands();
// createDirectory
server.addResponse("257 dir created");
session.createDirectory("foo");
cmd = server.popCommand();
assertTrue (cmd == "MKD foo");
// createDirectory (failing)
server.addResponse("550 exists");
try
{
session.createDirectory("foo");
fail("not found - must throw");
}
catch (FTPException&)
{
}
server.clearCommands();
// removeDirectory
server.addResponse("250 RMD OK");
session.removeDirectory("foo");
cmd = server.popCommand();
assertTrue (cmd == "RMD foo");
// removeDirectory (failing)
server.addResponse("550 not found");
try
{
session.removeDirectory("foo");
fail("not found - must throw");
}
catch (FTPException&)
{
}
server.clearCommands();
server.addResponse("221 Good Bye");
session.close();
}
void FTPSClientSessionTest::testDownloadPORT()
{
DialogServer server;
server.addResponse("220 localhost FTP ready");
server.addResponse("331 Password required");
server.addResponse("230 Welcome");
server.addResponse("200 Type set to I");
FTPSClientSession session("127.0.0.1", server.port());
session.setPassive(false);
session.login("user", "password");
server.clearCommands();
server.addResponse("500 EPRT not understood");
server.addResponse("200 PORT OK");
server.addResponse("150 Sending data\r\n226 Transfer complete");
ActiveDownloader dl(session);
ActiveResult<std::string> result = dl.download("test.txt");
std::string cmd = server.popCommandWait();
assertTrue (cmd.substr(0, 4) == "EPRT");
cmd = server.popCommandWait();
assertTrue (cmd.substr(0, 4) == "PORT");
std::string dummy;
int x, lo, hi;
for (std::string::iterator it = cmd.begin(); it != cmd.end(); ++it)
{
if (*it == ',') *it = ' ';
}
std::istringstream istr(cmd);
istr >> dummy >> x >> x >> x >> x >> hi >> lo;
int port = hi*256 + lo;
cmd = server.popCommandWait();
assertTrue (cmd == "RETR test.txt");
SocketAddress sa("127.0.0.1", (Poco::UInt16) port);
DialogSocket dataSock;
dataSock.connect(sa);
std::string data("This is some data");
dataSock.sendString(data);
dataSock.close();
result.wait();
std::string received = result.data();
assertTrue (received == data);
server.addResponse("221 Good Bye");
session.close();
}
void FTPSClientSessionTest::testDownloadEPRT()
{
DialogServer server;
server.addResponse("220 localhost FTP ready");
server.addResponse("331 Password required");
server.addResponse("230 Welcome");
server.addResponse("200 Type set to I");
FTPSClientSession session("127.0.0.1", server.port());
session.setPassive(false);
session.login("user", "password");
server.clearCommands();
server.addResponse("200 EPRT OK");
server.addResponse("150 Sending data\r\n226 Transfer complete");
ActiveDownloader dl(session);
ActiveResult<std::string> result = dl.download("test.txt");
std::string cmd = server.popCommandWait();
assertTrue (cmd.substr(0, 4) == "EPRT");
std::string dummy;
char c;
int d;
int port;
std::istringstream istr(cmd);
istr >> dummy >> c >> d >> c >> d >> c >> d >> c >> d >> c >> d >> c >> port >> c;
cmd = server.popCommandWait();
assertTrue (cmd == "RETR test.txt");
SocketAddress sa("127.0.0.1", (Poco::UInt16) port);
DialogSocket dataSock;
dataSock.connect(sa);
std::string data("This is some data");
dataSock.sendString(data);
dataSock.close();
result.wait();
std::string received = result.data();
assertTrue (received == data);
server.addResponse("221 Good Bye");
session.close();
}
void FTPSClientSessionTest::testDownloadPASV()
{
DialogServer server;
server.addResponse("220 localhost FTP ready");
server.addResponse("331 Password required");
server.addResponse("230 Welcome");
server.addResponse("200 Type set to I");
FTPSClientSession session("127.0.0.1", server.port());
session.login("user", "password");
server.clearCommands();
server.addResponse("500 EPSV not understood");
DialogServer dataServer(false);
Poco::UInt16 dataServerPort = dataServer.port();
dataServer.addResponse("This is some data");
std::ostringstream pasv;
pasv << "227 Entering Passive Mode (127,0,0,1," << (dataServerPort/256) << "," << (dataServerPort % 256) << ")";
server.addResponse(pasv.str());
server.addResponse("150 sending data\r\n226 Transfer complete");
std::istream& istr = session.beginDownload("test.txt");
std::ostringstream dataStr;
StreamCopier::copyStream(istr, dataStr);
session.endDownload();
std::string s(dataStr.str());
assertTrue (s == "This is some data\r\n");
server.addResponse("221 Good Bye");
session.close();
}
void FTPSClientSessionTest::testDownloadEPSV()
{
DialogServer server;
server.addResponse("220 localhost FTP ready");
server.addResponse("331 Password required");
server.addResponse("230 Welcome");
server.addResponse("200 Type set to I");
FTPSClientSession session("127.0.0.1", server.port());
session.login("user", "password");
server.clearCommands();
DialogServer dataServer(false);
dataServer.addResponse("This is some data");
std::ostringstream epsv;
epsv << "229 Entering Extended Passive Mode (|||" << dataServer.port() << "|)";
server.addResponse(epsv.str());
server.addResponse("150 sending data\r\n226 Transfer complete");
std::istream& istr = session.beginDownload("test.txt");
std::ostringstream dataStr;
StreamCopier::copyStream(istr, dataStr);
session.endDownload();
std::string s(dataStr.str());
assertTrue (s == "This is some data\r\n");
std::string cmd = server.popCommand();
assertTrue (cmd.substr(0, 4) == "EPSV");
cmd = server.popCommand();
assertTrue (cmd == "RETR test.txt");
server.addResponse("221 Good Bye");
session.close();
}
void FTPSClientSessionTest::testUpload()
{
DialogServer server;
server.addResponse("220 localhost FTP ready");
server.addResponse("331 Password required");
server.addResponse("230 Welcome");
server.addResponse("200 Type set to I");
FTPSClientSession session("127.0.0.1", server.port());
session.login("user", "password");
server.clearCommands();
DialogServer dataServer;
std::ostringstream epsv;
epsv << "229 Entering Extended Passive Mode (|||" << dataServer.port() << "|)";
server.addResponse(epsv.str());
server.addResponse("150 send data\r\n226 Transfer complete");
std::ostream& ostr = session.beginUpload("test.txt");
ostr << "This is some data\r\n";
session.endUpload();
std::string s(dataServer.popCommandWait());
assertTrue (s == "This is some data");
std::string cmd = server.popCommand();
assertTrue (cmd.substr(0, 4) == "EPSV");
cmd = server.popCommand();
assertTrue (cmd == "STOR test.txt");
server.addResponse("221 Good Bye");
session.close();
}
void FTPSClientSessionTest::testUploadSSL()
{
DialogServer server(true, true);
server.addResponse("220 localhost FTP ready");
server.addResponse("331 Password required");
server.addResponse("230 Welcome");
server.addResponse("200 Type set to I");
FTPSClientSession session("127.0.0.1", server.port());
session.login("user", "password");
server.clearCommands();
DialogServer dataServer(true, true);
Session::Ptr cSessionSSL = server.getSslSession();
dataServer.setSslSession(cSessionSSL);
std::ostringstream epsv;
epsv << "229 Entering Extended Passive Mode (|||" << dataServer.port() << "|)";
server.addResponse(epsv.str());
server.addResponse("150 send data\r\n226 Transfer complete");
std::ostream& ostr = session.beginUpload("test.txt");
ostr << "This is some data\r\n";
session.endUpload();
std::string s(dataServer.popCommandWait());
assertTrue (s == "This is some data");
std::string cmd = server.popCommand();
assertTrue (cmd.substr(0, 4) == "EPSV");
cmd = server.popCommand();
assertTrue (cmd == "STOR test.txt");
server.addResponse("221 Good Bye");
session.close();
}
void FTPSClientSessionTest::testList()
{
DialogServer server;
server.addResponse("220 localhost FTP ready");
server.addResponse("331 Password required");
server.addResponse("230 Welcome");
server.addResponse("200 Type set to I");
FTPSClientSession session("127.0.0.1", server.port());
session.login("user", "password");
server.clearCommands();
DialogServer dataServer(false);
dataServer.addResponse("file1\r\nfile2");
std::ostringstream epsv;
epsv << "229 Entering Extended Passive Mode (|||" << dataServer.port() << "|)";
server.addResponse(epsv.str());
server.addResponse("150 sending data\r\n226 Transfer complete");
std::istream& istr = session.beginList();
std::ostringstream dataStr;
StreamCopier::copyStream(istr, dataStr);
session.endList();
std::string s(dataStr.str());
assertTrue (s == "file1\r\nfile2\r\n");
std::string cmd = server.popCommand();
assertTrue (cmd.substr(0, 4) == "EPSV");
cmd = server.popCommand();
assertTrue (cmd == "NLST");
server.addResponse("221 Good Bye");
session.close();
}
void FTPSClientSessionTest::setUp()
{
}
void FTPSClientSessionTest::tearDown()
{
}
CppUnit::Test* FTPSClientSessionTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("FTPSClientSessionTest");
CppUnit_addTest(pSuite, FTPSClientSessionTest, testLogin1);
CppUnit_addTest(pSuite, FTPSClientSessionTest, testLogin2);
CppUnit_addTest(pSuite, FTPSClientSessionTest, testLogin3);
CppUnit_addTest(pSuite, FTPSClientSessionTest, testLoginFailed1);
CppUnit_addTest(pSuite, FTPSClientSessionTest, testLoginFailed2);
CppUnit_addTest(pSuite, FTPSClientSessionTest, testCommands);
CppUnit_addTest(pSuite, FTPSClientSessionTest, testDownloadPORT);
CppUnit_addTest(pSuite, FTPSClientSessionTest, testDownloadEPRT);
CppUnit_addTest(pSuite, FTPSClientSessionTest, testDownloadPASV);
CppUnit_addTest(pSuite, FTPSClientSessionTest, testDownloadEPSV);
CppUnit_addTest(pSuite, FTPSClientSessionTest, testUpload);
CppUnit_addTest(pSuite, FTPSClientSessionTest, testList);
CppUnit_addTest(pSuite, FTPSClientSessionTest, testUploadSSL);
return pSuite;
}

View File

@@ -0,0 +1,62 @@
//
// FTPClientSessionTest.h
//
// Definition of the FTPClientSessionTest class.
//
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef FTPClientSessionTest_INCLUDED
#define FTPClientSessionTest_INCLUDED
#include "Poco/Net/Net.h"
#include "Poco/CppUnit/TestCase.h"
namespace Poco {
namespace Net {
class FTPSClientSession;
} }
class DialogServer;
class FTPSClientSessionTest: public CppUnit::TestCase
{
public:
FTPSClientSessionTest(const std::string& name);
~FTPSClientSessionTest();
void testLogin1();
void testLogin2();
void testLogin3();
void testLoginFailed1();
void testLoginFailed2();
void testCommands();
void testDownloadPORT();
void testDownloadEPRT();
void testDownloadPASV();
void testDownloadEPSV();
void testUpload();
void testList();
void testUploadSSL();
void setUp();
void tearDown();
static CppUnit::Test* suite();
private:
void login(DialogServer& server, Poco::Net::FTPSClientSession& session);
};
#endif // FTPClientSessionTest_INCLUDED

View File

@@ -0,0 +1,22 @@
//
// FTPClientTestSuite.cpp
//
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "FTPSClientTestSuite.h"
#include "FTPSClientSessionTest.h"
CppUnit::Test* FTPSClientTestSuite::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("FTPSClientTestSuite");
pSuite->addTest(FTPSClientSessionTest::suite());
return pSuite;
}

View File

@@ -0,0 +1,27 @@
//
// FTPClientTestSuite.h
//
// Definition of the FTPClientTestSuite class.
//
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef FTPClientTestSuite_INCLUDED
#define FTPClientTestSuite_INCLUDED
#include "Poco/CppUnit/TestSuite.h"
class FTPSClientTestSuite
{
public:
static CppUnit::Test* suite();
};
#endif // FTPClientTestSuite_INCLUDED

View File

@@ -14,6 +14,7 @@
#include "TCPServerTestSuite.h"
#include "HTTPSServerTestSuite.h"
#include "WebSocketTestSuite.h"
#include "FTPSClientTestSuite.h"
CppUnit::Test* NetSSLTestSuite::suite()
@@ -24,6 +25,7 @@ CppUnit::Test* NetSSLTestSuite::suite()
pSuite->addTest(TCPServerTestSuite::suite());
pSuite->addTest(HTTPSServerTestSuite::suite());
pSuite->addTest(WebSocketTestSuite::suite());
pSuite->addTest(FTPSClientTestSuite::suite());
return pSuite;
}