mirror of
https://github.com/laurivosandi/certidude
synced 2025-09-06 13:51:12 +00:00
Attempt to fix tests
This commit is contained in:
@@ -1,25 +1,43 @@
|
||||
import os
|
||||
from click.testing import CliRunner
|
||||
from certidude.cli import entry_point as cli
|
||||
from datetime import datetime, timedelta
|
||||
from cryptography.hazmat.primitives import hashes, serialization
|
||||
from cryptography.x509.oid import NameOID
|
||||
|
||||
runner = CliRunner()
|
||||
|
||||
def test_cli_setup_authority():
|
||||
# Authority setup
|
||||
# TODO: parent, common-name, country, state, locality
|
||||
# {authority,certificate,revocation-list}-lifetime
|
||||
# organization, organizational-unit
|
||||
# pkcs11
|
||||
# {crl-distribution,ocsp-responder}-url
|
||||
# email-address
|
||||
# inbox, outbox
|
||||
|
||||
result = runner.invoke(cli, ['setup', 'authority'])
|
||||
assert not result.exception
|
||||
from certidude import const, config
|
||||
|
||||
from certidude import authority
|
||||
assert authority.certificate.serial_number == '0000000000000000000000000000000000000001'
|
||||
assert authority.certificate.signed < datetime.now()
|
||||
assert authority.certificate.expires > datetime.now() + timedelta(days=7000)
|
||||
assert authority.ca_cert.serial_number == 1
|
||||
assert authority.ca_cert.not_valid_before < datetime.now()
|
||||
assert authority.ca_cert.not_valid_after > datetime.now() + timedelta(days=7000)
|
||||
|
||||
|
||||
result = runner.invoke(cli, ['serve', '-f', '-p', '8080'])
|
||||
assert not result.exception
|
||||
|
||||
|
||||
from cryptography import x509
|
||||
from cryptography.hazmat.primitives.asymmetric import rsa, padding
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
key = rsa.generate_private_key(
|
||||
public_exponent=65537,
|
||||
key_size=4096,
|
||||
backend=default_backend()
|
||||
)
|
||||
|
||||
csr = x509.CertificateSigningRequestBuilder(
|
||||
).subject_name(x509.Name([x509.NameAttribute(NameOID.COMMON_NAME, u"test")]))
|
||||
|
||||
with open(os.path.join(config.REQUESTS_DIR, "test.pem"), "w") as f:
|
||||
f.write(csr.sign(key, hashes.SHA256(), default_backend()).public_bytes(serialization.Encoding.PEM))
|
||||
|
||||
result = runner.invoke(cli, ['sign', 'test', '-o'])
|
||||
assert not result.exception
|
||||
|
||||
result = runner.invoke(cli, ['revoke', 'test'])
|
||||
assert not result.exception
|
||||
|
Reference in New Issue
Block a user