Browse files

Improve tests and coverage for ``

Testing the `create_ca()` function with a predefined input string.
Also added more accurate descriptions.
  • Loading branch information...
plettich committed Nov 27, 2018
1 parent 4da61fa commit 2427347d975fcbf08d55c4df0130475a25526b04
Showing with 44 additions and 9 deletions.
  1. +13 −9 privacyidea/lib/caconnectors/
  2. +31 −0 tests/
@@ -359,8 +359,8 @@ def sign_request(self, csr, options=None):
:param options: Additional options like the validity time or the
template or spkac=1
:type options: dict
:return: Returns the certificate
:rtype: basestring
:return: Returns the certificate object
:rtype: X509
# Sign the certificate for one year
options = options or {}
@@ -504,6 +504,7 @@ def revoke_cert(self, certificate, reason=CRL_REASONS[0]):
cert_obj = certificate
raise CAError("Certificate in unsupported format")
serial = cert_obj.get_serial_number()
serial_hex = int_to_hex(serial)
filename = serial_hex + ".pem"
@@ -568,12 +569,14 @@ def create_crl(self, publish=True, check_validity=False):
return ret
def create_ca(cls, name):
def create_ca(name):
Create a new CA connector.
The configurations is requested at the command line in questions and
answers. The CA connector definition is also written to the database.
Create parameters for a new CA connector.
The configuration is requested at the command line in questions and
If the configuration is valid, the CA will be created on the file system
and the configuration for the new LocalCAConnector is returned.
We are asking for the following:
@@ -593,7 +596,9 @@ def create_ca(cls, name):
* We create two templates for users and for servers.
:param name: The name of the CA connector.
:type name: str
:return The LocalCAConnector configuration
:rtype: dict
config = CONFIG(name)
@@ -728,4 +733,3 @@ def _init_ca(config):
print("Please check the ownership of the private key")
print("!" * 60)
@@ -4,6 +4,11 @@
from .base import MyTestCase
import os
import sys
import six
import shutil
from io import StringIO
from contextlib import contextmanager
from privacyidea.lib.caconnectors.localca import LocalCAConnector, ATTR
from OpenSSL import crypto
from privacyidea.lib.utils import int_to_hex
@@ -73,6 +78,14 @@
def replace_stdin(target):
orig = sys.stdin
sys.stdin = target
sys.stdin = orig
class CAConnectorTestCase(MyTestCase):
Test the CA connector lib functions
@@ -277,3 +290,21 @@ def test_05_templates(self):
self.assertTrue(ddiff.days < 760, ddiff.days)
class CreateLocalCATestCase(MyTestCase):
test creating a new CA using the local caconnector
def test_01_create_ca(self):
cwd = os.getcwd()
workdir = os.path.join(cwd, WORKINGDIR + '2')
if os.path.exists(workdir):
inputstr = six.text_type(workdir + '\n\n\n\n\n\ny\n')
with replace_stdin(StringIO(inputstr)):
caconfig = LocalCAConnector.create_ca('localCA2')
self.assertEqual(caconfig.get("WorkingDir"), workdir)
cacon = LocalCAConnector('localCA2', caconfig)
self.assertEqual(, 'localCA2')
self.assertEqual(cacon.workingdir, workdir)
# check if the generated files exist
self.assertTrue(os.path.exists(os.path.join(workdir, 'cacert.pem')))

0 comments on commit 2427347

Please sign in to comment.