2006-05-05 20:50:26 +00:00
|
|
|
//
|
|
|
|
// VMime library (http://www.vmime.org)
|
2013-01-10 16:30:31 +00:00
|
|
|
// Copyright (C) 2002-2013 Vincent Richard <vincent@vmime.org>
|
2006-05-05 20:50:26 +00:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
2009-09-06 12:02:10 +00:00
|
|
|
// published by the Free Software Foundation; either version 3 of
|
2006-05-05 20:50:26 +00:00
|
|
|
// the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
//
|
|
|
|
// Linking this library statically or dynamically with other modules is making
|
|
|
|
// a combined work based on this library. Thus, the terms and conditions of
|
|
|
|
// the GNU General Public License cover the whole combination.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "tests/testUtils.hpp"
|
|
|
|
|
2013-06-20 09:02:39 +00:00
|
|
|
#include "vmime/net/smtp/SMTPTransport.hpp"
|
|
|
|
#include "vmime/net/smtp/SMTPChunkingOutputStreamAdapter.hpp"
|
2013-09-08 18:49:51 +00:00
|
|
|
#include "vmime/net/smtp/SMTPExceptions.hpp"
|
2013-06-20 09:02:39 +00:00
|
|
|
|
2013-06-24 13:32:40 +00:00
|
|
|
#include "SMTPTransportTestUtils.hpp"
|
2006-05-05 20:50:26 +00:00
|
|
|
|
|
|
|
|
2013-03-08 07:19:50 +00:00
|
|
|
VMIME_TEST_SUITE_BEGIN(SMTPTransportTest)
|
2006-05-05 20:50:26 +00:00
|
|
|
|
|
|
|
VMIME_TEST_LIST_BEGIN
|
2013-08-16 09:41:55 +00:00
|
|
|
VMIME_TEST(testConnectToInvalidServer)
|
2006-05-05 20:50:26 +00:00
|
|
|
VMIME_TEST(testGreetingError)
|
|
|
|
VMIME_TEST(testMAILandRCPT)
|
2013-06-20 09:02:39 +00:00
|
|
|
VMIME_TEST(testChunking)
|
2013-06-24 13:32:40 +00:00
|
|
|
VMIME_TEST(testSize_Chunking)
|
|
|
|
VMIME_TEST(testSize_NoChunking)
|
2006-05-05 20:50:26 +00:00
|
|
|
VMIME_TEST_LIST_END
|
|
|
|
|
|
|
|
|
2013-08-16 09:41:55 +00:00
|
|
|
void testConnectToInvalidServer()
|
|
|
|
{
|
2016-04-05 20:11:47 +00:00
|
|
|
vmime::shared_ptr <vmime::net::session> sess = vmime::net::session::create();
|
2013-08-16 09:41:55 +00:00
|
|
|
|
|
|
|
vmime::utility::url url("smtp://invalid-smtp-server");
|
2013-11-21 21:16:57 +00:00
|
|
|
vmime::shared_ptr <vmime::net::transport> store = sess->getTransport(url);
|
2013-08-16 09:41:55 +00:00
|
|
|
|
|
|
|
VASSERT_THROW("connect", store->connect(), vmime::exceptions::connection_error);
|
|
|
|
}
|
|
|
|
|
2006-05-05 20:50:26 +00:00
|
|
|
void testGreetingError()
|
|
|
|
{
|
2016-04-05 20:11:47 +00:00
|
|
|
vmime::shared_ptr <vmime::net::session> session = vmime::net::session::create();
|
2006-05-05 20:50:26 +00:00
|
|
|
|
2013-11-21 21:16:57 +00:00
|
|
|
vmime::shared_ptr <vmime::net::transport> tr = session->getTransport
|
2006-05-05 20:50:26 +00:00
|
|
|
(vmime::utility::url("smtp://localhost"));
|
|
|
|
|
2013-11-21 21:16:57 +00:00
|
|
|
tr->setSocketFactory(vmime::make_shared <testSocketFactory <greetingErrorSMTPTestSocket> >());
|
|
|
|
tr->setTimeoutHandlerFactory(vmime::make_shared <testTimeoutHandlerFactory>());
|
2006-05-05 20:50:26 +00:00
|
|
|
|
|
|
|
VASSERT_THROW("Connection", tr->connect(),
|
|
|
|
vmime::exceptions::connection_greeting_error);
|
|
|
|
}
|
|
|
|
|
|
|
|
void testMAILandRCPT()
|
|
|
|
{
|
2016-04-05 20:11:47 +00:00
|
|
|
vmime::shared_ptr <vmime::net::session> session = vmime::net::session::create();
|
2006-05-05 20:50:26 +00:00
|
|
|
|
2013-11-21 21:16:57 +00:00
|
|
|
vmime::shared_ptr <vmime::net::transport> tr = session->getTransport
|
2006-05-05 20:50:26 +00:00
|
|
|
(vmime::utility::url("smtp://localhost"));
|
|
|
|
|
2013-11-21 21:16:57 +00:00
|
|
|
tr->setSocketFactory(vmime::make_shared <testSocketFactory <MAILandRCPTSMTPTestSocket> >());
|
|
|
|
tr->setTimeoutHandlerFactory(vmime::make_shared <testTimeoutHandlerFactory>());
|
2006-05-05 20:50:26 +00:00
|
|
|
|
|
|
|
VASSERT_NO_THROW("Connection", tr->connect());
|
|
|
|
|
|
|
|
vmime::mailbox exp("expeditor@test.vmime.org");
|
|
|
|
|
|
|
|
vmime::mailboxList recips;
|
2013-11-21 21:16:57 +00:00
|
|
|
recips.appendMailbox(vmime::make_shared <vmime::mailbox>("recipient1@test.vmime.org"));
|
|
|
|
recips.appendMailbox(vmime::make_shared <vmime::mailbox>("recipient2@test.vmime.org"));
|
|
|
|
recips.appendMailbox(vmime::make_shared <vmime::mailbox>("recipient3@test.vmime.org"));
|
2006-05-05 20:50:26 +00:00
|
|
|
|
|
|
|
vmime::string data("Message data");
|
|
|
|
vmime::utility::inputStreamStringAdapter is(data);
|
|
|
|
|
|
|
|
tr->send(exp, recips, is, 0);
|
|
|
|
}
|
|
|
|
|
2013-06-20 09:02:39 +00:00
|
|
|
void testChunking()
|
|
|
|
{
|
2016-04-05 20:11:47 +00:00
|
|
|
vmime::shared_ptr <vmime::net::session> session = vmime::net::session::create();
|
2013-06-20 09:02:39 +00:00
|
|
|
|
2013-11-21 21:16:57 +00:00
|
|
|
vmime::shared_ptr <vmime::net::transport> tr = session->getTransport
|
2013-06-20 09:02:39 +00:00
|
|
|
(vmime::utility::url("smtp://localhost"));
|
|
|
|
|
2013-11-21 21:16:57 +00:00
|
|
|
tr->setSocketFactory(vmime::make_shared <testSocketFactory <chunkingSMTPTestSocket> >());
|
|
|
|
tr->setTimeoutHandlerFactory(vmime::make_shared <testTimeoutHandlerFactory>());
|
2013-06-20 09:02:39 +00:00
|
|
|
|
|
|
|
tr->connect();
|
|
|
|
|
|
|
|
VASSERT("Test server should report it supports the CHUNKING extension!",
|
2013-11-21 21:16:57 +00:00
|
|
|
vmime::dynamicCast <vmime::net::smtp::SMTPTransport>(tr)->getConnection()->hasExtension("CHUNKING"));
|
2013-06-20 09:02:39 +00:00
|
|
|
|
|
|
|
vmime::mailbox exp("expeditor@test.vmime.org");
|
|
|
|
|
|
|
|
vmime::mailboxList recips;
|
2013-11-21 21:16:57 +00:00
|
|
|
recips.appendMailbox(vmime::make_shared <vmime::mailbox>("recipient@test.vmime.org"));
|
2013-06-20 09:02:39 +00:00
|
|
|
|
2013-11-21 21:16:57 +00:00
|
|
|
vmime::shared_ptr <vmime::message> msg = vmime::make_shared <SMTPTestMessage>();
|
2013-06-20 09:02:39 +00:00
|
|
|
|
|
|
|
tr->send(msg, exp, recips);
|
|
|
|
}
|
|
|
|
|
2013-06-24 13:32:40 +00:00
|
|
|
void testSize_Chunking()
|
2006-05-05 20:50:26 +00:00
|
|
|
{
|
2016-04-05 20:11:47 +00:00
|
|
|
vmime::shared_ptr <vmime::net::session> session = vmime::net::session::create();
|
2013-06-20 09:02:39 +00:00
|
|
|
|
2013-11-21 21:16:57 +00:00
|
|
|
vmime::shared_ptr <vmime::net::transport> tr = session->getTransport
|
2013-06-24 13:32:40 +00:00
|
|
|
(vmime::utility::url("smtp://localhost"));
|
2013-06-20 09:02:39 +00:00
|
|
|
|
2013-11-21 21:16:57 +00:00
|
|
|
tr->setSocketFactory(vmime::make_shared <testSocketFactory <bigMessageSMTPTestSocket <true> > >());
|
|
|
|
tr->setTimeoutHandlerFactory(vmime::make_shared <testTimeoutHandlerFactory>());
|
2013-06-20 09:02:39 +00:00
|
|
|
|
2013-06-24 13:32:40 +00:00
|
|
|
tr->connect();
|
2013-06-20 09:02:39 +00:00
|
|
|
|
2013-06-24 13:32:40 +00:00
|
|
|
VASSERT("Test server should report it supports the SIZE extension!",
|
2013-11-21 21:16:57 +00:00
|
|
|
vmime::dynamicCast <vmime::net::smtp::SMTPTransport>(tr)->getConnection()->hasExtension("SIZE"));
|
2013-06-20 09:02:39 +00:00
|
|
|
|
2013-06-24 13:32:40 +00:00
|
|
|
vmime::mailbox exp("expeditor@test.vmime.org");
|
2013-06-20 09:02:39 +00:00
|
|
|
|
2013-06-24 13:32:40 +00:00
|
|
|
vmime::mailboxList recips;
|
2013-11-21 21:16:57 +00:00
|
|
|
recips.appendMailbox(vmime::make_shared <vmime::mailbox>("recipient@test.vmime.org"));
|
2013-06-20 09:02:39 +00:00
|
|
|
|
2013-11-21 21:16:57 +00:00
|
|
|
vmime::shared_ptr <vmime::message> msg = vmime::make_shared <SMTPBigTestMessage4MB>();
|
2013-06-20 09:02:39 +00:00
|
|
|
|
2013-06-24 13:32:40 +00:00
|
|
|
VASSERT_THROW("Connection", tr->send(msg, exp, recips),
|
2013-09-08 18:49:51 +00:00
|
|
|
vmime::net::smtp::SMTPMessageSizeExceedsMaxLimitsException);
|
2013-06-20 09:02:39 +00:00
|
|
|
}
|
|
|
|
|
2013-06-24 13:32:40 +00:00
|
|
|
void testSize_NoChunking()
|
2013-06-20 09:02:39 +00:00
|
|
|
{
|
2016-04-05 20:11:47 +00:00
|
|
|
vmime::shared_ptr <vmime::net::session> session = vmime::net::session::create();
|
2013-06-20 09:02:39 +00:00
|
|
|
|
2013-11-21 21:16:57 +00:00
|
|
|
vmime::shared_ptr <vmime::net::transport> tr = session->getTransport
|
2013-06-24 13:32:40 +00:00
|
|
|
(vmime::utility::url("smtp://localhost"));
|
2013-06-20 09:02:39 +00:00
|
|
|
|
2013-11-21 21:16:57 +00:00
|
|
|
tr->setSocketFactory(vmime::make_shared <testSocketFactory <bigMessageSMTPTestSocket <false> > >());
|
|
|
|
tr->setTimeoutHandlerFactory(vmime::make_shared <testTimeoutHandlerFactory>());
|
2013-06-20 09:02:39 +00:00
|
|
|
|
2013-06-24 13:32:40 +00:00
|
|
|
tr->connect();
|
2013-06-20 09:02:39 +00:00
|
|
|
|
2013-06-24 13:32:40 +00:00
|
|
|
VASSERT("Test server should report it supports the SIZE extension!",
|
2013-11-21 21:16:57 +00:00
|
|
|
vmime::dynamicCast <vmime::net::smtp::SMTPTransport>(tr)->getConnection()->hasExtension("SIZE"));
|
2013-06-20 09:02:39 +00:00
|
|
|
|
2013-06-24 13:32:40 +00:00
|
|
|
vmime::mailbox exp("expeditor@test.vmime.org");
|
2013-06-20 09:02:39 +00:00
|
|
|
|
2013-06-24 13:32:40 +00:00
|
|
|
vmime::mailboxList recips;
|
2013-11-21 21:16:57 +00:00
|
|
|
recips.appendMailbox(vmime::make_shared <vmime::mailbox>("recipient@test.vmime.org"));
|
2013-06-20 09:02:39 +00:00
|
|
|
|
2013-11-21 21:16:57 +00:00
|
|
|
vmime::shared_ptr <vmime::message> msg = vmime::make_shared <SMTPBigTestMessage4MB>();
|
2013-06-20 09:02:39 +00:00
|
|
|
|
2013-06-24 13:32:40 +00:00
|
|
|
VASSERT_THROW("Connection", tr->send(msg, exp, recips),
|
2013-09-08 18:49:51 +00:00
|
|
|
vmime::net::smtp::SMTPMessageSizeExceedsMaxLimitsException);
|
2013-06-20 09:02:39 +00:00
|
|
|
}
|
2006-05-05 20:50:26 +00:00
|
|
|
|
2013-06-24 13:32:40 +00:00
|
|
|
VMIME_TEST_SUITE_END
|
2006-05-05 20:50:26 +00:00
|
|
|
|