Skip to content

TESTS: Add access control simple filter tests#7882

Closed
andreboscatto wants to merge 1 commit intoSSSD:masterfrom
andreboscatto:testAccessControlSimple
Closed

TESTS: Add access control simple filter tests#7882
andreboscatto wants to merge 1 commit intoSSSD:masterfrom
andreboscatto:testAccessControlSimple

Conversation

@andreboscatto
Copy link
Contributor

Added 4 tests for access control simple filter using the new testing framework

@andreboscatto andreboscatto force-pushed the testAccessControlSimple branch 2 times, most recently from 268a984 to d42792e Compare March 17, 2025 21:30
@andreboscatto
Copy link
Contributor Author

andreboscatto commented Mar 17, 2025

  • Check with @pbrezina about def add_members(self, members: list[GenericNetgroupMember]) -> GenericNetgroup: -> Should we add str as a valid input or should I change the test itself?

@andreboscatto
Copy link
Contributor Author

@danlavu to achieve what you suggest using loops to create users and not having problems afterwards, there are a few ways (I have my opinions about that) but I'll list the options I currently know and we can explore it.

  1. Creating a dictionary with notation type
users: Dict[str, GenericProvider] = {}

for name in ["user1", "user2", "user3"]:
    users[name]: GenericProvider = provider.user(name).add()

print(users["user1"], users["user2"], users["user3"])
  1. Creating a dictionary without notation type
users = {}

for i in ["user1", "user2", "user3"]:
    users[i] = provider.user(i).add()

print(users["user1"], users["user2"], users["user3"])
  1. Using Globals()
for name in ["user1", "user2", "user3"]:
    globals()[name]: GenericProvider = provider.user(name).add()

print(user1, user2, user3)`
  1. Using Locals()
for i in ["user1", "user2", "user3"]:
    locals()[i] = provider.user(i).add()

print(user1, user2, user3)
  1. Using Exec()
for name in ["user1", "user2", "user3"]:
    exec(f"{name}: GenericProvider = provider.user('{name}').add()")

print(user1, user2, user3)
  1. Changing the notation in the add_members() as I wanted to talk to Pavel in my previous comment
FROM def add_members(self, members: list[GenericNetgroupMember]) 
TO def add_members(self, members: list[GenericNetgroupMember] | str)

My opinions:

  1. Globals -> Nops
  2. Locals -> Prune to errors
  3. Exec -> I don't have knowledge about that, so I'm not sure how it behaves
  4. Dictionaries are gentlemen ;)
  5. Changing the add_members -> I am biased, it can create precedent to other modifications which I don't like and having a specific notation helps during creating tests -> it is there for a reason

Why am I bringing all of that? There are errors during the build (https://github.com/SSSD/sssd/actions/runs/13910267393/job/38922743602?pr=7882)

@danlavu
Copy link

danlavu commented Mar 18, 2025

Why am I bringing all of that? There are errors during the build (https://github.com/SSSD/sssd/actions/runs/13910267393/job/38922743602?pr=7882)

    for i in ["group1", "o-group1"]:
        result = client.tools.getent.group(i)
        assert result is not None, "Group not found!"
        assert result.gid == 888888, "Group gid does not match override value!"
        assert "o-user1" in result.members, "Local override username not found in group!"

We do something like this, to ensure the object is of the correct type, we assert that the result is not None.

@andreboscatto
Copy link
Contributor Author

I understand you have a human way to avoid potential errors. I am talking about a "coding" level (https://mypy.readthedocs.io/en/latest/error_code_list.html#code-assignment). The code checker will evaluate if all the arguments fit the proper notation, thus my proposals.

@andreboscatto
Copy link
Contributor Author

Ahhhh I see! It is still complaining to me at least:

Incompatible types in assignment (expression has type "GroupEntry | None", variable has type "IdEntry | None")Mypy[assignment](https://mypy.readthedocs.io/en/latest/_refs.html#code-assignment)

  users = ["user1", "user2", "user3"]
   groups = ["group1", "group2", "group3"]

   for user in users:
           provider.user(user).add()

   for group in groups:
           provider.user(user).add()
.
.
.

   for group in groups:
       result = client.tools.getent.group(group)
       assert result is not None, f"Group {group} should be found."

@danlavu
Copy link

danlavu commented Mar 19, 2025

Tomorrow during our 1 on 1, remind me, we will go through the lint errors and ci failures.


tests/test_access_control_simple.py:105: error: List item 0 has incompatible type "str"; expected "GenericUser | GenericGroup"  [list-item]
tests/test_access_control_simple.py:105: error: List item 1 has incompatible type "str"; expected "GenericUser | GenericGroup"  [list-item]
tests/test_access_control_simple.py:106: error: List item 0 has incompatible type "str"; expected "GenericUser | GenericGroup"  [list-item]
tests/test_access_control_simple.py:106: error: List item 1 has incompatible type "str"; expected "GenericUser | GenericGroup"  [list-item]
tests/test_access_control_simple.py:151: error: Argument 1 to "add_member" of "GenericGroup" has incompatible type "str"; expected "GenericUser | GenericGroup"  [arg-type]
tests/test_access_control_simple.py:152: error: Argument 1 to "add_member" of "GenericGroup" has incompatible type "str"; expected "GenericUser | GenericGroup"  [arg-type]

@andreboscatto andreboscatto force-pushed the testAccessControlSimple branch 2 times, most recently from 750c227 to 610caf8 Compare March 19, 2025 09:59
@andreboscatto andreboscatto force-pushed the testAccessControlSimple branch 2 times, most recently from b587b5e to 7c6f985 Compare March 20, 2025 15:25
@andreboscatto andreboscatto requested a review from danlavu March 20, 2025 15:26
Copy link

@danlavu danlavu left a comment

Choose a reason for hiding this comment

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

Just the titles, other than that, LG2M, thank you Andre.

@andreboscatto andreboscatto force-pushed the testAccessControlSimple branch from 7c6f985 to 9839f07 Compare March 21, 2025 11:12
@andreboscatto andreboscatto requested a review from danlavu March 21, 2025 11:12
@andreboscatto
Copy link
Contributor Author

I asked to review again because I'm not familiar with the process... a LG2M is sufficient or do you need to "confirm" with the button?

@andreboscatto
Copy link
Contributor Author

And thank you for all the support and patience with me through this learning process :) I hope the others will go faster after this learning curve.

Copy link
Member

@pbrezina pbrezina left a comment

Choose a reason for hiding this comment

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

Ack. I left some suggestions, but its up to you if you want to change it or not. Let me know and I'll set the "approve" flag.

@andreboscatto andreboscatto force-pushed the testAccessControlSimple branch 2 times, most recently from c357249 to 80fdd42 Compare March 26, 2025 18:35
@andreboscatto andreboscatto requested a review from aplopez March 26, 2025 20:29
Copy link

@danlavu danlavu left a comment

Choose a reason for hiding this comment

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

Great work!

@andreboscatto andreboscatto force-pushed the testAccessControlSimple branch 3 times, most recently from 0a49513 to a4b7169 Compare March 26, 2025 20:41
Copy link
Contributor

@aplopez aplopez left a comment

Choose a reason for hiding this comment

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

ACK

@andreboscatto andreboscatto force-pushed the testAccessControlSimple branch 3 times, most recently from 461c192 to f656fac Compare April 2, 2025 18:27
Copy link

@danlavu danlavu left a comment

Choose a reason for hiding this comment

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

This is great, thank you @andreboscatto

@alexey-tikhonov
Copy link
Member

@andreboscatto, please rebase.

Added 4 tests for access control simple filter using the new testing framework
@alexey-tikhonov
Copy link
Member

Pushed PR: #7882

  • master
    • d61ba81 - TESTS: Add access control simple filter tests
  • sssd-2-10
    • 907548b - TESTS: Add access control simple filter tests
  • sssd-2-9
    • 5f37296 - TESTS: Add access control simple filter tests

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.

5 participants