Submit
Path:
~
/
/
usr
/
lib
/
python2.7
/
site-packages
/
passlib
/
tests
/
File Content:
test_pwd.py
"""passlib.tests -- tests for passlib.pwd""" #============================================================================= # imports #============================================================================= # core import itertools import logging; log = logging.getLogger(__name__) # site # pkg from passlib.tests.utils import TestCase # local __all__ = [ "UtilsTest", "GenerateTest", "StrengthTest", ] #============================================================================= # #============================================================================= class UtilsTest(TestCase): """test internal utilities""" descriptionPrefix = "passlib.pwd" def test_self_info_rate(self): """_self_info_rate()""" from passlib.pwd import _self_info_rate self.assertEqual(_self_info_rate(""), 0) self.assertEqual(_self_info_rate("a" * 8), 0) self.assertEqual(_self_info_rate("ab"), 1) self.assertEqual(_self_info_rate("ab" * 8), 1) self.assertEqual(_self_info_rate("abcd"), 2) self.assertEqual(_self_info_rate("abcd" * 8), 2) self.assertAlmostEqual(_self_info_rate("abcdaaaa"), 1.5488, places=4) # def test_total_self_info(self): # """_total_self_info()""" # from passlib.pwd import _total_self_info # # self.assertEqual(_total_self_info(""), 0) # # self.assertEqual(_total_self_info("a" * 8), 0) # # self.assertEqual(_total_self_info("ab"), 2) # self.assertEqual(_total_self_info("ab" * 8), 16) # # self.assertEqual(_total_self_info("abcd"), 8) # self.assertEqual(_total_self_info("abcd" * 8), 64) # self.assertAlmostEqual(_total_self_info("abcdaaaa"), 12.3904, places=4) #============================================================================= # word generation #============================================================================= # import subject from passlib.pwd import genword, default_charsets ascii_62 = default_charsets['ascii_62'] hex = default_charsets['hex'] class WordGeneratorTest(TestCase): """test generation routines""" descriptionPrefix = "passlib.pwd.genword()" def setUp(self): super(WordGeneratorTest, self).setUp() # patch some RNG references so they're reproducible. from passlib.pwd import SequenceGenerator self.patchAttr(SequenceGenerator, "rng", self.getRandom("pwd generator")) def assertResultContents(self, results, count, chars, unique=True): """check result list matches expected count & charset""" self.assertEqual(len(results), count) if unique: if unique is True: unique = count self.assertEqual(len(set(results)), unique) self.assertEqual(set("".join(results)), set(chars)) def test_general(self): """general behavior""" # basic usage result = genword() self.assertEqual(len(result), 9) # malformed keyword should have useful error. self.assertRaisesRegex(TypeError, "(?i)unexpected keyword.*badkwd", genword, badkwd=True) def test_returns(self): """'returns' keyword""" # returns=int option results = genword(returns=5000) self.assertResultContents(results, 5000, ascii_62) # returns=iter option gen = genword(returns=iter) results = [next(gen) for _ in range(5000)] self.assertResultContents(results, 5000, ascii_62) # invalid returns option self.assertRaises(TypeError, genword, returns='invalid-type') def test_charset(self): """'charset' & 'chars' options""" # charset option results = genword(charset="hex", returns=5000) self.assertResultContents(results, 5000, hex) # chars option # there are 3**3=27 possible combinations results = genword(length=3, chars="abc", returns=5000) self.assertResultContents(results, 5000, "abc", unique=27) # chars + charset self.assertRaises(TypeError, genword, chars='abc', charset='hex') # TODO: test rng option #============================================================================= # phrase generation #============================================================================= # import subject from passlib.pwd import genphrase simple_words = ["alpha", "beta", "gamma"] class PhraseGeneratorTest(TestCase): """test generation routines""" descriptionPrefix = "passlib.pwd.genphrase()" def assertResultContents(self, results, count, words, unique=True, sep=" "): """check result list matches expected count & charset""" self.assertEqual(len(results), count) if unique: if unique is True: unique = count self.assertEqual(len(set(results)), unique) out = set(itertools.chain.from_iterable(elem.split(sep) for elem in results)) self.assertEqual(out, set(words)) def test_general(self): """general behavior""" # basic usage result = genphrase() self.assertEqual(len(result.split(" ")), 4) # 48 / log(7776, 2) ~= 3.7 -> 4 # malformed keyword should have useful error. self.assertRaisesRegex(TypeError, "(?i)unexpected keyword.*badkwd", genphrase, badkwd=True) def test_entropy(self): """'length' & 'entropy' keywords""" # custom entropy result = genphrase(entropy=70) self.assertEqual(len(result.split(" ")), 6) # 70 / log(7776, 2) ~= 5.4 -> 6 # custom length result = genphrase(length=3) self.assertEqual(len(result.split(" ")), 3) # custom length < entropy result = genphrase(length=3, entropy=48) self.assertEqual(len(result.split(" ")), 4) # custom length > entropy result = genphrase(length=4, entropy=12) self.assertEqual(len(result.split(" ")), 4) def test_returns(self): """'returns' keyword""" # returns=int option results = genphrase(returns=1000, words=simple_words) self.assertResultContents(results, 1000, simple_words) # returns=iter option gen = genphrase(returns=iter, words=simple_words) results = [next(gen) for _ in range(1000)] self.assertResultContents(results, 1000, simple_words) # invalid returns option self.assertRaises(TypeError, genphrase, returns='invalid-type') def test_wordset(self): """'wordset' & 'words' options""" # wordset option results = genphrase(words=simple_words, returns=5000) self.assertResultContents(results, 5000, simple_words) # words option results = genphrase(length=3, words=simple_words, returns=5000) self.assertResultContents(results, 5000, simple_words, unique=3**3) # words + wordset self.assertRaises(TypeError, genphrase, words=simple_words, wordset='bip39') #============================================================================= # eof #=============================================================================
Edit
Rename
Chmod
Delete
FILE
FOLDER
Name
Size
Permission
Action
__init__.py
20 bytes
0644
__init__.pyc
181 bytes
0644
__init__.pyo
181 bytes
0644
__main__.py
82 bytes
0644
__main__.pyc
293 bytes
0644
__main__.pyo
293 bytes
0644
_test_bad_register.py
541 bytes
0644
_test_bad_register.pyc
919 bytes
0644
_test_bad_register.pyo
919 bytes
0644
backports.py
2513 bytes
0644
backports.pyc
1258 bytes
0644
backports.pyo
1258 bytes
0644
sample1.cfg
243 bytes
0644
sample1b.cfg
252 bytes
0644
sample1c.cfg
490 bytes
0644
sample_config_1s.cfg
238 bytes
0644
test_apache.py
25208 bytes
0644
test_apache.pyc
20198 bytes
0644
test_apache.pyo
20198 bytes
0644
test_apps.py
5281 bytes
0644
test_apps.pyc
5972 bytes
0644
test_apps.pyo
5972 bytes
0644
test_context.py
75039 bytes
0644
test_context.pyc
42392 bytes
0644
test_context.pyo
42392 bytes
0644
test_context_deprecated.py
29282 bytes
0644
test_context_deprecated.pyc
20648 bytes
0644
test_context_deprecated.pyo
20569 bytes
0644
test_crypto_builtin_md4.py
5660 bytes
0644
test_crypto_builtin_md4.pyc
6010 bytes
0644
test_crypto_builtin_md4.pyo
6010 bytes
0644
test_crypto_des.py
8874 bytes
0644
test_crypto_des.pyc
6692 bytes
0644
test_crypto_des.pyo
6692 bytes
0644
test_crypto_digest.py
18670 bytes
0644
test_crypto_digest.pyc
13552 bytes
0644
test_crypto_digest.pyo
13552 bytes
0644
test_crypto_scrypt.py
25655 bytes
0644
test_crypto_scrypt.pyc
21381 bytes
0644
test_crypto_scrypt.pyo
21302 bytes
0644
test_ext_django.py
32811 bytes
0644
test_ext_django.pyc
21620 bytes
0644
test_ext_django.pyo
21345 bytes
0644
test_ext_django_source.py
11034 bytes
0644
test_ext_django_source.pyc
7075 bytes
0644
test_ext_django_source.pyo
7028 bytes
0644
test_handlers.py
62786 bytes
0644
test_handlers.pyc
60928 bytes
0644
test_handlers.pyo
60928 bytes
0644
test_handlers_argon2.py
16951 bytes
0644
test_handlers_argon2.pyc
13606 bytes
0644
test_handlers_argon2.pyo
13514 bytes
0644
test_handlers_bcrypt.py
23507 bytes
0644
test_handlers_bcrypt.pyc
19655 bytes
0644
test_handlers_bcrypt.pyo
19493 bytes
0644
test_handlers_cisco.py
20471 bytes
0644
test_handlers_cisco.pyc
17618 bytes
0644
test_handlers_cisco.pyo
17618 bytes
0644
test_handlers_django.py
15109 bytes
0644
test_handlers_django.pyc
16025 bytes
0644
test_handlers_django.pyo
15911 bytes
0644
test_handlers_pbkdf2.py
18788 bytes
0644
test_handlers_pbkdf2.pyc
17158 bytes
0644
test_handlers_pbkdf2.pyo
17158 bytes
0644
test_handlers_scrypt.py
4124 bytes
0644
test_handlers_scrypt.pyc
4089 bytes
0644
test_handlers_scrypt.pyo
4089 bytes
0644
test_hosts.py
3906 bytes
0644
test_hosts.pyc
3852 bytes
0644
test_hosts.pyo
3852 bytes
0644
test_pwd.py
7190 bytes
0644
test_pwd.pyc
6456 bytes
0644
test_pwd.pyo
6456 bytes
0644
test_registry.py
9459 bytes
0644
test_registry.pyc
7715 bytes
0644
test_registry.pyo
7715 bytes
0644
test_totp.py
65562 bytes
0644
test_totp.pyc
40189 bytes
0644
test_totp.pyo
40005 bytes
0644
test_utils.py
40242 bytes
0644
test_utils.pyc
30495 bytes
0644
test_utils.pyo
30495 bytes
0644
test_utils_handlers.py
32134 bytes
0644
test_utils_handlers.pyc
29250 bytes
0644
test_utils_handlers.pyo
29188 bytes
0644
test_utils_md4.py
1474 bytes
0644
test_utils_md4.pyc
1588 bytes
0644
test_utils_md4.pyo
1588 bytes
0644
test_utils_pbkdf2.py
12108 bytes
0644
test_utils_pbkdf2.pyc
10552 bytes
0644
test_utils_pbkdf2.pyo
10552 bytes
0644
test_win32.py
1920 bytes
0644
test_win32.pyc
2030 bytes
0644
test_win32.pyo
2030 bytes
0644
tox_support.py
2473 bytes
0644
tox_support.pyc
2842 bytes
0644
tox_support.pyo
2842 bytes
0644
utils.py
138326 bytes
0644
utils.pyc
95162 bytes
0644
utils.pyo
94702 bytes
0644
N4ST4R_ID | Naxtarrr