Skip to content

rewriting memcache tests#8485

Open
danlavu wants to merge 2 commits intoSSSD:masterfrom
danlavu:tests-rm-memcache
Open

rewriting memcache tests#8485
danlavu wants to merge 2 commits intoSSSD:masterfrom
danlavu:tests-rm-memcache

Conversation

@danlavu
Copy link

@danlavu danlavu commented Feb 27, 2026

No description provided.

@danlavu danlavu added the Tests label Feb 27, 2026
@danlavu danlavu marked this pull request as draft February 27, 2026 07:57
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a significant refactoring of the memcache tests, aiming to reduce code duplication by introducing helper functions and parametrizing tests. While this is a great improvement for maintainability, the new implementation introduces several critical and high-severity issues, including a syntax error, flawed test logic that would cause failures, and several inconsistencies between test names, docstrings, and their implementations. I've detailed these issues in the review comments.

@danlavu danlavu force-pushed the tests-rm-memcache branch from 4164a67 to 92e2433 Compare March 1, 2026 00:20
@danlavu danlavu force-pushed the tests-rm-memcache branch 4 times, most recently from 800149e to 79780ef Compare March 2, 2026 22:48
@danlavu danlavu force-pushed the tests-rm-memcache branch 2 times, most recently from 36e1b79 to 757722f Compare March 3, 2026 01:32
@danlavu danlavu force-pushed the tests-rm-memcache branch 2 times, most recently from bc7b7a2 to b484bad Compare March 3, 2026 03:41
@danlavu danlavu marked this pull request as ready for review March 3, 2026 04:33
@madhuriupadhye
Copy link
Contributor

@danlavu, can you please check,
ValueError: Required field 'customerscenario' is missing for 'tests/test_memcache.py::test_memcache__lookup_objects_by_name[users] (ldap)'

@danlavu
Copy link
Author

danlavu commented Mar 12, 2026

@madhuriupadhye @andreboscatto I suggest reviewing this PR using the split diff view and not the unified diff.

@andreboscatto
Copy link
Contributor

@madhuriupadhye @andreboscatto I suggest reviewing this PR using the split diff view and not the unified diff.

Indeed, I started reviewing the old document, understanding each case and looking at yours. Doing that side by side is helpful.

@danlavu
Copy link
Author

danlavu commented Mar 13, 2026

@danlavu, can you please check, ValueError: Required field 'customerscenario' is missing for 'tests/test_memcache.py::test_memcache__lookup_objects_by_name[users] (ldap)'

fixed.

Each cache type the user membership is checked differently. For 'users' cache, it will use 'id' and check the
memberof attribute. For 'groups' cache, it will use 'getent group' and check the members attribute. For
'initgroups' cache, it will use 'getent initgroups' and check the memberof attribute with group ids. Importantly,
for 'initgroups' the results are ids; using the user_map, a lookup is performed to get the correct GIDs.DD
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra DD at the end of line, ...to get the correct GIDs..

Check the existence of objects, either users, groups, or initgroups.

This is a helper function to parameterize the memcache test. The assertions for each
cache time are different. Looking up 'users, will use 'id', groups will use 'getent group',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update to Looking up 'users', will use

cache time or cache type?

):
"""
:title: Invalidate all parts of cache after SSSD is stopped
:title: Lookup objects and changing when the cache is invalidated, before or after stooping sssd
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

**stopping** sssd.

@pytest.mark.preferred_topology(KnownTopology.LDAP)
def test_memcache__all_caches_disabled_and_all_lookups_fails(client: Client, provider: GenericProvider):
:param provider: Known topology.
:type provider: KnownTopology
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong parameter type,
:type provider: GenericProvider

7. User is not found
8. Group is not found
:customerscenario: False
2. Users are found
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace 2. to 1..

@pytest.mark.topology(KnownTopologyGroup.AnyProvider)
@pytest.mark.preferred_topology(KnownTopology.LDAP)
def test_memcache__invalidate_user_cache_after_stop(client: Client, provider: GenericProvider):
def test_memcache__lookup_users_by_name_with_case_sensitive_false(client: Client, provider: GenericProvider):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name suggests “case_sensitive false”, but the test sets case_sensitive = "True" and checks that uppercase lookup fails. So either rename (e.g. to something like ...when_case_sensitive_true) or fix the docstring/title so they clearly describe “when case_sensitive is True, different case is not found”.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To even add more confusion, the test use to be called case_insensitivity

:type cache: str
:param id: Lookup object by id, default is False
:type id: bool
:return:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return: is empty. Either document “None” or remove the line.

@madhuriupadhye
Copy link
Contributor

madhuriupadhye commented Mar 16, 2026

please check,
ValueError: Number of steps and results do not match in idm-sssd-tc::tests/test_memcache.py::test_memcache__lookup_objects_by_id[users] (ldap)

289: 2: Group membership is correct -> 2. Group membership is correct


if cache == "initgroups":
for initgroup in objects.get("users", []):
_group = objects.get("groups", [])[-1].name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getent.initgroups returns None if the user is not found, and then calling memberof() will throw an error instead of a graceful failure, right?

Even if that's not the case, the logic is verifying only the last group [-1], so, even tough the user is in other groups, the test pass. Shouldn't it verify if the user is NOT in any of the groups?

Please correct me if my understanding is wrong :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this logic is confusing. I pass in the created user objects, so those objects will always exist. The .get method returns a list of dict objects, and the value is another list. We iterate through the added group list and check whether the get entry results contain that value. It's the last item in the list because the first item is the user's gidnumber.

user1
[user_group, group1] # Since it has one group, it will iterate once

user2
[user_group, group1]
[user_group, group1, group2]

Not the prettiest logic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm I see. Is it worth to add a comment there for future reference? Your call, I am fine with the explanation, but I want to avoid people changing anything in the test and having a hard time figuring out the logic.


if cache == "initgroups":
for initgroup in objects.get("users", []):
result_initgroup = client.tools.getent.initgroups(str(initgroup.name))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also check which groups are there or None is sufficient? I don't recall it, it was a long time ago I played with that attribute.

Dan Lavu added 2 commits March 17, 2026 01:23
* parametrized test cases
* added colliding hash test case
* remove poor test scenarios
@danlavu danlavu force-pushed the tests-rm-memcache branch 2 times, most recently from f45a3e2 to 3ab0a1e Compare March 17, 2026 05:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants