5c8636
From 7f30ddb1b7e30c22f9b7d14d2658b58a0ea6b459 Mon Sep 17 00:00:00 2001
5c8636
From: Mohammad Rizwan <myusuf@redhat.com>
5c8636
Date: Tue, 2 Feb 2021 17:33:57 +0530
5c8636
Subject: [PATCH] ipatests: Test if ipa-cert-fix renews expired certs
5c8636
5c8636
Test moves system date to expire certs. Then calls ipa-cert-fix
5c8636
to renew them. This certs include subsystem, audit-signing,
5c8636
OCSP signing, Dogtag HTTPS, IPA RA agent, LDAP and KDC certs.
5c8636
5c8636
related: https://pagure.io/freeipa/issue/7885
5c8636
5c8636
Signed-off-by: Mohammad Rizwan <myusuf@redhat.com>
5c8636
Reviewed-By: Florence Blanc-Renaud <flo@redhat.com>
5c8636
Reviewed-By: Anuja More <amore@redhat.com>
5c8636
Reviewed-By: Florence Blanc-Renaud <flo@redhat.com>
5c8636
Reviewed-By: Anuja More <amore@redhat.com>
5c8636
---
5c8636
 .../test_integration/test_ipa_cert_fix.py     | 60 +++++++++++++++++++
5c8636
 1 file changed, 60 insertions(+)
5c8636
5c8636
diff --git a/ipatests/test_integration/test_ipa_cert_fix.py b/ipatests/test_integration/test_ipa_cert_fix.py
5c8636
index f9e5fe6e2..da68af573 100644
5c8636
--- a/ipatests/test_integration/test_ipa_cert_fix.py
5c8636
+++ b/ipatests/test_integration/test_ipa_cert_fix.py
5c8636
@@ -8,12 +8,16 @@ Module provides tests for ipa-cert-fix CLI.
5c8636
 import pytest
5c8636
 import time
5c8636
 
5c8636
+import logging
5c8636
 from ipaplatform.paths import paths
5c8636
 from ipatests.pytest_ipa.integration import tasks
5c8636
 from ipatests.test_integration.base import IntegrationTest
5c8636
 from ipatests.test_integration.test_caless import CALessBase, ipa_certs_cleanup
5c8636
 
5c8636
 
5c8636
+logger = logging.getLogger(__name__)
5c8636
+
5c8636
+
5c8636
 def server_install_teardown(func):
5c8636
     def wrapped(*args):
5c8636
         master = args[0].master
5c8636
@@ -24,6 +28,26 @@ def server_install_teardown(func):
5c8636
     return wrapped
5c8636
 
5c8636
 
5c8636
+def check_status(host, cert_count, state, timeout=600):
5c8636
+    """Helper method to check that if all the certs are in given state
5c8636
+    :param host: the host
5c8636
+    :param cert_count: no of cert to look for
5c8636
+    :param state: state to check for
5c8636
+    :param timeout: max time in seconds to wait for the state
5c8636
+    """
5c8636
+    for _i in range(0, timeout, 10):
5c8636
+        result = host.run_command(['getcert', 'list'])
5c8636
+        count = result.stdout_text.count(f"status: {state}")
5c8636
+        logger.info("cert count in %s state : %s", state, count)
5c8636
+        if int(count) == cert_count:
5c8636
+            break
5c8636
+        time.sleep(10)
5c8636
+    else:
5c8636
+        raise RuntimeError("request timed out")
5c8636
+
5c8636
+    return count
5c8636
+
5c8636
+
5c8636
 class TestIpaCertFix(IntegrationTest):
5c8636
     @classmethod
5c8636
     def uninstall(cls, mh):
5c8636
@@ -106,6 +130,42 @@ class TestIpaCertFix(IntegrationTest):
5c8636
                 # timeout
5c8636
                 raise AssertionError('Timeout: Failed to renew all the certs')
5c8636
 
5c8636
+    def test_renew_expired_cert_on_master(self, expire_cert_critical):
5c8636
+        """Test if ipa-cert-fix renews expired certs
5c8636
+
5c8636
+        Test moves system date to expire certs. Then calls ipa-cert-fix
5c8636
+        to renew them. This certs include subsystem, audit-signing,
5c8636
+        OCSP signing, Dogtag HTTPS, IPA RA agent, LDAP and KDC certs.
5c8636
+
5c8636
+        related: https://pagure.io/freeipa/issue/7885
5c8636
+        """
5c8636
+        # wait for cert expiry
5c8636
+        check_status(self.master, 8, "CA_UNREACHABLE")
5c8636
+
5c8636
+        self.master.run_command(['ipa-cert-fix', '-v'], stdin_text='yes\n')
5c8636
+
5c8636
+        check_status(self.master, 9, "MONITORING")
5c8636
+
5c8636
+        # second iteration of ipa-cert-fix
5c8636
+        result = self.master.run_command(
5c8636
+            ['ipa-cert-fix', '-v'],
5c8636
+            stdin_text='yes\n'
5c8636
+        )
5c8636
+        assert "Nothing to do" in result.stdout_text
5c8636
+        check_status(self.master, 9, "MONITORING")
5c8636
+
5c8636
+    def test_ipa_cert_fix_non_ipa(self):
5c8636
+        """Test ipa-cert-fix doesn't work on non ipa system
5c8636
+
5c8636
+        ipa-cert-fix tool should not work on non ipa system.
5c8636
+
5c8636
+        related: https://pagure.io/freeipa/issue/7885
5c8636
+        """
5c8636
+        result = self.master.run_command(['ipa-cert-fix', '-v'],
5c8636
+                                         stdin_text='yes\n',
5c8636
+                                         raiseonerr=False)
5c8636
+        assert result.returncode == 2
5c8636
+
5c8636
 
5c8636
 class TestIpaCertFixThirdParty(CALessBase):
5c8636
     """
5c8636
-- 
5c8636
2.29.2
5c8636
5c8636
From 36a60dbb35cb4429f00528f79bec8b7982a30c74 Mon Sep 17 00:00:00 2001
5c8636
From: Mohammad Rizwan <myusuf@redhat.com>
5c8636
Date: Thu, 11 Feb 2021 16:54:22 +0530
5c8636
Subject: [PATCH] Move fixture outside the class and add setup_kra capability
5c8636
5c8636
Moved fixture to use across multiple classes. Added capability
5c8636
to install the KRA to the fixture
5c8636
5c8636
Signed-off-by: Mohammad Rizwan <myusuf@redhat.com>
5c8636
Reviewed-By: Florence Blanc-Renaud <flo@redhat.com>
5c8636
Reviewed-By: Anuja More <amore@redhat.com>
5c8636
Reviewed-By: Florence Blanc-Renaud <flo@redhat.com>
5c8636
Reviewed-By: Anuja More <amore@redhat.com>
5c8636
---
5c8636
 .../test_integration/test_ipa_cert_fix.py     | 46 ++++++++++++-------
5c8636
 1 file changed, 30 insertions(+), 16 deletions(-)
5c8636
5c8636
diff --git a/ipatests/test_integration/test_ipa_cert_fix.py b/ipatests/test_integration/test_ipa_cert_fix.py
5c8636
index da68af573..591dc5031 100644
5c8636
--- a/ipatests/test_integration/test_ipa_cert_fix.py
5c8636
+++ b/ipatests/test_integration/test_ipa_cert_fix.py
5c8636
@@ -48,6 +48,33 @@ def check_status(host, cert_count, state, timeout=600):
5c8636
     return count
5c8636
 
5c8636
 
5c8636
+@pytest.fixture
5c8636
+def expire_cert_critical():
5c8636
+    """
5c8636
+    Fixture to expire the certs by moving the system date using
5c8636
+    date -s command and revert it back
5c8636
+    """
5c8636
+
5c8636
+    hosts = dict()
5c8636
+
5c8636
+    def _expire_cert_critical(host, setup_kra=False):
5c8636
+        hosts['host'] = host
5c8636
+        # Do not install NTP as the test plays with the date
5c8636
+        tasks.install_master(host, setup_dns=False,
5c8636
+                             extra_args=['--no-ntp'])
5c8636
+        if setup_kra:
5c8636
+            tasks.install_kra(host)
5c8636
+        host.run_command(['systemctl', 'stop', 'chronyd'])
5c8636
+        host.run_command(['date', '-s', '+3Years+1day'])
5c8636
+
5c8636
+    yield _expire_cert_critical
5c8636
+
5c8636
+    host = hosts.pop('host')
5c8636
+    tasks.uninstall_master(host)
5c8636
+    host.run_command(['date', '-s', '-3Years-1day'])
5c8636
+    host.run_command(['systemctl', 'start', 'chronyd'])
5c8636
+
5c8636
+
5c8636
 class TestIpaCertFix(IntegrationTest):
5c8636
     @classmethod
5c8636
     def uninstall(cls, mh):
5c8636
@@ -55,22 +82,6 @@ class TestIpaCertFix(IntegrationTest):
5c8636
         # the fixture
5c8636
         pass
5c8636
 
5c8636
-    @pytest.fixture
5c8636
-    def expire_cert_critical(self):
5c8636
-        """
5c8636
-        Fixture to expire the certs by moving the system date using
5c8636
-        date -s command and revert it back
5c8636
-        """
5c8636
-        # Do not install NTP as the test plays with the date
5c8636
-        tasks.install_master(self.master, setup_dns=False,
5c8636
-                             extra_args=['--no-ntp'])
5c8636
-        self.master.run_command(['systemctl', 'stop', 'chronyd'])
5c8636
-        self.master.run_command(['date','-s', '+3Years+1day'])
5c8636
-        yield
5c8636
-        tasks.uninstall_master(self.master)
5c8636
-        self.master.run_command(['date','-s', '-3Years-1day'])
5c8636
-        self.master.run_command(['systemctl', 'start', 'chronyd'])
5c8636
-
5c8636
     def test_missing_csr(self, expire_cert_critical):
5c8636
         """
5c8636
         Test that ipa-cert-fix succeeds when CSR is missing from CS.cfg
5c8636
@@ -82,6 +93,7 @@ class TestIpaCertFix(IntegrationTest):
5c8636
         - call getcert resubmit in order to create the CSR in certmonger file
5c8636
         - use ipa-cert-fix, no issue should be seen
5c8636
         """
5c8636
+        expire_cert_critical(self.master)
5c8636
         # pki must be stopped in order to edit CS.cfg
5c8636
         self.master.run_command(['ipactl', 'stop'])
5c8636
         self.master.run_command(['sed', '-i', r'/ca\.sslserver\.certreq=/d',
5c8636
@@ -139,6 +151,8 @@ class TestIpaCertFix(IntegrationTest):
5c8636
 
5c8636
         related: https://pagure.io/freeipa/issue/7885
5c8636
         """
5c8636
+        expire_cert_critical(self.master)
5c8636
+
5c8636
         # wait for cert expiry
5c8636
         check_status(self.master, 8, "CA_UNREACHABLE")
5c8636
 
5c8636
-- 
5c8636
2.29.2
5c8636
5c8636
From c84e0547e1a693ba0e9edbfeea7bafdb2fb2b4a2 Mon Sep 17 00:00:00 2001
5c8636
From: Mohammad Rizwan <myusuf@redhat.com>
5c8636
Date: Thu, 11 Feb 2021 16:59:53 +0530
5c8636
Subject: [PATCH] ipatests: Test if ipa-cert-fix renews expired certs with kra
5c8636
 installed
5c8636
5c8636
This test check if ipa-cert-fix renews certs with kra
5c8636
certificate installed.
5c8636
5c8636
related: https://pagure.io/freeipa/issue/7885
5c8636
5c8636
Signed-off-by: Mohammad Rizwan <myusuf@redhat.com>
5c8636
Reviewed-By: Florence Blanc-Renaud <flo@redhat.com>
5c8636
Reviewed-By: Anuja More <amore@redhat.com>
5c8636
Reviewed-By: Florence Blanc-Renaud <flo@redhat.com>
5c8636
Reviewed-By: Anuja More <amore@redhat.com>
5c8636
---
5c8636
 .../test_integration/test_ipa_cert_fix.py     | 25 +++++++++++++++++++
5c8636
 1 file changed, 25 insertions(+)
5c8636
5c8636
diff --git a/ipatests/test_integration/test_ipa_cert_fix.py b/ipatests/test_integration/test_ipa_cert_fix.py
5c8636
index 591dc5031..b2e92d4dc 100644
5c8636
--- a/ipatests/test_integration/test_ipa_cert_fix.py
5c8636
+++ b/ipatests/test_integration/test_ipa_cert_fix.py
5c8636
@@ -225,3 +225,28 @@ class TestIpaCertFixThirdParty(CALessBase):
5c8636
         # the DS nickname is used and not a hardcoded value.
5c8636
         result = self.master.run_command(['ipa-cert-fix', '-v'],)
5c8636
         assert self.nickname in result.stderr_text
5c8636
+
5c8636
+
5c8636
+class TestCertFixKRA(IntegrationTest):
5c8636
+    @classmethod
5c8636
+    def uninstall(cls, mh):
5c8636
+        # Uninstall method is empty as the uninstallation is done in
5c8636
+        # the fixture
5c8636
+        pass
5c8636
+
5c8636
+    def test_renew_expired_cert_with_kra(self, expire_cert_critical):
5c8636
+        """Test if ipa-cert-fix renews expired certs with kra installed
5c8636
+
5c8636
+        This test check if ipa-cert-fix renews certs with kra
5c8636
+        certificate installed.
5c8636
+
5c8636
+        related: https://pagure.io/freeipa/issue/7885
5c8636
+        """
5c8636
+        expire_cert_critical(self.master, setup_kra=True)
5c8636
+
5c8636
+        # check if all subsystem cert expired
5c8636
+        check_status(self.master, 11, "CA_UNREACHABLE")
5c8636
+
5c8636
+        self.master.run_command(['ipa-cert-fix', '-v'], stdin_text='yes\n')
5c8636
+
5c8636
+        check_status(self.master, 12, "MONITORING")
5c8636
-- 
5c8636
2.29.2
5c8636
5c8636
From 260fbcb03297ef1ed5418b16c0df0587d2989b22 Mon Sep 17 00:00:00 2001
5c8636
From: Mohammad Rizwan <myusuf@redhat.com>
5c8636
Date: Tue, 2 Mar 2021 11:42:36 +0530
5c8636
Subject: [PATCH] ipatests: update nightly definition for ipa_cert_fix suite
5c8636
5c8636
Signed-off-by: Mohammad Rizwan <myusuf@redhat.com>
5c8636
Reviewed-By: Florence Blanc-Renaud <flo@redhat.com>
5c8636
Reviewed-By: Anuja More <amore@redhat.com>
5c8636
---
5c8636
 ipatests/prci_definitions/nightly_ipa-4-9_latest.yaml         | 2 +-
5c8636
 ipatests/prci_definitions/nightly_ipa-4-9_latest_selinux.yaml | 2 +-
5c8636
 ipatests/prci_definitions/nightly_ipa-4-9_previous.yaml       | 2 +-
5c8636
 3 files changed, 3 insertions(+), 3 deletions(-)
5c8636
5c8636
diff --git a/ipatests/prci_definitions/nightly_ipa-4-9_latest.yaml b/ipatests/prci_definitions/nightly_ipa-4-9_latest.yaml
5c8636
index ebd539246..8a88698eb 100644
5c8636
--- a/ipatests/prci_definitions/nightly_ipa-4-9_latest.yaml
5c8636
+++ b/ipatests/prci_definitions/nightly_ipa-4-9_latest.yaml
5c8636
@@ -1687,5 +1687,5 @@ jobs:
5c8636
         build_url: '{fedora-latest-ipa-4-9/build_url}'
5c8636
         test_suite: test_integration/test_ipa_cert_fix.py
5c8636
         template: *ci-ipa-4-9-latest
5c8636
-        timeout: 3600
5c8636
+        timeout: 7200
5c8636
         topology: *master_1repl
5c8636
diff --git a/ipatests/prci_definitions/nightly_ipa-4-9_latest_selinux.yaml b/ipatests/prci_definitions/nightly_ipa-4-9_latest_selinux.yaml
5c8636
index d4b597d6e..14f0c4292 100644
5c8636
--- a/ipatests/prci_definitions/nightly_ipa-4-9_latest_selinux.yaml
5c8636
+++ b/ipatests/prci_definitions/nightly_ipa-4-9_latest_selinux.yaml
5c8636
@@ -1821,5 +1821,5 @@ jobs:
5c8636
         selinux_enforcing: True
5c8636
         test_suite: test_integration/test_ipa_cert_fix.py
5c8636
         template: *ci-ipa-4-9-latest
5c8636
-        timeout: 3600
5c8636
+        timeout: 7200
5c8636
         topology: *master_1repl
5c8636
diff --git a/ipatests/prci_definitions/nightly_ipa-4-9_previous.yaml b/ipatests/prci_definitions/nightly_ipa-4-9_previous.yaml
5c8636
index 1fd589e6a..b7f8d2b3e 100644
5c8636
--- a/ipatests/prci_definitions/nightly_ipa-4-9_previous.yaml
5c8636
+++ b/ipatests/prci_definitions/nightly_ipa-4-9_previous.yaml
5c8636
@@ -1687,5 +1687,5 @@ jobs:
5c8636
         build_url: '{fedora-previous-ipa-4-9/build_url}'
5c8636
         test_suite: test_integration/test_ipa_cert_fix.py
5c8636
         template: *ci-ipa-4-9-previous
5c8636
-        timeout: 3600
5c8636
+        timeout: 7200
5c8636
         topology: *master_1repl
5c8636
-- 
5c8636
2.29.2
5c8636