From: ale Date: Wed, 8 Feb 2012 10:27:22 +0000 (+0000) Subject: add a full integration test via main() X-Git-Url: https://v.licheni.net/stack/cam.git/commitdiff_plain/a3143f42f255d439fb27494f381e26c27667986a add a full integration test via main() --- diff --git a/cam/tests/test_main.py b/cam/tests/test_main.py new file mode 100644 index 0000000..a370960 --- /dev/null +++ b/cam/tests/test_main.py @@ -0,0 +1,61 @@ +import getpass +import os +import shutil +import subprocess +import sys +import tempfile +import unittest +from cam import main + + +class MainTest(unittest.TestCase): + + def setUp(self): + self.tmpdir = tempfile.mkdtemp() + self.cfgfile = os.path.join(self.tmpdir, 'test.conf') + with open(self.cfgfile, 'w') as fd: + fd.write(""" +[ca] +cn = Test Ca +org = Test +country = IE +email = ca@test.org +bits = 1024 + +[web] +cn = www.test.org +""") + + def _fake_getpass(prompt): + return 'testpass' + getpass.getpass = _fake_getpass + + def tearDown(self): + shutil.rmtree(self.tmpdir) + + def _run(self, *args): + sys.argv = ['cam', '--config=%s' % self.cfgfile] + list(args) + try: + return main.main() + except SystemExit, e: + return e.code + + def test_init_and_sanity_check(self): + self.assertEquals(None, self._run('init')) + self.assertEquals(None, self._run('gen', 'web')) + + ca_file = os.path.join(self.tmpdir, 'public/ca.pem') + crt_file = os.path.join(self.tmpdir, 'public/certs/web.pem') + self.assertTrue(os.path.exists(ca_file)) + self.assertTrue(os.path.exists(crt_file)) + + pipe = subprocess.Popen( + ['openssl', 'verify', '-CAfile', ca_file, '-verbose', crt_file], + stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + output = pipe.communicate()[0] + result = pipe.returncode + self.assertEquals(0, result) + + print output + self.assertTrue('error ' not in output) +