Skip to content

Commit

Permalink
Add integration tests for cryptography
Browse files Browse the repository at this point in the history
  • Loading branch information
hynek committed Jan 14, 2024
1 parent 1c6c8e3 commit e1f1bd5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
File renamed without changes.
31 changes: 30 additions & 1 deletion tests/test_cryptography.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
verify_certificate_ip_address,
)
from service_identity.exceptions import (
CertificateError,
DNSMismatch,
IPAddressMismatch,
VerificationError,
Expand All @@ -24,7 +25,12 @@
URIPattern,
)

from .util import PEM_CN_ONLY, PEM_DNS_ONLY, PEM_EVERYTHING, PEM_OTHER_NAME
from .certificates import (
PEM_CN_ONLY,
PEM_DNS_ONLY,
PEM_EVERYTHING,
PEM_OTHER_NAME,
)


backend = default_backend()
Expand All @@ -35,6 +41,29 @@


class TestPublicAPI:
def test_no_cert_patterns_hostname(self):
"""
A certificate without subjectAltNames raises a helpful
CertificateError.
"""
with pytest.raises(
CertificateError,
match="Certificate does not contain any `subjectAltName`s.",
):
verify_certificate_hostname(X509_CN_ONLY, "example.com")

@pytest.mark.parametrize("ip", ["203.0.113.0", "2001:db8::"])
def test_no_cert_patterns_ip_address(self, ip):
"""
A certificate without subjectAltNames raises a helpful
CertificateError.
"""
with pytest.raises(
CertificateError,
match="Certificate does not contain any `subjectAltName`s.",
):
verify_certificate_ip_address(X509_CN_ONLY, ip)

def test_certificate_verify_hostname_ok(self):
"""
verify_certificate_hostname succeeds if the hostnames match.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_hazmat.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
verify_service_identity,
)

from .certificates import DNS_IDS
from .test_cryptography import CERT_EVERYTHING
from .util import DNS_IDS


try:
Expand Down
7 changes: 6 additions & 1 deletion tests/test_pyopenssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
verify_ip_address,
)

from .util import PEM_CN_ONLY, PEM_DNS_ONLY, PEM_EVERYTHING, PEM_OTHER_NAME
from .certificates import (
PEM_CN_ONLY,
PEM_DNS_ONLY,
PEM_EVERYTHING,
PEM_OTHER_NAME,
)


if pytest.importorskip("OpenSSL"):
Expand Down

0 comments on commit e1f1bd5

Please sign in to comment.