Skip to content

Commit 05ae5f2

Browse files
committed
Tests: Test trasformation SSSD does not crash in nss responder after netgroup timeout when backend is offline
SSSD does not crash in nss responder after netgroup timeout when backend is offline
1 parent 196ad92 commit 05ae5f2

File tree

1 file changed

+152
-0
lines changed

1 file changed

+152
-0
lines changed

src/tests/system/tests/test_netgroups.py

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66

77
from __future__ import annotations
88

9+
import time
10+
911
import pytest
1012
from sssd_test_framework.roles.ad import AD
1113
from sssd_test_framework.roles.client import Client
1214
from sssd_test_framework.roles.generic import GenericProvider
15+
from sssd_test_framework.roles.ipa import IPA
1316
from sssd_test_framework.roles.ldap import LDAP
1417
from sssd_test_framework.roles.samba import Samba
1518
from sssd_test_framework.topology import KnownTopology, KnownTopologyGroup
@@ -309,3 +312,152 @@ def test_netgroup__uid_gt_2147483647(client: Client, provider: GenericProvider):
309312
result = client.tools.getent.group(grpname)
310313
assert result is not None, f"getent group for group '{grpname}' is empty!"
311314
assert result.name == grpname, f"Group name '{grpname}' did not match result '{result.name}'!"
315+
316+
317+
@pytest.mark.importance("low")
318+
@pytest.mark.ticket(bz=1576852)
319+
@pytest.mark.topology(KnownTopologyGroup.AnyProvider)
320+
def test_netgroup__nss_responder(client: Client, provider: GenericProvider):
321+
"""
322+
:title: SSSD does not crash in nss responder after netgroup timeout when backend is offline
323+
:setup:
324+
1. A user (user-1) and a netgroup (ng-1) are created, and the user is added as a member of the netgroup
325+
2. SSSD is restarted with a clean configuration to ensure no stale data is present
326+
:steps:
327+
1. Depending on the type of provider (AD, IPA, Samba, or LDAP), the script updates the SSSD configuration
328+
with an incorrect server URI (e.g., typo.dc.hostname)
329+
2. SSSD is restarted again to apply the new configuration
330+
3. Checks the status of the SSSD domain to ensure it is offline due to the misconfigured server
331+
4. Capture the process ID (PID) of the sssd_nss process
332+
5. Try to retrieve the netgroup information again, expecting it to fail since the SSSD domain is offline
333+
6. Verify that the SSSD processes (sssd, sssd_be, sssd_nss, sssd_pam) are still running and that the
334+
sssd_nss process ID has not changed, indicating that SSSD has not crashed or restarted unexpectedly
335+
:expectedresults:
336+
1. SSSD configured with incorrect server backend
337+
2. SSSD restarted
338+
3. SSSD Offline
339+
4. Pid of sssd_nss captured
340+
5. Netgroup info cant be retrieve
341+
6. SSSD not crashed
342+
:customerscenario: True
343+
"""
344+
user = provider.user("user-1").add()
345+
netgroup = provider.netgroup("ng-1").add().add_member(user=user)
346+
client.sssd.restart(clean=True)
347+
348+
result = client.tools.getent.netgroup(netgroup.name)
349+
assert result is not None
350+
assert result.members[0].user == "user-1"
351+
352+
hostname = client.host.hostname
353+
if isinstance(provider, (AD)):
354+
bad_ldap_uri = "typo.dc.%s" % hostname
355+
client.sssd.dom("test").update(ad_server=bad_ldap_uri)
356+
357+
if isinstance(provider, (IPA)):
358+
bad_ldap_uri = "typo.master.%s" % hostname
359+
client.sssd.dom("test").update(ipa_server=bad_ldap_uri)
360+
361+
if isinstance(provider, (Samba)):
362+
bad_ldap_uri = "typo.dc.%s" % hostname
363+
client.sssd.dom("test").update(ad_server=bad_ldap_uri)
364+
365+
if isinstance(provider, (LDAP)):
366+
bad_ldap_uri = "ldaps://typo.%s" % hostname
367+
client.sssd.dom("test").update(ldap_uri=bad_ldap_uri)
368+
369+
client.sssd.restart(clean=True)
370+
371+
# Check backend status
372+
assert "Offline" in client.host.conn.run("sssctl domain-status test -o").stdout
373+
374+
pid_nss = "pidof sssd_nss"
375+
pid_nss1 = client.host.conn.run(pid_nss).stdout
376+
377+
# request for netgroup
378+
assert not client.tools.getent.netgroup(netgroup.name)
379+
380+
sssd_proc = ["sssd", "sssd_be", "sssd_nss", "sssd_pam"]
381+
for proc in sssd_proc:
382+
pgrep = "pgrep %s" % proc
383+
client.host.conn.run(pgrep)
384+
385+
pid_nss2 = client.host.conn.run(pid_nss).stdout
386+
assert pid_nss1 == pid_nss2
387+
388+
389+
@pytest.mark.importance("low")
390+
@pytest.mark.ticket(bz=1406437)
391+
@pytest.mark.topology(KnownTopologyGroup.AnyProvider)
392+
def test_netgroup__sssctl_netgroup_show(client: Client, provider: GenericProvider):
393+
"""
394+
:title: The command sssctl netgroup-show contains the expected netgroup and
395+
does not contain any memory allocation errors
396+
:setup:
397+
1. Restart SSSD service with the clean option
398+
2. Create a user and a netgroup. Add user as a member of the netgroup.
399+
:steps:
400+
1. Use "getent" command to query the netgroup and asserts that the netgroup exists
401+
and that user is a member of the netgroup
402+
2. Use "sssctl netgroup-show" command to display information about the netgroup and
403+
checks that the output contains the expected netgroup name
404+
and does not contain any memory allocation errors
405+
:expectedresults:
406+
1. The netgroup exists and user is a member of the netgroup
407+
2. The command "sssctl netgroup-show" does not contain any memory allocation errors
408+
:customerscenario: True
409+
"""
410+
client.sssd.restart(clean=True)
411+
user = provider.user("user-1").add()
412+
netgroup = provider.netgroup("ng-1").add().add_member(user=user)
413+
414+
result = client.tools.getent.netgroup(netgroup.name)
415+
assert result is not None
416+
assert result.members[0].user == "user-1"
417+
output = client.host.conn.run(f"sssctl netgroup-show {netgroup.name}@test").stdout
418+
assert "Name: ng-1" in output
419+
assert "Cannot allocate memory" not in output
420+
421+
422+
@pytest.mark.importance("low")
423+
@pytest.mark.ticket(bz=1779486)
424+
@pytest.mark.topology(KnownTopologyGroup.AnyProvider)
425+
def test_netgroup__background_refresh(client: Client, provider: GenericProvider):
426+
"""
427+
:title: Verify Netgroup Membership Updates in SSSD Cache After User Addition and Cache Expiry
428+
:setup:
429+
1. Update SSSD configuration
430+
2. Restart SSSD
431+
3. Create a user and netgroup
432+
4. A second user is created and added to the netgroup
433+
:steps:
434+
1. The getent command is used to retrieve the netgroup information and user is member of the netgroup
435+
2. Wait for 30 seconds to allow the cache to expire and be refreshed
436+
3. The ldbsearch command is used to query the SSSD cache database (cache_test.ldb)
437+
to verify that second user is now part of the netgroup in the cache
438+
:expectedresults:
439+
1. Retrieves the netgroup information and user is member of the netgroup
440+
2. Successfully wait
441+
3. Second user is now part of the netgroup in the cache
442+
:customerscenario: True
443+
"""
444+
client.sssd.dom("test").update(entry_cache_timeout="10", refresh_expired_interval="5")
445+
client.sssd.restart(clean=True)
446+
user = provider.user("user-1").add()
447+
netgroup = provider.netgroup("ng-1").add().add_member(user=user)
448+
449+
result = client.tools.getent.netgroup(netgroup.name)
450+
assert result is not None
451+
assert result.members[0].user == "user-1"
452+
453+
user2 = provider.user("user-2").add()
454+
netgroup.add_member(user=user2.name)
455+
456+
time.sleep(30)
457+
458+
assert (
459+
user2.name
460+
in client.host.conn.run(
461+
"ldbsearch -H /var/lib/sss/db/cache_test.ldb " "-b cn=Netgroups,cn=test,cn=sysdb"
462+
).stdout
463+
)

0 commit comments

Comments
 (0)