Ejemplo n.º 1
0
void SMTPClientSessionTest::testLoginHELO()
{
	DialogServer server;
	server.addResponse("220 localhost SMTP ready");
	server.addResponse("500 EHLO not understood");
	server.addResponse("250 Hello localhost");
	server.addResponse("221 Bye");
	SMTPClientSession session("localhost", server.port());
	session.login("localhost");
	std::string cmd = server.popCommand();
	assert (cmd == "EHLO localhost");
	cmd = server.popCommand();
	assert (cmd == "HELO localhost");
	session.close();
	cmd = server.popCommand();
	assert (cmd == "QUIT");
}
Ejemplo n.º 2
0
void POP3ClientSessionTest::testLogin()
{
	DialogServer server;
	server.addResponse("+OK POP3 Ready...");
	server.addResponse("+OK USER");
	server.addResponse("+OK PASS");
	server.addResponse("+OK QUIT");
	POP3ClientSession session("localhost", server.port());
	session.login("user", "secret");
	std::string cmd = server.popCommand();
	assert (cmd == "USER user");
	cmd = server.popCommand();
	assert (cmd == "PASS secret");
	session.close();
	cmd = server.popCommand();
	assert (cmd == "QUIT");
}
Ejemplo n.º 3
0
void FTPClientSessionTest::testLogin()
{
	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");
	std::string cmd = server.popCommand();
	assert (cmd == "USER user");
	cmd = server.popCommand();
	assert (cmd == "PASS password");
	cmd = server.popCommand();
	assert (cmd == "TYPE I");
	
	assert (session.getFileType() == FTPClientSession::TYPE_BINARY);
	
	server.addResponse("221 Good Bye");
	session.close();
}
Ejemplo n.º 4
0
void POP3ClientSessionTest::testDeleteMessage()
{
	DialogServer server;
	server.addResponse("+OK POP3 Ready...");
	server.addResponse("+OK USER");
	server.addResponse("+OK PASS");
	server.addResponse("+OK DELETED");
	server.addResponse("+OK QUIT");
	POP3ClientSession session("localhost", server.port());
	session.login("user", "secret");
	server.clearCommands();
	session.deleteMessage(42);
	std::string cmd = server.popCommand();
	assert (cmd == "DELE 42");
	session.close();
}
Ejemplo n.º 5
0
void POP3ClientSessionTest::testMessageCount()
{
	DialogServer server;
	server.addResponse("+OK POP3 Ready...");
	server.addResponse("+OK USER");
	server.addResponse("+OK PASS");
	server.addResponse("+OK 42 12345");
	server.addResponse("+OK QUIT");
	POP3ClientSession session("localhost", server.port());
	session.login("user", "secret");
	server.clearCommands();
	int n = session.messageCount();
	std::string cmd = server.popCommand();
	assert (cmd == "STAT");
	assert (n == 42);
	session.close();
}
Ejemplo n.º 6
0
void POP3ClientSessionTest::testRetrieveMessage()
{
	DialogServer server;
	server.addResponse("+OK POP3 Ready...");
	server.addResponse("+OK USER");
	server.addResponse("+OK PASS");
	server.addResponse(
		"+OK Here comes the message\r\n"
		"From: [email protected]\r\n"
		"To: [email protected]\r\n"
		"Subject: test\r\n"
		"\r\n"
		"Hello Jane,\r\n"
		"\r\n"
		"blah blah blah...\r\n"
		"....\r\n"
		"\r\n"
		"Yours, John\r\n"
		".\r\n"
	);
	server.addResponse("+OK QUIT");
	POP3ClientSession session("localhost", server.port());
	session.login("user", "secret");
	server.clearCommands();
	MailMessage message;
	session.retrieveMessage(1, message);
	std::string cmd = server.popCommand();
	assert (cmd == "RETR 1");

	assert (message.getContent() ==
		"Hello Jane,\r\n"
		"\r\n"
		"blah blah blah...\r\n"
		"...\r\n"
		"\r\n"
		"Yours, John\r\n"
	);

	session.close();
}
Ejemplo n.º 7
0
void FTPClientSessionTest::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");
	FTPClientSession session("localhost", server.port());
	session.login("user", "password");
	std::string cmd = server.popCommand();
	assert (cmd == "USER user");
	cmd = server.popCommand();
	assert (cmd == "PASS password");
	cmd = server.popCommand();
	assert (cmd == "TYPE I");
	
	// systemType
	server.clearCommands();
	server.addResponse("215 UNIX Type: L8 Version: dummyFTP 1.0");
	std::string type = session.systemType();
	cmd = server.popCommand();
	assert (cmd == "SYST");
	assert (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();
	assert (cmd == "PWD");
	assert (cwd == "/usr/test");

	// getWorkingDirectory (quotes in filename)
	server.addResponse("257 \"\"\"quote\"\"\" is current directory");
	cwd = session.getWorkingDirectory();
	cmd = server.popCommand();
	assert (cmd == "PWD");
	assert (cwd == "\"quote\"");
	
	// setWorkingDirectory
	server.addResponse("250 CWD OK");
	session.setWorkingDirectory("test");
	cmd = server.popCommand();
	assert (cmd == "CWD test");
	
	server.addResponse("250 CDUP OK");
	session.cdup();
	cmd = server.popCommand();
	assert (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();
	assert (cmd == "RNFR old.txt");
	cmd = server.popCommand();
	assert (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();
	assert (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();
	assert (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();
	assert (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();
}