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