def test_starttls(self): sock = self.mox.CreateMockAnything() sock.fileno = lambda: -1 def socket_creator(address): return sock sock.sendall("STARTTLS\r\n") sock.recv(IsA(int)).AndReturn("220 Go ahead\r\n") sock.tls_wrapper(sock, self.tls_args).AndReturn(sock) sock.sendall("STARTTLS\r\n") sock.recv(IsA(int)).AndReturn("420 Stop\r\n") self.mox.ReplayAll() client = SmtpRelayClient( None, self.queue, socket_creator=socket_creator, tls=self.tls_args, tls_wrapper=sock.tls_wrapper, tls_required=True, ) client._connect() client._starttls() with self.assertRaises(TransientRelayError): client._starttls()
def test_starttls(self): self.sock.sendall(b'STARTTLS\r\n') self.sock.recv(IsA(int)).AndReturn(b'220 Go ahead\r\n') self.context.wrap_socket(self.sock, server_hostname='addr').AndReturn(self.sock) self.sock.sendall(b'STARTTLS\r\n') self.sock.recv(IsA(int)).AndReturn(b'420 Stop\r\n') self.mox.ReplayAll() client = SmtpRelayClient(('addr', 0), self.queue, socket_creator=self._socket_creator, context=self.context, tls_required=True) client._connect() client._starttls() with self.assertRaises(TransientRelayError): client._starttls()
def test_starttls(self): tls_wrapper = self.mox.CreateMockAnything() self.sock.sendall(b'STARTTLS\r\n') self.sock.recv(IsA(int)).AndReturn(b'220 Go ahead\r\n') tls_wrapper(self.sock, self.tls_args).AndReturn(self.sock) self.sock.sendall(b'STARTTLS\r\n') self.sock.recv(IsA(int)).AndReturn(b'420 Stop\r\n') self.mox.ReplayAll() client = SmtpRelayClient('addr', self.queue, socket_creator=self._socket_creator, tls=self.tls_args, tls_wrapper=tls_wrapper, tls_required=True) client._connect() client._starttls() with self.assertRaises(TransientRelayError): client._starttls()
def test_starttls(self): sock = self.mox.CreateMockAnything() sock.fileno = lambda: -1 def socket_creator(address): return sock sock.sendall('STARTTLS\r\n') sock.recv(IsA(int)).AndReturn('220 Go ahead\r\n') sock.tls_wrapper(sock, self.tls_args).AndReturn(sock) sock.sendall('STARTTLS\r\n') sock.recv(IsA(int)).AndReturn('420 Stop\r\n') self.mox.ReplayAll() client = SmtpRelayClient(None, self.queue, socket_creator=socket_creator, tls=self.tls_args, tls_wrapper=sock.tls_wrapper, tls_required=True) client._connect() client._starttls() with self.assertRaises(TransientRelayError): client._starttls()
def test_starttls(self): self.sock.sendall(b'STARTTLS\r\n') self.sock.recv(IsA(int)).AndReturn(b'220 Go ahead\r\n') self.context.wrap_socket(self.sock, server_hostname='addr').AndReturn(self.sock) self.sock.sendall(b'STARTTLS\r\n') self.sock.recv(IsA(int)).AndReturn(b'420 Stop\r\n') self.mox.ReplayAll() client = SmtpRelayClient(('addr', 0), self.queue, socket_creator=self._socket_creator, context=self.context, tls_required=True) client._connect() client._starttls() with self.assertRaises(TransientRelayError): client._starttls()
def test_starttls(self): tls_wrapper = self.mox.CreateMockAnything() self.sock.sendall(b'STARTTLS\r\n') self.sock.recv(IsA(int)).AndReturn(b'220 Go ahead\r\n') tls_wrapper(self.sock, self.tls_args).AndReturn(self.sock) self.sock.sendall(b'STARTTLS\r\n') self.sock.recv(IsA(int)).AndReturn(b'420 Stop\r\n') self.mox.ReplayAll() client = SmtpRelayClient('addr', self.queue, socket_creator=self._socket_creator, tls=self.tls_args, tls_wrapper=tls_wrapper, tls_required=True) client._connect() client._starttls() with self.assertRaises(TransientRelayError): client._starttls()