From f1695970623284deff57fc234683611f73ed4b63 Mon Sep 17 00:00:00 2001 From: Ivan Desiatov Date: Sat, 7 Sep 2024 11:32:26 +0200 Subject: [PATCH] Don't use modern typing syntax. --- tests/x509/verification/test_limbo.py | 3 ++- tests/x509/verification/test_verification.py | 25 ++++++++++---------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/tests/x509/verification/test_limbo.py b/tests/x509/verification/test_limbo.py index c3fece44b21eb..114405f2393eb 100644 --- a/tests/x509/verification/test_limbo.py +++ b/tests/x509/verification/test_limbo.py @@ -6,6 +6,7 @@ import ipaddress import json import os +from typing import Type, Union import pytest @@ -100,7 +101,7 @@ def _get_limbo_peer(expected_peer): def _limbo_testcase( id_, testcase, - builder_type: type[PolicyBuilder] | type[CustomPolicyBuilder], + builder_type: Union[Type[PolicyBuilder], Type[CustomPolicyBuilder]], ): if id_ in LIMBO_SKIP_TESTCASES: pytest.skip(f"explicitly skipped testcase: {id_}") diff --git a/tests/x509/verification/test_verification.py b/tests/x509/verification/test_verification.py index 576aefc9e5bc6..8b89112b66544 100644 --- a/tests/x509/verification/test_verification.py +++ b/tests/x509/verification/test_verification.py @@ -6,6 +6,7 @@ import os from functools import lru_cache from ipaddress import IPv4Address +from typing import Type, Union import pytest @@ -33,7 +34,7 @@ def dummy_store() -> Store: return Store([cert]) -AnyPolicyBuilder = PolicyBuilder | CustomPolicyBuilder +AnyPolicyBuilder = Union[PolicyBuilder, CustomPolicyBuilder] @pytest.mark.parametrize("builder_type", [PolicyBuilder, CustomPolicyBuilder]) @@ -43,23 +44,23 @@ class TestPolicyBuilderCommon: PolicyBuilder and CustomPolicyBuilder. """ - def test_time_already_set(self, builder_type: type[AnyPolicyBuilder]): + def test_time_already_set(self, builder_type: Type[AnyPolicyBuilder]): with pytest.raises(ValueError): builder_type().time(datetime.datetime.now()).time( datetime.datetime.now() ) - def test_store_already_set(self, builder_type: type[AnyPolicyBuilder]): + def test_store_already_set(self, builder_type: Type[AnyPolicyBuilder]): with pytest.raises(ValueError): builder_type().store(dummy_store()).store(dummy_store()) def test_max_chain_depth_already_set( - self, builder_type: type[AnyPolicyBuilder] + self, builder_type: Type[AnyPolicyBuilder] ): with pytest.raises(ValueError): builder_type().max_chain_depth(8).max_chain_depth(9) - def test_ipaddress_subject(self, builder_type: type[AnyPolicyBuilder]): + def test_ipaddress_subject(self, builder_type: Type[AnyPolicyBuilder]): policy = ( builder_type() .store(dummy_store()) @@ -67,7 +68,7 @@ def test_ipaddress_subject(self, builder_type: type[AnyPolicyBuilder]): ) assert policy.subject == IPAddress(IPv4Address("0.0.0.0")) - def test_dnsname_subject(self, builder_type: type[AnyPolicyBuilder]): + def test_dnsname_subject(self, builder_type: Type[AnyPolicyBuilder]): policy = ( builder_type() .store(dummy_store()) @@ -75,7 +76,7 @@ def test_dnsname_subject(self, builder_type: type[AnyPolicyBuilder]): ) assert policy.subject == DNSName("cryptography.io") - def test_subject_bad_types(self, builder_type: type[AnyPolicyBuilder]): + def test_subject_bad_types(self, builder_type: Type[AnyPolicyBuilder]): # Subject must be a supported GeneralName type with pytest.raises(TypeError): builder_type().store(dummy_store()).build_server_verifier( @@ -92,7 +93,7 @@ def test_subject_bad_types(self, builder_type: type[AnyPolicyBuilder]): with pytest.raises(TypeError): builder_type().store(dummy_store()).build_server_verifier(None) # type: ignore[arg-type] - def test_builder_pattern(self, builder_type: type[AnyPolicyBuilder]): + def test_builder_pattern(self, builder_type: Type[AnyPolicyBuilder]): now = datetime.datetime.now().replace(microsecond=0) store = dummy_store() max_chain_depth = 16 @@ -110,7 +111,7 @@ def test_builder_pattern(self, builder_type: type[AnyPolicyBuilder]): assert verifier.eku == ExtendedKeyUsageOID.SERVER_AUTH def test_build_server_verifier_missing_store( - self, builder_type: type[AnyPolicyBuilder] + self, builder_type: Type[AnyPolicyBuilder] ): with pytest.raises( ValueError, match="A server verifier must have a trust store" @@ -153,14 +154,14 @@ def test_store_rejects_non_certificates(self): ) class TestClientVerifier: def test_build_client_verifier_missing_store( - self, builder_type: type[AnyPolicyBuilder] + self, builder_type: Type[AnyPolicyBuilder] ): with pytest.raises( ValueError, match="A client verifier must have a trust store" ): builder_type().build_client_verifier() - def test_verify(self, builder_type: type[AnyPolicyBuilder]): + def test_verify(self, builder_type: Type[AnyPolicyBuilder]): # expires 2018-11-16 01:15:03 UTC leaf = _load_cert( os.path.join("x509", "cryptography.io.pem"), @@ -210,7 +211,7 @@ def test_verify(self, builder_type: type[AnyPolicyBuilder]): assert len(verified_client.sans) == 2 def test_verify_fails_renders_oid( - self, builder_type: type[AnyPolicyBuilder] + self, builder_type: Type[AnyPolicyBuilder] ): leaf = _load_cert( os.path.join("x509", "custom", "ekucrit-testuser-cert.pem"),