mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
@@ -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
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# coding: utf8
|
||||
|
||||
"""Tests for core application."""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
@@ -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))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user