コード例 #1
0
    def test_handshake_starttls(self):
        sock = self.mox.CreateMockAnything()
        sock.fileno = lambda: -1

        def socket_creator(address):
            return sock

        sock.recv(IsA(int)).AndReturn("220 Welcome\r\n")
        sock.sendall("EHLO test\r\n")
        sock.recv(IsA(int)).AndReturn("250-Hello\r\n250 STARTTLS\r\n")
        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("EHLO test\r\n")
        sock.recv(IsA(int)).AndReturn("250 Hello\r\n")
        self.mox.ReplayAll()
        client = SmtpRelayClient(
            None,
            self.queue,
            socket_creator=socket_creator,
            tls=self.tls_args,
            tls_wrapper=sock.tls_wrapper,
            ehlo_as="test",
        )
        client._connect()
        client._handshake()
コード例 #2
0
    def test_handshake_authenticate_callable(self):
        sock = self.mox.CreateMockAnything()
        sock.fileno = lambda: -1

        def socket_creator(address):
            return sock

        sock.recv(IsA(int)).AndReturn(b'220 Welcome\r\n')
        sock.sendall(b'EHLO test\r\n')
        sock.recv(IsA(int)).AndReturn(b'250-Hello\r\n250 AUTH PLAIN\r\n')
        sock.sendall(b'AUTH PLAIN AHRlc3RAZXhhbXBsZS5jb20AcGFzc3dk\r\n')
        sock.recv(IsA(int)).AndReturn(b'235 Ok\r\n')
        self.mox.ReplayAll()

        def yield_creds():
            yield '*****@*****.**'
            yield 'passwd'

        client = SmtpRelayClient('addr',
                                 self.queue,
                                 socket_creator=socket_creator,
                                 credentials=yield_creds,
                                 ehlo_as='test')
        client._connect()
        client._handshake()
コード例 #3
0
 def test_handshake_tls_immediately(self):
     self.context.wrap_socket(self.sock, server_hostname='addr').AndReturn(self.sock)
     self.sock.recv(IsA(int)).AndReturn(b'220 Welcome\r\n')
     self.sock.sendall(b'EHLO there\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250 Hello\r\n')
     self.mox.ReplayAll()
     client = SmtpRelayClient(('addr', 0), self.queue, socket_creator=self._socket_creator, context=self.context, tls_immediately=True, ehlo_as='there')
     client._connect()
     client._handshake()
コード例 #4
0
 def test_handshake_authenticate(self):
     self.sock.recv(IsA(int)).AndReturn(b'220 Welcome\r\n')
     self.sock.sendall(b'EHLO there\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250-Hello\r\n250 AUTH PLAIN\r\n')
     self.sock.sendall(b'AUTH PLAIN AHRlc3RAZXhhbXBsZS5jb20AcGFzc3dk\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'235 Ok\r\n')
     self.mox.ReplayAll()
     client = SmtpRelayClient(('addr', 0), self.queue, socket_creator=self._socket_creator, credentials=('*****@*****.**', 'passwd'), ehlo_as='there')
     client._connect()
     client._handshake()
コード例 #5
0
 def test_handshake_tls_immediately(self):
     tls_wrapper = self.mox.CreateMockAnything()
     tls_wrapper(self.sock, self.tls_args).AndReturn(self.sock)
     self.sock.recv(IsA(int)).AndReturn(b'220 Welcome\r\n')
     self.sock.sendall(b'EHLO there\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250 Hello\r\n')
     self.mox.ReplayAll()
     client = SmtpRelayClient('addr', self.queue, socket_creator=self._socket_creator, tls=self.tls_args, tls_wrapper=tls_wrapper, tls_immediately=True, ehlo_as='there')
     client._connect()
     client._handshake()
コード例 #6
0
 def test_handshake_authenticate_badcreds(self):
     self.sock.recv(IsA(int)).AndReturn(b'220 Welcome\r\n')
     self.sock.sendall(b'EHLO there\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250-Hello\r\n250 AUTH PLAIN\r\n')
     self.sock.sendall(b'AUTH PLAIN AHRlc3RAZXhhbXBsZS5jb20AcGFzc3dk\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'535 Nope!\r\n')
     self.mox.ReplayAll()
     client = SmtpRelayClient(('addr', 0), self.queue, socket_creator=self._socket_creator, credentials=('*****@*****.**', 'passwd'), ehlo_as='there', auth_mechanism=b'PLAIN')
     client._connect()
     with self.assertRaises(PermanentRelayError):
         client._handshake()
コード例 #7
0
 def test_handshake_tls_immediately(self):
     sock = self.mox.CreateMockAnything()
     sock.fileno = lambda: -1
     def socket_creator(address):
         return sock
     sock.tls_wrapper(sock, self.tls_args).AndReturn(sock)
     sock.recv(IsA(int)).AndReturn(b'220 Welcome\r\n')
     sock.sendall(b'EHLO test\r\n')
     sock.recv(IsA(int)).AndReturn(b'250 Hello\r\n')
     self.mox.ReplayAll()
     client = SmtpRelayClient('addr', self.queue, socket_creator=socket_creator, tls=self.tls_args, tls_wrapper=sock.tls_wrapper, tls_immediately=True, ehlo_as='test')
     client._connect()
     client._handshake()
コード例 #8
0
 def test_handshake_tls_immediately(self):
     sock = self.mox.CreateMockAnything()
     sock.fileno = lambda: -1
     def socket_creator(address):
         return sock
     sock.tls_wrapper(sock, self.tls_args).AndReturn(sock)
     sock.recv(IsA(int)).AndReturn('220 Welcome\r\n')
     sock.sendall('EHLO test\r\n')
     sock.recv(IsA(int)).AndReturn('250 Hello\r\n')
     self.mox.ReplayAll()
     client = SmtpRelayClient(None, self.queue, socket_creator=socket_creator, tls=self.tls_args, tls_wrapper=sock.tls_wrapper, tls_immediately=True, ehlo_as='test')
     client._connect()
     client._handshake()
コード例 #9
0
 def test_handshake_authenticate(self):
     sock = self.mox.CreateMockAnything()
     sock.fileno = lambda: -1
     def socket_creator(address):
         return sock
     sock.recv(IsA(int)).AndReturn(b'220 Welcome\r\n')
     sock.sendall(b'EHLO test\r\n')
     sock.recv(IsA(int)).AndReturn(b'250-Hello\r\n250 AUTH PLAIN\r\n')
     sock.sendall(b'AUTH PLAIN AHRlc3RAZXhhbXBsZS5jb20AcGFzc3dk\r\n')
     sock.recv(IsA(int)).AndReturn(b'235 Ok\r\n')
     self.mox.ReplayAll()
     client = SmtpRelayClient('addr', self.queue, socket_creator=socket_creator, credentials=('*****@*****.**', 'passwd'), ehlo_as='test')
     client._connect()
     client._handshake()
コード例 #10
0
 def test_handshake_authenticate(self):
     self.sock.recv(IsA(int)).AndReturn(b'220 Welcome\r\n')
     self.sock.sendall(b'EHLO there\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250-Hello\r\n250 AUTH PLAIN\r\n')
     self.sock.sendall(b'AUTH PLAIN AHRlc3RAZXhhbXBsZS5jb20AcGFzc3dk\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'235 Ok\r\n')
     self.mox.ReplayAll()
     client = SmtpRelayClient(('addr', 0),
                              self.queue,
                              socket_creator=self._socket_creator,
                              credentials=('*****@*****.**', 'passwd'),
                              ehlo_as='there')
     client._connect()
     client._handshake()
コード例 #11
0
 def test_handshake_tls_immediately(self):
     self.context.wrap_socket(self.sock,
                              server_hostname='addr').AndReturn(self.sock)
     self.sock.recv(IsA(int)).AndReturn(b'220 Welcome\r\n')
     self.sock.sendall(b'EHLO there\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250 Hello\r\n')
     self.mox.ReplayAll()
     client = SmtpRelayClient(('addr', 0),
                              self.queue,
                              socket_creator=self._socket_creator,
                              context=self.context,
                              tls_immediately=True,
                              ehlo_as='there')
     client._connect()
     client._handshake()
コード例 #12
0
 def test_handshake_authenticate_badcreds(self):
     sock = self.mox.CreateMockAnything()
     sock.fileno = lambda: -1
     def socket_creator(address):
         return sock
     sock.recv(IsA(int)).AndReturn('220 Welcome\r\n')
     sock.sendall('EHLO test\r\n')
     sock.recv(IsA(int)).AndReturn('250-Hello\r\n250 AUTH PLAIN\r\n')
     sock.sendall('AUTH PLAIN AHRlc3RAZXhhbXBsZS5jb20AcGFzc3dk\r\n')
     sock.recv(IsA(int)).AndReturn('535 Nope!\r\n')
     self.mox.ReplayAll()
     client = SmtpRelayClient(None, self.queue, socket_creator=socket_creator, credentials=('*****@*****.**', 'passwd'), ehlo_as='test')
     client._connect()
     with self.assertRaises(PermanentRelayError):
         client._handshake()
コード例 #13
0
 def test_handshake_authenticate_badcreds(self):
     self.sock.recv(IsA(int)).AndReturn(b'220 Welcome\r\n')
     self.sock.sendall(b'EHLO there\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250-Hello\r\n250 AUTH PLAIN\r\n')
     self.sock.sendall(b'AUTH PLAIN AHRlc3RAZXhhbXBsZS5jb20AcGFzc3dk\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'535 Nope!\r\n')
     self.mox.ReplayAll()
     client = SmtpRelayClient(('addr', 0),
                              self.queue,
                              socket_creator=self._socket_creator,
                              credentials=('*****@*****.**', 'passwd'),
                              ehlo_as='there',
                              auth_mechanism=b'PLAIN')
     client._connect()
     with self.assertRaises(PermanentRelayError):
         client._handshake()
コード例 #14
0
 def test_handshake_tls_immediately(self):
     tls_wrapper = self.mox.CreateMockAnything()
     tls_wrapper(self.sock, self.tls_args).AndReturn(self.sock)
     self.sock.recv(IsA(int)).AndReturn(b'220 Welcome\r\n')
     self.sock.sendall(b'EHLO there\r\n')
     self.sock.recv(IsA(int)).AndReturn(b'250 Hello\r\n')
     self.mox.ReplayAll()
     client = SmtpRelayClient('addr',
                              self.queue,
                              socket_creator=self._socket_creator,
                              tls=self.tls_args,
                              tls_wrapper=tls_wrapper,
                              tls_immediately=True,
                              ehlo_as='there')
     client._connect()
     client._handshake()
コード例 #15
0
    def test_handshake_authenticate_callable(self):
        sock = self.mox.CreateMockAnything()
        sock.fileno = lambda: -1

        def socket_creator(address):
            return sock

        sock.recv(IsA(int)).AndReturn("220 Welcome\r\n")
        sock.sendall("EHLO test\r\n")
        sock.recv(IsA(int)).AndReturn("250-Hello\r\n250 AUTH PLAIN\r\n")
        sock.sendall("AUTH PLAIN AHRlc3RAZXhhbXBsZS5jb20AcGFzc3dk\r\n")
        sock.recv(IsA(int)).AndReturn("235 Ok\r\n")
        self.mox.ReplayAll()

        def yield_creds():
            yield "*****@*****.**"
            yield "passwd"

        client = SmtpRelayClient(
            None, self.queue, socket_creator=socket_creator, credentials=yield_creds, ehlo_as="test"
        )
        client._connect()
        client._handshake()
コード例 #16
0
    def test_handshake_starttls(self):
        sock = self.mox.CreateMockAnything()
        sock.fileno = lambda: -1

        def socket_creator(address):
            return sock

        sock.recv(IsA(int)).AndReturn(b'220 Welcome\r\n')
        sock.sendall(b'EHLO test\r\n')
        sock.recv(IsA(int)).AndReturn(b'250-Hello\r\n250 STARTTLS\r\n')
        sock.sendall(b'STARTTLS\r\n')
        sock.recv(IsA(int)).AndReturn(b'220 Go ahead\r\n')
        sock.tls_wrapper(sock, self.tls_args).AndReturn(sock)
        sock.sendall(b'EHLO test\r\n')
        sock.recv(IsA(int)).AndReturn(b'250 Hello\r\n')
        self.mox.ReplayAll()
        client = SmtpRelayClient('addr',
                                 self.queue,
                                 socket_creator=socket_creator,
                                 tls=self.tls_args,
                                 tls_wrapper=sock.tls_wrapper,
                                 ehlo_as='test')
        client._connect()
        client._handshake()