-
Notifications
You must be signed in to change notification settings - Fork 0
FIx: update network policy for deleting groups during updates #909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+121
−21
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d89ed7a
Refactor: Enhance network policy update process with dedicated method…
2b8b923
Add: Introduce network policy use case fixture and tests for creating…
cc67291
Remove unused fixture from network policy test case
053adf4
Enhance NetworkPolicyUseCase: Replace uniqueness validation method wi…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule interface
updated
from 95ed5e to f31962
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| """Test network policy use case with empty groups. | ||
|
|
||
| Copyright (c) 2025 MultiFactor | ||
| License: https://github.com/MultiDirectoryLab/MultiDirectory/blob/main/LICENSE | ||
| """ | ||
|
|
||
| from ipaddress import IPv4Network | ||
|
|
||
| import pytest | ||
|
|
||
| from enums import MFAFlags | ||
| from ldap_protocol.policies.network import NetworkPolicyUseCase | ||
| from ldap_protocol.policies.network.dto import ( | ||
| NetworkPolicyDTO, | ||
| NetworkPolicyUpdateDTO, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_create_policy( | ||
| network_policy_use_case: NetworkPolicyUseCase, | ||
| ) -> None: | ||
| """Test creating policy with empty groups and mfa_groups.""" | ||
| dto = NetworkPolicyDTO[None]( | ||
| id=None, | ||
| name="Test Empty Groups", | ||
| netmasks=[IPv4Network("192.168.1.0/24")], | ||
| raw=["192.168.1.0/24"], | ||
| priority=2, | ||
| mfa_status=MFAFlags.DISABLED, | ||
| groups=[], | ||
| mfa_groups=[], | ||
| ) | ||
|
|
||
| result = await network_policy_use_case.create(dto) | ||
| poicy = await network_policy_use_case.get(result.id) | ||
| assert poicy.groups == [] | ||
| assert poicy.mfa_groups == [] | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| @pytest.mark.usefixtures("setup_session") | ||
| async def test_update_policy_to_empty_groups( | ||
| network_policy_use_case: NetworkPolicyUseCase, | ||
| ) -> None: | ||
| """Test updating policy from groups to empty.""" | ||
| dto = NetworkPolicyDTO[None]( | ||
| id=None, | ||
| name="Test Update Groups", | ||
| netmasks=[IPv4Network("172.16.0.0/12")], | ||
| raw=["172.16.0.0/12"], | ||
| priority=3, | ||
| mfa_status=MFAFlags.DISABLED, | ||
| groups=["cn=domain admins,cn=Groups,dc=md,dc=test"], | ||
| mfa_groups=["cn=domain admins,cn=Groups,dc=md,dc=test"], | ||
| ) | ||
|
|
||
| created = await network_policy_use_case.create(dto) | ||
| assert created.groups | ||
| assert created.mfa_groups | ||
|
|
||
| update_dto = NetworkPolicyUpdateDTO( | ||
| id=created.id, | ||
| groups=[], | ||
| mfa_groups=[], | ||
| ) | ||
|
|
||
| updated = await network_policy_use_case.update(update_dto) | ||
|
|
||
| assert updated.groups == [] | ||
| assert updated.mfa_groups == [] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
может стоит внутри метода
get_with_for_updateсделать# NOTE:с небольшим описанием того, зачем используется.with_for_update()?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
расписать что делает алхимический with_for_update? ИМХО избыточно
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
нужна блокировка на запись(в целом with_for_update для этого и используют)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
я про то, зачем нам здесь нужна блокировка. может несколько запрсоов на изменение прийти?