summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Collins <elic@assurancetechnologies.com>2020-10-03 15:18:23 -0400
committerEli Collins <elic@assurancetechnologies.com>2020-10-03 15:18:23 -0400
commitb252bf6b0ecfda46d81bb29b530b33466cec3cef (patch)
tree5d806150c268dfa877a0546f89944cfb7e4a2827
parentc46effcc6188a8402cef6d9fc9cffd06b8eb77cb (diff)
downloadpasslib-b252bf6b0ecfda46d81bb29b530b33466cec3cef.tar.gz
passlib.tests: silence some warnings, fix some MissingBackendError messages
* tests now filter out some passlib deprecation warnings * bugfix: @doesnt_require_backend() decorator (rev XXX) now silences MissingBackendError exceptions thrown during HandlerCase.setUp() * simplified some monkeypatching within test_registry
-rw-r--r--passlib/tests/test_handlers.py2
-rw-r--r--passlib/tests/test_registry.py7
-rw-r--r--passlib/tests/test_totp.py2
-rw-r--r--passlib/tests/utils.py22
4 files changed, 22 insertions, 11 deletions
diff --git a/passlib/tests/test_handlers.py b/passlib/tests/test_handlers.py
index c92e4ad..9d81036 100644
--- a/passlib/tests/test_handlers.py
+++ b/passlib/tests/test_handlers.py
@@ -627,7 +627,7 @@ class _ldap_sha1_crypt_test(HandlerCase):
kwds.setdefault("rounds", 10)
super(_ldap_sha1_crypt_test, self).populate_settings(kwds)
- def test_77_fuzz_input(self):
+ def test_77_fuzz_input(self, **ignored):
raise self.skipTest("unneeded")
# create test cases for specific backends
diff --git a/passlib/tests/test_registry.py b/passlib/tests/test_registry.py
index 7540ee2..8cec48d 100644
--- a/passlib/tests/test_registry.py
+++ b/passlib/tests/test_registry.py
@@ -189,8 +189,8 @@ class RegistryTest(TestCase):
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
+ from passlib import hash
+ hash.__dict__["_fake"] = "dummy"
for name in ["_fake", "__package__"]:
self.assertRaises(KeyError, get_crypt_handler, name)
self.assertIs(get_crypt_handler(name, None), None)
@@ -200,8 +200,7 @@ class RegistryTest(TestCase):
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
+ hash.__dict__["_fake"] = "dummy"
for name in list_crypt_handlers():
self.assertFalse(name.startswith("_"), "%r: " % name)
unload_handler_name("_fake")
diff --git a/passlib/tests/test_totp.py b/passlib/tests/test_totp.py
index d994d6c..604d2e9 100644
--- a/passlib/tests/test_totp.py
+++ b/passlib/tests/test_totp.py
@@ -372,6 +372,8 @@ class AppWalletTest(TestCase):
wallet.encrypt_cost += 3
delta2, _ = time_call(partial(wallet.encrypt_key, KEY1_RAW), maxtime=0)
+ # TODO: rework timing test here to inject mock pbkdf2_hmac() function instead;
+ # and test that it's being invoked w/ proper options.
self.assertAlmostEqual(delta2, delta*8, delta=(delta*8)*0.5)
#=============================================================================
diff --git a/passlib/tests/utils.py b/passlib/tests/utils.py
index 6a1cc85..07b0f5a 100644
--- a/passlib/tests/utils.py
+++ b/passlib/tests/utils.py
@@ -369,6 +369,7 @@ class TestCase(_TestCase):
# should be kept until then, so we test the legacy paths.
warnings.filterwarnings("ignore", r"the method .*\.(encrypt|genconfig|genhash)\(\) is deprecated")
warnings.filterwarnings("ignore", r"the 'vary_rounds' option is deprecated")
+ warnings.filterwarnings("ignore", r"Support for `(py-bcrypt|bcryptor)` is deprecated")
#---------------------------------------------------------------
# tweak message formatting so longMessage mode is only enabled
@@ -678,6 +679,8 @@ def doesnt_require_backend(func):
decorator for HandlerCase.create_backend_case() --
used to decorate methods that should be run even if backend isn't present
(by default, full test suite is skipped when backend is missing)
+
+ NOTE: tests decorated with this should not rely on handler have expected (or any!) backend.
"""
func._doesnt_require_backend = True
return func
@@ -980,20 +983,27 @@ class HandlerCase(TestCase):
# check if test is disabled due to missing backend;
# and that it wasn't exempted via @doesnt_require_backend() decorator
- skip_backend_reason = self._skip_backend_reason
- if skip_backend_reason and self._test_requires_backend():
- raise self.skipTest(skip_backend_reason)
+ test_requires_backend = self._test_requires_backend()
+ if test_requires_backend and self._skip_backend_reason:
+ raise self.skipTest(self._skip_backend_reason)
super(HandlerCase, self).setUp()
# if needed, select specific backend for duration of test
+ # NOTE: skipping this if create_backend_case() signalled we're skipping backend
+ # (can only get here for @doesnt_require_backend decorated methods)
handler = self.handler
backend = self.backend
if backend:
if not hasattr(handler, "set_backend"):
raise RuntimeError("handler doesn't support multiple backends")
- self.addCleanup(handler.set_backend, handler.get_backend())
- handler.set_backend(backend)
+ try:
+ self.addCleanup(handler.set_backend, handler.get_backend())
+ handler.set_backend(backend)
+ except uh.exc.MissingBackendError:
+ if test_requires_backend:
+ raise
+ # else test is decorated with @doesnt_require_backend, let it through.
# patch some RNG references so they're reproducible.
from passlib.utils import handlers
@@ -3180,7 +3190,7 @@ class OsCryptMixin(HandlerCase):
reason = super(OsCryptMixin, cls)._get_skip_backend_reason(backend)
from passlib.utils import has_crypt
- if reason == cls.BACKEND_NOT_AVAILABLE and has_crypt:
+ if reason == cls._BACKEND_NOT_AVAILABLE and has_crypt:
if TEST_MODE("full") and cls._get_safe_crypt_handler_backend()[1]:
# in this case, _patch_safe_crypt() will monkeypatch os_crypt
# to use another backend, just so we can test os_crypt fully.