From c0d7d0d393e67e6e6b8dd4b2225e2305524c92b2 Mon Sep 17 00:00:00 2001 From: Dan Lavu Date: Fri, 12 Jul 2024 03:15:58 -0400 Subject: [PATCH] tests: housekeeping - netgroups housekeeping, the following is looked at and may have been done: * fixed typos and standardized formatting * renamed test cases to improve the clarity of what the test does * improved docstring language, setup, steps and expected results * synced code with the docstring order * removed necessary configuration relevant to the test * added pytest.mark.importance to test cases * added error messages to assertions noteable changes: * moved netgroup tests to the the cache tests file, it tests the cache for netgroup objects --- src/tests/system/tests/test_cache.py | 103 ++++++++++++++++++++- src/tests/system/tests/test_netgroups.py | 110 ----------------------- 2 files changed, 102 insertions(+), 111 deletions(-) delete mode 100644 src/tests/system/tests/test_netgroups.py diff --git a/src/tests/system/tests/test_cache.py b/src/tests/system/tests/test_cache.py index 092241d1e11..c504d91cd67 100644 --- a/src/tests/system/tests/test_cache.py +++ b/src/tests/system/tests/test_cache.py @@ -17,7 +17,7 @@ import pytest from sssd_test_framework.roles.client import Client from sssd_test_framework.roles.generic import GenericProvider -from sssd_test_framework.topology import KnownTopology, KnownTopologyGroup +from sssd_test_framework.topology import KnownTopologyGroup @pytest.mark.importance("critical") @@ -86,6 +86,7 @@ def test_cache__is_refreshed_as_configured(client: Client, provider: GenericProv assert last_update[s] <= (int(y[1][0])), f"{s} lastUpdate value is greater than expected!" +@pytest.mark.importance("critical") @pytest.mark.topology(KnownTopologyGroup.AnyProvider) def test_cache__search_for_user_in_ldb_databases(client: Client, provider: GenericProvider): """ @@ -118,6 +119,7 @@ def test_cache__search_for_user_in_ldb_databases(client: Client, provider: Gener assert ldb2 != {}, f"ldbsearch failed to find user1 in {timestamps}" +@pytest.mark.importance("critical") @pytest.mark.topology(KnownTopologyGroup.AnyProvider) def test_cache__search_for_user_using_fully_qualified_name_in_ldb_databases(client: Client, provider: GenericProvider): """ @@ -150,6 +152,7 @@ def test_cache__search_for_user_using_fully_qualified_name_in_ldb_databases(clie assert ldb2 != {}, f"ldbsearch failed to find user1@test in {timestamps}" +@pytest.mark.importance("critical") @pytest.mark.topology(KnownTopologyGroup.AnyProvider) def test_cache__check_ldb_database_for_latest_user_changes_when_modified_and_deleted( client: Client, provider: GenericProvider @@ -190,3 +193,101 @@ def test_cache__check_ldb_database_for_latest_user_changes_when_modified_and_del assert not client.auth.ssh.password("user-delete", "Secret123"), "Login successful!" assert client.tools.getent.passwd("user-modify").shell == "/bin/sh", "User shell did not update!" + + +@pytest.mark.importance("medium") +@pytest.mark.ticket(gh=6652, bz=2162552) +@pytest.mark.topology(KnownTopologyGroup.AnyProvider) +def test_cache__netgroups_add_remove_netgroup_triple(client: Client, provider: GenericProvider): + """ + :title: Netgroup triple is correctly removed from cached record + :setup: + 1. Create local user "user-1" + 2. Create netgroup "ng-1" + 3. Add "(-,user-1,)" triple to the netgroup + 4. Start SSSD + :steps: + 1. Run "getent netgroup ng-1" + 2. Remove "(-,user-1,)" triple from "ng-1" + 3. Invalidate netgroup in cache "sssctl cache-expire -n ng-1" + 4. Run "getent netgroup ng-1" + :expectedresults: + 1. "(-,user-1,)" is present in the netgroup + 2. Triple was removed from the netgroup + 3. Cached record was invalidated + 4. "(-,user-1,)" is not present in the netgroup + :customerscenario: True + :requirement: netgroup + """ + user = provider.user("user-1").add() + ng = provider.netgroup("ng-1").add().add_member(user=user) + + client.sssd.start() + + result = client.tools.getent.netgroup("ng-1") + assert result is not None, "Netgroup not found!" + assert result.name == "ng-1", f"Netgroup 'ng-1' name doesn't match {result.name}!" + assert len(result.members) == 1, "Wrong number of netgroup members!" + assert "(-, user-1)" in result.members, "user-1 not in netgroup triple!" + + ng.remove_member(user=user) + client.sssctl.cache_expire(netgroups=True) + + result = client.tools.getent.netgroup("ng-1") + assert result is not None, "Netgroup not found!" + assert result.name == "ng-1", f"Netgroup 'ng-1' name doesn't match {result.name}!" + assert len(result.members) == 0, "Wrong number of netgroup members!" + + +@pytest.mark.importance("medium") +@pytest.mark.ticket(gh=6652, bz=2162552) +@pytest.mark.topology(KnownTopologyGroup.AnyProvider) +def test_cache__netgroups_add_remove_netgroup_member(client: Client, provider: GenericProvider): + """ + :title: Netgroup member is correctly removed from cached record + :setup: + 1. Create local user "user-1" + 2. Create local user "user-2" + 3. Create netgroup "ng-1" + 4. Create netgroup "ng-2" + 5. Add "(-,user-1,)" triple to the netgroup "ng-1" + 6. Add "(-,user-2,)" triple to the netgroup "ng-2" + 7. Add "ng-1" as a member to "ng-2" + 8. Start SSSD + :steps: + 1. Run "getent netgroup ng-2" + 2. Remove "ng-1" from "ng-2" + 3. Invalidate netgroup "ng-2" in cache "sssctl cache-expire -n ng-2" + 4. Run "getent netgroup ng-2" + :expectedresults: + 1. "(-,user-1,)", "(-,user-2,)" is present in the netgroup + 2. Netgroup member was removed from the netgroup + 3. Cached record was invalidated + 4. "(-,user-1,)" is not present in the netgroup, only "(-,user-2,)" + :customerscenario: True + :requirement: netgroup + """ + u1 = provider.user("user-1").add() + u2 = provider.user("user-2").add() + + ng1 = provider.netgroup("ng-1").add().add_member(user=u1) + ng2 = provider.netgroup("ng-2").add().add_member(user=u2, ng=ng1) + + client.sssd.start() + + result = client.tools.getent.netgroup("ng-2") + assert result is not None, "Netgroup 'ng-2' not found!" + assert result.name == "ng-2", f"Netgroup 'ng-2' name doesn't match {result.name}!" + assert len(result.members) == 2, "Wrong number of netgroup members!" + assert "(-, user-1)" in result.members, "user-1 not in netgroup triple!" + assert "(-, user-2)" in result.members, "user-2 not in netgroup triple!" + + ng2.remove_member(ng=ng1) + client.sssctl.cache_expire(netgroups=True) + + result = client.tools.getent.netgroup("ng-2") + assert result is not None, "Netgroup 'ng-2' not found!" + assert result.name == "ng-2", f"Netgroup 'ng-2' name doesn't match {result.name}!" + assert len(result.members) == 1, "Wrong number of netgroup members!" + assert "(-, user-1)" not in result.members, "user-1 in netgroup triple!" + assert "(-, user-2)" in result.members, "user-2 not in netgroup triple!" diff --git a/src/tests/system/tests/test_netgroups.py b/src/tests/system/tests/test_netgroups.py deleted file mode 100644 index 87ebafd21f2..00000000000 --- a/src/tests/system/tests/test_netgroups.py +++ /dev/null @@ -1,110 +0,0 @@ -""" -Netgroup tests. - -:requirement: netgroup -""" - -from __future__ import annotations - -import pytest -from sssd_test_framework.roles.client import Client -from sssd_test_framework.roles.generic import GenericProvider -from sssd_test_framework.topology import KnownTopologyGroup - - -@pytest.mark.importance("medium") -@pytest.mark.cache -@pytest.mark.ticket(gh=6652, bz=2162552) -@pytest.mark.topology(KnownTopologyGroup.AnyProvider) -def test_netgroups__add_remove_netgroup_triple(client: Client, provider: GenericProvider): - """ - :title: Netgroup triple is correctly removed from cached record - :setup: - 1. Create local user "user-1" - 2. Create netgroup "ng-1" - 3. Add "(-,user-1,)" triple to the netgroup - 4. Start SSSD - :steps: - 1. Run "getent netgroup ng-1" - 2. Remove "(-,user-1,)" triple from "ng-1" - 3. Invalidate netgroup in cache "sssctl cache-expire -n ng-1" - 4. Run "getent netgroup ng-1" - :expectedresults: - 1. "(-,user-1,)" is present in the netgroup - 2. Triple was removed from the netgroup - 3. Cached record was invalidated - 4. "(-,user-1,)" is not present in the netgroup - :customerscenario: True - """ - user = provider.user("user-1").add() - ng = provider.netgroup("ng-1").add().add_member(user=user) - - client.sssd.start() - - result = client.tools.getent.netgroup("ng-1") - assert result is not None - assert result.name == "ng-1" - assert len(result.members) == 1 - assert "(-, user-1)" in result.members - - ng.remove_member(user=user) - client.sssctl.cache_expire(netgroups=True) - - result = client.tools.getent.netgroup("ng-1") - assert result is not None - assert result.name == "ng-1" - assert len(result.members) == 0 - - -@pytest.mark.importance("medium") -@pytest.mark.cache -@pytest.mark.ticket(gh=6652, bz=2162552) -@pytest.mark.topology(KnownTopologyGroup.AnyProvider) -def test_netgroups__add_remove_netgroup_member(client: Client, provider: GenericProvider): - """ - :title: Netgroup member is correctly removed from cached record - :setup: - 1. Create local user "user-1" - 2. Create local user "user-2" - 3. Create netgroup "ng-1" - 4. Create netgroup "ng-2" - 5. Add "(-,user-1,)" triple to the netgroup "ng-1" - 6. Add "(-,user-2,)" triple to the netgroup "ng-2" - 7. Add "ng-1" as a member to "ng-2" - 8. Start SSSD - :steps: - 1. Run "getent netgroup ng-2" - 2. Remove "ng-1" from "ng-2" - 3. Invalidate netgroup "ng-2" in cache "sssctl cache-expire -n ng-2" - 4. Run "getent netgroup ng-2" - :expectedresults: - 1. "(-,user-1,)", "(-,user-2,)" is present in the netgroup - 2. Netgroup member was removed from the netgroup - 3. Cached record was invalidated - 4. "(-,user-1,)" is not present in the netgroup, only "(-,user-2,)" - :customerscenario: True - """ - u1 = provider.user("user-1").add() - u2 = provider.user("user-2").add() - - ng1 = provider.netgroup("ng-1").add().add_member(user=u1) - ng2 = provider.netgroup("ng-2").add().add_member(user=u2, ng=ng1) - - client.sssd.start() - - result = client.tools.getent.netgroup("ng-2") - assert result is not None - assert result.name == "ng-2" - assert len(result.members) == 2 - assert "(-, user-1)" in result.members - assert "(-, user-2)" in result.members - - ng2.remove_member(ng=ng1) - client.sssctl.cache_expire(netgroups=True) - - result = client.tools.getent.netgroup("ng-2") - assert result is not None - assert result.name == "ng-2" - assert len(result.members) == 1 - assert "(-, user-1)" not in result.members - assert "(-, user-2)" in result.members