11 class MainTest(unittest.TestCase):
14 self.tmpdir = tempfile.mkdtemp()
15 self.cfgfile = os.path.join(self.tmpdir, 'test.conf')
16 with open(self.cfgfile, 'w') as fd:
29 def _fake_getpass(prompt):
31 getpass.getpass = _fake_getpass
34 shutil.rmtree(self.tmpdir)
36 def _run(self, *args):
37 sys.argv = ['cam', '--config=%s' % self.cfgfile] + list(args)
43 def test_init_and_sanity_check(self):
44 self.assertEquals(None, self._run('init'))
45 self.assertEquals(None, self._run('gen', 'web'))
47 ca_file = os.path.join(self.tmpdir, 'public/ca.pem')
48 crt_file = os.path.join(self.tmpdir, 'public/certs/web.pem')
49 self.assertTrue(os.path.exists(ca_file))
50 self.assertTrue(os.path.exists(crt_file))
52 subprocess.call(['openssl', 'x509', '-in', ca_file,
54 subprocess.call(['openssl', 'x509', '-in', crt_file,
57 pipe = subprocess.Popen(
58 ['openssl', 'verify', '-CAfile', ca_file, '-verbose', crt_file],
59 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
60 output = pipe.communicate()[0]
61 result = pipe.returncode
62 self.assertEquals(0, result)
65 self.assertTrue('error ' not in output)