Submit
Path:
~
/
/
usr
/
lib
/
python2.7
/
site-packages
/
passlib
/
tests
/
File Content:
test_registry.py
"""tests for passlib.hash -- (c) Assurance Technologies 2003-2009""" #============================================================================= # imports #============================================================================= from __future__ import with_statement # core from logging import getLogger import warnings import sys # site # pkg from passlib import hash, registry, exc from passlib.registry import register_crypt_handler, register_crypt_handler_path, \ get_crypt_handler, list_crypt_handlers, _unload_handler_name as unload_handler_name import passlib.utils.handlers as uh from passlib.tests.utils import TestCase # module log = getLogger(__name__) #============================================================================= # dummy handlers # # NOTE: these are defined outside of test case # since they're used by test_register_crypt_handler_path(), # which needs them to be available as module globals. #============================================================================= class dummy_0(uh.StaticHandler): name = "dummy_0" class alt_dummy_0(uh.StaticHandler): name = "dummy_0" dummy_x = 1 #============================================================================= # test registry #============================================================================= class RegistryTest(TestCase): descriptionPrefix = "passlib.registry" def setUp(self): super(RegistryTest, self).setUp() # backup registry state & restore it after test. locations = dict(registry._locations) handlers = dict(registry._handlers) def restore(): registry._locations.clear() registry._locations.update(locations) registry._handlers.clear() registry._handlers.update(handlers) self.addCleanup(restore) def test_hash_proxy(self): """test passlib.hash proxy object""" # check dir works dir(hash) # check repr works repr(hash) # check non-existent attrs raise error self.assertRaises(AttributeError, getattr, hash, 'fooey') # GAE tries to set __loader__, # make sure that doesn't call register_crypt_handler. old = getattr(hash, "__loader__", None) test = object() hash.__loader__ = test self.assertIs(hash.__loader__, test) if old is None: del hash.__loader__ self.assertFalse(hasattr(hash, "__loader__")) else: hash.__loader__ = old self.assertIs(hash.__loader__, old) # check storing attr calls register_crypt_handler class dummy_1(uh.StaticHandler): name = "dummy_1" hash.dummy_1 = dummy_1 self.assertIs(get_crypt_handler("dummy_1"), dummy_1) # check storing under wrong name results in error self.assertRaises(ValueError, setattr, hash, "dummy_1x", dummy_1) def test_register_crypt_handler_path(self): """test register_crypt_handler_path()""" # NOTE: this messes w/ internals of registry, shouldn't be used publically. paths = registry._locations # check namespace is clear self.assertTrue('dummy_0' not in paths) self.assertFalse(hasattr(hash, 'dummy_0')) # check invalid names are rejected self.assertRaises(ValueError, register_crypt_handler_path, "dummy_0", ".test_registry") self.assertRaises(ValueError, register_crypt_handler_path, "dummy_0", __name__ + ":dummy_0:xxx") self.assertRaises(ValueError, register_crypt_handler_path, "dummy_0", __name__ + ":dummy_0.xxx") # try lazy load register_crypt_handler_path('dummy_0', __name__) self.assertTrue('dummy_0' in list_crypt_handlers()) self.assertTrue('dummy_0' not in list_crypt_handlers(loaded_only=True)) self.assertIs(hash.dummy_0, dummy_0) self.assertTrue('dummy_0' in list_crypt_handlers(loaded_only=True)) unload_handler_name('dummy_0') # try lazy load w/ alt register_crypt_handler_path('dummy_0', __name__ + ':alt_dummy_0') self.assertIs(hash.dummy_0, alt_dummy_0) unload_handler_name('dummy_0') # check lazy load w/ wrong type fails register_crypt_handler_path('dummy_x', __name__) self.assertRaises(TypeError, get_crypt_handler, 'dummy_x') # check lazy load w/ wrong name fails register_crypt_handler_path('alt_dummy_0', __name__) self.assertRaises(ValueError, get_crypt_handler, "alt_dummy_0") unload_handler_name("alt_dummy_0") # TODO: check lazy load which calls register_crypt_handler (warning should be issued) sys.modules.pop("passlib.tests._test_bad_register", None) register_crypt_handler_path("dummy_bad", "passlib.tests._test_bad_register") with warnings.catch_warnings(): warnings.filterwarnings("ignore", "xxxxxxxxxx", DeprecationWarning) h = get_crypt_handler("dummy_bad") from passlib.tests import _test_bad_register as tbr self.assertIs(h, tbr.alt_dummy_bad) def test_register_crypt_handler(self): """test register_crypt_handler()""" self.assertRaises(TypeError, register_crypt_handler, {}) self.assertRaises(ValueError, register_crypt_handler, type('x', (uh.StaticHandler,), dict(name=None))) self.assertRaises(ValueError, register_crypt_handler, type('x', (uh.StaticHandler,), dict(name="AB_CD"))) self.assertRaises(ValueError, register_crypt_handler, type('x', (uh.StaticHandler,), dict(name="ab-cd"))) self.assertRaises(ValueError, register_crypt_handler, type('x', (uh.StaticHandler,), dict(name="ab__cd"))) self.assertRaises(ValueError, register_crypt_handler, type('x', (uh.StaticHandler,), dict(name="default"))) class dummy_1(uh.StaticHandler): name = "dummy_1" class dummy_1b(uh.StaticHandler): name = "dummy_1" self.assertTrue('dummy_1' not in list_crypt_handlers()) register_crypt_handler(dummy_1) register_crypt_handler(dummy_1) self.assertIs(get_crypt_handler("dummy_1"), dummy_1) self.assertRaises(KeyError, register_crypt_handler, dummy_1b) self.assertIs(get_crypt_handler("dummy_1"), dummy_1) register_crypt_handler(dummy_1b, force=True) self.assertIs(get_crypt_handler("dummy_1"), dummy_1b) self.assertTrue('dummy_1' in list_crypt_handlers()) def test_get_crypt_handler(self): """test get_crypt_handler()""" class dummy_1(uh.StaticHandler): name = "dummy_1" # without available handler self.assertRaises(KeyError, get_crypt_handler, "dummy_1") self.assertIs(get_crypt_handler("dummy_1", None), None) # already loaded handler register_crypt_handler(dummy_1) self.assertIs(get_crypt_handler("dummy_1"), dummy_1) with warnings.catch_warnings(): warnings.filterwarnings("ignore", "handler names should be lower-case, and use underscores instead of hyphens:.*", UserWarning) # already loaded handler, using incorrect name self.assertIs(get_crypt_handler("DUMMY-1"), dummy_1) # lazy load of unloaded handler, using incorrect name register_crypt_handler_path('dummy_0', __name__) self.assertIs(get_crypt_handler("DUMMY-0"), dummy_0) # check system & private names aren't returned import passlib.hash # ensure module imported, so py3.3 sets __package__ passlib.hash.__dict__["_fake"] = "dummy" # so behavior seen under py2x also for name in ["_fake", "__package__"]: self.assertRaises(KeyError, get_crypt_handler, name) self.assertIs(get_crypt_handler(name, None), None) def test_list_crypt_handlers(self): """test list_crypt_handlers()""" from passlib.registry import list_crypt_handlers # check system & private names aren't returned import passlib.hash # ensure module imported, so py3.3 sets __package__ passlib.hash.__dict__["_fake"] = "dummy" # so behavior seen under py2x also for name in list_crypt_handlers(): self.assertFalse(name.startswith("_"), "%r: " % name) unload_handler_name("_fake") def test_handlers(self): """verify we have tests for all builtin handlers""" from passlib.registry import list_crypt_handlers from passlib.tests.test_handlers import get_handler_case, conditionally_available_hashes for name in list_crypt_handlers(): # skip some wrappers that don't need independant testing if name.startswith("ldap_") and name[5:] in list_crypt_handlers(): continue if name in ["roundup_plaintext"]: continue # check the remaining ones all have a handler try: self.assertTrue(get_handler_case(name)) except exc.MissingBackendError: if name in conditionally_available_hashes: # expected to fail on some setups continue raise #============================================================================= # 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