lepture / authlib

The ultimate Python library in building OAuth, OpenID Connect clients and servers. JWS,JWE,JWK,JWA,JWT included.
https://authlib.org/
BSD 3-Clause "New" or "Revised" License
4.53k stars 452 forks source link

Two tests/jose/test_jwe.py tests failing #456

Open mcepl opened 2 years ago

mcepl commented 2 years ago

While packaging this package for openSUSE we try to start running the testsuite during the packaging (so that we may catch some unexpected failure to build package correctly) and when running tests/jose I got this:

[   11s] + python3.9 -mpytest tests/jose
[   11s] ============================= test session starts ==============================
[   11s] platform linux -- Python 3.9.12, pytest-7.1.1, pluggy-1.0.0
[   11s] rootdir: /home/abuild/rpmbuild/BUILD/authlib-1.0.1, configfile: tox.ini
[   11s] plugins: anyio-3.5.0, asyncio-0.17.2
[   11s] asyncio: mode=auto
[   11s] collected 134 items
[   11s]
[   11s] tests/jose/test_jwe.py ..................F.............................. [ 36%]
[   11s] ............................F                                            [ 58%]
[   12s] tests/jose/test_jwk.py .......................                           [ 75%]
[   12s] tests/jose/test_jws.py ................                                  [ 87%]
[   12s] tests/jose/test_jwt.py .................                                 [100%]
[   12s]
[   12s] =================================== FAILURES ===================================
[   12s] __________________________ JWETest.test_dir_alg_xc20p __________________________
[   12s]
[   12s] self = <tests.jose.test_jwe.JWETest testMethod=test_dir_alg_xc20p>
[   12s]
[   12s]     def test_dir_alg_xc20p(self):
[   12s]         jwe = JsonWebEncryption()
[   12s]         key = OctKey.generate_key(256, is_private=True)
[   12s]         protected = {'alg': 'dir', 'enc': 'XC20P'}
[   12s] >       data = jwe.serialize_compact(protected, b'hello', key)
[   12s]
[   12s] tests/jose/test_jwe.py:2657:
[   12s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
[   12s] authlib/jose/rfc7516/jwe.py:80: in serialize_compact
[   12s]     enc = self.get_header_enc(protected)
[   12s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
[   12s]
[   12s] self = <authlib.jose.rfc7516.jwe.JsonWebEncryption object at 0x7fad22f4ac40>
[   12s] header = {'alg': 'dir', 'enc': 'XC20P'}
[   12s]
[   12s]     def get_header_enc(self, header):
[   12s]         if 'enc' not in header:
[   12s]             raise MissingEncryptionAlgorithmError()
[   12s]         enc = header['enc']
[   12s]         if self._algorithms and enc not in self._algorithms:
[   12s]             raise UnsupportedEncryptionAlgorithmError()
[   12s]         if enc not in self.ENC_REGISTRY:
[   12s] >           raise UnsupportedEncryptionAlgorithmError()
[   12s] E           authlib.jose.errors.UnsupportedEncryptionAlgorithmError: unsupported_encryption_algorithm: Unsupported "enc" value in header
[   12s]
[   12s] authlib/jose/rfc7516/jwe.py:678: UnsupportedEncryptionAlgorithmError
[   12s] _______________ JWETest.test_xc20p_content_encryption_decryption _______________
[   12s]
[   12s] self = <tests.jose.test_jwe.JWETest testMethod=test_xc20p_content_encryption_decryption>
[   12s]
[   12s]     def test_xc20p_content_encryption_decryption(self):
[   12s]         # https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-xchacha-03#appendix-A.3.1
[   12s] >       enc = JsonWebEncryption.ENC_REGISTRY['XC20P']
[   12s] E       KeyError: 'XC20P'
[   12s]
[   12s] tests/jose/test_jwe.py:2672: KeyError
[   12s] =========================== short test summary info ============================
[   12s] FAILED tests/jose/test_jwe.py::JWETest::test_dir_alg_xc20p - authlib.jose.err...
[   12s] FAILED tests/jose/test_jwe.py::JWETest::test_xc20p_content_encryption_decryption
[   12s] ======================== 2 failed, 132 passed in 1.08s =========================

Complete build log with all details of packages used and steps taken to reproduce.

lepture commented 2 years ago

It is working well with GitHub actions. I'll need to split test_jwe.py to several files.