summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAde Lee <alee@redhat.com>2015-09-14 22:42:57 -0400
committerAde Lee <alee@redhat.com>2015-09-27 11:16:06 -0400
commite037a73e1ea52719473e03c554ce6e3544967907 (patch)
treef58d265c30f27e6b8a3f18078af63ce999ef72c5 /tests
parentd8f9c77a62a7bfea82e892f8ecb309630826fed5 (diff)
downloadpki-e037a73e1ea52719473e03c554ce6e3544967907.tar.gz
pki-e037a73e1ea52719473e03c554ce6e3544967907.tar.xz
pki-e037a73e1ea52719473e03c554ce6e3544967907.zip
Python client for subcas
Includes python code (and unit tests!) to list, get and create subCAs. Also fixed a couple of PEP 8 violations that crept in.
Diffstat (limited to 'tests')
-rw-r--r--tests/python/test_authority.py131
1 files changed, 131 insertions, 0 deletions
diff --git a/tests/python/test_authority.py b/tests/python/test_authority.py
new file mode 100644
index 000000000..b45eddf89
--- /dev/null
+++ b/tests/python/test_authority.py
@@ -0,0 +1,131 @@
+# -*- coding: utf-8 -*-
+# Authors:
+# Ade Lee <alee@redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Copyright (C) 2015 Red Hat, Inc.
+# All rights reserved.
+#
+
+import mock
+import requests
+import unittest
+import uuid
+
+from pki import authority
+
+
+class AuthorityTests(unittest.TestCase):
+ """ Unit test cases for the authority resource
+ """
+
+ def setUp(self):
+ super(AuthorityTests, self).setUp()
+
+ self.connection = mock.MagicMock()
+ self.authority_client = authority.AuthorityClient(self.connection)
+ self.top_level_aid = str(uuid.uuid4())
+ self.aid = str(uuid.uuid4())
+ self.aid2 = str(uuid.uuid4())
+ self.dn = "cn=subordinate ca, o=example.com"
+ self.dn2 = "cn=subordinate ca2, o=example.com"
+ self.description = "subordinate CA1"
+ self.description2 = "subordinate CA2"
+
+ self.subca_data = {
+ "dn": self.dn,
+ "description": self.description,
+ "parent_aid": self.top_level_aid
+ }
+
+ self.ca1_data = {
+ "aid": self.aid,
+ "dn": self.dn,
+ "description": self.description
+ }
+
+ self.ca2_data = {
+ "aid": self.aid2,
+ "dn": self.dn2,
+ "description": self.description2
+ }
+ post_return = mock.MagicMock()
+ post_return.json.return_value = self.ca1_data
+ self.connection.post.return_value = post_return
+
+ def test_should_create_subca(self):
+ authority_data = authority.AuthorityData(** self.subca_data)
+ ca = self.authority_client.create_ca(authority_data)
+ self.assertEquals(ca.aid, self.aid)
+ self.assertEquals(ca.dn, self.dn)
+
+ def test_create_should_raise_ca_data_not_defined(self):
+ self.assertRaises(
+ ValueError,
+ self.authority_client.create_ca,
+ None
+ )
+
+ def test_create_should_raise_dn_not_defined(self):
+ del self.subca_data['dn']
+ authority_data = authority.AuthorityData(** self.subca_data)
+ self.assertRaises(
+ ValueError,
+ self.authority_client.create_ca,
+ authority_data
+ )
+
+ def test_create_should_raise_description_not_defined(self):
+ del self.subca_data['description']
+ authority_data = authority.AuthorityData(** self.subca_data)
+ self.assertRaises(
+ ValueError,
+ self.authority_client.create_ca,
+ authority_data
+ )
+
+ def test_create_should_raise_parent_aid_not_defined(self):
+ del self.subca_data["parent_aid"]
+ authority_data = authority.AuthorityData(** self.subca_data)
+ self.assertRaises(
+ ValueError,
+ self.authority_client.create_ca,
+ authority_data
+ )
+
+
+ def test_should_get_ca(self):
+ get_return = mock.MagicMock()
+ get_return.json.return_value = self.ca1_data
+ self.connection.get.return_value = get_return
+
+ ca = self.authority_client.get_ca(self.aid)
+ self.assertEquals(ca.aid, self.aid)
+ self.assertEquals(ca.dn, self.dn)
+
+ def test_should_list_cas(self):
+ get_return = mock.MagicMock()
+ ca_list = [self.ca1_data, self.ca2_data]
+ get_return.json.return_value = ca_list
+ self.connection.get.return_value = get_return
+
+ cas = self.authority_client.list_cas()
+ for ca in cas:
+ self.assertIsInstance(ca, authority.AuthorityData)
+ if ca.aid == self.aid2:
+ self.assertEquals(ca.dn, self.dn2)
+ else:
+ self.assertEquals(ca.dn, self.dn)
+