comparison MoinMoin/support/passlib/tests/test_apps.py @ 6130:7f0616feeae9

upgrade passlib to 1.7.1, update CHANGES
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 11 Apr 2017 22:53:58 +0200
parents
children
comparison
equal deleted inserted replaced
6129:7f12cf241d5e 6130:7f0616feeae9
1 """test passlib.apps"""
2 #=============================================================================
3 # imports
4 #=============================================================================
5 from __future__ import with_statement
6 # core
7 import logging; log = logging.getLogger(__name__)
8 # site
9 # pkg
10 from passlib import apps, hash as hashmod
11 from passlib.tests.utils import TestCase
12 # module
13
14 #=============================================================================
15 # test predefined app contexts
16 #=============================================================================
17 class AppsTest(TestCase):
18 """perform general tests to make sure contexts work"""
19 # NOTE: these tests are not really comprehensive,
20 # since they would do little but duplicate
21 # the presets in apps.py
22 #
23 # they mainly try to ensure no typos
24 # or dynamic behavior foul-ups.
25
26 def test_master_context(self):
27 ctx = apps.master_context
28 self.assertGreater(len(ctx.schemes()), 50)
29
30 def test_custom_app_context(self):
31 ctx = apps.custom_app_context
32 self.assertEqual(ctx.schemes(), ("sha512_crypt", "sha256_crypt"))
33 for hash in [
34 ('$6$rounds=41128$VoQLvDjkaZ6L6BIE$4pt.1Ll1XdDYduEwEYPCMOBiR6W6'
35 'znsyUEoNlcVXpv2gKKIbQolgmTGe6uEEVJ7azUxuc8Tf7zV9SD2z7Ij751'),
36 ('$5$rounds=31817$iZGmlyBQ99JSB5n6$p4E.pdPBWx19OajgjLRiOW0itGny'
37 'xDGgMlDcOsfaI17'),
38 ]:
39 self.assertTrue(ctx.verify("test", hash))
40
41 def test_django16_context(self):
42 ctx = apps.django16_context
43 for hash in [
44 'pbkdf2_sha256$29000$ZsgquwnCyBs2$fBxRQpfKd2PIeMxtkKPy0h7SrnrN+EU/cm67aitoZ2s=',
45 'sha1$0d082$cdb462ae8b6be8784ef24b20778c4d0c82d5957f',
46 'md5$b887a$37767f8a745af10612ad44c80ff52e92',
47 'crypt$95a6d$95x74hLDQKXI2',
48 '098f6bcd4621d373cade4e832627b4f6',
49 ]:
50 self.assertTrue(ctx.verify("test", hash))
51
52 self.assertEqual(ctx.identify("!"), "django_disabled")
53 self.assertFalse(ctx.verify("test", "!"))
54
55 def test_django_context(self):
56 ctx = apps.django_context
57 for hash in [
58 'pbkdf2_sha256$29000$ZsgquwnCyBs2$fBxRQpfKd2PIeMxtkKPy0h7SrnrN+EU/cm67aitoZ2s=',
59 ]:
60 self.assertTrue(ctx.verify("test", hash))
61
62 self.assertEqual(ctx.identify("!"), "django_disabled")
63 self.assertFalse(ctx.verify("test", "!"))
64
65 def test_ldap_nocrypt_context(self):
66 ctx = apps.ldap_nocrypt_context
67 for hash in [
68 '{SSHA}cPusOzd6d5n3OjSVK3R329ZGCNyFcC7F',
69 'test',
70 ]:
71 self.assertTrue(ctx.verify("test", hash))
72
73 self.assertIs(ctx.identify('{CRYPT}$5$rounds=31817$iZGmlyBQ99JSB5'
74 'n6$p4E.pdPBWx19OajgjLRiOW0itGnyxDGgMlDcOsfaI17'), None)
75
76 def test_ldap_context(self):
77 ctx = apps.ldap_context
78 for hash in [
79 ('{CRYPT}$5$rounds=31817$iZGmlyBQ99JSB5n6$p4E.pdPBWx19OajgjLRiOW0'
80 'itGnyxDGgMlDcOsfaI17'),
81 '{SSHA}cPusOzd6d5n3OjSVK3R329ZGCNyFcC7F',
82 'test',
83 ]:
84 self.assertTrue(ctx.verify("test", hash))
85
86 def test_ldap_mysql_context(self):
87 ctx = apps.mysql_context
88 for hash in [
89 '*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29',
90 '378b243e220ca493',
91 ]:
92 self.assertTrue(ctx.verify("test", hash))
93
94 def test_postgres_context(self):
95 ctx = apps.postgres_context
96 hash = 'md55d9c68c6c50ed3d02a2fcf54f63993b6'
97 self.assertTrue(ctx.verify("test", hash, user='user'))
98
99 def test_phppass_context(self):
100 ctx = apps.phpass_context
101 for hash in [
102 '$P$8Ja1vJsKa5qyy/b3mCJGXM7GyBnt6..',
103 '$H$8b95CoYQnQ9Y6fSTsACyphNh5yoM02.',
104 '_cD..aBxeRhYFJvtUvsI',
105 ]:
106 self.assertTrue(ctx.verify("test", hash))
107
108 h1 = "$2a$04$yjDgE74RJkeqC0/1NheSSOrvKeu9IbKDpcQf/Ox3qsrRS/Kw42qIS"
109 if hashmod.bcrypt.has_backend():
110 self.assertTrue(ctx.verify("test", h1))
111 self.assertEqual(ctx.default_scheme(), "bcrypt")
112 self.assertEqual(ctx.handler().name, "bcrypt")
113 else:
114 self.assertEqual(ctx.identify(h1), "bcrypt")
115 self.assertEqual(ctx.default_scheme(), "phpass")
116 self.assertEqual(ctx.handler().name, "phpass")
117
118 def test_phpbb3_context(self):
119 ctx = apps.phpbb3_context
120 for hash in [
121 '$P$8Ja1vJsKa5qyy/b3mCJGXM7GyBnt6..',
122 '$H$8b95CoYQnQ9Y6fSTsACyphNh5yoM02.',
123 ]:
124 self.assertTrue(ctx.verify("test", hash))
125 self.assertTrue(ctx.hash("test").startswith("$H$"))
126
127 def test_roundup_context(self):
128 ctx = apps.roundup_context
129 for hash in [
130 '{PBKDF2}9849$JMTYu3eOUSoFYExprVVqbQ$N5.gV.uR1.BTgLSvi0qyPiRlGZ0',
131 '{SHA}a94a8fe5ccb19ba61c4c0873d391e987982fbbd3',
132 '{CRYPT}dptOmKDriOGfU',
133 '{plaintext}test',
134 ]:
135 self.assertTrue(ctx.verify("test", hash))
136
137 #=============================================================================
138 # eof
139 #=============================================================================