7e1b55
From c9bc471e063f2865d6423e4f1c9b81e73a45e43f Mon Sep 17 00:00:00 2001
7e1b55
From: Stanislav Levin <slev@altlinux.org>
7e1b55
Date: Wed, 4 Aug 2021 18:38:16 +0300
7e1b55
Subject: [PATCH] ipatests: Fix TestAJPSecretUpgrade tests on systems without
7e1b55
 pkiuser
7e1b55
7e1b55
Tests in `test_ipaserver.test_secure_ajp_connector' assume that there
7e1b55
is pkiuser in OS, but this is not always true (for example, in systems
7e1b55
having minimum installed dependencies, in particular, without pki-server
7e1b55
RPM package). Since the tests already use the mock and pkiuser entity is
7e1b55
not the subject of testing the pwd.getpwnam has been mocked.
7e1b55
7e1b55
Fixes: https://pagure.io/freeipa/issue/8942
7e1b55
Signed-off-by: Stanislav Levin <slev@altlinux.org>
7e1b55
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
7e1b55
---
7e1b55
 .../test_secure_ajp_connector.py              | 40 ++++++++++++++++---
7e1b55
 1 file changed, 34 insertions(+), 6 deletions(-)
7e1b55
7e1b55
diff --git a/ipatests/test_ipaserver/test_secure_ajp_connector.py b/ipatests/test_ipaserver/test_secure_ajp_connector.py
7e1b55
index 2719dbc48..35ef7407a 100644
7e1b55
--- a/ipatests/test_ipaserver/test_secure_ajp_connector.py
7e1b55
+++ b/ipatests/test_ipaserver/test_secure_ajp_connector.py
7e1b55
@@ -1,5 +1,6 @@
7e1b55
 # Copyright (C) 2021  FreeIPA Project Contributors - see LICENSE file
7e1b55
 
7e1b55
+from collections import namedtuple
7e1b55
 from io import BytesIO
7e1b55
 from lxml.etree import parse as myparse  # pylint: disable=no-name-in-module
7e1b55
 import pytest
7e1b55
@@ -32,6 +33,32 @@ def mock_etree_parse(data):
7e1b55
     return myparse(f)
7e1b55
 
7e1b55
 
7e1b55
+def mock_pkiuser_entity():
7e1b55
+    """Return struct_passwd for mocked pkiuser"""
7e1b55
+    StructPasswd = namedtuple(
7e1b55
+        "StructPasswd",
7e1b55
+        [
7e1b55
+            "pw_name",
7e1b55
+            "pw_passwd",
7e1b55
+            "pw_uid",
7e1b55
+            "pw_gid",
7e1b55
+            "pw_gecos",
7e1b55
+            "pw_dir",
7e1b55
+            "pw_shell",
7e1b55
+        ]
7e1b55
+    )
7e1b55
+    pkiuser_entity = StructPasswd(
7e1b55
+        constants.PKI_USER,
7e1b55
+        pw_passwd="x",
7e1b55
+        pw_uid=-1,
7e1b55
+        pw_gid=-1,
7e1b55
+        pw_gecos="",
7e1b55
+        pw_dir="/dev/null",
7e1b55
+        pw_shell="/sbin/nologin",
7e1b55
+    )
7e1b55
+    return pkiuser_entity
7e1b55
+
7e1b55
+
7e1b55
 # Format of test_data is:
7e1b55
 #    (
7e1b55
 #        is_newer_tomcat (boolean),
7e1b55
@@ -148,14 +175,15 @@ test_data = (
7e1b55
 
7e1b55
 
7e1b55
 class TestAJPSecretUpgrade:
7e1b55
-    @patch('os.chown')
7e1b55
-    @patch('lxml.etree.parse')
7e1b55
-    @pytest.mark.parametrize('is_newer, data, secret, expect, rewrite',
7e1b55
-                             test_data)
7e1b55
-    def test_connecter(self, mock_parse, mock_chown, is_newer, data, secret,
7e1b55
-                       expect, rewrite):
7e1b55
+    @patch("ipaplatform.base.constants.pwd.getpwnam")
7e1b55
+    @patch("ipaplatform.base.constants.os.chown")
7e1b55
+    @patch("ipaserver.install.dogtaginstance.lxml.etree.parse")
7e1b55
+    @pytest.mark.parametrize("test_data", test_data)
7e1b55
+    def test_connecter(self, mock_parse, mock_chown, mock_getpwnam, test_data):
7e1b55
+        is_newer, data, secret, expect, rewrite = test_data
7e1b55
         mock_chown.return_value = None
7e1b55
         mock_parse.return_value = mock_etree_parse(data)
7e1b55
+        mock_getpwnam.return_value = mock_pkiuser_entity()
7e1b55
 
7e1b55
         dogtag = MyDogtagInstance(is_newer)
7e1b55
         with patch('ipaserver.install.dogtaginstance.open', mock_open()) \
7e1b55
-- 
7e1b55
2.31.1
7e1b55