Skip to content

Commit

Permalink
Skip tests for unsupported algorithm on old OpenSSL version
Browse files Browse the repository at this point in the history
  • Loading branch information
vzhestkov committed May 6, 2024
1 parent 4ec5c8b commit c84793e
Showing 1 changed file with 35 additions and 16 deletions.
51 changes: 35 additions & 16 deletions tests/pytests/functional/modules/test_x509_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
try:
import cryptography
import cryptography.x509 as cx509
from cryptography.exceptions import UnsupportedAlgorithm
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.serialization import (
load_pem_private_key,
Expand Down Expand Up @@ -678,7 +679,10 @@ def crl_revoked():
@pytest.mark.parametrize("algo", ["rsa", "ec", "ed25519", "ed448"])
def test_create_certificate_self_signed(x509, algo, request):
privkey = request.getfixturevalue(f"{algo}_privkey")
res = x509.create_certificate(signing_private_key=privkey, CN="success")
try:
res = x509.create_certificate(signing_private_key=privkey, CN="success")
except UnsupportedAlgorithm:
pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version")
assert res.startswith("-----BEGIN CERTIFICATE-----")
cert = _get_cert(res)
assert cert.subject.rfc4514_string() == "CN=success"
Expand Down Expand Up @@ -743,12 +747,15 @@ def test_create_certificate_raw(x509, rsa_privkey):
@pytest.mark.parametrize("algo", ["rsa", "ec", "ed25519", "ed448"])
def test_create_certificate_from_privkey(x509, ca_key, ca_cert, algo, request):
privkey = request.getfixturevalue(f"{algo}_privkey")
res = x509.create_certificate(
signing_cert=ca_cert,
signing_private_key=ca_key,
private_key=privkey,
CN="success",
)
try:
res = x509.create_certificate(
signing_cert=ca_cert,
signing_private_key=ca_key,
private_key=privkey,
CN="success",
)
except UnsupportedAlgorithm:
pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version")
assert res.startswith("-----BEGIN CERTIFICATE-----")
cert = _get_cert(res)
assert cert.subject.rfc4514_string() == "CN=success"
Expand Down Expand Up @@ -788,12 +795,15 @@ def test_create_certificate_from_encrypted_privkey_with_encrypted_privkey(
@pytest.mark.parametrize("algo", ["rsa", "ec", "ed25519", "ed448"])
def test_create_certificate_from_pubkey(x509, ca_key, ca_cert, algo, request):
pubkey = request.getfixturevalue(f"{algo}_pubkey")
res = x509.create_certificate(
signing_cert=ca_cert,
signing_private_key=ca_key,
public_key=pubkey,
CN="success",
)
try:
res = x509.create_certificate(
signing_cert=ca_cert,
signing_private_key=ca_key,
public_key=pubkey,
CN="success",
)
except UnsupportedAlgorithm:
pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version")
assert res.startswith("-----BEGIN CERTIFICATE-----")
cert = _get_cert(res)
assert cert.subject.rfc4514_string() == "CN=success"
Expand Down Expand Up @@ -1329,7 +1339,10 @@ def test_create_crl_raw(x509, crl_args):
@pytest.mark.parametrize("algo", ["rsa", "ec", "ed25519", "ed448"])
def test_create_csr(x509, algo, request):
privkey = request.getfixturevalue(f"{algo}_privkey")
res = x509.create_csr(private_key=privkey)
try:
res = x509.create_csr(private_key=privkey)
except UnsupportedAlgorithm:
pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version")
assert res.startswith("-----BEGIN CERTIFICATE REQUEST-----")


Expand Down Expand Up @@ -1444,7 +1457,10 @@ def test_create_private_key_raw(x509):
)
def test_get_private_key_size(x509, algo, expected, request):
privkey = request.getfixturevalue(f"{algo}_privkey")
res = x509.get_private_key_size(privkey)
try:
res = x509.get_private_key_size(privkey)
except UnsupportedAlgorithm:
pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version")
assert res == expected


Expand Down Expand Up @@ -1588,7 +1604,10 @@ def test_verify_private_key(x509, ca_key, ca_cert):
@pytest.mark.parametrize("algo", ["rsa", "ec", "ed25519", "ed448"])
def test_verify_signature(x509, algo, request):
wrong_privkey = request.getfixturevalue(f"{algo}_privkey")
privkey = x509.create_private_key(algo=algo)
try:
privkey = x509.create_private_key(algo=algo)
except UnsupportedAlgorithm:
pytest.skip(f"Algorithm '{algo}' is not supported on this OpenSSL version")
cert = x509.create_certificate(signing_private_key=privkey)
assert x509.verify_signature(cert, privkey)
assert not x509.verify_signature(cert, wrong_privkey)
Expand Down

0 comments on commit c84793e

Please sign in to comment.