mirror of
https://github.com/laurivosandi/certidude
synced 2024-12-22 08:15:18 +00:00
Add basic tests
This commit is contained in:
parent
79ee9aa22c
commit
4c1c2010c6
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,6 +2,7 @@
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
.goutputstream*
|
||||
*.swp
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
@ -474,7 +474,10 @@ def certidude_setup_authority(parent, country, state, locality, organization, or
|
||||
|
||||
slug = os.path.basename(directory[:-1] if directory.endswith('/') else directory)
|
||||
if not slug:
|
||||
raise ValueError("Please supply proper target path")
|
||||
raise click.ClickException("Please supply proper target path")
|
||||
# Make sure slug is valid
|
||||
if not re.match(r"^[_a-zA-Z0-9]+$", slug):
|
||||
raise click.ClickException("CA name can contain only alphanumeric and '_' characters")
|
||||
|
||||
click.echo("CA configuration files are saved to: {}".format(os.path.abspath(slug)))
|
||||
|
||||
|
34
tests/test_cli.py
Normal file
34
tests/test_cli.py
Normal file
@ -0,0 +1,34 @@
|
||||
import os
|
||||
from click.testing import CliRunner
|
||||
from certidude.cli import entry_point as cli
|
||||
|
||||
runner = CliRunner()
|
||||
|
||||
def test_cli():
|
||||
|
||||
# Authority setup
|
||||
# TODO: group, parent, common-name, country, state, locality
|
||||
# {authority,certificate,revocation-list}-lifetime
|
||||
# organization, organizational-unit
|
||||
# pkcs11
|
||||
# {crl-distribution,ocsp-responder}-url
|
||||
# email-address
|
||||
# inbox, outbox
|
||||
with runner.isolated_filesystem():
|
||||
result = runner.invoke(cli, ['setup', 'authority', 'ca'])
|
||||
|
||||
assert not result.exception
|
||||
# Check whether required files were generated
|
||||
for f in ('ca_key.pem', 'ca_crt.pem', 'ca_crl.pem',
|
||||
'serial', 'openssl.cnf.example'):
|
||||
assert os.path.isfile(os.path.join('ca', f))
|
||||
for d in ('requests', 'revoked', 'signed'):
|
||||
assert os.path.isdir(os.path.join('ca', d))
|
||||
|
||||
def test_cli_setup_authority_slug_name():
|
||||
with runner.isolated_filesystem():
|
||||
result = runner.invoke(cli, ['setup', 'authority'])
|
||||
assert result.exception
|
||||
|
||||
result = runner.invoke(cli, ['setup', 'authority', '""'])
|
||||
assert result.exception
|
Loading…
Reference in New Issue
Block a user