1
1
# Copyright 2010 Canonical Ltd. This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
5
from datetime import date, datetime, time, timedelta
5
6
from uuid import uuid4
12
13
from django.test import TestCase
13
14
from django.test.utils import override_settings
16
from identityprovider import utils
15
17
from identityprovider.models.person import Person
16
18
from identityprovider.utils import (
266
268
request = self.factory.make_request(**kwargs)
267
269
with self.assertRaises(SuspiciousOperation):
268
270
get_provider_url(request)
273
class BlacklistedPasswordTestCase(TestCase):
275
@override_settings(PASSWORD_BLACKLIST_FILE="bl_test_filename")
276
def test_populate_password_blacklist(self):
277
raw_pass_data = ("cthulhu50\nr'lyeh25\ndunwich600\nDunWich600"
278
"\n\r \r\n e \nCthulhu50")
279
with open(settings.PASSWORD_BLACKLIST_FILE, "w") as bl_file:
280
self.addCleanup(os.unlink, settings.PASSWORD_BLACKLIST_FILE)
281
bl_file.write(raw_pass_data)
282
expected_passwords = {
283
'cthulhu50', "r'lyeh25", 'dunwich600', ' ', ' e '}
284
utils.populate_password_blacklist()
285
self.assertEqual(utils.get_password_blacklist(),
288
def test_password_is_not_blacklisted(self):
289
utils.blackted_password_set = set(['bogus', 'blacklist'])
290
self.assertFalse(utils.password_is_blacklisted('goodpass'))
292
def test_password_is_blacklisted(self):
293
utils.blacklisted_password_set = set(['bogus', 'blacklist'])
294
self.assertTrue(utils.password_is_blacklisted('blacklist'))
296
def test_password_is_blacklisted_variable_case(self):
297
utils.blacklisted_password_set = set(['bogus', 'blacklist'])
298
self.assertTrue(utils.password_is_blacklisted('BlackList'))