89cb6d
From f42a868f4be40f9f8e6c96a6100f15bd16ac1c3b Mon Sep 17 00:00:00 2001
89cb6d
From: Florence Blanc-Renaud <flo@redhat.com>
89cb6d
Date: Wed, 25 Nov 2020 10:00:39 +0100
89cb6d
Subject: [PATCH] ipatests: add test for PKI subsystem detection
89cb6d
89cb6d
Add a new upgrade test. Scenario:
89cb6d
- create an empty /var/lib/pki/pki-tomcat/kra directory
89cb6d
- call ipa-server-upgrade
89cb6d
89cb6d
With issue 8596, the upgrade fails because it assumes KRA is
89cb6d
installed. With the fix, ipa-server-upgrade completes successfully.
89cb6d
89cb6d
Related: https://pagure.io/freeipa/issue/8596
89cb6d
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
89cb6d
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
89cb6d
Reviewed-By: Alexander Bokovoy <abbra@users.noreply.github.com>
89cb6d
---
89cb6d
 ipatests/pytest_ipa/integration/tasks.py  | 12 +++++++++
89cb6d
 ipatests/test_integration/test_upgrade.py | 31 +++++++++++++++++++++++
89cb6d
 2 files changed, 43 insertions(+)
89cb6d
89cb6d
diff --git a/ipatests/pytest_ipa/integration/tasks.py b/ipatests/pytest_ipa/integration/tasks.py
89cb6d
index 26e03e90cb40519a209baf17c088c18af841e2df..6384f0bf29c30e1c5345beb6c7a4cb3029d922e2 100755
89cb6d
--- a/ipatests/pytest_ipa/integration/tasks.py
89cb6d
+++ b/ipatests/pytest_ipa/integration/tasks.py
89cb6d
@@ -1903,3 +1903,15 @@ def ldapmodify_dm(host, ldif_text, **kwargs):
89cb6d
         '-w', host.config.dirman_password
89cb6d
     ]
89cb6d
     return host.run_command(args, stdin_text=ldif_text, **kwargs)
89cb6d
+
89cb6d
+
89cb6d
+def get_pki_version(host):
89cb6d
+    """Get pki version on remote host."""
89cb6d
+    data = host.get_file_contents("/usr/share/pki/VERSION", encoding="utf-8")
89cb6d
+
89cb6d
+    groups = re.match(r'.*\nSpecification-Version: ([\d+\.]*)\n.*', data)
89cb6d
+    if groups:
89cb6d
+        version_string = groups.groups(0)[0]
89cb6d
+        return parse_version(version_string)
89cb6d
+    else:
89cb6d
+        raise ValueError("get_pki_version: pki is not installed")
89cb6d
diff --git a/ipatests/test_integration/test_upgrade.py b/ipatests/test_integration/test_upgrade.py
89cb6d
index 5cc890e2e93b77a9259d72ad9d4961983942a7ce..c866b28dda6efdd10ccd1bee42253ccb6e1285be 100644
89cb6d
--- a/ipatests/test_integration/test_upgrade.py
89cb6d
+++ b/ipatests/test_integration/test_upgrade.py
89cb6d
@@ -5,9 +5,14 @@
89cb6d
 """
89cb6d
 Module provides tests to verify that the upgrade script works.
89cb6d
 """
89cb6d
+from __future__ import absolute_import
89cb6d
 
89cb6d
 import base64
89cb6d
+import os
89cb6d
 from cryptography.hazmat.primitives import serialization
89cb6d
+import pytest
89cb6d
+
89cb6d
+from ipaplatform.paths import paths
89cb6d
 from ipapython.dn import DN
89cb6d
 from ipatests.test_integration.base import IntegrationTest
89cb6d
 from ipatests.pytest_ipa.integration import tasks
89cb6d
@@ -58,3 +63,29 @@ class TestUpgrade(IntegrationTest):
89cb6d
         except ValueError:
89cb6d
             raise AssertionError('%s contains a double-encoded cert'
89cb6d
                                  % entry.dn)
89cb6d
+
89cb6d
+    def test_kra_detection(self):
89cb6d
+        """Test that ipa-server-upgrade correctly detects KRA presence
89cb6d
+
89cb6d
+        Test for https://pagure.io/freeipa/issue/8596
89cb6d
+        When the directory /var/lib/pki/pki-tomcat/kra/ exists, the upgrade
89cb6d
+        wrongly assumes that KRA component is installed and crashes.
89cb6d
+        The test creates an empty dir and calls ipa-server-upgrade
89cb6d
+        to make sure that KRA detection is not based on the directory
89cb6d
+        presence.
89cb6d
+        """
89cb6d
+        # Skip test if pki 10.10.0 is installed
89cb6d
+        # because of https://github.com/dogtagpki/pki/issues/3397
89cb6d
+        # pki fails to start if empty dir /var/lib/pki/pki-tomcat/kra exists
89cb6d
+        if tasks.get_pki_version(self.master) \
89cb6d
+           == tasks.parse_version('10.10.0'):
89cb6d
+            pytest.skip("Skip test with pki 10.10.0")
89cb6d
+
89cb6d
+        kra_path = os.path.join(paths.VAR_LIB_PKI_TOMCAT_DIR, "kra")
89cb6d
+        try:
89cb6d
+            self.master.run_command(["mkdir", "-p", kra_path])
89cb6d
+            result = self.master.run_command(['ipa-server-upgrade'])
89cb6d
+            err_msg = 'Upgrade failed with no such entry'
89cb6d
+            assert err_msg not in result.stderr_text
89cb6d
+        finally:
89cb6d
+            self.master.run_command(["rmdir", kra_path])
89cb6d
-- 
89cb6d
2.26.2
89cb6d