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
More test coverage for hmac #58530
Comments
|
Adding some tests to non-default code paths in hmac.py to get to 100% coverage. |
|
Thanks for the patch. Could you rewrite it using self.assert* methods instead of asserts? I’m not an hmac expert, so you may have to wait a bit for another core developer to see and commit the patch. |
|
Updated to use the correct assert* methods. |
|
Some style comments:
/home/antoine/cpython/default/Lib/test/test_hmac.py:254: RuntimeWarning: No block_size attribute on given digest object; Assuming 64. |
|
IIRC we also need a signed contributor agreement in order to commit your patch. |
|
If there isn't a signed contributor agreement I'll put up a new version of the patch. In msg156758 Antoine said 'don't use "except: self.fail()", just let the exception pass through'. There are several of these in the existing code. Should they all be removed or must it be done on a case by case basis? |
|
The patch is out of date and needs to be refreshed. |
|
The only things I think we should add to the current hmac tests are test_update_error_handling and test_with_invalid_msg. For test_withnoncallable_digestmod(), hmac itself seems it can no longer be used: >>> hmac.HMAC(b"gggg", None, "hmac")
<module '_hashlib' from '/Users/arjun/Python/Sources/cpython/build/lib.macosx-11.4-x86_64-3.11-pydebug/_hashlib.cpython-311d-darwin.so'>
using new
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/arjun/Python/Sources/cpython/Lib/hmac.py", line 61, in __init__
self._init_hmac(key, msg, digestmod)
File "/Users/arjun/Python/Sources/cpython/Lib/hmac.py", line 69, in _init_hmac
self._hmac = _hashopenssl.hmac_new(key, msg, digestmod=digestmod)
ValueError: unsupported hash type hmacFor tests test_small_block_size and test_no_block_size, a custom .blocksize cannot be set (changing .block_size has no difference on digest()): >>> hmac.HMAC(b"gggg", None, "md5").blocksize = 15
<module '_hashlib' from '/Users/arjun/Python/Sources/cpython/build/lib.macosx-11.4-x86_64-3.11-pydebug/_hashlib.cpython-311d-darwin.so'>
using new
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'HMAC' object attribute 'blocksize' is read-only
Does this sound okay? I can go ahead an implement it if so. |
|
would the update invalid test belong in the TestVectorsTestCase class or should I make a new one? |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: