summaryrefslogtreecommitdiff
path: root/test/option/hash-format.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/option/hash-format.py')
-rw-r--r--test/option/hash-format.py42
1 files changed, 33 insertions, 9 deletions
diff --git a/test/option/hash-format.py b/test/option/hash-format.py
index 9fa10ee84..f0156f3ef 100644
--- a/test/option/hash-format.py
+++ b/test/option/hash-format.py
@@ -27,28 +27,52 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
import hashlib
import os
import TestSCons
+import warnings
+from SCons.Util import ALLOWED_HASH_FORMATS, DEFAULT_HASH_FORMATS
# Test passing the hash format by command-line.
INVALID_ALGORITHM = 'testfailure'
-for algorithm in ['md5', 'sha1', 'sha256', INVALID_ALGORITHM, None]:
+
+for algorithm in [*DEFAULT_HASH_FORMATS, INVALID_ALGORITHM, None]:
test = TestSCons.TestSCons()
test.dir_fixture('hash-format')
+ # Expect failure due to an unsupported/invalid algorithm.
+ # The error message however changes if SCons detects that the host system doesn't support one or more algorithms
+ # Primary reason the message changes is so user doesn't have to start with unsupported algorithm A and then attempt
+ # to switch to unsupported algorithm B.
+ # On normal systems (allowed=default) this will output a fixed message, but on FIPS-enabled or other weird systems
+ # that don't have default allowed algorithms, it informs the user of the mismatch _and_ the currently supported
+ # algorithms on the system they're using.
+ # In Python 3.9 this becomes somewhat obselete as the hashlib is informed we don't use hashing for security but
+ # for loose integrity.
if algorithm == INVALID_ALGORITHM:
- # Expect failure due to an unsupported/invalid algorithm.
- test.run('--hash-format=%s .' % algorithm, stderr=r"""
-scons: \*\*\* Hash format "{}" is not supported by SCons. Only the following hash formats are supported: md5, sha1, sha256
+ if ALLOWED_HASH_FORMATS == DEFAULT_HASH_FORMATS:
+ test.run('--hash-format=%s .' % algorithm, stderr=r"""
+scons: \*\*\* Hash format "{}" is not supported by SCons. Only the following hash formats are supported: {}
+File "[^"]+", line \d+, in \S+
+""".format(algorithm, ', '.join(DEFAULT_HASH_FORMATS)), status=2, match=TestSCons.match_re)
+ else:
+ test.run('--hash-format=%s .' % algorithm, stderr=r"""
+scons: \*\*\* Hash format "{}" is not supported by SCons. SCons supports more hash formats than your local system is reporting; SCons supports: {}. Your local system only supports: {}
File "[^"]+", line \d+, in \S+
-""".format(algorithm), status=2, match=TestSCons.match_re)
+""".format(algorithm, ', '.join(DEFAULT_HASH_FORMATS), ', '.join(ALLOWED_HASH_FORMATS)), status=2, match=TestSCons.match_re)
continue
elif algorithm is not None:
- # Skip any algorithm that the Python interpreter doesn't have.
- if hasattr(hashlib, algorithm):
+ if algorithm in ALLOWED_HASH_FORMATS:
expected_dblite = test.workpath('.sconsign_%s.dblite' % algorithm)
test.run('--hash-format=%s .' % algorithm)
else:
- print('Skipping test with --hash-format=%s because that '
- 'algorithm is not available.' % algorithm)
+ test.run('--hash-format=%s' % algorithm, stderr=r"""
+scons: \*\*\* While hash format "{}" is supported by SCons, the local system indicates only the following hash formats are supported by the hashlib library: {}
+File "[^"]+", line \d+, in \S+
+Error in atexit._run_exitfuncs:
+Traceback \(most recent call last\):
+ File "[^"]+", line \d+, in \S+
+ assert csig == '[a-z0-9]+', csig
+AssertionError: [a-z0-9]+
+""".format(algorithm, ', '.join(ALLOWED_HASH_FORMATS)), status=2, match=TestSCons.match_re)
+ continue
else:
# The SConsign file in the hash-format folder has logic to call
# SCons.Util.set_hash_format('sha256') if the default algorithm is