Skip to content

Commit 7daf461

Browse files
authored
Fix x509 test fails on old openssl systems (#682)
1 parent bbdb569 commit 7daf461

File tree

3 files changed

+75
-18
lines changed

3 files changed

+75
-18
lines changed

tests/pytests/functional/modules/test_x509_v2.py

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,13 @@ def test_create_certificate_self_signed(x509, algo, request):
681681
privkey = request.getfixturevalue(f"{algo}_privkey")
682682
try:
683683
res = x509.create_certificate(signing_private_key=privkey, CN="success")
684-
except UnsupportedAlgorithm:
684+
except (UnsupportedAlgorithm, NotImplementedError):
685685
pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version")
686+
except salt.exceptions.CommandExecutionError as e:
687+
if "Could not load PEM-encoded" in e.error:
688+
pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version")
689+
else:
690+
raise e
686691
assert res.startswith("-----BEGIN CERTIFICATE-----")
687692
cert = _get_cert(res)
688693
assert cert.subject.rfc4514_string() == "CN=success"
@@ -754,8 +759,13 @@ def test_create_certificate_from_privkey(x509, ca_key, ca_cert, algo, request):
754759
private_key=privkey,
755760
CN="success",
756761
)
757-
except UnsupportedAlgorithm:
762+
except (UnsupportedAlgorithm, NotImplementedError):
758763
pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version")
764+
except salt.exceptions.CommandExecutionError as e:
765+
if "Could not load PEM-encoded" in e.error:
766+
pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version")
767+
else:
768+
raise e
759769
assert res.startswith("-----BEGIN CERTIFICATE-----")
760770
cert = _get_cert(res)
761771
assert cert.subject.rfc4514_string() == "CN=success"
@@ -802,8 +812,13 @@ def test_create_certificate_from_pubkey(x509, ca_key, ca_cert, algo, request):
802812
public_key=pubkey,
803813
CN="success",
804814
)
805-
except UnsupportedAlgorithm:
815+
except (UnsupportedAlgorithm, NotImplementedError):
806816
pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version")
817+
except salt.exceptions.CommandExecutionError as e:
818+
if "Could not load PEM-encoded" in e.error:
819+
pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version")
820+
else:
821+
raise e
807822
assert res.startswith("-----BEGIN CERTIFICATE-----")
808823
cert = _get_cert(res)
809824
assert cert.subject.rfc4514_string() == "CN=success"
@@ -1341,8 +1356,13 @@ def test_create_csr(x509, algo, request):
13411356
privkey = request.getfixturevalue(f"{algo}_privkey")
13421357
try:
13431358
res = x509.create_csr(private_key=privkey)
1344-
except UnsupportedAlgorithm:
1359+
except (UnsupportedAlgorithm, NotImplementedError):
13451360
pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version")
1361+
except salt.exceptions.CommandExecutionError as e:
1362+
if "Could not load PEM-encoded" in e.error:
1363+
pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version")
1364+
else:
1365+
raise e
13461366
assert res.startswith("-----BEGIN CERTIFICATE REQUEST-----")
13471367

13481368

@@ -1402,7 +1422,7 @@ def test_create_csr_raw(x509, rsa_privkey):
14021422
def test_create_private_key(x509, algo):
14031423
try:
14041424
res = x509.create_private_key(algo=algo)
1405-
except UnsupportedAlgorithm:
1425+
except (UnsupportedAlgorithm, NotImplementedError):
14061426
pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version")
14071427
assert res.startswith("-----BEGIN PRIVATE KEY-----")
14081428

@@ -1413,7 +1433,7 @@ def test_create_private_key_with_passphrase(x509, algo):
14131433
passphrase = "hunter2"
14141434
try:
14151435
res = x509.create_private_key(algo=algo, passphrase=passphrase)
1416-
except UnsupportedAlgorithm:
1436+
except (UnsupportedAlgorithm, NotImplementedError):
14171437
pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version")
14181438
assert res.startswith("-----BEGIN ENCRYPTED PRIVATE KEY-----")
14191439
# ensure it can be loaded
@@ -1465,8 +1485,13 @@ def test_get_private_key_size(x509, algo, expected, request):
14651485
privkey = request.getfixturevalue(f"{algo}_privkey")
14661486
try:
14671487
res = x509.get_private_key_size(privkey)
1468-
except UnsupportedAlgorithm:
1488+
except (UnsupportedAlgorithm, NotImplementedError):
14691489
pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version")
1490+
except salt.exceptions.CommandExecutionError as e:
1491+
if "Could not load PEM-encoded" in e.error:
1492+
pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version")
1493+
else:
1494+
raise e
14701495
assert res == expected
14711496

14721497

@@ -1612,7 +1637,7 @@ def test_verify_signature(x509, algo, request):
16121637
wrong_privkey = request.getfixturevalue(f"{algo}_privkey")
16131638
try:
16141639
privkey = x509.create_private_key(algo=algo)
1615-
except UnsupportedAlgorithm:
1640+
except (UnsupportedAlgorithm, NotImplementedError):
16161641
pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version")
16171642
cert = x509.create_certificate(signing_private_key=privkey)
16181643
assert x509.verify_signature(cert, privkey)

tests/pytests/functional/states/test_x509_v2.py

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -574,9 +574,9 @@ def existing_cert(x509, cert_args, ca_key, rsa_privkey, request):
574574
ca_key,
575575
encoding=cert_args.get("encoding", "pem"),
576576
passphrase=cert_args.get("pkcs12_passphrase"),
577-
subject=subject
578-
if "signing_policy" not in cert_args
579-
else "CN=from_signing_policy",
577+
subject=(
578+
subject if "signing_policy" not in cert_args else "CN=from_signing_policy"
579+
),
580580
)
581581
yield cert_args["name"]
582582

@@ -694,8 +694,12 @@ def existing_csr_exts(x509, csr_args, csr_args_exts, ca_key, rsa_privkey, reques
694694
def existing_pk(x509, pk_args, request):
695695
pk_args.update(request.param)
696696
ret = x509.private_key_managed(**pk_args)
697-
if ret.result == False and "UnsupportedAlgorithm" in ret.comment:
698-
pytest.skip(f"Algorithm '{pk_args['algo']}' is not supported on this OpenSSL version")
697+
if ret.result == False and (
698+
"UnsupportedAlgorithm" in ret.comment or "NotImplementedError" in ret.comment
699+
):
700+
pytest.skip(
701+
f"Algorithm '{pk_args['algo']}' is not supported on this OpenSSL version"
702+
)
699703
_assert_pk_basic(
700704
ret,
701705
pk_args.get("algo", "rsa"),
@@ -1054,6 +1058,8 @@ def test_certificate_managed_days_valid_does_not_override_days_remaining(
10541058
def test_certificate_managed_privkey_change(x509, cert_args, ec_privkey, ca_key):
10551059
cert_args["private_key"] = ec_privkey
10561060
ret = x509.certificate_managed(**cert_args)
1061+
if ret.result == False and "NotImplementedError" in ret.comment:
1062+
pytest.skip("Current OpenSSL does not support 'ec' algorithm")
10571063
_assert_cert_basic(ret, cert_args["name"], ec_privkey, ca_key)
10581064
assert ret.changes["private_key"]
10591065

@@ -1237,6 +1243,8 @@ def test_certificate_managed_wrong_ca_key(
12371243
cert_args["private_key"] = ec_privkey
12381244
cert_args["signing_private_key"] = rsa_privkey
12391245
ret = x509.certificate_managed(**cert_args)
1246+
if ret.result == False and "NotImplementedError" in ret.comment:
1247+
pytest.skip("Current OpenSSL does not support 'ec' algorithm")
12401248
assert ret.result is False
12411249
assert not ret.changes
12421250
assert "Signing private key does not match the certificate" in ret.comment
@@ -1917,6 +1925,8 @@ def test_csr_managed_existing_invalid_version(x509, csr_args, rsa_privkey):
19171925
def test_csr_managed_privkey_change(x509, csr_args, ec_privkey):
19181926
csr_args["private_key"] = ec_privkey
19191927
ret = x509.csr_managed(**csr_args)
1928+
if ret.result == False and "NotImplementedError" in ret.comment:
1929+
pytest.skip("Current OpenSSL does not support 'ec' algorithm")
19201930
_assert_csr_basic(ret, ec_privkey)
19211931
assert ret.changes["private_key"]
19221932

@@ -2141,11 +2151,14 @@ def test_private_key_managed(x509, pk_args, algo, encoding, passphrase):
21412151
pytest.skip(
21422152
"PKCS12 serialization of Edwards-curve keys requires cryptography v37"
21432153
)
2154+
21442155
pk_args["algo"] = algo
21452156
pk_args["encoding"] = encoding
21462157
pk_args["passphrase"] = passphrase
21472158
ret = x509.private_key_managed(**pk_args)
2148-
if ret.result == False and "UnsupportedAlgorithm" in ret.comment:
2159+
if ret.result == False and (
2160+
"UnsupportedAlgorithm" in ret.comment or "NotImplementedError" in ret.comment
2161+
):
21492162
pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version")
21502163
_assert_pk_basic(ret, algo, encoding, passphrase)
21512164

@@ -2155,6 +2168,8 @@ def test_private_key_managed_keysize(x509, pk_args, algo, keysize):
21552168
pk_args["algo"] = algo
21562169
pk_args["keysize"] = keysize
21572170
ret = x509.private_key_managed(**pk_args)
2171+
if ret.result == False and "NotImplementedError" in ret.comment:
2172+
pytest.skip("Current OpenSSL does not support 'ec' algorithm")
21582173
pk = _assert_pk_basic(ret, algo)
21592174
assert pk.key_size == keysize
21602175

@@ -2174,8 +2189,12 @@ def test_private_key_managed_keysize(x509, pk_args, algo, keysize):
21742189
)
21752190
def test_private_key_managed_existing(x509, pk_args):
21762191
ret = x509.private_key_managed(**pk_args)
2177-
if ret.result == False and "UnsupportedAlgorithm" in ret.comment:
2178-
pytest.skip(f"Algorithm '{pk_args['algo']}' is not supported on this OpenSSL version")
2192+
if ret.result == False and (
2193+
"UnsupportedAlgorithm" in ret.comment or "NotImplementedError" in ret.comment
2194+
):
2195+
pytest.skip(
2196+
f"Algorithm '{pk_args['algo']}' is not supported on this OpenSSL version"
2197+
)
21792198
_assert_not_changed(ret)
21802199

21812200

@@ -2382,6 +2401,8 @@ def test_private_key_managed_follow_symlinks_changes(
23822401
pk_args["encoding"] = encoding
23832402
pk_args["algo"] = "ec"
23842403
ret = x509.private_key_managed(**pk_args)
2404+
if ret.result == False and "NotImplementedError" in ret.comment:
2405+
pytest.skip("Current OpenSSL does not support 'ec' algorithm")
23852406
assert ret.changes
23862407
assert Path(ret.name).is_symlink() == follow
23872408

@@ -2722,7 +2743,12 @@ def _get_cert(cert, encoding="pem", passphrase=None):
27222743
def _belongs_to(cert_or_pubkey, privkey):
27232744
if isinstance(cert_or_pubkey, cx509.Certificate):
27242745
cert_or_pubkey = cert_or_pubkey.public_key()
2725-
return x509util.is_pair(cert_or_pubkey, x509util.load_privkey(privkey))
2746+
try:
2747+
return x509util.is_pair(cert_or_pubkey, x509util.load_privkey(privkey))
2748+
except NotImplementedError:
2749+
pytest.skip(
2750+
"This OpenSSL version does not support current cryptographic algorithm"
2751+
)
27262752

27272753

27282754
def _signed_by(cert, privkey):

tests/pytests/scenarios/performance/test_performance.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@
1010

1111
from salt.version import SaltVersionsInfo, __version__
1212

13-
pytestmark = [pytest.mark.skip_if_binaries_missing("docker")]
13+
pytestmark = [
14+
pytest.mark.skip_if_binaries_missing("docker"),
15+
pytest.mark.skipif(
16+
os.environ.get("GITHUB_ACTIONS", "") == "true",
17+
reason="Cannot spawn containers in GH actions run",
18+
),
19+
]
1420

1521

1622
class ContainerMaster(SaltDaemon, master.SaltMaster):

0 commit comments

Comments
 (0)