def test_data_connectionlost(self): self.sock.sendall('220 ESMTP server\r\n') self.sock.recv(IsA(int)).AndReturn('DATA\r\n') self.sock.sendall('354 Start mail input; end with <CRLF>.<CRLF>\r\n') self.sock.recv(IsA(int)).AndReturn('') self.mox.ReplayAll() s = Server(self.sock, None) s.ehlo_as = 'test' s.have_mailfrom = True s.have_rcptto = True assert_raises(ConnectionLost, s.handle)
def test_data_connectionlost(self): self.sock.sendall(b'220 ESMTP server\r\n') self.sock.recv(IsA(int)).AndReturn(b'DATA\r\n') self.sock.sendall(b'354 Start mail input; end with <CRLF>.<CRLF>\r\n') self.sock.recv(IsA(int)).AndReturn(b'') self.mox.ReplayAll() s = Server(self.sock, None) s.ehlo_as = b'test' s.have_mailfrom = True s.have_rcptto = True self.assertRaises(ConnectionLost, s.handle)
def test_data_bad(self): self.sock.sendall(b'220 ESMTP server\r\n') self.sock.recv(IsA(int)).AndReturn(b'DATA arg\r\n') self.sock.sendall(b'501 5.5.4 Syntax error in parameters or arguments\r\n') self.sock.recv(IsA(int)).AndReturn(b'DATA\r\n') self.sock.sendall(b'503 5.5.1 Bad sequence of commands\r\n') self.sock.recv(IsA(int)).AndReturn(b'QUIT\r\n') self.sock.sendall(b'221 2.0.0 Bye\r\n') self.mox.ReplayAll() s = Server(self.sock, None) s.ehlo_as = b'test' s.have_mailfrom = True s.handle()
def test_data(self): self.sock.sendall(b'220 ESMTP server\r\n') self.sock.recv(IsA(int)).AndReturn(b'DATA\r\n') self.sock.sendall(b'354 Start mail input; end with <CRLF>.<CRLF>\r\n') self.sock.recv(IsA(int)).AndReturn(b'.\r\nQUIT\r\n') self.sock.sendall(b'250 2.6.0 Message accepted for delivery\r\n') self.sock.sendall(b'221 2.0.0 Bye\r\n') self.mox.ReplayAll() s = Server(self.sock, None) s.ehlo_as = b'test' s.have_mailfrom = True s.have_rcptto = True s.handle()
def test_data_bad(self): self.sock.sendall('220 ESMTP server\r\n') self.sock.recv(IsA(int)).AndReturn('DATA arg\r\n') self.sock.sendall('501 5.5.4 Syntax error in parameters or arguments\r\n') self.sock.recv(IsA(int)).AndReturn('DATA\r\n') self.sock.sendall('503 5.5.1 Bad sequence of commands\r\n') self.sock.recv(IsA(int)).AndReturn('QUIT\r\n') self.sock.sendall('221 2.0.0 Bye\r\n') self.mox.ReplayAll() s = Server(self.sock, None) s.ehlo_as = 'test' s.have_mailfrom = True s.handle()
def test_data(self): self.sock.sendall('220 ESMTP server\r\n') self.sock.recv(IsA(int)).AndReturn('DATA\r\n') self.sock.sendall('354 Start mail input; end with <CRLF>.<CRLF>\r\n') self.sock.recv(IsA(int)).AndReturn('.\r\nQUIT\r\n') self.sock.sendall('250 2.6.0 Message Accepted for Delivery\r\n') self.sock.sendall('221 2.0.0 Bye\r\n') self.mox.ReplayAll() s = Server(self.sock, None) s.ehlo_as = 'test' s.have_mailfrom = True s.have_rcptto = True s.handle()
def test_rcptto(self): self.sock.sendall(b'220 ESMTP server\r\n') self.sock.recv(IsA(int)).AndReturn(b'RCPT TO:<test">"addr>\r\n') self.sock.sendall(b'250 2.1.5 Recipient <test">"addr> Ok\r\n') self.sock.recv(IsA(int)).AndReturn(b'RCPT TO:<test2>\r\n') self.sock.sendall(b'250 2.1.5 Recipient <test2> Ok\r\n') self.sock.recv(IsA(int)).AndReturn(b'QUIT\r\n') self.sock.sendall(b'221 2.0.0 Bye\r\n') self.mox.ReplayAll() s = Server(self.sock, None) s.ehlo_as = b'test' s.have_mailfrom = True s.handle() self.assertTrue(s.have_rcptto)
def test_rcptto(self): self.sock.sendall('220 ESMTP server\r\n') self.sock.recv(IsA(int)).AndReturn('RCPT TO:<test">"addr>\r\n') self.sock.sendall('250 2.1.5 Recipient <test">"addr> Ok\r\n') self.sock.recv(IsA(int)).AndReturn('RCPT TO:<test2>\r\n') self.sock.sendall('250 2.1.5 Recipient <test2> Ok\r\n') self.sock.recv(IsA(int)).AndReturn('QUIT\r\n') self.sock.sendall('221 2.0.0 Bye\r\n') self.mox.ReplayAll() s = Server(self.sock, None) s.ehlo_as = 'test' s.have_mailfrom = True s.handle() assert_true(s.have_rcptto)
def test_custom_command(self): class TestHandlers(object): def TEST(self2, reply, arg, server): self.assertTrue(server.have_mailfrom) reply.code = '250' reply.message = 'Doing '+arg.decode() self.sock.sendall(b'220 ESMTP server\r\n') self.sock.recv(IsA(int)).AndReturn(b'TEST stuff\r\n') self.sock.sendall(b'250 2.0.0 Doing stuff\r\n') self.sock.recv(IsA(int)).AndReturn(b'QUIT\r\n') self.sock.sendall(b'221 2.0.0 Bye\r\n') self.mox.ReplayAll() s = Server(self.sock, TestHandlers()) s.have_mailfrom = True s.handle()
def test_custom_command(self): class TestHandlers(object): def TEST(self2, reply, arg, server): assert_true(server.have_mailfrom) reply.code = '250' reply.message = 'Doing '+arg self.sock.sendall('220 ESMTP server\r\n') self.sock.recv(IsA(int)).AndReturn('TEST stuff\r\n') self.sock.sendall('250 2.0.0 Doing stuff\r\n') self.sock.recv(IsA(int)).AndReturn('QUIT\r\n') self.sock.sendall('221 2.0.0 Bye\r\n') self.mox.ReplayAll() s = Server(self.sock, TestHandlers()) s.have_mailfrom = True s.handle()