Skip to content

Commit

Permalink
tests: housekeeping - schema
Browse files Browse the repository at this point in the history
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

Notable changes:

* added integration marker
* moved schema tests to cache
* renamed schema test names

Reviewed-by: Alejandro López <[email protected]>
Reviewed-by: Jakub Vávra <[email protected]>
  • Loading branch information
Dan Lavu authored and pbrezina committed Aug 8, 2024
1 parent b9a279b commit fcda45b
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 164 deletions.
2 changes: 1 addition & 1 deletion src/tests/system/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ markers =
config:
contains_workaround_for(gh=...,bz=...):
identity:
schema:
integration:
slow:
tools:
ticket_tools = bz,gh,jira
Expand Down
136 changes: 130 additions & 6 deletions src/tests/system/tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
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.roles.ldap import LDAP
from sssd_test_framework.topology import KnownTopology, KnownTopologyGroup


@pytest.mark.importance("critical")
@pytest.mark.integration
@pytest.mark.importance("low")
@pytest.mark.topology(KnownTopologyGroup.AnyProvider)
def test_cache__is_refreshed_as_configured(client: Client, provider: GenericProvider):
def test_cache__entries_are_refreshed_as_configured(client: Client, provider: GenericProvider):
"""
:title: Ensuring LDB cache refreshes at configured intervals
:setup:
Expand Down Expand Up @@ -86,8 +88,10 @@ 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.integration
@pytest.mark.importance("low")
@pytest.mark.topology(KnownTopologyGroup.AnyProvider)
def test_cache__search_for_user_in_ldb_databases(client: Client, provider: GenericProvider):
def test_cache__writes_to_both_database_files(client: Client, provider: GenericProvider):
"""
:title: Search for user in the following ldb databases, cache_*.ldb and timestamp_*.ldb
:setup:
Expand Down Expand Up @@ -118,8 +122,12 @@ 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.integration
@pytest.mark.importance("low")
@pytest.mark.topology(KnownTopologyGroup.AnyProvider)
def test_cache__search_for_user_using_fully_qualified_name_in_ldb_databases(client: Client, provider: GenericProvider):
def test_cache__writes_to_both_database_files_when_using_fully_qualified_names(
client: Client, provider: GenericProvider
):
"""
:title: Search for user using fully qualified name in the following ldb databases, cache_*.ldb and timestamp_*.ldb
:setup:
Expand Down Expand Up @@ -150,8 +158,10 @@ 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.integration
@pytest.mark.importance("low")
@pytest.mark.topology(KnownTopologyGroup.AnyProvider)
def test_cache__check_ldb_database_for_latest_user_changes_when_modified_and_deleted(
def test_cache__user_entries_contains_latest_changes_when_modified_and_deleted(
client: Client, provider: GenericProvider
):
"""
Expand Down Expand Up @@ -194,3 +204,117 @@ def test_cache__check_ldb_database_for_latest_user_changes_when_modified_and_del
result = client.tools.getent.passwd("user-modify")
assert result is not None, "User not found!"
assert result.shell == "/bin/sh", "User shell did not update!"


@pytest.mark.integration
@pytest.mark.importance("low")
@pytest.mark.topology(KnownTopologyGroup.AnyProvider)
def test_cache__extra_attributes_are_stored(client: Client, provider: GenericProvider):
"""
:title: Extra attributes are cached
:setup:
1. Create user "user1"
2. Edit SSSD configuration and set "ldap_user_extra_attrs =
description:gecos, userID:uidNumber, shell:loginShell, groupID:gidNumber" and
"ldap_id_mapping = false"
3. Start SSSD
:steps:
1. Lookup user
2. Lookup user in cache
:expectedresults:
1. User is found
2. User is found and cache contains correct attributes and values
:customerscenario: True
"""
provider.user("user1").add(gid=111111, uid=100110, gecos="gecos user1", shell="/bin/sh", home="/home/user1")
client.sssd.domain["ldap_user_extra_attrs"] = (
"description:gecos, userID:uidNumber, shell:loginShell, groupID:gidNumber"
)
client.sssd.domain["ldap_id_mapping"] = "false"
client.sssd.start()

result = client.tools.getent.passwd("user1")
assert result is not None, "User not found!"

search = client.ldb.search(
f"/var/lib/sss/db/cache_{client.sssd.default_domain}.ldb", f"cn=users,cn={client.sssd.default_domain},cn=sysdb"
)

user_dict = search["name=user1@test,cn=users,cn=test,cn=sysdb"]
assert user_dict["description"] == ["gecos user1"], "attribute 'description' was not correct"
assert user_dict["shell"] == ["/bin/sh"], "attribute 'shell' was not correct"
assert user_dict["userID"] == ["100110"], "attribute 'userID' was not correct"
assert user_dict["groupID"] == ["111111"], "attribute 'groupID' was not correct"


@pytest.mark.integration
@pytest.mark.importance("low")
@pytest.mark.topology(KnownTopologyGroup.AnyProvider)
def test_cache__extra_attributes_with_empty_values_are_ignored(client: Client, provider: GenericProvider):
"""
:title: When extra attribute of user is added but not assigned, it is neither cached nor displayed
:setup:
1. Create user "user1"
2. Configure SSSD with "ldap_user_extra_attr = number:telephonenumber"
3. Start SSSD
:steps:
1. Lookup user
2. Lookup user in cache
:expectedresults:
1. User is found
2. User is found and does not have the extra numbers attribute
:customerscenario: False
"""
provider.user("user1").add()
client.sssd.domain["ldap_user_extra_attrs"] = "number:telephonenumber"
client.sssd.start()

result = client.tools.getent.passwd("user1")
assert result is not None, "User is not found!"

search = client.ldb.search(
f"/var/lib/sss/db/cache_{client.sssd.default_domain}.ldb", f"cn=users,cn={client.sssd.default_domain},cn=sysdb"
)
assert search != {}, "User not found!"

search = client.ldb.search(f"/var/lib/sss/db/cache_{client.sssd.default_domain}.ldb", "number=*")
assert search == {}


@pytest.mark.integration
@pytest.mark.importance("low")
@pytest.mark.topology(KnownTopology.LDAP)
def test_cache__both_ldap_user_email_and_extra_attribute_email_are_stored(client: Client, ldap: LDAP):
"""
:title: Setting ldap_user_email and email using extra attributes are cached
:setup:
1. Create user "user1" with gecos and mail attributes`
2. Configure SSSD with "ldap_user_extra_attrs = email:mail, description:gecos" and
"ldap_user_email = mail"
3. Start SSSD
:steps:
1. Lookup user
2. Lookup user in cache
:expectedresults:
1. User is found
2. User is found with description, mail and email attributes
:customerscenario: False
"""
ldap.user("user1").add(gecos="gecos1", mail="[email protected]")

client.sssd.domain["ldap_user_email"] = "mail"
client.sssd.domain["ldap_user_extra_attrs"] = "email:mail, description:gecos"
client.sssd.start()

result = client.tools.getent.passwd("user1")
assert result is not None, "User is not found"
assert result.name == "user1", "User has wrong name"

search = client.ldb.search(
f"/var/lib/sss/db/cache_{client.sssd.default_domain}.ldb", f"cn=users,cn={client.sssd.default_domain},cn=sysdb"
)

user_dict = search["name=user1@test,cn=users,cn=test,cn=sysdb"]
assert user_dict["description"] == ["gecos1"], "attribute 'description' was not correct"
assert user_dict["mail"] == ["[email protected]"], "attribute 'mail' was not correct"
assert user_dict["email"] == ["[email protected]"], "attribute 'email' was not correct"
34 changes: 32 additions & 2 deletions src/tests/system/tests/test_infopipe.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 KnownTopology
from sssd_test_framework.topology import KnownTopology, KnownTopologyGroup


@pytest.mark.topology(KnownTopology.LDAP)
Expand Down Expand Up @@ -58,7 +58,7 @@ def test_infopipe__get_user_properties(client: Client, provider: GenericProvider


@pytest.mark.topology(KnownTopology.LDAP)
def test_infopipe__get_domain_properties(client: Client, provider: GenericProvider):
def test_infopipe__get_domain_properties(client: Client):
"""
:title: Access a domain's information through InfoPipe
:setup:
Expand Down Expand Up @@ -248,3 +248,33 @@ def test_infopipe__list_by_name(client: Client, provider: GenericProvider):

result = users.ListByName("nouser*", 0)
assert len(result) == 0, "ListByName('nouser*', 0) returned unexpected elements"


@pytest.mark.importance("medium")
@pytest.mark.ticket(bz=1667252)
@pytest.mark.topology(KnownTopologyGroup.AnyProvider)
def test_infopipe__lookup_user_with_extra_attributes(client: Client, provider: GenericProvider):
"""
:title: Infopipe does not crash looking up extra attribute
:setup:
1. Create user "user1"
2. Enable infopipe, add a test attribute and start SSSD
:steps:
1. Lookup user using sssctl
2. Check SSSD service
:expectedresults:
1. User found
2. Service is running
:customerscenario: True
"""
provider.user("user1").add()
client.sssd.sssd["services"] = "nss, pam, ifp"
client.sssd.domain["ldap_user_extra_attrs"] = "test:homeDirectory"
client.sssd.ifp["user_attributes"] = "+test"
client.sssd.start()

result = client.sssctl.user_checks("user1")
assert result.rc == 0, "User not found!"

result = client.sssd.svc.status("sssd")
assert result.rc == 0, "Service is not running!"
Loading

0 comments on commit fcda45b

Please sign in to comment.