|
| 1 | +From 7daf461528c90776b8f865cd58d20e23bd5b6f3f Mon Sep 17 00:00:00 2001 |
| 2 | +From: Marek Czernek < [email protected]> |
| 3 | +Date: Wed, 2 Oct 2024 09:09:34 +0200 |
| 4 | +Subject: [PATCH] Fix x509 test fails on old openssl systems (#682) |
| 5 | + |
| 6 | +--- |
| 7 | + .../functional/modules/test_x509_v2.py | 41 +++++++++++++---- |
| 8 | + .../pytests/functional/states/test_x509_v2.py | 44 +++++++++++++++---- |
| 9 | + .../scenarios/performance/test_performance.py | 8 +++- |
| 10 | + 3 files changed, 75 insertions(+), 18 deletions(-) |
| 11 | + |
| 12 | +diff --git a/tests/pytests/functional/modules/test_x509_v2.py b/tests/pytests/functional/modules/test_x509_v2.py |
| 13 | +index 2e8152d04a..7de8f3b01f 100644 |
| 14 | +--- a/tests/pytests/functional/modules/test_x509_v2.py |
| 15 | ++++ b/tests/pytests/functional/modules/test_x509_v2.py |
| 16 | +@@ -681,8 +681,13 @@ def test_create_certificate_self_signed(x509, algo, request): |
| 17 | + privkey = request.getfixturevalue(f"{algo}_privkey") |
| 18 | + try: |
| 19 | + res = x509.create_certificate(signing_private_key=privkey, CN="success") |
| 20 | +- except UnsupportedAlgorithm: |
| 21 | ++ except (UnsupportedAlgorithm, NotImplementedError): |
| 22 | + pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version") |
| 23 | ++ except salt.exceptions.CommandExecutionError as e: |
| 24 | ++ if "Could not load PEM-encoded" in e.error: |
| 25 | ++ pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version") |
| 26 | ++ else: |
| 27 | ++ raise e |
| 28 | + assert res.startswith("-----BEGIN CERTIFICATE-----") |
| 29 | + cert = _get_cert(res) |
| 30 | + assert cert.subject.rfc4514_string() == "CN=success" |
| 31 | +@@ -754,8 +759,13 @@ def test_create_certificate_from_privkey(x509, ca_key, ca_cert, algo, request): |
| 32 | + private_key=privkey, |
| 33 | + CN="success", |
| 34 | + ) |
| 35 | +- except UnsupportedAlgorithm: |
| 36 | ++ except (UnsupportedAlgorithm, NotImplementedError): |
| 37 | + pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version") |
| 38 | ++ except salt.exceptions.CommandExecutionError as e: |
| 39 | ++ if "Could not load PEM-encoded" in e.error: |
| 40 | ++ pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version") |
| 41 | ++ else: |
| 42 | ++ raise e |
| 43 | + assert res.startswith("-----BEGIN CERTIFICATE-----") |
| 44 | + cert = _get_cert(res) |
| 45 | + assert cert.subject.rfc4514_string() == "CN=success" |
| 46 | +@@ -802,8 +812,13 @@ def test_create_certificate_from_pubkey(x509, ca_key, ca_cert, algo, request): |
| 47 | + public_key=pubkey, |
| 48 | + CN="success", |
| 49 | + ) |
| 50 | +- except UnsupportedAlgorithm: |
| 51 | ++ except (UnsupportedAlgorithm, NotImplementedError): |
| 52 | + pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version") |
| 53 | ++ except salt.exceptions.CommandExecutionError as e: |
| 54 | ++ if "Could not load PEM-encoded" in e.error: |
| 55 | ++ pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version") |
| 56 | ++ else: |
| 57 | ++ raise e |
| 58 | + assert res.startswith("-----BEGIN CERTIFICATE-----") |
| 59 | + cert = _get_cert(res) |
| 60 | + assert cert.subject.rfc4514_string() == "CN=success" |
| 61 | +@@ -1341,8 +1356,13 @@ def test_create_csr(x509, algo, request): |
| 62 | + privkey = request.getfixturevalue(f"{algo}_privkey") |
| 63 | + try: |
| 64 | + res = x509.create_csr(private_key=privkey) |
| 65 | +- except UnsupportedAlgorithm: |
| 66 | ++ except (UnsupportedAlgorithm, NotImplementedError): |
| 67 | + pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version") |
| 68 | ++ except salt.exceptions.CommandExecutionError as e: |
| 69 | ++ if "Could not load PEM-encoded" in e.error: |
| 70 | ++ pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version") |
| 71 | ++ else: |
| 72 | ++ raise e |
| 73 | + assert res.startswith("-----BEGIN CERTIFICATE REQUEST-----") |
| 74 | + |
| 75 | + |
| 76 | +@@ -1402,7 +1422,7 @@ def test_create_csr_raw(x509, rsa_privkey): |
| 77 | + def test_create_private_key(x509, algo): |
| 78 | + try: |
| 79 | + res = x509.create_private_key(algo=algo) |
| 80 | +- except UnsupportedAlgorithm: |
| 81 | ++ except (UnsupportedAlgorithm, NotImplementedError): |
| 82 | + pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version") |
| 83 | + assert res.startswith("-----BEGIN PRIVATE KEY-----") |
| 84 | + |
| 85 | +@@ -1413,7 +1433,7 @@ def test_create_private_key_with_passphrase(x509, algo): |
| 86 | + passphrase = "hunter2" |
| 87 | + try: |
| 88 | + res = x509.create_private_key(algo=algo, passphrase=passphrase) |
| 89 | +- except UnsupportedAlgorithm: |
| 90 | ++ except (UnsupportedAlgorithm, NotImplementedError): |
| 91 | + pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version") |
| 92 | + assert res.startswith("-----BEGIN ENCRYPTED PRIVATE KEY-----") |
| 93 | + # ensure it can be loaded |
| 94 | +@@ -1465,8 +1485,13 @@ def test_get_private_key_size(x509, algo, expected, request): |
| 95 | + privkey = request.getfixturevalue(f"{algo}_privkey") |
| 96 | + try: |
| 97 | + res = x509.get_private_key_size(privkey) |
| 98 | +- except UnsupportedAlgorithm: |
| 99 | ++ except (UnsupportedAlgorithm, NotImplementedError): |
| 100 | + pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version") |
| 101 | ++ except salt.exceptions.CommandExecutionError as e: |
| 102 | ++ if "Could not load PEM-encoded" in e.error: |
| 103 | ++ pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version") |
| 104 | ++ else: |
| 105 | ++ raise e |
| 106 | + assert res == expected |
| 107 | + |
| 108 | + |
| 109 | +@@ -1612,7 +1637,7 @@ def test_verify_signature(x509, algo, request): |
| 110 | + wrong_privkey = request.getfixturevalue(f"{algo}_privkey") |
| 111 | + try: |
| 112 | + privkey = x509.create_private_key(algo=algo) |
| 113 | +- except UnsupportedAlgorithm: |
| 114 | ++ except (UnsupportedAlgorithm, NotImplementedError): |
| 115 | + pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version") |
| 116 | + cert = x509.create_certificate(signing_private_key=privkey) |
| 117 | + assert x509.verify_signature(cert, privkey) |
| 118 | +diff --git a/tests/pytests/functional/states/test_x509_v2.py b/tests/pytests/functional/states/test_x509_v2.py |
| 119 | +index 47a1c555f8..139f7b1906 100644 |
| 120 | +--- a/tests/pytests/functional/states/test_x509_v2.py |
| 121 | ++++ b/tests/pytests/functional/states/test_x509_v2.py |
| 122 | +@@ -574,9 +574,9 @@ def existing_cert(x509, cert_args, ca_key, rsa_privkey, request): |
| 123 | + ca_key, |
| 124 | + encoding=cert_args.get("encoding", "pem"), |
| 125 | + passphrase=cert_args.get("pkcs12_passphrase"), |
| 126 | +- subject=subject |
| 127 | +- if "signing_policy" not in cert_args |
| 128 | +- else "CN=from_signing_policy", |
| 129 | ++ subject=( |
| 130 | ++ subject if "signing_policy" not in cert_args else "CN=from_signing_policy" |
| 131 | ++ ), |
| 132 | + ) |
| 133 | + yield cert_args["name"] |
| 134 | + |
| 135 | +@@ -694,8 +694,12 @@ def existing_csr_exts(x509, csr_args, csr_args_exts, ca_key, rsa_privkey, reques |
| 136 | + def existing_pk(x509, pk_args, request): |
| 137 | + pk_args.update(request.param) |
| 138 | + ret = x509.private_key_managed(**pk_args) |
| 139 | +- if ret.result == False and "UnsupportedAlgorithm" in ret.comment: |
| 140 | +- pytest.skip(f"Algorithm '{pk_args['algo']}' is not supported on this OpenSSL version") |
| 141 | ++ if ret.result == False and ( |
| 142 | ++ "UnsupportedAlgorithm" in ret.comment or "NotImplementedError" in ret.comment |
| 143 | ++ ): |
| 144 | ++ pytest.skip( |
| 145 | ++ f"Algorithm '{pk_args['algo']}' is not supported on this OpenSSL version" |
| 146 | ++ ) |
| 147 | + _assert_pk_basic( |
| 148 | + ret, |
| 149 | + pk_args.get("algo", "rsa"), |
| 150 | +@@ -1054,6 +1058,8 @@ def test_certificate_managed_days_valid_does_not_override_days_remaining( |
| 151 | + def test_certificate_managed_privkey_change(x509, cert_args, ec_privkey, ca_key): |
| 152 | + cert_args["private_key"] = ec_privkey |
| 153 | + ret = x509.certificate_managed(**cert_args) |
| 154 | ++ if ret.result == False and "NotImplementedError" in ret.comment: |
| 155 | ++ pytest.skip("Current OpenSSL does not support 'ec' algorithm") |
| 156 | + _assert_cert_basic(ret, cert_args["name"], ec_privkey, ca_key) |
| 157 | + assert ret.changes["private_key"] |
| 158 | + |
| 159 | +@@ -1237,6 +1243,8 @@ def test_certificate_managed_wrong_ca_key( |
| 160 | + cert_args["private_key"] = ec_privkey |
| 161 | + cert_args["signing_private_key"] = rsa_privkey |
| 162 | + ret = x509.certificate_managed(**cert_args) |
| 163 | ++ if ret.result == False and "NotImplementedError" in ret.comment: |
| 164 | ++ pytest.skip("Current OpenSSL does not support 'ec' algorithm") |
| 165 | + assert ret.result is False |
| 166 | + assert not ret.changes |
| 167 | + assert "Signing private key does not match the certificate" in ret.comment |
| 168 | +@@ -1917,6 +1925,8 @@ def test_csr_managed_existing_invalid_version(x509, csr_args, rsa_privkey): |
| 169 | + def test_csr_managed_privkey_change(x509, csr_args, ec_privkey): |
| 170 | + csr_args["private_key"] = ec_privkey |
| 171 | + ret = x509.csr_managed(**csr_args) |
| 172 | ++ if ret.result == False and "NotImplementedError" in ret.comment: |
| 173 | ++ pytest.skip("Current OpenSSL does not support 'ec' algorithm") |
| 174 | + _assert_csr_basic(ret, ec_privkey) |
| 175 | + assert ret.changes["private_key"] |
| 176 | + |
| 177 | +@@ -2141,11 +2151,14 @@ def test_private_key_managed(x509, pk_args, algo, encoding, passphrase): |
| 178 | + pytest.skip( |
| 179 | + "PKCS12 serialization of Edwards-curve keys requires cryptography v37" |
| 180 | + ) |
| 181 | ++ |
| 182 | + pk_args["algo"] = algo |
| 183 | + pk_args["encoding"] = encoding |
| 184 | + pk_args["passphrase"] = passphrase |
| 185 | + ret = x509.private_key_managed(**pk_args) |
| 186 | +- if ret.result == False and "UnsupportedAlgorithm" in ret.comment: |
| 187 | ++ if ret.result == False and ( |
| 188 | ++ "UnsupportedAlgorithm" in ret.comment or "NotImplementedError" in ret.comment |
| 189 | ++ ): |
| 190 | + pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version") |
| 191 | + _assert_pk_basic(ret, algo, encoding, passphrase) |
| 192 | + |
| 193 | +@@ -2155,6 +2168,8 @@ def test_private_key_managed_keysize(x509, pk_args, algo, keysize): |
| 194 | + pk_args["algo"] = algo |
| 195 | + pk_args["keysize"] = keysize |
| 196 | + ret = x509.private_key_managed(**pk_args) |
| 197 | ++ if ret.result == False and "NotImplementedError" in ret.comment: |
| 198 | ++ pytest.skip("Current OpenSSL does not support 'ec' algorithm") |
| 199 | + pk = _assert_pk_basic(ret, algo) |
| 200 | + assert pk.key_size == keysize |
| 201 | + |
| 202 | +@@ -2174,8 +2189,12 @@ def test_private_key_managed_keysize(x509, pk_args, algo, keysize): |
| 203 | + ) |
| 204 | + def test_private_key_managed_existing(x509, pk_args): |
| 205 | + ret = x509.private_key_managed(**pk_args) |
| 206 | +- if ret.result == False and "UnsupportedAlgorithm" in ret.comment: |
| 207 | +- pytest.skip(f"Algorithm '{pk_args['algo']}' is not supported on this OpenSSL version") |
| 208 | ++ if ret.result == False and ( |
| 209 | ++ "UnsupportedAlgorithm" in ret.comment or "NotImplementedError" in ret.comment |
| 210 | ++ ): |
| 211 | ++ pytest.skip( |
| 212 | ++ f"Algorithm '{pk_args['algo']}' is not supported on this OpenSSL version" |
| 213 | ++ ) |
| 214 | + _assert_not_changed(ret) |
| 215 | + |
| 216 | + |
| 217 | +@@ -2382,6 +2401,8 @@ def test_private_key_managed_follow_symlinks_changes( |
| 218 | + pk_args["encoding"] = encoding |
| 219 | + pk_args["algo"] = "ec" |
| 220 | + ret = x509.private_key_managed(**pk_args) |
| 221 | ++ if ret.result == False and "NotImplementedError" in ret.comment: |
| 222 | ++ pytest.skip("Current OpenSSL does not support 'ec' algorithm") |
| 223 | + assert ret.changes |
| 224 | + assert Path(ret.name).is_symlink() == follow |
| 225 | + |
| 226 | +@@ -2722,7 +2743,12 @@ def _get_cert(cert, encoding="pem", passphrase=None): |
| 227 | + def _belongs_to(cert_or_pubkey, privkey): |
| 228 | + if isinstance(cert_or_pubkey, cx509.Certificate): |
| 229 | + cert_or_pubkey = cert_or_pubkey.public_key() |
| 230 | +- return x509util.is_pair(cert_or_pubkey, x509util.load_privkey(privkey)) |
| 231 | ++ try: |
| 232 | ++ return x509util.is_pair(cert_or_pubkey, x509util.load_privkey(privkey)) |
| 233 | ++ except NotImplementedError: |
| 234 | ++ pytest.skip( |
| 235 | ++ "This OpenSSL version does not support current cryptographic algorithm" |
| 236 | ++ ) |
| 237 | + |
| 238 | + |
| 239 | + def _signed_by(cert, privkey): |
| 240 | +diff --git a/tests/pytests/scenarios/performance/test_performance.py b/tests/pytests/scenarios/performance/test_performance.py |
| 241 | +index 85b92ed986..6319e26ce1 100644 |
| 242 | +--- a/tests/pytests/scenarios/performance/test_performance.py |
| 243 | ++++ b/tests/pytests/scenarios/performance/test_performance.py |
| 244 | +@@ -10,7 +10,13 @@ from saltfactories.utils import random_string |
| 245 | + |
| 246 | + from salt.version import SaltVersionsInfo, __version__ |
| 247 | + |
| 248 | +-pytestmark = [pytest.mark.skip_if_binaries_missing("docker")] |
| 249 | ++pytestmark = [ |
| 250 | ++ pytest.mark.skip_if_binaries_missing("docker"), |
| 251 | ++ pytest.mark.skipif( |
| 252 | ++ os.environ.get("GITHUB_ACTIONS", "") == "true", |
| 253 | ++ reason="Cannot spawn containers in GH actions run", |
| 254 | ++ ), |
| 255 | ++] |
| 256 | + |
| 257 | + |
| 258 | + class ContainerMaster(SaltDaemon, master.SaltMaster): |
| 259 | +-- |
| 260 | +2.46.1 |
| 261 | + |
0 commit comments