From 089039d0f6bb34d6a8b4dcdb04265547abc74c1d Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Thu, 21 Mar 2024 22:44:41 -0400 Subject: [PATCH] Added additional PKCS#12 tests (#10625) --- tests/hazmat/primitives/test_pkcs12.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/hazmat/primitives/test_pkcs12.py b/tests/hazmat/primitives/test_pkcs12.py index f5284b788..9217e4eca 100644 --- a/tests/hazmat/primitives/test_pkcs12.py +++ b/tests/hazmat/primitives/test_pkcs12.py @@ -529,6 +529,30 @@ class TestPKCS12Creation: assert parsed_key is None assert parsed_more_certs == [cert] + def test_generate_cert_only_none_cas(self, backend): + # Same as test_generate_cert_only, but passing None instead of an + # empty list for cas. + cert, _ = _load_ca(backend) + p12 = serialize_key_and_certificates( + None, None, cert, None, serialization.NoEncryption() + ) + parsed_key, parsed_cert, parsed_more_certs = load_key_and_certificates( + p12, None + ) + assert parsed_cert is None + assert parsed_key is None + assert parsed_more_certs == [cert] + + def test_invalid_utf8_friendly_name(self, backend): + if rust_openssl.CRYPTOGRAPHY_IS_LIBRESSL: + pytest.skip("Temporarily doesn't work on LibreSSL") + + cert, _ = _load_ca(backend) + with pytest.raises(ValueError): + serialize_key_and_certificates( + b"\xc9", None, cert, None, serialization.NoEncryption() + ) + def test_must_supply_something(self): with pytest.raises(ValueError) as exc: serialize_key_and_certificates(