mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-01-11 00:31:56 -06:00
ipatests: Fix TestAJPSecretUpgrade tests on systems without pkiuser
Tests in `test_ipaserver.test_secure_ajp_connector' assume that there is pkiuser in OS, but this is not always true (for example, in systems having minimum installed dependencies, in particular, without pki-server RPM package). Since the tests already use the mock and pkiuser entity is not the subject of testing the pwd.getpwnam has been mocked. Fixes: https://pagure.io/freeipa/issue/8942 Signed-off-by: Stanislav Levin <slev@altlinux.org> Reviewed-By: Rob Crittenden <rcritten@redhat.com>
This commit is contained in:
parent
16b3788f68
commit
bb628aebaf
@ -1,5 +1,6 @@
|
||||
# Copyright (C) 2021 FreeIPA Project Contributors - see LICENSE file
|
||||
|
||||
from collections import namedtuple
|
||||
from io import BytesIO
|
||||
from lxml.etree import parse as myparse # pylint: disable=no-name-in-module
|
||||
import pytest
|
||||
@ -32,6 +33,32 @@ def mock_etree_parse(data):
|
||||
return myparse(f)
|
||||
|
||||
|
||||
def mock_pkiuser_entity():
|
||||
"""Return struct_passwd for mocked pkiuser"""
|
||||
StructPasswd = namedtuple(
|
||||
"StructPasswd",
|
||||
[
|
||||
"pw_name",
|
||||
"pw_passwd",
|
||||
"pw_uid",
|
||||
"pw_gid",
|
||||
"pw_gecos",
|
||||
"pw_dir",
|
||||
"pw_shell",
|
||||
]
|
||||
)
|
||||
pkiuser_entity = StructPasswd(
|
||||
constants.PKI_USER,
|
||||
pw_passwd="x",
|
||||
pw_uid=-1,
|
||||
pw_gid=-1,
|
||||
pw_gecos="",
|
||||
pw_dir="/dev/null",
|
||||
pw_shell="/sbin/nologin",
|
||||
)
|
||||
return pkiuser_entity
|
||||
|
||||
|
||||
# Format of test_data is:
|
||||
# (
|
||||
# is_newer_tomcat (boolean),
|
||||
@ -148,14 +175,15 @@ test_data = (
|
||||
|
||||
|
||||
class TestAJPSecretUpgrade:
|
||||
@patch('os.chown')
|
||||
@patch('lxml.etree.parse')
|
||||
@pytest.mark.parametrize('is_newer, data, secret, expect, rewrite',
|
||||
test_data)
|
||||
def test_connecter(self, mock_parse, mock_chown, is_newer, data, secret,
|
||||
expect, rewrite):
|
||||
@patch("ipaplatform.base.constants.pwd.getpwnam")
|
||||
@patch("ipaplatform.base.constants.os.chown")
|
||||
@patch("ipaserver.install.dogtaginstance.lxml.etree.parse")
|
||||
@pytest.mark.parametrize("test_data", test_data)
|
||||
def test_connecter(self, mock_parse, mock_chown, mock_getpwnam, test_data):
|
||||
is_newer, data, secret, expect, rewrite = test_data
|
||||
mock_chown.return_value = None
|
||||
mock_parse.return_value = mock_etree_parse(data)
|
||||
mock_getpwnam.return_value = mock_pkiuser_entity()
|
||||
|
||||
dogtag = MyDogtagInstance(is_newer)
|
||||
with patch('ipaserver.install.dogtaginstance.open', mock_open()) \
|
||||
|
Loading…
Reference in New Issue
Block a user