Skip to content

Commit

Permalink
Tests: Test transformation of bash-ldap-id-ldap-auth netgroup
Browse files Browse the repository at this point in the history
Test transformation of bash-ldap-id-ldap-auth netgroup
  • Loading branch information
aborah-sudo committed Nov 12, 2024
1 parent b928dbe commit abc7d8e
Showing 1 changed file with 127 additions and 1 deletion.
128 changes: 127 additions & 1 deletion src/tests/system/tests/test_netgroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,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 KnownTopologyGroup
from sssd_test_framework.topology import KnownTopology, KnownTopologyGroup


@pytest.mark.importance("medium")
Expand Down Expand Up @@ -108,3 +108,129 @@ def test_netgroups__add_remove_netgroup_member(client: Client, provider: Generic
assert len(result.members) == 1
assert "(-, user-1)" not in result.members
assert "(-, user-2)" in result.members


@pytest.mark.parametrize("operation", ["Add", "Replace"])
@pytest.mark.importance("low")
@pytest.mark.topology(KnownTopology.LDAP)
@pytest.mark.topology(KnownTopology.AD)
@pytest.mark.topology(KnownTopology.Samba)
def test_netgroup__user_attribute_membernisnetgroup_uses_group_dn(
client: Client, provider: GenericProvider, operation: str
):
"""
:title: User's 'memberNisNetgroup' attribute values are the DN of the group
:setup:
1. Create users and groups
2. Create a new netgroup called group and add a member (ng1) to group
3. Create another netgroup named nested_group and add a member (ng2) to nested_group
4. Modify the nested_group to replace its members with the members of group
5. Start sssd
:steps:
1. Retrieve all members of the nested_group
2. Confirm that the member directly added to nested_group is present
3. Confirm that the member from group is now part of nested_group
:expectedresults:
1. All members should be retrieved
2. Members directly added to nested_group is present
3. Members from group is now part of nested_group
:customerscenario: False
"""
for id in [1, 2]:
provider.user(f"ng{id}").add()

netgroup_group = provider.netgroup("group").add()
netgroup_group.add_member(host="testhost1", user="ng1", domain="ldap.test")

netgroup_nested = provider.netgroup("nested_group").add()
netgroup_nested.add_member(host="testhost2", user="ng2", domain="ldap.test")
if operation == "Replace":
netgroup_nested.add_member(ng=netgroup_group.dn)
else:
netgroup_nested.add_member(ng="group")
client.sssd.start()

member = client.tools.getent.netgroup("nested_group").members
assert "(testhost2, ng2, ldap.test)" in member
assert "(testhost1, ng1, ldap.test)" in member


@pytest.mark.importance("low")
@pytest.mark.topology(KnownTopology.LDAP)
@pytest.mark.topology(KnownTopology.AD)
@pytest.mark.topology(KnownTopology.Samba)
def test_netgroup__lookup_nested_groups(client: Client, provider: GenericProvider):
"""
:title: Looking up nested netgroups
:setup:
1. Create users and groups
2. Create netgroups and add member
3. Add Members to nested_netgroup
4. Make netgroup and nested_netgroup members of one another, looping the groups
5. Start sssd
:steps:
1. Lookup nested_netgroup
:expectedresults:
1. Netgroup is found, and both netgroups and users are members
"""
for id in [1, 2, 3]:
provider.user(f"ng{id}").add()

netgroup = provider.netgroup("group").add()
netgroup.add_member(host="testhost1", user="ng1", domain="ldap.test")

nested_netgroup = provider.netgroup("nested_netgroup").add()
nested_netgroup.add_member(ng=netgroup.dn)
nested_netgroup.add_member(host="testhost2", user="ng2", domain="ldap.test")
nested_netgroup.add_member(user="ng3")

netgroup.add_member(ng=nested_netgroup.dn)

client.sssd.start()

member = client.tools.getent.netgroup("nested_netgroup").members
assert "(testhost1,ng1,ldap.test)" in member
assert "(-,ng3,)" in member
assert "(testhost2,ng2,ldap.test)" in member


@pytest.mark.parametrize(
"user, domain, expected",
[("host", "host.ldap.test", "(host,-,host.ldap.test)"), ("ng3", "", "(-,ng3,)")],
)
@pytest.mark.importance("low")
@pytest.mark.topology(KnownTopology.LDAP)
@pytest.mark.topology(KnownTopology.AD)
@pytest.mark.topology(KnownTopology.Samba)
def test_netgroup__lookup_nested_groups_with_host_and_domain_values_present(
client: Client, provider: GenericProvider, user: str, domain: str, expected: str
):
"""
:title: Netgroup contains a member that has a host and domain specified
:setup:
1. Create users and groups
2. Create netgroups and add member
3. Start sssd
:steps:
1. Check whether the expected member is present in the nested_group netgroup
:expectedresults:
1. Member is present in the nested_group netgroup
:customerscenario: False
"""
for id in [1, 2]:
provider.user(f"ng{id}").add()

netgroup_group = provider.netgroup("group").add()
netgroup_group.add_member(host="testhost1", user="ng1", domain="ldap.test")

netgroup_nested = provider.netgroup("nested_group").add()
netgroup_nested.add_member(host="testhost2", user="ng2", domain="ldap.test")
if domain == "host.ldap.test":
netgroup_nested.add_member(host=user, domain=domain)
else:
netgroup_nested.add_member(user=user)

client.sssd.start()

member = client.tools.getent.netgroup("nested_group").members
assert expected in member

0 comments on commit abc7d8e

Please sign in to comment.