URL: https://github.com/freeipa/freeipa/pull/503
Author: Akasurde
 Title: #503: [WIP] Update testcase for cert plugin
Action: opened

PR body:
"""
Fixes https://fedorahosted.org/freeipa/ticket/6275

Signed-off-by: Abhijeet Kasurde <akasu...@redhat.com>
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/503/head:pr503
git checkout pr503
From 76dcaceaed890e76a38915e4fd5345a04140794d Mon Sep 17 00:00:00 2001
From: Abhijeet Kasurde <akasu...@redhat.com>
Date: Fri, 24 Feb 2017 13:21:49 +0530
Subject: [PATCH] [WIP] Update testcase for cert plugin

Fixes https://fedorahosted.org/freeipa/ticket/6275

Signed-off-by: Abhijeet Kasurde <akasu...@redhat.com>
---
 ipatests/test_xmlrpc/test_cert_plugin.py | 56 +++++++++++++++++++++++++++-----
 1 file changed, 47 insertions(+), 9 deletions(-)

diff --git a/ipatests/test_xmlrpc/test_cert_plugin.py b/ipatests/test_xmlrpc/test_cert_plugin.py
index 0b8277b..140bd02 100644
--- a/ipatests/test_xmlrpc/test_cert_plugin.py
+++ b/ipatests/test_xmlrpc/test_cert_plugin.py
@@ -50,6 +50,7 @@
 _EXP_CRL_URI = ''.join(['http://ipa-ca.', _DOMAIN, '/ipa/crl/MasterCRL.bin'])
 _EXP_OCSP_URI = ''.join(['http://ipa-ca.', _DOMAIN, '/ca/ocsp'])
 
+
 def is_db_configured():
     """
     Raise an exception if we are testing against lite-server and the
@@ -88,6 +89,8 @@ def setup_class(cls):
             raise nose.SkipTest('cert_request not registered')
         if 'cert_show' not in api.Command:
             raise nose.SkipTest('cert_show not registered')
+        if 'cert_status' not in api.Command:
+            raise nose.SkipTest('cert_status not registered')
 
         is_db_configured()
 
@@ -97,15 +100,14 @@ def run_certutil(self, args, stdin=None):
         return ipautil.run(new_args, stdin)
 
     def setup(self):
-        self.reqdir = tempfile.mkdtemp(prefix = "tmp-")
+        self.reqdir = tempfile.mkdtemp(prefix="tmp-")
         self.reqfile = self.reqdir + "/test.csr"
         self.pwname = self.reqdir + "/pwd"
         self.certfile = self.reqdir + "/cert.crt"
 
         # Create an empty password file
-        fp = open(self.pwname, "w")
-        fp.write("\n")
-        fp.close()
+        with open(self.pwname, "w") as fp:
+            fp.write("\n")
 
         # Create our temporary NSS database
         self.run_certutil(["-N", "-f", self.pwname])
@@ -122,9 +124,8 @@ def generateCSR(self, subject):
                            "-f", self.pwname,
                            "-a",
                            ])
-        fp = open(self.reqfile, "r")
-        data = fp.read()
-        fp.close()
+        with open(self.reqfile, "r") as fp:
+            data = fp.read()
         return data
 
     host_fqdn = u'ipatestcert.%s' % api.env.domain
@@ -191,10 +192,10 @@ def test_0005_cert_uris(self):
 
         See https://fedorahosted.org/freeipa/ticket/5881
         """
-        result = api.Command.cert_show(sn, out=unicode(self.certfile))
+        api.Command['cert_show'](sn, out=unicode(self.certfile))
         with open(self.certfile, "r") as f:
             pem_cert = unicode(f.read())
-        result = run(['openssl', 'x509', '-text'],
+        result = run([paths.OPENSSL, 'x509', '-text'],
                      stdin=pem_cert, capture_output=True)
         assert _EXP_CRL_URI in result.output
         assert _EXP_OCSP_URI in result.output
@@ -290,6 +291,7 @@ def test_0002_find_CA(self):
         """
         res = api.Command['cert_find'](subject=u'Certificate Authority')
         assert 'count' in res and res['count'] == 1
+        assert u'CN=Certificate Authority' in res['result'][0]['subject']
 
     def test_0003_find_OCSP(self):
         """
@@ -298,6 +300,7 @@ def test_0003_find_OCSP(self):
         res = api.Command['cert_find'](subject=u'OCSP Subsystem')
         assert 'count' in res
         assert res['count'], "No OSCP certificate found"
+        assert u'CN=OCSP Subsystem' in res['result'][0]['subject']
 
     def test_0004_find_this_host(self):
         """
@@ -305,6 +308,7 @@ def test_0004_find_this_host(self):
         """
         res = api.Command['cert_find'](subject=api.env.host)
         assert 'count' in res and res['count'] > 1
+        assert api.env.host in res['result'][0]['subject']
 
     def test_0005_find_this_host_exact(self):
         """
@@ -312,6 +316,7 @@ def test_0005_find_this_host_exact(self):
         """
         res = api.Command['cert_find'](subject=api.env.host, exactly=True)
         assert 'count' in res and res['count'] > 1
+        assert api.env.host in res['result'][0]['subject']
 
     def test_0006_find_this_short_host_exact(self):
         """
@@ -319,6 +324,7 @@ def test_0006_find_this_short_host_exact(self):
         """
         res = api.Command['cert_find'](subject=self.short, exactly=True)
         assert 'count' in res and res['count'] == 0
+        assert u'0 certificates matched' in res['summary']
 
     # tests 0007 to 0016 removed
 
@@ -423,6 +429,7 @@ def test_0029_search_for_notfound(self):
         """
         res = api.Command['cert_find'](subject=u'notfound')
         assert 'count' in res and res['count'] == 0
+        assert u'0 certificates matched' in res['summary']
 
     def test_0030_search_for_testcerts(self):
         """
@@ -499,3 +506,34 @@ def test_revoke_with_reason_9(self):
 
     def test_revoke_with_reason_10(self):
         self.revoke_cert(10)
+
+
+@pytest.mark.tier1
+class test_cert_status(BaseCert):
+
+    @classmethod
+    def setup_class(cls):
+        super(test_cert_status, cls).setup_class()
+
+    """
+    Test the `cert-status` command.
+    """
+
+    def test_0001_cert_status(self):
+        """
+        Show status of certificate using request id
+        """
+        res = api.Command['cert_status'](request_id=1)['result']
+
+        assert 'cert_request_status' in res
+        assert 'complete' in res['cert_request_status']
+
+    def test_0002_cert_status_ca(self):
+        """
+        Show status of certificate using request id and CA
+        """
+        res = api.Command['cert_status'](request_id=1,
+                                         cacn=unicode('ipa'))['result']
+
+        assert 'cert_request_status' in res
+        assert 'complete' in res['cert_request_status']
-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to