Imported Debian patch 4.0.5-6~numeezy
This commit is contained in:
committed by
Mario Fetka
parent
c44de33144
commit
10dfc9587b
@@ -28,26 +28,24 @@ once per test run.
|
||||
import os
|
||||
import tempfile
|
||||
import shutil
|
||||
import six
|
||||
|
||||
from ipalib import api, x509
|
||||
from ipaserver.plugins import rabase
|
||||
from ipapython import ipautil
|
||||
from ipaplatform.paths import paths
|
||||
from ipapython.dn import DN
|
||||
|
||||
if six.PY3:
|
||||
unicode = str
|
||||
_testcert = None
|
||||
|
||||
|
||||
def get_testcert(subject, principal):
|
||||
def get_testcert():
|
||||
"""Get the certificate, creating it if it doesn't exist"""
|
||||
reqdir = tempfile.mkdtemp(prefix="tmp-")
|
||||
try:
|
||||
_testcert = makecert(reqdir, subject,
|
||||
principal)
|
||||
finally:
|
||||
shutil.rmtree(reqdir)
|
||||
global _testcert
|
||||
if _testcert is None:
|
||||
reqdir = tempfile.mkdtemp(prefix="tmp-")
|
||||
try:
|
||||
_testcert = makecert(reqdir)
|
||||
finally:
|
||||
shutil.rmtree(reqdir)
|
||||
return x509.strip_header(_testcert)
|
||||
|
||||
|
||||
@@ -74,12 +72,12 @@ def generate_csr(reqdir, pwname, subject):
|
||||
return fp.read()
|
||||
|
||||
|
||||
def makecert(reqdir, subject, principal):
|
||||
def makecert(reqdir):
|
||||
"""
|
||||
Generate a certificate that can be used during unit testing.
|
||||
Generate a service certificate that can be used during unit testing.
|
||||
"""
|
||||
|
||||
ra = rabase.rabase(api)
|
||||
ra = rabase.rabase()
|
||||
if (not os.path.exists(ra.sec_dir) and
|
||||
api.env.xmlrpc_uri == 'http://localhost:8888/ipa/xml'):
|
||||
raise AssertionError('The self-signed CA is not configured, '
|
||||
@@ -98,7 +96,9 @@ def makecert(reqdir, subject, principal):
|
||||
subject_base = res['result']['ipacertificatesubjectbase'][0]
|
||||
|
||||
cert = None
|
||||
subject = DN(('CN', api.env.host), subject_base)
|
||||
princ = 'unittest/%s@%s' % (api.env.host, api.env.realm)
|
||||
csr = unicode(generate_csr(reqdir, pwname, str(subject)))
|
||||
|
||||
res = api.Command['cert_request'](csr, principal=principal, add=True)
|
||||
res = api.Command['cert_request'](csr, principal=princ, add=True)
|
||||
return x509.make_pem(res['result']['certificate'])
|
||||
|
||||
Reference in New Issue
Block a user