summaryrefslogtreecommitdiffstats
path: root/Lib/test/support
diff options
context:
space:
mode:
authorChristian Heimes <christian@python.org>2019-09-25 14:30:20 (GMT)
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-09-25 14:30:20 (GMT)
commitc64a1a61e6fc542cada40eb069a239317e1af36e (patch)
treed4f780b036c5f2b3ba66df525a7a535058bd887d /Lib/test/support
parent417089e88bd4ea146b9497e06e8edeb58a59cd65 (diff)
downloadcpython-c64a1a61e6fc542cada40eb069a239317e1af36e.zip
cpython-c64a1a61e6fc542cada40eb069a239317e1af36e.tar.gz
cpython-c64a1a61e6fc542cada40eb069a239317e1af36e.tar.bz2
bpo-38270: Check for hash digest algorithms and avoid MD5 (GH-16382)
Make it easier to run and test Python on systems with restrict crypto policies: * add requires_hashdigest to test.support to check if a hash digest algorithm is available and working * avoid MD5 in test_hmac * replace MD5 with SHA256 in test_tarfile * mark network tests that require MD5 for MD5-based digest auth or CRAM-MD5 https://bugs.python.org/issue38270
Diffstat (limited to 'Lib/test/support')
-rw-r--r--Lib/test/support/__init__.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 46d646f..e401090 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -12,6 +12,7 @@ import fnmatch
import functools
import gc
import glob
+import hashlib
import importlib
import importlib.util
import locale
@@ -648,6 +649,29 @@ def requires_mac_ver(*min_version):
return decorator
+def requires_hashdigest(digestname):
+ """Decorator raising SkipTest if a hashing algorithm is not available
+
+ The hashing algorithm could be missing or blocked by a strict crypto
+ policy.
+
+ ValueError: [digital envelope routines: EVP_DigestInit_ex] disabled for FIPS
+ ValueError: unsupported hash type md4
+ """
+ def decorator(func):
+ @functools.wraps(func)
+ def wrapper(*args, **kwargs):
+ try:
+ hashlib.new(digestname)
+ except ValueError:
+ raise unittest.SkipTest(
+ f"hash digest '{digestname}' is not available."
+ )
+ return func(*args, **kwargs)
+ return wrapper
+ return decorator
+
+
HOST = "localhost"
HOSTv4 = "127.0.0.1"
HOSTv6 = "::1"