Skip to content

Commit 15d926b

Browse files
authored
gh-130149: fix HMAC tests for some FIPS-only build bots (#130788)
Skips some HMAC tests for some FIPS-only build bots that do not have the underlying hash functions.
1 parent d780f0a commit 15d926b

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

Lib/test/test_hmac.py

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -566,32 +566,52 @@ def test_with_fallback(self):
566566
cache.pop('foo')
567567

568568

569-
class PyRFCTestCase(PyTestVectorsMixin, ThroughObjectMixin,
570-
RFCTestCasesMixin, unittest.TestCase):
571-
"""Python implementation of HMAC using hmac.HMAC()."""
572-
573-
574-
class PyDotNewRFCTestCase(PyTestVectorsMixin, ThroughModuleAPIMixin,
575-
RFCTestCasesMixin, unittest.TestCase):
576-
"""Python implementation of HMAC using hmac.new()."""
577-
578-
579-
@hashlib_helper.requires_hashlib()
580-
class OpenSSLRFCTestCase(OpenSSLTestVectorsMixin, RFCTestCasesMixin,
581-
unittest.TestCase):
582-
"""OpenSSL implementation of HMAC."""
569+
class RFCWithOpenSSLHashFunctionTestCasesMixin(RFCTestCasesMixin):
583570

584571
def __init_subclass__(cls, *args, **kwargs):
585572
super().__init_subclass__(*args, **kwargs)
586573

587574
for name in cls.ALGORITHMS:
588575
@property
576+
@hashlib_helper.requires_hashlib()
589577
@hashlib_helper.requires_hashdigest(name, openssl=True)
590578
def func(self, *, __name=name): # __name needed to bind 'name'
591579
return getattr(_hashlib, f'openssl_{__name}')
592580
setattr(cls, name, func)
593581

594582

583+
class PyRFCTestCase(PyTestVectorsMixin, ThroughObjectMixin,
584+
RFCWithOpenSSLHashFunctionTestCasesMixin,
585+
unittest.TestCase):
586+
"""Python implementation of HMAC using hmac.HMAC().
587+
588+
The underlying hash functions are OpenSSL-based.
589+
"""
590+
591+
592+
class PyDotNewRFCTestCase(PyTestVectorsMixin, ThroughModuleAPIMixin,
593+
RFCWithOpenSSLHashFunctionTestCasesMixin,
594+
unittest.TestCase):
595+
"""Python implementation of HMAC using hmac.new().
596+
597+
The underlying hash functions are OpenSSL-based.
598+
"""
599+
600+
601+
class OpenSSLRFCTestCase(OpenSSLTestVectorsMixin,
602+
RFCWithOpenSSLHashFunctionTestCasesMixin,
603+
unittest.TestCase):
604+
"""OpenSSL implementation of HMAC.
605+
606+
The underlying hash functions are also OpenSSL-based."""
607+
608+
609+
# TODO(picnixz): once we have a HACL* HMAC, we should also test the Python
610+
# implementation of HMAC with a HACL*-based hash function. For now, we only
611+
# test it partially via the '_sha2' module, but for completeness we could
612+
# also test the RFC test vectors against all possible implementations.
613+
614+
595615
class DigestModTestCaseMixin(CreatorMixin, DigestMixin):
596616
"""Tests for the 'digestmod' parameter."""
597617

0 commit comments

Comments
 (0)