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