|
| 1 | +""" |
| 2 | +SSSD Socket Activation Tests. |
| 3 | +
|
| 4 | +:requirement: sssd_socket |
| 5 | +""" |
| 6 | + |
| 7 | +from __future__ import annotations |
| 8 | + |
| 9 | +import pytest |
| 10 | +from sssd_test_framework.roles.client import Client |
| 11 | +from sssd_test_framework.roles.generic import GenericProvider |
| 12 | +from sssd_test_framework.roles.nfs import NFS |
| 13 | +from sssd_test_framework.topology import KnownTopology |
| 14 | + |
| 15 | + |
| 16 | +@pytest.mark.topology(KnownTopology.LDAP) |
| 17 | +@pytest.mark.parametrize("responder", ["nss", "pam", "ssh", "autofs"]) |
| 18 | +def test_socket__responders__socket_activation_lifecycle( |
| 19 | + client: Client, provider: GenericProvider, nfs: NFS, responder: str |
| 20 | +): |
| 21 | + """ |
| 22 | + :title: Socket-Activated Responder Lifecycle |
| 23 | + :description: | |
| 24 | + Verify that socket-activated responders: |
| 25 | + 1. Have their socket unit active |
| 26 | + 2. Have their service unit inactive initially |
| 27 | + 3. Start automatically on first client request via systemd socket activation |
| 28 | + :setup: |
| 29 | + 1. Configure SSSD with socket activation enabled |
| 30 | + 2. Add test user to LDAP backend |
| 31 | + :steps: |
| 32 | + 1. Verify socket unit is active and service unit is inactive |
| 33 | + 2. Trigger first request, service unit becomes active |
| 34 | + :expectedresults: |
| 35 | + 1. Service unit is inactive before first request |
| 36 | + 2. Service unit becomes active after first request |
| 37 | + :customerscenario: False |
| 38 | + """ |
| 39 | + u = provider.user("user1").add(password="Secret123") |
| 40 | + if responder == "autofs": |
| 41 | + nfs_export = nfs.export("export").add() |
| 42 | + auto_master = provider.automount.map("auto.master").add() |
| 43 | + auto_export = provider.automount.map("auto.export").add() |
| 44 | + auto_master.key("/var/export").add(info=auto_export) |
| 45 | + auto_export.key("export").add(info=nfs_export) |
| 46 | + |
| 47 | + if responder in ["pam", "sudo", "ssh"]: |
| 48 | + client.sssd.sssd["services"] = "nss" |
| 49 | + else: |
| 50 | + client.sssd.sssd["services"] = "" |
| 51 | + |
| 52 | + client.sssd.restart() |
| 53 | + client.sssd.common.socket_responders([responder]) |
| 54 | + |
| 55 | + socket_unit = f"sssd-{responder}.socket" |
| 56 | + service_unit = f"sssd-{responder}.service" |
| 57 | + |
| 58 | + assert client.sssd.svc.is_active(socket_unit), f"{responder} socket should be active" |
| 59 | + assert not client.sssd.svc.is_active(service_unit), f"{responder} service should be inactive initially" |
| 60 | + |
| 61 | + if responder == "nss": |
| 62 | + client.tools.getent.passwd(u.name) |
| 63 | + elif responder == "pam": |
| 64 | + result = client.auth.ssh.password(u.name, "Secret123") |
| 65 | + assert result, f"PAM authentication failed for {u.name}" |
| 66 | + elif responder == "ssh": |
| 67 | + client.host.conn.run(f"sss_ssh_authorizedkeys {u.name}", raise_on_error=False) |
| 68 | + elif responder == "autofs": |
| 69 | + client.automount.reload() |
| 70 | + result = client.automount.mount("/var/export/export", nfs_export) |
| 71 | + assert result, "AUTOFS mount failed for /var/export/export" |
| 72 | + |
| 73 | + assert client.sssd.svc.is_active(service_unit), f"{responder} service should be active after request" |
| 74 | + |
| 75 | + |
| 76 | +@pytest.mark.topology(KnownTopology.LDAP) |
| 77 | +@pytest.mark.parametrize("socket_responder", ["nss", "ssh", "autofs"]) |
| 78 | +def test_socket__responders__mixed_socket_and_traditional_services( |
| 79 | + client: Client, provider: GenericProvider, nfs: NFS, socket_responder: str |
| 80 | +): |
| 81 | + """ |
| 82 | + :title: Mixed Socket-Activated and Traditional Responders |
| 83 | + :description: | |
| 84 | + Verify that some responders can be socket-activated while others run as traditional services |
| 85 | + :setup: |
| 86 | + 1. Configure mixed socket-activated and traditional services |
| 87 | + 2. Add test user to LDAP backend |
| 88 | + :steps: |
| 89 | + 1. Verify socket unit is active and service unit is inactive for socket-activated responder |
| 90 | + 2. Verify traditional responder is configured in services |
| 91 | + 3. Trigger request for socket-activated responder |
| 92 | + 4. Verify its service unit becomes active |
| 93 | + :expectedresults: |
| 94 | + 1. Socket-activated responder is inactive before request |
| 95 | + 2. Traditional responder is configured in traditional mode |
| 96 | + 3. Request triggered for socket-activated responder |
| 97 | + 3. Socket-activated responder starts automatically on first request |
| 98 | + :customerscenario: False |
| 99 | + """ |
| 100 | + u = provider.user("user1").add(password="Secret123") |
| 101 | + |
| 102 | + if socket_responder == "autofs": |
| 103 | + nfs_export = nfs.export("export").add() |
| 104 | + auto_master = provider.automount.map("auto.master").add() |
| 105 | + auto_export = provider.automount.map("auto.export").add() |
| 106 | + auto_master.key("/var/export").add(info=auto_export) |
| 107 | + auto_export.key("export").add(info=nfs_export) |
| 108 | + |
| 109 | + if socket_responder == "nss": |
| 110 | + traditional_responder = "ssh" |
| 111 | + else: |
| 112 | + traditional_responder = "nss" |
| 113 | + |
| 114 | + client.sssd.sssd["services"] = traditional_responder |
| 115 | + client.sssd.restart() |
| 116 | + |
| 117 | + client.sssd.common.socket_responders([socket_responder]) |
| 118 | + |
| 119 | + socket_unit = f"sssd-{socket_responder}.socket" |
| 120 | + socket_service = f"sssd-{socket_responder}.service" |
| 121 | + |
| 122 | + assert client.sssd.svc.is_active(socket_unit), f"{socket_responder} socket should be active" |
| 123 | + assert not client.sssd.svc.is_active(socket_service), f"{socket_responder} service should be inactive initially" |
| 124 | + assert ( |
| 125 | + traditional_responder in client.sssd.sssd["services"] |
| 126 | + ), f"{traditional_responder} should be listed in services (traditional mode)" |
| 127 | + |
| 128 | + if socket_responder == "nss": |
| 129 | + client.tools.getent.passwd(u.name) |
| 130 | + elif socket_responder == "ssh": |
| 131 | + client.host.conn.run(f"sss_ssh_authorizedkeys {u.name}", raise_on_error=False) |
| 132 | + elif socket_responder == "autofs": |
| 133 | + client.automount.reload() |
| 134 | + result = client.automount.mount("/var/export/export", nfs_export) |
| 135 | + assert result, "AUTOFS mount failed for /var/export/export" |
| 136 | + |
| 137 | + assert client.sssd.svc.is_active(socket_service), f"{socket_responder} service should be active after request" |
0 commit comments