-
-
Notifications
You must be signed in to change notification settings - Fork 34.1k
gh-145028: Fix blake2 tests in test_hashlib when it is missing due to configure --without-builtin-hashlib-hashes #145029
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tucif
wants to merge
4
commits into
python:main
Choose a base branch
from
tucif:tucif/without_blake2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+26
−4
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3c1de38
reuse blake2 conditionals in missing places and skip subtest for test…
tucif dc7c6c6
only skip on value error specific for blake2 if not in builtins in te…
tucif 1fdc8c7
Address reviewer comments
tucif 17eb629
add skip_if_blake2_not_builtin helper and use it also from test_threa…
tucif File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -134,8 +134,11 @@ def __init__(self, *args, **kwargs): | |||||||||||||
| algorithms.add(algorithm.lower()) | ||||||||||||||
|
|
||||||||||||||
| _blake2 = self._conditional_import_module('_blake2') | ||||||||||||||
| blake2_hashes = {'blake2b', 'blake2s'} | ||||||||||||||
| if _blake2: | ||||||||||||||
| algorithms.update({'blake2b', 'blake2s'}) | ||||||||||||||
| algorithms.update(blake2_hashes) | ||||||||||||||
| else: | ||||||||||||||
| algorithms.difference_update(blake2_hashes) | ||||||||||||||
|
|
||||||||||||||
| self.constructors_to_test = {} | ||||||||||||||
| for algorithm in algorithms: | ||||||||||||||
|
|
@@ -232,7 +235,13 @@ def test_algorithms_available(self): | |||||||||||||
| # all available algorithms must be loadable, bpo-47101 | ||||||||||||||
| self.assertNotIn("undefined", hashlib.algorithms_available) | ||||||||||||||
| for name in hashlib.algorithms_available: | ||||||||||||||
| digest = hashlib.new(name, usedforsecurity=False) | ||||||||||||||
| with self.subTest(name): | ||||||||||||||
| try: | ||||||||||||||
| digest = hashlib.new(name, usedforsecurity=False) | ||||||||||||||
| assert digest is not None | ||||||||||||||
| except ValueError as verr: | ||||||||||||||
| self.skip_if_blake2_not_builtin(name, verr) | ||||||||||||||
| raise | ||||||||||||||
|
Comment on lines
+242
to
+244
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| def test_usedforsecurity_true(self): | ||||||||||||||
| hashlib.new("sha256", usedforsecurity=True) | ||||||||||||||
|
|
@@ -504,6 +513,7 @@ def test_sha3_256_update_over_4gb(self): | |||||||||||||
| self.assertEqual(h.hexdigest(), "e2d4535e3b613135c14f2fe4e026d7ad8d569db44901740beffa30d430acb038") | ||||||||||||||
|
|
||||||||||||||
| @requires_resource('cpu') | ||||||||||||||
| @requires_blake2 | ||||||||||||||
| def test_blake2_update_over_4gb(self): | ||||||||||||||
| # blake2s or blake2b doesn't matter based on how our C code is structured, this tests the | ||||||||||||||
| # common loop macro logic. | ||||||||||||||
|
|
@@ -798,6 +808,12 @@ def test_case_sha512_3(self): | |||||||||||||
| "e718483d0ce769644e2e42c7bc15b4638e1f98b13b2044285632a803afa973eb"+ | ||||||||||||||
| "de0ff244877ea60a4cb0432ce577c31beb009c5c2c49aa2e4eadb217ad8cc09b") | ||||||||||||||
|
|
||||||||||||||
| def skip_if_blake2_not_builtin(self, name, skip_reason): | ||||||||||||||
| # blake2 builtins may be absent if python built with | ||||||||||||||
| # a subset of --with-builtin-hashlib-hashes or none. | ||||||||||||||
| if "blake2" in name and "blake2" not in builtin_hashes: | ||||||||||||||
| self.skipTest(skip_reason) | ||||||||||||||
|
|
||||||||||||||
| def check_blake2(self, constructor, salt_size, person_size, key_size, | ||||||||||||||
| digest_size, max_offset): | ||||||||||||||
| self.assertEqual(constructor.SALT_SIZE, salt_size) | ||||||||||||||
|
|
@@ -1080,10 +1096,16 @@ def test_sha256_gil(self): | |||||||||||||
| def test_threaded_hashing_fast(self): | ||||||||||||||
| # Same as test_threaded_hashing_slow() but only tests some functions | ||||||||||||||
| # since otherwise test_hashlib.py becomes too slow during development. | ||||||||||||||
| for name in ['md5', 'sha1', 'sha256', 'sha3_256', 'blake2s']: | ||||||||||||||
| algos = ['md5', 'sha1', 'sha256', 'sha3_256', 'blake2s'] | ||||||||||||||
| for name in algos: | ||||||||||||||
| if constructor := getattr(hashlib, name, None): | ||||||||||||||
| with self.subTest(name): | ||||||||||||||
| self.do_test_threaded_hashing(constructor, is_shake=False) | ||||||||||||||
| try: | ||||||||||||||
| self.do_test_threaded_hashing(constructor, is_shake=False) | ||||||||||||||
| except ValueError as verr: | ||||||||||||||
| self.skip_if_blake2_not_builtin(name, verr) | ||||||||||||||
| raise | ||||||||||||||
|
|
||||||||||||||
| if shake_128 := getattr(hashlib, 'shake_128', None): | ||||||||||||||
| self.do_test_threaded_hashing(shake_128, is_shake=True) | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
digesetis None assertion is not useful I think (I'm not sure hashlib.new() can return or can it?) if this is just for testing the existence, it's fine to just have_ = hashlib.new(...)