diff --git a/modoboa/admin/tests/test_account.py b/modoboa/admin/tests/test_account.py index f1d3114e9..016c740b2 100644 --- a/modoboa/admin/tests/test_account.py +++ b/modoboa/admin/tests/test_account.py @@ -18,6 +18,31 @@ from .. import factories from .. import models +class AuthenticationTestCase(ModoTestCase): + """Check authentication.""" + + @classmethod + def setUpTestData(cls): + """Create test data.""" + super(AuthenticationTestCase, cls).setUpTestData() + cls.mb = factories.MailboxFactory( + domain__name="test.com", address="user", + user__username="user@test.com", + user__groups=('SimpleUsers',) + ) + + def test_authentication_unicode(self): + """Test with unicode password.""" + self.client.logout() + password = "Tété1234" + self.mb.user.set_password(password) + self.mb.user.save(update_fields=["password"]) + data = {"username": self.mb.full_address, "password": password} + response = self.client.post(reverse("core:login"), data) + self.assertEqual(response.status_code, 302) + self.assertTrue(response.url.endswith(reverse("core:user_index"))) + + class AccountTestCase(ModoTestCase): @classmethod diff --git a/modoboa/core/tests/test_authentication.py b/modoboa/core/tests/test_authentication.py index 0575a88aa..4b05d4219 100644 --- a/modoboa/core/tests/test_authentication.py +++ b/modoboa/core/tests/test_authentication.py @@ -1,3 +1,5 @@ +# coding: utf8 + """Tests for core application.""" from __future__ import unicode_literals diff --git a/modoboa/lib/cryptutils.py b/modoboa/lib/cryptutils.py index 758a75052..d7f25c5ca 100644 --- a/modoboa/lib/cryptutils.py +++ b/modoboa/lib/cryptutils.py @@ -36,9 +36,10 @@ def encrypt(clear): cipher = Cipher(algorithms.AES(key), modes.ECB(), backend=backend) encryptor = cipher.encryptor() block_size = algorithms.AES.block_size + clear = force_bytes(clear) if len(clear) % block_size: - clear += " " * (block_size - len(clear) % block_size) - ct = encryptor.update(force_bytes(clear)) + encryptor.finalize() + clear += b" " * (block_size - len(clear) % block_size) + ct = encryptor.update(clear) + encryptor.finalize() return force_text(base64.b64encode(ct))