Skip to content

Commit

Permalink
A exception on request callback must to response as a Internal confus…
Browse files Browse the repository at this point in the history
…ion.
  • Loading branch information
puentesarrin committed Feb 8, 2014
1 parent cbb20cd commit d8fa27d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
2 changes: 1 addition & 1 deletion bonzo/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,5 +287,5 @@ def command_data(self, arg):

def _on_data(self, data):
message = email.message_from_string(data)
self.write("250 Ok")
self.request_callback(message)
self.write("250 Ok")
47 changes: 39 additions & 8 deletions tests/server_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@

from tornado.escape import utf8
from tornado.iostream import IOStream
from tornado.testing import LogTrapTestCase
from bonzo import version
from bonzo.testing import AsyncSMTPTestCase


def request_callback(message):
pass


class SMTPServerTest(AsyncSMTPTestCase):

def get_request_callback(self):
return request_callback
class BaseSMTPServerTest(AsyncSMTPTestCase):

def connect(self, read_response=True):
self.stream = IOStream(socket.socket(), io_loop=self.io_loop)
Expand All @@ -32,6 +26,16 @@ def close(self):
self.stream.close()
del self.stream


def request_callback(message):
pass


class SMTPConnectionTest(BaseSMTPServerTest):

def get_request_callback(self):
return request_callback

def test_welcome_connection(self):
self.connect(read_response=False)
data = self.read_response()
Expand Down Expand Up @@ -226,3 +230,30 @@ def test_data_with_arguments(self):
data = self.read_response()
self.assertEqual(data, b'501 Syntax: DATA\r\n')
self.close()


def request_callback_raises_exception(message):
raise Exception('This is a custom exception')


class SMTPServerTest(BaseSMTPServerTest, LogTrapTestCase):

def get_request_callback(self):
return request_callback_raises_exception

def test_internal_confusion(self):
self.connect()
self.stream.write(b'MAIL FROM:mail@example.com\r\n')
data = self.read_response()
self.assertEqual(data, b'250 Ok\r\n')
for address in ['mail@example.com', '<mail@example.com>']:
self.stream.write(utf8('RCPT TO:%s\r\n' % address))
data = self.read_response()
self.assertEqual(data, b'250 Ok\r\n')
self.stream.write(b'DATA\r\n')
data = self.read_response()
self.assertEqual(data, b'354 End data with <CR><LF>.<CR><LF>\r\n')
self.stream.write(b'This is a message\r\n.\r\n')
data = self.read_response()
self.assertEqual(data, b'451 Internal confusion\r\n')
self.close()

0 comments on commit d8fa27d

Please sign in to comment.