2015-09-09 05:31:48 +00:00
|
|
|
import os
|
2015-09-14 08:15:35 +00:00
|
|
|
import pwd
|
|
|
|
import pytest
|
2015-09-09 05:31:48 +00:00
|
|
|
from click.testing import CliRunner
|
|
|
|
from certidude.cli import entry_point as cli
|
|
|
|
|
|
|
|
runner = CliRunner()
|
|
|
|
|
2015-09-14 08:15:35 +00:00
|
|
|
def user_check(name='certidude'):
|
|
|
|
try:
|
|
|
|
pwd.getpwnam(name)
|
|
|
|
return False
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
return True
|
|
|
|
|
2015-09-29 11:44:31 +00:00
|
|
|
def test_cli_setup_authority():
|
2015-09-09 05:31:48 +00:00
|
|
|
# Authority setup
|
2015-09-29 11:44:31 +00:00
|
|
|
# TODO: parent, common-name, country, state, locality
|
2015-09-09 05:31:48 +00:00
|
|
|
# {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))
|
|
|
|
|
2015-09-29 11:44:31 +00:00
|
|
|
def test_cli_setup_authority_invalid_name():
|
2015-09-09 05:31:48 +00:00
|
|
|
with runner.isolated_filesystem():
|
|
|
|
result = runner.invoke(cli, ['setup', 'authority'])
|
|
|
|
assert result.exception
|
|
|
|
|
|
|
|
result = runner.invoke(cli, ['setup', 'authority', '""'])
|
|
|
|
assert result.exception
|
2015-09-29 12:04:35 +00:00
|
|
|
|
|
|
|
def test_cli_setup_authority_overwrite():
|
|
|
|
with runner.isolated_filesystem():
|
|
|
|
result = runner.invoke(cli, ['setup', 'authority', 'foo'])
|
|
|
|
assert not result.exception
|
|
|
|
|
|
|
|
result = runner.invoke(cli, ['setup', 'authority', 'foo'])
|
|
|
|
assert result.exception
|