Add a crypto_util test and mark few lines as no cover

This commit is contained in:
Joona Hoikkala 2019-12-20 20:19:00 +02:00
parent 857f98d4ec
commit 11fce9a870
No known key found for this signature in database
GPG key ID: D5AA86BBF9B29A5C
3 changed files with 20 additions and 4 deletions

View file

@ -112,7 +112,7 @@ class RevocationChecker(object):
"-verify_other", chain_path,
"-trust_other",
"-header"] + self.host_args(host)
if response_file:
if response_file: # pragma: no cover
cmd += ["-respout", response_file]
logger.debug("Querying OCSP for %s", cert_path)
logger.debug(" ".join(cmd))
@ -176,7 +176,7 @@ def _check_ocsp_cryptography(cert_path, chain_path, url, response_file=None):
logger.info("OCSP check failed for %s (HTTP status: %d)", cert_path, response.status_code)
return False
if response_file:
if response_file: # pragma: no cover
with open(response_file, 'wb') as fh:
fh.write(response.content)

View file

@ -225,7 +225,9 @@ def verify_renewable_cert(renewable_cert):
def load_cert(cert_path):
"""Reads the certificate PEM file and returns a cryptography.x509 object
:param str cert_path: Path to the certificate
:rtype `cryptography.x509`:
:returns: x509 certificate object
"""

View file

@ -25,6 +25,7 @@ P256_KEY = test_util.load_vector('nistp256_key.pem')
P256_CERT_PATH = test_util.vector_path('cert-nosans_nistp256.pem')
P256_CERT = test_util.load_vector('cert-nosans_nistp256.pem')
class InitSaveKeyTest(test_util.TempDirTestCase):
"""Tests for certbot.crypto_util.init_save_key."""
def setUp(self):
@ -369,8 +370,10 @@ class Sha256sumTest(unittest.TestCase):
"""Tests for certbot.crypto_util.notAfter"""
def test_sha256sum(self):
from certbot.crypto_util import sha256sum
self.assertEqual(sha256sum(CERT_PATH),
'914ffed8daf9e2c99d90ac95c77d54f32cbd556672facac380f0c063498df84e')
self.assertEqual(
sha256sum(CERT_PATH),
'914ffed8daf9e2c99d90ac95c77d54f32cbd556672facac380f0c063498df84e'
)
class CertAndChainFromFullchainTest(unittest.TestCase):
@ -388,5 +391,16 @@ class CertAndChainFromFullchainTest(unittest.TestCase):
self.assertEqual(chain_out, chain_pem)
class CertFingerprintTest(unittest.TestCase):
"""Tests for certbot.crypto_util.cert_sha1_fingerprint"""
def test_cert_sha1_fingerprint(self):
from certbot.crypto_util import cert_sha1_fingerprint
self.assertEqual(
cert_sha1_fingerprint(CERT_PATH),
b'\t\xf8\xce\x01E\r(\x84g\xc32j\xc0E~5\x199\xc7.'
)
if __name__ == '__main__':
unittest.main() # pragma: no cover