void FTPClientSessionTest::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"); FTPClientSession session("localhost", 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(); assert (cmd.substr(0, 4) == "EPRT"); cmd = server.popCommandWait(); assert (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(); assert (cmd == "RETR test.txt"); SocketAddress sa("localhost", (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(); assert (received == data); server.addResponse("221 Good Bye"); session.close(); }
void FTPClientSessionTest::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"); FTPClientSession session("localhost", 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()); assert (s == "This is some data"); std::string cmd = server.popCommand(); assert (cmd.substr(0, 4) == "EPSV"); cmd = server.popCommand(); assert (cmd == "STOR test.txt"); server.addResponse("221 Good Bye"); session.close(); }
void FTPClientSessionTest::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"); FTPClientSession session("localhost", 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(); assert (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(); assert (cmd == "RETR test.txt"); SocketAddress sa("localhost", (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(); assert (received == data); server.addResponse("221 Good Bye"); session.close(); }
void SMTPClientSessionTest::testSend() { DialogServer server; server.addResponse("220 localhost SMTP ready"); server.addResponse("250 Hello localhost"); server.addResponse("250 OK"); server.addResponse("250 OK"); server.addResponse("354 Send data"); server.addResponse("250 OK"); server.addResponse("221 Bye"); SMTPClientSession session("localhost", server.port()); session.login("localhost"); MailMessage message; message.setSender("*****@*****.**"); message.addRecipient(MailRecipient(MailRecipient::PRIMARY_RECIPIENT, "*****@*****.**", "Jane Doe")); message.setSubject("Test Message"); message.setContent("Hello\r\nblah blah\r\n\r\nJohn\r\n"); server.clearCommands(); session.sendMessage(message); std::string cmd = server.popCommandWait(); assert (cmd == "MAIL FROM: <*****@*****.**>"); cmd = server.popCommandWait(); assert (cmd == "RCPT TO: <*****@*****.**>"); cmd = server.popCommandWait(); assert (cmd == "DATA"); cmd = server.popCommandWait(); assert (cmd.substr(0, 4) == "Date"); cmd = server.popCommandWait(); assert (cmd == "Content-Type: text/plain"); cmd = server.popCommandWait(); assert (cmd == "From: [email protected]"); cmd = server.popCommandWait(); assert (cmd == "Subject: Test Message"); cmd = server.popCommandWait(); assert (cmd == "Content-Transfer-Encoding: quoted-printable"); cmd = server.popCommandWait(); assert (cmd == "To: Jane Doe <*****@*****.**>"); cmd = server.popCommandWait(); assert (cmd == "Hello"); cmd = server.popCommandWait(); assert (cmd == "blah blah"); cmd = server.popCommandWait(); assert (cmd == "John"); cmd = server.popCommandWait(); assert (cmd == "."); session.close(); }