Exemple #1
0
    def test_incompleteUsername(self):
        """
        Test that a login attempt using a username without a domain part
        results in a customized authentication failure message which points
        out that a domain part should be included in the username.
        """
        mta = mail.MailTransferAgent(store=self.store)
        installOn(mta, self.store)
        factory = mta.getFactory()
        protocol = factory.buildProtocol(("192.168.1.1", 12345))
        transport = StringTransport()
        transport.getHost = lambda: IPv4Address("TCP", "192.168.1.1", 54321)
        transport.getPeer = lambda: IPv4Address("TCP", "192.168.1.1", 12345)
        protocol.makeConnection(transport)
        protocol.dataReceived("EHLO example.net\r\n")
        protocol.dataReceived("AUTH LOGIN\r\n")
        protocol.dataReceived("testuser".encode("base64") + "\r\n")
        transport.clear()
        protocol.dataReceived("password".encode("base64") + "\r\n")
        written = transport.value()
        protocol.connectionLost(failure.Failure(error.ConnectionDone()))

        self.assertEquals(
            written,
            "535 Authentication failure [Username without domain name (ie "
            '"yourname" instead of "yourname@yourdomain") not allowed; try '
            "with a domain name.]\r\n",
        )
class MockClient(Client):
            
    factory = MockFactory()
    
    def __init__(self):
        Client.__init__(self)
        self.transport = StringTransport()
        self.makeConnection(self.transport)
        
    def connectionMade(self):
        self.host = self.transport.getHost().host
        self.server_host = 'testing_srv'
        
    def dataReceived(self, data):
        LineOnlyReceiver.dataReceived(self, data)
    
    def t_get_data(self):
        return self.transport.value()
    
    def t_flush_data(self):
        self.transport.clear()
        
    def t_send_lines(self, *lines):
        lines = '\n'.join(lines) 
        self.dataReceived(lines + '\n')
        
    def t_send_line(self, line):
        self.dataReceived(line + '\n')

        
Exemple #3
0
    def test_incompleteUsername(self):
        """
        Test that a login attempt using a username without a domain part
        results in a customized authentication failure message which points
        out that a domain part should be included in the username.
        """
        mta = mail.MailTransferAgent(store=self.store)
        installOn(mta, self.store)
        factory = mta.getFactory()
        protocol = factory.buildProtocol(('192.168.1.1', 12345))
        transport = StringTransport()
        transport.getHost = lambda: IPv4Address('TCP', '192.168.1.1', 54321)
        transport.getPeer = lambda: IPv4Address('TCP', '192.168.1.1', 12345)
        protocol.makeConnection(transport)
        protocol.dataReceived('EHLO example.net\r\n')
        protocol.dataReceived('AUTH LOGIN\r\n')
        protocol.dataReceived('testuser'.encode('base64') + '\r\n')
        transport.clear()
        protocol.dataReceived('password'.encode('base64') + '\r\n')
        written = transport.value()
        protocol.connectionLost(failure.Failure(error.ConnectionDone()))

        self.assertEquals(
            written,
            '535 Authentication failure [Username without domain name (ie '
            '"yourname" instead of "yourname@yourdomain") not allowed; try '
            'with a domain name.]\r\n')