From af9d4112024b33b207ad562f3cadb199155b9575 Mon Sep 17 00:00:00 2001 From: Jude N Date: Wed, 11 Mar 2015 00:27:23 -0400 Subject: [PATCH] BATS is pretty sweet. Fixes for autoloading / unexpected ca string are on deck --- certmaster/config.py | 1 - tests/certmaster.bats | 113 ++++++++++++++++++++++++++++++++++++++ tests/certmaster.conf.tst | 23 ++++++++ tests/minion.conf.tst | 15 +++++ 4 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 tests/certmaster.bats create mode 100644 tests/certmaster.conf.tst create mode 100644 tests/minion.conf.tst diff --git a/certmaster/config.py b/certmaster/config.py index cac9394..205af35 100644 --- a/certmaster/config.py +++ b/certmaster/config.py @@ -495,6 +495,5 @@ def read_config(config_file, BaseConfigDerived): opts.ca[ca_name] = {} for (key,value) in items: opts.ca[ca_name][key] = value - print 'opts.ca: %s %s %s' % (ca_name, key, value) return opts diff --git a/tests/certmaster.bats b/tests/certmaster.bats new file mode 100644 index 0000000..f10672c --- /dev/null +++ b/tests/certmaster.bats @@ -0,0 +1,113 @@ +#!/usr/bin/env bats + +setup() { + /etc/init.d/certmaster stop || true + mkdir -p /etc/certmaster + cp certmaster.conf.tst /etc/certmaster/certmaster.conf + cp minion.conf.tst /etc/certmaster/minion.conf + rm -rf /var/lib/certmaster/certmaster + rm -rf /var/lib/certmaster/test + rm -rf /etc/pki/certmaster + rm -rf /etc/pki/certmaster-test + /etc/init.d/certmaster start +} + +teardown() { + /etc/init.d/certmaster stop +} + +@test "check that certmaster-ca is availabe" { + command -v certmaster-ca +} + +@test "check that certmaster-request is available" { + command -v certmaster-request +} + +@test "check that the certmaster daemon is running" { + /etc/init.d/certmaster status +} + +@test "check certmaster-request --help" { + run certmaster-request --help + + expected=$(cat < blah.txt + output=`certmaster-ca --list` + echo "$output" >> blah.txt + [[ $output == *"defaultcert.pwan.co"* ]] + + run certmaster-ca --sign defaultcert.pwan.co + + stat /etc/pki/certmaster + stat /etc/pki/certmaster/defaultcert,pwan.co.cert + stat /etc/pki/certmaster/defaultcert,pwan.co.pem + stat /etc/pki/certmaster/defaultcert,pwan.co.csr + + subject=`openssl x509 -in /etc/pki/certmaster/defaultcert.pwan.co.cert -subject -noout` + [[ $subject == *"CN=defaultcert.pwan.co"* ]] + + openssl rsa -in /etc/pki/certmaster/defaultcert.pwan.co.pem -check + openssl req -text -noout -verify -in /etc/pki/certmaster/defaultcert.pwan.co.csr + +} diff --git a/tests/certmaster.conf.tst b/tests/certmaster.conf.tst new file mode 100644 index 0000000..e380d06 --- /dev/null +++ b/tests/certmaster.conf.tst @@ -0,0 +1,23 @@ +# This is the test /etc/certmaster.conf file used with the certmaster bats tests + +[main] +listen_addr = +listen_port = 51235 +cert_extension = cert +sync_certs = False + +# Use thse settings if no --ca flag provided +autosign = no +cadir = /etc/pki/certmaster/ca +cert_dir = /etc/pki/certmaster +certroot = /var/lib/certmaster/certmaster/certs +csrroot = /var/lib/certmaster/certmaster/csrs + +# use these directories if '--ca=yourapp' provided in the certmaster-ca commands +[ca:test] +autosign = yes +cadir = /etc/pki/certmaster/test-ca +cert_dir = /etc/pki/certmaster/test +certroot = /var/lib/certmaster/test/certs +csrroot = /var/lib/certmaster/test/csrs + diff --git a/tests/minion.conf.tst b/tests/minion.conf.tst new file mode 100644 index 0000000..86c0efe --- /dev/null +++ b/tests/minion.conf.tst @@ -0,0 +1,15 @@ +# configuration for minions + +[main] +#certmaster = certmaster +certmaster = localhost +certmaster_port = 51235 +log_level = DEBUG +cert_dir = /etc/pki/certmaster + +# [ca:ldap] +# cert_dir = /etc/pki/certmaster-ldap + +[ca:test] +cert_dir = /etc/pki/certmaster-test + -- 2.39.5