From e75dcd59d3e5bc1eadc73cb778d5702d6585989c Mon Sep 17 00:00:00 2001 From: George Pantelakis Date: Tue, 3 Feb 2026 11:54:53 +0100 Subject: [PATCH] Fix tests to reflect changes for SCAutolib V3.4.10 --- Kerberos/test_kerberos_ssh_login.py | 2 +- .../test_kerberos_user_change_password.py | 2 +- Local-user/test_local_user_passwd.py | 2 +- Sanity/test_certs.py | 4 ++-- Sanity/test_ttylogin.py | 4 ++-- conftest.py | 23 +++++++++---------- fixtures.py | 8 +++---- 7 files changed, 22 insertions(+), 23 deletions(-) diff --git a/Kerberos/test_kerberos_ssh_login.py b/Kerberos/test_kerberos_ssh_login.py index f3ec0fd..ec3b5b3 100644 --- a/Kerberos/test_kerberos_ssh_login.py +++ b/Kerberos/test_kerberos_ssh_login.py @@ -4,7 +4,7 @@ import pytest from SCAutolib.models.authselect import Authselect -from SCAutolib.isDistro import isDistro +from SCAutolib.utils import isDistro def test_krb_user_ssh(ipa_user, user_shell): diff --git a/Kerberos/test_kerberos_user_change_password.py b/Kerberos/test_kerberos_user_change_password.py index 620aa36..d0c0177 100644 --- a/Kerberos/test_kerberos_user_change_password.py +++ b/Kerberos/test_kerberos_user_change_password.py @@ -2,7 +2,7 @@ import conftest from SCAutolib.models.authselect import Authselect -from SCAutolib.isDistro import isDistro +from SCAutolib.utils import isDistro @pytest.mark.parametrize("required,insert,expect,secret", diff --git a/Local-user/test_local_user_passwd.py b/Local-user/test_local_user_passwd.py index b93c397..119ffd4 100644 --- a/Local-user/test_local_user_passwd.py +++ b/Local-user/test_local_user_passwd.py @@ -1,7 +1,7 @@ import pytest from SCAutolib.models.authselect import Authselect -from SCAutolib.isDistro import isDistro +from SCAutolib.utils import isDistro @pytest.mark.parametrize( diff --git a/Sanity/test_certs.py b/Sanity/test_certs.py index 5aa9a2c..24f47b2 100644 --- a/Sanity/test_certs.py +++ b/Sanity/test_certs.py @@ -5,7 +5,7 @@ from SCAutolib.models.authselect import Authselect from SCAutolib.models.file import File -from SCAutolib.utils import ca_factory +from SCAutolib.models.CA import BaseCA @pytest.mark.parametrize("sssd_db", [File("/etc/sssd/pki/sssd_auth_ca_db.pem")]) @@ -33,7 +33,7 @@ def test_wrong_issuer_cert(local_user, sssd_db, user_shell, tmp_path): sssd_db.path.unlink() run(['mkdir', tmp_path.joinpath("ca")]) - ca_factory(path=tmp_path.joinpath("ca"), create=True) + ca = BaseCA.factory(path=tmp_path.joinpath("ca"), create=True) run(['restorecon', "-v", "/etc/sssd/pki/sssd_auth_ca_db.pem"]) with Authselect(): diff --git a/Sanity/test_ttylogin.py b/Sanity/test_ttylogin.py index 0600e6b..320c90f 100644 --- a/Sanity/test_ttylogin.py +++ b/Sanity/test_ttylogin.py @@ -14,7 +14,7 @@ import pytest from SCAutolib.models.authselect import Authselect -from SCAutolib.isDistro import isDistro +from SCAutolib.utils import isDistro def login_shell_factory(username): @@ -390,4 +390,4 @@ def test_login_kerberos_su_to_root(ipa_user, root_user, required): login_shell.sendline('su - root -c "whoami"') login_shell.expect_exact("Password:") login_shell.sendline(root_user.password) - login_shell.expect_exact("root") \ No newline at end of file + login_shell.expect_exact("root") diff --git a/conftest.py b/conftest.py index cbd1b8d..53e8f24 100644 --- a/conftest.py +++ b/conftest.py @@ -1,11 +1,10 @@ import logging - -from SCAutolib.utils import load_user, ipa_factory, load_token, \ - ca_factory +from SCAutolib.models.CA import BaseCA, IPAServerCA +from SCAutolib.models.card import Card +from SCAutolib.models.user import User from fixtures import * -from pathlib import Path log = logging.getLogger("PyTest") log.setLevel(logging.DEBUG) @@ -20,17 +19,18 @@ def load_tokens(user, token_list, update_sssd): for index, token in enumerate(token_list): log.debug("Loading %s. token", index) setattr( - user, f"card_{index}", load_token(token, update_sssd = update_sssd) + user, f"card_{index}", + Card.load(card_name = token, update_sssd = update_sssd) ) log.debug(f"Token %s is loaded", index) def update_ca(user, token_list): log.info("Loading local CA") - for index, token in enumerate(token_list): + for index, _ in enumerate(token_list): card_name = f"card_{index}" card = getattr(user, card_name, None) - ca = ca_factory(ca_name=card.ca_name) + ca = BaseCA.factory(ca_name = card.ca_name) ca.update_ca_db() log.debug("CA database is updated") @@ -50,11 +50,11 @@ def pytest_configure(config): if user_type in ["ipa", "all"]: log.debug("Loading IPA client") - ipa_server = ipa_factory() + ipa_server = IPAServerCA.factory() log.debug("IPA client is loaded") log.debug("Loading IPA user") - ipa_user = load_user( - config.getoption("ipa_username"), + ipa_user = User.load( + username = config.getoption("ipa_username"), ipa_server=ipa_server) assert ipa_user.user_type == "ipa" log.debug("IPA user is loaded") @@ -63,8 +63,7 @@ def pytest_configure(config): ipa_user.pin = ipa_user.card.pin if user_type in ["local", "all"]: log.debug("Loading local user") - local_user = load_user(config.getoption( - "local_username")) + local_user = User.load(username = config.getoption("local_username")) assert local_user.user_type == "local" log.debug("Local user is loaded") load_tokens(local_user, tokens, config.getoption("keep_sssd")) diff --git a/fixtures.py b/fixtures.py index 8a67962..2374e74 100644 --- a/fixtures.py +++ b/fixtures.py @@ -5,7 +5,7 @@ from SCAutolib import run from SCAutolib.models.file import SSSDConf -from SCAutolib.utils import load_user +from SCAutolib.models.user import User @pytest.fixture(scope="function") @@ -26,7 +26,7 @@ def root_shell(): @pytest.fixture(scope="function") def allow_sudo_commands(ipa_user): """ - Modifying the IPA server's sudo rules to allow the test user to + Modifying the IPA server's sudo rules to allow the test user to run sudo commands and restore the original state afterward. """ logger = logging.getLogger() @@ -44,12 +44,12 @@ def allow_sudo_commands(ipa_user): @pytest.fixture(scope="session") def root_user(): - return load_user("root") + return User.load(username = "root") @pytest.fixture(scope="session") def base_user(): - return load_user("base-user") + return User.load(username = "base-user") @pytest.fixture(scope="session")