def test_create_ca(self): """Create a ca object; return results object.""" ca_name = 'test-create-ca' ca_dir = os.path.join(self.ca_base_dir, ca_name) ca_key_dir = os.path.join(ca_dir, self.ca_key_rdir) ca_cert_dir = os.path.join(ca_dir, self.ca_cert_rdir) ca_key_file = os.path.join(ca_key_dir, self.ca_key_name) ca_cert_file = os.path.join(ca_cert_dir, self.ca_cert_name) ca = SpokeCA(ca_name) expected_result = { 'count': 1, 'type': 'CA', 'exit_code': 0, 'msg': 'Created CA:' } expected_result['data'] = [{ 'ca_cn': self.ca_cn, 'ca_key': ca_key_file, 'ca_def_duration': self.ca_def_duration, 'ca_cert_file': ca_cert_file, 'ca_cert_as_pem': '' }] result = ca.create(self.ca_cn) result['data'][0]['ca_cert_as_pem'] = '' self.assertEqual(result, expected_result) ca.delete()
def test_get_missing_ca(self): """Retrieve a missing ca; return an empty result object.""" ca_name = 'missing-ca' ca = SpokeCA(ca_name) result = ca.get() expected_result = {'count': 0, 'type': 'CA', 'data': [], 'exit_code': 3, 'msg': 'No CA(s) found'} self.assertEqual(result, expected_result)
def test_create_sub_ca_with_missing_parent(self): """Create a subordinate ca with missing parent; raise NotFound.""" root_ca = 'missing-root-ca' sub_ca_name = 'test-sub-ca-missing-parent' testsubcn = 'Test Subordinate Authority' subca = SpokeCA(sub_ca_name) self.assertRaises(error.NotFound, subca.create, testsubcn, root_ca) subca.delete()
def test_create_sub_ca(self): """Create a subordinate ca; validate cert with parent ca; return True.""" sub_ca_name = 'test-sub-ca' testsubcn = 'Test Subordinate Authority' subca = SpokeCA(sub_ca_name) subca.create(testsubcn, self.ca_name) cert = SpokeCACert(testsubcn, sub_ca_name, self.ca_name) self.assertTrue(cert._verify()) subca.delete()
def test_delete_ca(self): """Delete a ca; return True.""" ca_name = 'test-delete-ca' ca_cn = 'Test Delete Certificate Authority' ca = SpokeCA(ca_name) ca.create(ca_cn) result = ca.delete() expected_result = {'count': 0, 'type': 'CA', 'data': [], 'exit_code': 3, 'msg': 'Deleted CA:'} self.assertEqual(result, expected_result)
def test_delete_ca_files(self): """Delete a ca; ensure private key is removed.""" ca_name = 'test-delete-files-ca' ca_cn = 'Test Delete Files Certificate Authority' ca_dir = os.path.join(self.ca_base_dir, ca_name) ca = SpokeCA(ca_name) ca.create(ca_cn) ca.delete() ca_tree = [] self.assertEqual(ca_tree, self.get_tree(ca_dir))
def test_get_missing_ca(self): """Retrieve a missing ca; return an empty result object.""" ca_name = 'missing-ca' ca = SpokeCA(ca_name) result = ca.get() expected_result = { 'count': 0, 'type': 'CA', 'data': [], 'exit_code': 3, 'msg': 'No CA(s) found' } self.assertEqual(result, expected_result)
def test_get_ca(self): """Retrieve a ca; return result object.""" ca = SpokeCA(self.ca_name) expected_result = {'count': 1, 'type': 'CA', 'exit_code': 0, 'msg': 'Found CA:'} expected_result['data'] = [{'ca_cn': self.ca_cn, 'ca_key': self.ca_key_file, 'ca_def_duration': self.ca_def_duration, 'ca_cert_file': self.ca_cert_file, 'ca_cert_as_pem': ''}] result = ca.get() result['data'][0]['ca_cert_as_pem'] = '' self.assertEqual(result, expected_result)
def test_delete_ca(self): """Delete a ca; return True.""" ca_name = 'test-delete-ca' ca_cn = 'Test Delete Certificate Authority' ca = SpokeCA(ca_name) ca.create(ca_cn) result = ca.delete() expected_result = { 'count': 0, 'type': 'CA', 'data': [], 'exit_code': 3, 'msg': 'Deleted CA:' } self.assertEqual(result, expected_result)
def test_get_ca(self): """Retrieve a ca; return result object.""" ca = SpokeCA(self.ca_name) expected_result = { 'count': 1, 'type': 'CA', 'exit_code': 0, 'msg': 'Found CA:' } expected_result['data'] = [{ 'ca_cn': self.ca_cn, 'ca_key': self.ca_key_file, 'ca_def_duration': self.ca_def_duration, 'ca_cert_file': self.ca_cert_file, 'ca_cert_as_pem': '' }] result = ca.get() result['data'][0]['ca_cert_as_pem'] = '' self.assertEqual(result, expected_result)
def test_create_ca(self): """Create a ca object; return results object.""" ca_name = 'test-create-ca' ca_dir = os.path.join(self.ca_base_dir, ca_name) ca_key_dir = os.path.join(ca_dir, self.ca_key_rdir) ca_cert_dir = os.path.join(ca_dir, self.ca_cert_rdir) ca_key_file = os.path.join(ca_key_dir, self.ca_key_name) ca_cert_file = os.path.join(ca_cert_dir, self.ca_cert_name) ca = SpokeCA(ca_name) expected_result = {'count': 1, 'type': 'CA', 'exit_code': 0, 'msg': 'Created CA:'} expected_result['data'] = [{'ca_cn': self.ca_cn, 'ca_key': ca_key_file, 'ca_def_duration': self.ca_def_duration, 'ca_cert_file': ca_cert_file, 'ca_cert_as_pem': ''}] result = ca.create(self.ca_cn) result['data'][0]['ca_cert_as_pem'] = '' self.assertEqual(result, expected_result) ca.delete()
def tearDown(self): ca = SpokeCA(self.ca_name) ca.delete()
def setUp(self): ca = SpokeCA(self.ca_name) ca.create(self.ca_cn)
def test_create_invalid_ca_cn(self): """Create a CA with a non shell safe cn; raise InputError.""" ca_name = 'test-invalid-cn-ca' ca_cn = 'do naughty; stuff' ca = SpokeCA(ca_name) self.assertRaises(error.InputError, ca.create, ca_cn)
def test_create_ca_twice(self): """Create an existing CA; raise AlreadyExists.""" ca = SpokeCA(self.ca_name) self.assertRaises(error.AlreadyExists, ca.create, self.ca_cn)
def test_delete_missing_ca(self): """Delete missing ca; raise NotFound.""" ca_name = 'missing-ca' ca = SpokeCA(ca_name) self.assertRaises(error.NotFound, ca.delete)