diff options
Diffstat (limited to 'dev-python/python-jose')
-rw-r--r-- | dev-python/python-jose/Manifest | 3 | ||||
-rw-r--r-- | dev-python/python-jose/files/python-jose-3.3.0-test.patch | 119 | ||||
-rw-r--r-- | dev-python/python-jose/python-jose-3.3.0-r1.ebuild | 14 |
3 files changed, 130 insertions, 6 deletions
diff --git a/dev-python/python-jose/Manifest b/dev-python/python-jose/Manifest index 8f666cd1c406..d97d0aea8c3f 100644 --- a/dev-python/python-jose/Manifest +++ b/dev-python/python-jose/Manifest @@ -1,3 +1,4 @@ +AUX python-jose-3.3.0-test.patch 5171 BLAKE2B 581bffa2ae6af4527a1fa7758c6627f1bf24197590aed459a46021b3aaf16bf9594cef8efe5f9b9a8e4aec89a4be461ed3bbf12007274ac3fc34cf3b39759437 SHA512 2c77d7fd504199862fc2ab0166e41e0c8ee28a2107df1dd002d8577f58025327759535a2110ef189fd944df07edbfc1be33db4585ad850f60b7148f7319dc095 DIST python-jose-3.3.0.gh.tar.gz 126578 BLAKE2B d1279d2a0788b4d395e760ee3a1b2ce8c9340ad12ebe103cb1ba98aea33566cf0134d5af75be9727fff96adab4fc88f1b471ba9ea7d36c16de10587a9efd1304 SHA512 de7147cc6e12406d6e459c32829acae46395acba727c53e65bc05f4794ee3050eecd355e3ae2e87f4ebdbd871f53822eea08a10f25d7ca6088fc6128dc7d9637 -EBUILD python-jose-3.3.0-r1.ebuild 1103 BLAKE2B 677517ee3a5910773a14cd5503df92b222635eb4268922de77da3fb9b8cecaff1bc686aa6ae4f54c4ff98caed4293444d08302b42c9215a7fadf2424d8d940ab SHA512 7bab7c15a88336feaa92724d40b08546b6a93aa0ea9100f9f8314aad1d9aed1753ebffe3afda5378a557bb9b0b88f83e708db24212cc055b0d38fd51d8428659 +EBUILD python-jose-3.3.0-r1.ebuild 1243 BLAKE2B b18e34ee58f1c9ac68d7d35e776136c3773ec3345beeb6bcc883a085762ad73aa10b268606af0cf1492c0730130475db0a017863feb216742a56b7c26bc43d8d SHA512 bf93dbc024b1ac3d596fa63674a95373540422378014437a4e645a00d0e4a01a64ebc364b5253eb0f643d39f3170daf4d6683298d01b237f38653b6fd2ceed80 MISC metadata.xml 570 BLAKE2B b931b6de4f0dc9a5cefa9b31805590b2c667c5d2bc1ea31aea6f7c4b47db6d861e9fdc4666e66784b25e4dcc84e2d6d257e9ed19a80c1310d83948467cbfdcb2 SHA512 369591ec42b7dcfd9e28f0fb510bfac1212e678e9829f5c8ffbc35993446865b721457d790dbf63551f8247f28e4990bef7e9928600e74541d50cf353f41eafb diff --git a/dev-python/python-jose/files/python-jose-3.3.0-test.patch b/dev-python/python-jose/files/python-jose-3.3.0-test.patch new file mode 100644 index 000000000000..7f87069853d7 --- /dev/null +++ b/dev-python/python-jose/files/python-jose-3.3.0-test.patch @@ -0,0 +1,119 @@ +From 19677540e74eba4392be53ae434b561cf74ad9a6 Mon Sep 17 00:00:00 2001 +From: Todd Wildey <twwildey@amazon.com> +Date: Thu, 30 May 2024 16:02:09 -0700 +Subject: [PATCH] Adding `get_pem_for_key` and `normalize_pem` methods to + normalize PEM formatting of keys in `tests/algorithms/test_EC.py` and + updating `tests/algorithms/test_EC_compat.py` to use these methods + +Test failures were occurring due to differences of line lengths generated by the `cryptography` vs `ecdsa` PIP libraries for PEM formatting of cryptographic keys. This method removes newlines from the bodies of PEM-formated keys so that test comparisons will not fail on differentiated line lengths between PEM formattings. +--- + tests/algorithms/test_EC.py | 28 +++++++++++++++++++++++++++- + tests/algorithms/test_EC_compat.py | 14 +++++++------- + 2 files changed, 34 insertions(+), 8 deletions(-) + +diff --git a/tests/algorithms/test_EC.py b/tests/algorithms/test_EC.py +index 6c167d29..b9028a77 100644 +--- a/tests/algorithms/test_EC.py ++++ b/tests/algorithms/test_EC.py +@@ -1,4 +1,5 @@ + import json ++import re + + from jose.backends import ECKey + from jose.constants import ALGORITHMS +@@ -48,6 +49,31 @@ + b"\xfeMO\x04\xb2[\x86A\xbd\xc6hu\x953X\x1e" + ) + ++# Define the regex pattern to capture the header, body, and footer of the PEM file ++PEM_REGEX = re.compile(r"(-----BEGIN [A-Z ]+-----)(.*?)(-----END [A-Z ]+-----)", re.DOTALL) ++WHITE_SPACE_REGEX = re.compile(r"\s+") ++ ++ ++def get_pem_for_key(key): ++ return key.to_pem().strip().decode("utf-8") ++ ++ ++def normalize_pem(key_pem_str): ++ # Search for the PEM sections ++ pem_match = PEM_REGEX.search(key_pem_str) ++ if not pem_match: ++ raise ValueError("The provided string does not contain a valid PEM formatted data.") ++ ++ header = pem_match.group(1) ++ body = pem_match.group(2) ++ footer = pem_match.group(3) ++ ++ # Remove all newlines and spaces from the body ++ clean_body = WHITE_SPACE_REGEX.sub("", body) ++ ++ # Reassemble the PEM string ++ return f"{header}\n{clean_body}\n{footer}" ++ + + def _backend_exception_types(): + """Build the backend exception types based on available backends.""" +@@ -104,7 +130,7 @@ def test_key_from_pem(self): + def test_to_pem(self): + key = ECKey(private_key, ALGORITHMS.ES256) + assert not key.is_public() +- assert key.to_pem().strip() == private_key.strip().encode("utf-8") ++ assert normalize_pem(get_pem_for_key(key)) == normalize_pem(private_key.strip()) + + public_pem = key.public_key().to_pem() + assert ECKey(public_pem, ALGORITHMS.ES256).is_public() +diff --git a/tests/algorithms/test_EC_compat.py b/tests/algorithms/test_EC_compat.py +index 05d033cc..1bb7373a 100644 +--- a/tests/algorithms/test_EC_compat.py ++++ b/tests/algorithms/test_EC_compat.py +@@ -7,7 +7,7 @@ + ECDSAECKey = CryptographyECKey = None + from jose.constants import ALGORITHMS + +-from .test_EC import private_key ++from .test_EC import get_pem_for_key, normalize_pem, private_key + + + @pytest.mark.backend_compatibility +@@ -37,7 +37,7 @@ def test_public_key_to_pem(self, BackendFrom, BackendTo): + key = BackendFrom(private_key, ALGORITHMS.ES256) + key2 = BackendTo(private_key, ALGORITHMS.ES256) + +- assert key.public_key().to_pem().strip() == key2.public_key().to_pem().strip() ++ assert normalize_pem(get_pem_for_key(key.public_key())) == normalize_pem(get_pem_for_key(key2.public_key())) + + @pytest.mark.parametrize("BackendFrom", [ECDSAECKey, CryptographyECKey]) + @pytest.mark.parametrize("BackendTo", [ECDSAECKey, CryptographyECKey]) +@@ -45,7 +45,7 @@ def test_private_key_to_pem(self, BackendFrom, BackendTo): + key = BackendFrom(private_key, ALGORITHMS.ES256) + key2 = BackendTo(private_key, ALGORITHMS.ES256) + +- assert key.to_pem().strip() == key2.to_pem().strip() ++ assert normalize_pem(get_pem_for_key(key)) == normalize_pem(get_pem_for_key(key2)) + + @pytest.mark.parametrize("BackendFrom", [ECDSAECKey, CryptographyECKey]) + @pytest.mark.parametrize("BackendTo", [ECDSAECKey, CryptographyECKey]) +@@ -53,19 +53,19 @@ def test_public_key_load_cycle(self, BackendFrom, BackendTo): + key = BackendFrom(private_key, ALGORITHMS.ES256) + pubkey = key.public_key() + +- pub_pem_source = pubkey.to_pem().strip() ++ pub_pem_source = normalize_pem(get_pem_for_key(pubkey)) + + pub_target = BackendTo(pub_pem_source, ALGORITHMS.ES256) + +- assert pub_pem_source == pub_target.to_pem().strip() ++ assert pub_pem_source == normalize_pem(get_pem_for_key(pub_target)) + + @pytest.mark.parametrize("BackendFrom", [ECDSAECKey, CryptographyECKey]) + @pytest.mark.parametrize("BackendTo", [ECDSAECKey, CryptographyECKey]) + def test_private_key_load_cycle(self, BackendFrom, BackendTo): + key = BackendFrom(private_key, ALGORITHMS.ES256) + +- pem_source = key.to_pem().strip() ++ pem_source = normalize_pem(get_pem_for_key(key)) + + target = BackendTo(pem_source, ALGORITHMS.ES256) + +- assert pem_source == target.to_pem().strip() ++ assert pem_source == normalize_pem(get_pem_for_key(target)) diff --git a/dev-python/python-jose/python-jose-3.3.0-r1.ebuild b/dev-python/python-jose/python-jose-3.3.0-r1.ebuild index e64e737b8e73..ecfd9c2c9724 100644 --- a/dev-python/python-jose/python-jose-3.3.0-r1.ebuild +++ b/dev-python/python-jose/python-jose-3.3.0-r1.ebuild @@ -1,10 +1,10 @@ -# Copyright 1999-2023 Gentoo Authors +# Copyright 1999-2024 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 EAPI=8 DISTUTILS_USE_PEP517=setuptools -PYTHON_COMPAT=( python3_{10..12} ) +PYTHON_COMPAT=( python3_{10..13} ) inherit distutils-r1 @@ -37,8 +37,12 @@ distutils_enable_tests pytest distutils_enable_sphinx docs python_prepare_all() { - sed -e '/pytest-runner/d' \ - -i setup.py || die - sed -e '/addopts/d' -i setup.cfg || die + local PATCHES=( + # https://github.com/mpdavis/python-jose/commit/19677540e74eba4392be53ae434b561cf74ad9a6 + "${FILESDIR}/${P}-test.patch" + ) + distutils-r1_python_prepare_all + sed -e '/pytest-runner/d' -i setup.py || die + sed -e '/addopts/d' -i setup.cfg || die } |