Ejemplo n.º 1
0
    def test_auth_plain_with_bad_credentials_is_rejected(self):
        self.session._authenticator = DummyAuthenticator()

        self.send('EHLO', 'foo.example.com')
        base64_credentials = b64encode('\x00foo\x00bar')
        self.send('AUTH PLAIN', base64_credentials, expected_first_digit=5)
        self._check_last_code(535)
Ejemplo n.º 2
0
    def test_auth_plain_with_bad_base64_is_rejected(self):
        self.session._authenticator = DummyAuthenticator()

        self.send('EHLO', 'foo.example.com')
        self.send('AUTH PLAIN', 'foo', expected_first_digit=5)
        assert_length(3, self.command_parser.replies)
        self._check_last_code(501)
Ejemplo n.º 3
0
 def test_parse_auth_login_with_username(self):
     self.parser = self.init_command_parser(
         authenticator=DummyAuthenticator())
     self.send('EHLO foo\r\n')
     self.send('AUTH LOGIN %s\r\n' % b64encode('foo'))
     self.send('%s\r\n' % b64encode('secret'))
     self.send('MAIL FROM: [email protected]\r\n')
Ejemplo n.º 4
0
    def test_auth_login_3step(self):
        self.session._authenticator = DummyAuthenticator()

        self.send('EHLO', 'foo.example.com')
        self.send_auth_login(username='******',
                             password='******',
                             reduce_roundtrips=False)
        assert_equals((235, 'Authentication successful'), self.last_reply())
Ejemplo n.º 5
0
    def test_auth_login_can_be_rejected(self):
        class FalsePolicy(IMTAPolicy):
            def accept_auth_login(self, username, message):
                return False

        self.init(policy=FalsePolicy(), authenticator=DummyAuthenticator())
        self.send('EHLO', 'foo.example.com')
        self.send('AUTH LOGIN', expected_first_digit=5)
Ejemplo n.º 6
0
    def test_auth_plain_with_username_and_password_is_accepted(self):
        self.session._authenticator = DummyAuthenticator()

        self.send('EHLO', 'foo.example.com')
        self.send('AUTH PLAIN', b64encode('\x00foo\x00foo'))
        assert_length(3, self.command_parser.replies)
        self._check_last_code(235)
        code, reply_text = self.last_reply()
        assert_equals('Authentication successful', reply_text)
Ejemplo n.º 7
0
    def test_auth_plain_can_be_rejected(self):
        class FalsePolicy(IMTAPolicy):
            def accept_auth_plain(self, username, password, message):
                return False

        self.init(policy=FalsePolicy(), authenticator=DummyAuthenticator())
        self.send('EHLO', 'foo.example.com')
        base64_credentials = b64encode('\x00foo\x00foo')
        self.send('AUTH PLAIN', base64_credentials, expected_first_digit=5)
Ejemplo n.º 8
0
    def test_auth_plain_with_authzid_username_and_password_is_accepted(self):
        self.session._authenticator = DummyAuthenticator()

        self.send('EHLO', 'foo.example.com')
        # RFC 4616 defines SASL PLAIN in the form
        # [authzid] \x00 authcid \x00 passwd
        # smtplib in Python 2.3 will send an additional authzid (which is equal
        # to authcid)
        self.send('AUTH PLAIN', b64encode('ignored\x00foo\x00foo'))
        assert_length(3, self.command_parser.replies)
        self._check_last_code(235)
        code, reply_text = self.last_reply()
        assert_equals('Authentication successful', reply_text)
Ejemplo n.º 9
0
    def test_auth_login_with_bad_base64_password_is_rejected(self):
        self.session._authenticator = DummyAuthenticator()

        self.send('EHLO', 'foo.example.com')
        self.send_auth_login(username='******', password_b64='foo')
        self._check_last_code(501)

        # state machine should switch back to normal command mode
        code, reply_text = self._handle_auth_credentials('foo')
        assert_equals(
            501,
            code,
            message='need to retart AUTH LOGIN, not just send password again')
        self.send_auth_login(username='******', password='******')
        assert_equals((235, 'Authentication successful'), self.last_reply())
    def test_can_use_smtp_auth(self, auth_type):
        class AuthPolicy(IMTAPolicy):
            def auth_methods(self, peer):
                return (auth_type, )

        socket_mock = SocketMock(policy=AuthPolicy(),
                                 authenticator=DummyAuthenticator())

        fake_client = fake_smtp_client(socket_mock=socket_mock)
        mailer = SMTPMailer(client=fake_client, username='******', password='******')
        message = b'Header: value\n\nbody\n'
        msg_was_sent = mailer.send('*****@*****.**', '*****@*****.**',
                                   message)

        assert_true(msg_was_sent)
        received_queue = fake_client.server.received_messages
        assert_equals(1, received_queue.qsize())
Ejemplo n.º 11
0
    def test_auth_login_with_bad_base64_username_is_rejected(self):
        self.session._authenticator = DummyAuthenticator()

        self.send('EHLO', 'foo.example.com')
        self.send_auth_login(username_b64='foo', password='******')
        self._check_last_code(501)
Ejemplo n.º 12
0
    def test_auth_login_with_bad_credentials_is_rejected(self):
        self.session._authenticator = DummyAuthenticator()

        self.send('EHLO', 'foo.example.com')
        self.send_auth_login(username='******', password='******')
        self._check_last_code(535)
Ejemplo n.º 13
0
    def test_auth_login_with_username_and_password_is_accepted(self):
        self.session._authenticator = DummyAuthenticator()

        self.send('EHLO', 'foo.example.com')
        self.send_auth_login(username='******', password='******')
        assert_equals((235, 'Authentication successful'), self.last_reply())
Ejemplo n.º 14
0
    def test_authenticator_advertises_auth_plain_support(self):
        self.session._authenticator = DummyAuthenticator()

        self.send('EHLO', 'foo.example.com')
        code, reply_texts = self.last_reply()
        assert_contains('AUTH PLAIN', reply_texts)