Skip to content

Commit

Permalink
tests: update the tests to work with latest pytest-mh
Browse files Browse the repository at this point in the history
Latest version added an option to replace SSH connections with podman
or docker, therefore a generic interface was created. Most notably,
`host.ssh` was replaced with `host.conn`.

Reviewed-by: Dan Lavu <[email protected]>
Reviewed-by: Tomáš Halman <[email protected]>
  • Loading branch information
pbrezina committed Aug 2, 2024
1 parent c3ce4bc commit d213e59
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/tests/system/tests/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_files__enumeration_should_not_work(client: Client):
client.sssd.sssd["enable_files_domain"] = "true"
client.sssd.start()

assert not client.host.ssh.run("getent passwd -s sss").stdout, "Entries found!"
assert not client.host.conn.run("getent passwd -s sss").stdout, "Entries found!"


@pytest.mark.importance("low")
Expand Down
12 changes: 6 additions & 6 deletions src/tests/system/tests/test_kcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import time

import pytest
from pytest_mh.ssh import SSHProcessError
from pytest_mh.conn import ProcessError
from sssd_test_framework.roles.client import Client
from sssd_test_framework.roles.kdc import KDC
from sssd_test_framework.roles.ldap import LDAP
Expand Down Expand Up @@ -423,7 +423,7 @@ def test_kcm__kinit_user_after_login(client: Client, kdc: KDC):
with client.ssh(username, password) as ssh:
with client.auth.kerberos(ssh) as krb:
assert krb.kinit(username, password=password).rc == 0, "kinit failed!"
with pytest.raises(SSHProcessError):
with pytest.raises(ProcessError):
krb.kinit(username, password="wrong")
assert krb.klist().rc == 0, "klist failed!"

Expand Down Expand Up @@ -462,7 +462,7 @@ def kcm_log_length() -> int:
try:
output = client.fs.wc(kcm_log_file, lines=True).stdout
return int(output.split()[0])
except SSHProcessError:
except ProcessError:
return 0

user = "user1"
Expand Down Expand Up @@ -579,7 +579,7 @@ def test_kcm__configure_max_uid_ccaches_with_different_values(client: Client, kd
client.sssd.config_apply()
client.svc.restart("sssd-kcm")
assert krb.kinit(user0, password=password).rc == 0, "max_uid_ccache = 1, kinit failed!"
with pytest.raises(SSHProcessError):
with pytest.raises(ProcessError):
krb.kinit(user1, password=password)

# max_uid_ccaches set to default (64)
Expand All @@ -589,15 +589,15 @@ def test_kcm__configure_max_uid_ccaches_with_different_values(client: Client, kd
for i in range(1, 64):
user = f"user{i}"
assert krb.kinit(user, password=password).rc == 0, "max_uid_ccache = 64, kinit failed!"
with pytest.raises(SSHProcessError):
with pytest.raises(ProcessError):
krb.kinit("user64", password=password)

# max_uid_ccaches set to 65
client.sssd.kcm["max_uid_ccaches"] = "65"
client.sssd.config_apply()
client.svc.restart("sssd-kcm")
assert krb.kinit("user64", password=password).rc == 0, "max_uid_ccache = 65, kinit failed!"
with pytest.raises(SSHProcessError):
with pytest.raises(ProcessError):
krb.kinit("user65", password=password)

# kinit as another user
Expand Down
2 changes: 1 addition & 1 deletion src/tests/system/tests/test_ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def test_ldap__password_change_new_password_does_not_meet_complexity_requirement

assert (
"pam_sss(passwd:chauthtok): User info message: Password change failed."
in client.host.ssh.run("journalctl").stdout
in client.host.conn.run("journalctl").stdout
)


Expand Down
2 changes: 1 addition & 1 deletion src/tests/system/tests/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_logging__default_debug_level_check_with_login(client: Client):

client.fs.copy("/var/log/sssd", "/tmp/copy")
assert client.auth.ssh.password("user1", "Secret123"), "Authentication failed"
assert not client.host.ssh.run("diff /var/log/sssd /tmp/copy").stdout, "Debug messages were generated"
assert not client.host.conn.run("diff /var/log/sssd /tmp/copy").stdout, "Debug messages were generated"


@pytest.mark.ticket(bz=1893159)
Expand Down
6 changes: 3 additions & 3 deletions src/tests/system/tests/test_memcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -1548,7 +1548,7 @@ def test_memcache__memcache_timeout_zero(client: Client, provider: GenericProvid
client.sssd.domain["ldap_id_mapping"] = "false"
client.sssd.start()

r = client.host.ssh.exec(["ls", "/var/lib/sss/mc"])
r = client.host.conn.exec(["ls", "/var/lib/sss/mc"])
assert r.stdout == "", "Cache directory is not empty"
assert r.stderr == "", "Ls command failed"

Expand Down Expand Up @@ -1616,9 +1616,9 @@ def test_memcache__removed_cache_without_invalidation(client: Client, provider:

client.sssd.stop()

r = client.host.ssh.exec(["ls", "/var/lib/sss/mc"])
r = client.host.conn.exec(["ls", "/var/lib/sss/mc"])
for file in r.stdout.split():
check = client.host.ssh.exec(["rm", f"/var/lib/sss/mc/{file}"])
check = client.host.conn.exec(["rm", f"/var/lib/sss/mc/{file}"])
assert check.rc == 0, "Cache file was not removed successfully"

assert client.tools.id("user1") is None, "User user1 was found which is not expected"
Expand Down
3 changes: 2 additions & 1 deletion src/tests/system/tests/test_passkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@


def passkey_requires_root(client: Client) -> tuple[bool, str] | bool:
if client.svc.get_property("sssd", "User") != "root":
user = client.svc.get_property("sssd", "User")
if user and user != "root":
return False, "Passkey tests don't work if SSSD runs under non-root"

return True
Expand Down
9 changes: 5 additions & 4 deletions src/tests/system/tests/test_sssctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import time

import pytest
from pytest_mh.ssh import SSHAuthenticationError, SSHProcessError
from pytest_mh.conn import ProcessError
from pytest_mh.conn.ssh import SSHAuthenticationError
from sssd_test_framework.roles.client import Client
from sssd_test_framework.roles.ldap import LDAP
from sssd_test_framework.topology import KnownTopology
Expand Down Expand Up @@ -41,7 +42,7 @@ def test_sssctl__check_missing_id_provider(client: Client):
client.sssd.config_apply(check_config=False)

# Check the error message in output of # sssctl config-check
output = client.host.ssh.run("sssctl config-check", raise_on_error=False)
output = client.host.conn.run("sssctl config-check", raise_on_error=False)
assert "[rule/sssd_checks]: Attribute 'id_provider' is missing in section 'domain/test'." in output.stdout_lines[1]


Expand Down Expand Up @@ -71,7 +72,7 @@ def test_sssctl__check_invalid_id_provider(client: Client):
client.sssd.config_apply(check_config=False)

# Check the return code of # sssctl config-check command
output = client.host.ssh.run("sssctl config-check", raise_on_error=False)
output = client.host.conn.run("sssctl config-check", raise_on_error=False)
assert (
"[rule/sssd_checks]: Attribute 'id_provider' in section 'domain/test' has an invalid value: invalid"
in output.stdout_lines[1]
Expand Down Expand Up @@ -234,7 +235,7 @@ def test_sssctl__check_missing_domain_name(client: Client):
"""
client.sssd.dom("")["debug_level"] = "9"

with pytest.raises(SSHProcessError) as ex:
with pytest.raises(ProcessError) as ex:
client.sssd.start(raise_on_error=True, check_config=True)

assert ex.match(r"Section \[domain\/\] is not allowed. Check for typos.*"), "Wrong error message was returned"
Expand Down
8 changes: 4 additions & 4 deletions src/tests/system/tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from __future__ import annotations

import pytest
from pytest_mh.ssh import SSHProcessError
from pytest_mh.conn import ProcessError
from sssd_test_framework.roles.client import Client
from sssd_test_framework.topology import KnownTopology

Expand Down Expand Up @@ -46,16 +46,16 @@ def test_tools__sss_cache_expired_does_not_print_unrelated_message(client: Clien
client.sssd.sssd["enable_files_domain"] = "false"
client.local.user("user1").add()

with pytest.raises(SSHProcessError):
with pytest.raises(ProcessError):
client.sssd.restart()

res = client.host.ssh.run("usermod -a -G wheel user1")
res = client.host.conn.run("usermod -a -G wheel user1")
assert (
"No domains configured, fatal error!" not in res.stdout
), "'No domains configured, fatal error!' printed to stdout!"

for cmd in ("sss_cache -U", "sss_cache -G", "sss_cache -E", "sss_cache --user=nonexisting"):
res = client.host.ssh.run(cmd)
res = client.host.conn.run(cmd)
assert (
"No domains configured, fatal error!" not in res.stdout
), "'No domains configured, fatal error!' printed to stdout!"

0 comments on commit d213e59

Please sign in to comment.