-
Notifications
You must be signed in to change notification settings - Fork 3.7k
fix: resource permission definition bugs in cache and event notification #25017
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
Open
maliming
wants to merge
7
commits into
rel-10.1
Choose a base branch
from
fix/resource-permission-definition-bugs
base: rel-10.1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+268
−23
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2beee2a
fix: fix resource permission definition bugs
maliming 2c15a60
fix: apply Providers, StateCheckers and ExtraProperties to resource p…
maliming 474e1bf
test: add regression tests for DynamicPermissionDefinitionStoreInMemo…
maliming 0722e74
refactor: extract ApplyPermissionProperties to eliminate duplication …
maliming bacca3a
fix: add AbpUiResource as base type in AbpPermissionManagementWebModu…
maliming a57e249
fix: guard against null provider key and stale search results in Reso…
maliming ef84dba
Include sorting and paging in role list fetch
maliming 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
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
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
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
214 changes: 214 additions & 0 deletions
214
...ests/Volo/Abp/PermissionManagement/DynamicPermissionDefinitionStoreInMemoryCache_Tests.cs
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,214 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using Shouldly; | ||
| using Volo.Abp.MultiTenancy; | ||
| using Xunit; | ||
|
|
||
| namespace Volo.Abp.PermissionManagement; | ||
|
|
||
| public class DynamicPermissionDefinitionStoreInMemoryCache_Tests : PermissionTestBase | ||
| { | ||
| private readonly IDynamicPermissionDefinitionStoreInMemoryCache _cache; | ||
|
|
||
| public DynamicPermissionDefinitionStoreInMemoryCache_Tests() | ||
| { | ||
| _cache = GetRequiredService<IDynamicPermissionDefinitionStoreInMemoryCache>(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task FillAsync_Should_Populate_ResourcePermissionDefinitions() | ||
| { | ||
| // Arrange | ||
| var permissionGroupRecords = new List<PermissionGroupDefinitionRecord>(); | ||
| var permissionRecords = new List<PermissionDefinitionRecord> | ||
| { | ||
| new PermissionDefinitionRecord( | ||
| Guid.NewGuid(), | ||
| groupName: null, | ||
| name: "TestResourcePerm1", | ||
| resourceName: "TestResource", | ||
| managementPermissionName: "TestManagementPerm", | ||
| parentName: null, | ||
| displayName: "F:Test Resource Permission 1", | ||
| isEnabled: true, | ||
| multiTenancySide: MultiTenancySides.Both, | ||
| providers: "R,U", | ||
| stateCheckers: null | ||
| ) | ||
| }; | ||
|
|
||
| // Act | ||
| await _cache.FillAsync(permissionGroupRecords, permissionRecords); | ||
|
|
||
| // Assert | ||
| var resourcePermissions = _cache.GetResourcePermissions(); | ||
| resourcePermissions.Count.ShouldBe(1); | ||
|
|
||
| var resourcePermission = _cache.GetResourcePermissionOrNull("TestResource", "TestResourcePerm1"); | ||
| resourcePermission.ShouldNotBeNull(); | ||
| resourcePermission.Name.ShouldBe("TestResourcePerm1"); | ||
| resourcePermission.ResourceName.ShouldBe("TestResource"); | ||
| resourcePermission.ManagementPermissionName.ShouldBe("TestManagementPerm"); | ||
| resourcePermission.IsEnabled.ShouldBeTrue(); | ||
| resourcePermission.MultiTenancySide.ShouldBe(MultiTenancySides.Both); | ||
| resourcePermission.Providers.Count.ShouldBe(2); | ||
| resourcePermission.Providers.ShouldContain("R"); | ||
| resourcePermission.Providers.ShouldContain("U"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task FillAsync_Should_Populate_ResourcePermission_With_ExtraProperties() | ||
| { | ||
| // Arrange | ||
| var permissionGroupRecords = new List<PermissionGroupDefinitionRecord>(); | ||
| var record = new PermissionDefinitionRecord( | ||
| Guid.NewGuid(), | ||
| groupName: null, | ||
| name: "TestResourcePerm2", | ||
| resourceName: "TestResource", | ||
| managementPermissionName: "TestManagementPerm", | ||
| parentName: null, | ||
| displayName: "F:Test Resource Permission 2" | ||
| ); | ||
| record.ExtraProperties["CustomProp1"] = "CustomValue1"; | ||
|
|
||
| var permissionRecords = new List<PermissionDefinitionRecord> { record }; | ||
|
|
||
| // Act | ||
| await _cache.FillAsync(permissionGroupRecords, permissionRecords); | ||
|
|
||
| // Assert | ||
| var resourcePermission = _cache.GetResourcePermissionOrNull("TestResource", "TestResourcePerm2"); | ||
| resourcePermission.ShouldNotBeNull(); | ||
| resourcePermission["CustomProp1"].ShouldBe("CustomValue1"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task FillAsync_Should_Not_Mix_Resource_And_Regular_Permissions() | ||
| { | ||
| // Arrange | ||
| var permissionGroupRecords = new List<PermissionGroupDefinitionRecord> | ||
| { | ||
| new PermissionGroupDefinitionRecord( | ||
| Guid.NewGuid(), | ||
| name: "TestGroup", | ||
| displayName: "F:Test Group" | ||
| ) | ||
| }; | ||
|
|
||
| var permissionRecords = new List<PermissionDefinitionRecord> | ||
| { | ||
| // Regular permission | ||
| new PermissionDefinitionRecord( | ||
| Guid.NewGuid(), | ||
| groupName: "TestGroup", | ||
| name: "RegularPerm1", | ||
| resourceName: null, | ||
| managementPermissionName: null, | ||
| parentName: null, | ||
| displayName: "F:Regular Permission 1" | ||
| ), | ||
| // Resource permission | ||
| new PermissionDefinitionRecord( | ||
| Guid.NewGuid(), | ||
| groupName: null, | ||
| name: "ResourcePerm1", | ||
| resourceName: "TestResource", | ||
| managementPermissionName: "ManagementPerm", | ||
| parentName: null, | ||
| displayName: "F:Resource Permission 1" | ||
| ) | ||
| }; | ||
|
|
||
| // Act | ||
| await _cache.FillAsync(permissionGroupRecords, permissionRecords); | ||
|
|
||
| // Assert | ||
| var regularPermissions = _cache.GetPermissions(); | ||
| regularPermissions.Count.ShouldBe(1); | ||
| regularPermissions.First().Name.ShouldBe("RegularPerm1"); | ||
|
|
||
| var resourcePermissions = _cache.GetResourcePermissions(); | ||
| resourcePermissions.Count.ShouldBe(1); | ||
| resourcePermissions.First().Name.ShouldBe("ResourcePerm1"); | ||
|
|
||
| _cache.GetPermissionOrNull("RegularPerm1").ShouldNotBeNull(); | ||
| _cache.GetPermissionOrNull("ResourcePerm1").ShouldBeNull(); | ||
|
|
||
| _cache.GetResourcePermissionOrNull("TestResource", "ResourcePerm1").ShouldNotBeNull(); | ||
| _cache.GetResourcePermissionOrNull("TestResource", "RegularPerm1").ShouldBeNull(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task FillAsync_Should_Populate_ResourcePermission_With_StateCheckers() | ||
| { | ||
| // Arrange | ||
| var permissionGroupRecords = new List<PermissionGroupDefinitionRecord>(); | ||
| var permissionRecords = new List<PermissionDefinitionRecord> | ||
| { | ||
| new PermissionDefinitionRecord( | ||
| Guid.NewGuid(), | ||
| groupName: null, | ||
| name: "TestResourcePerm3", | ||
| resourceName: "TestResource", | ||
| managementPermissionName: "TestManagementPerm", | ||
| parentName: null, | ||
| displayName: "F:Test Resource Permission 3", | ||
| stateCheckers: "[{\"T\":\"A\"}]" | ||
| ) | ||
| }; | ||
|
|
||
| // Act | ||
| await _cache.FillAsync(permissionGroupRecords, permissionRecords); | ||
|
|
||
| // Assert | ||
| var resourcePermission = _cache.GetResourcePermissionOrNull("TestResource", "TestResourcePerm3"); | ||
| resourcePermission.ShouldNotBeNull(); | ||
| resourcePermission.StateCheckers.Count.ShouldBe(1); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task FillAsync_Should_Clear_Previous_ResourcePermissions() | ||
| { | ||
| // Arrange - first fill | ||
| var permissionRecords1 = new List<PermissionDefinitionRecord> | ||
| { | ||
| new PermissionDefinitionRecord( | ||
| Guid.NewGuid(), | ||
| groupName: null, | ||
| name: "OldResourcePerm", | ||
| resourceName: "TestResource", | ||
| managementPermissionName: "ManagementPerm", | ||
| parentName: null, | ||
| displayName: "F:Old Resource Permission" | ||
| ) | ||
| }; | ||
| await _cache.FillAsync(new List<PermissionGroupDefinitionRecord>(), permissionRecords1); | ||
| _cache.GetResourcePermissions().Count.ShouldBe(1); | ||
|
|
||
| // Arrange - second fill with different data | ||
| var permissionRecords2 = new List<PermissionDefinitionRecord> | ||
| { | ||
| new PermissionDefinitionRecord( | ||
| Guid.NewGuid(), | ||
| groupName: null, | ||
| name: "NewResourcePerm", | ||
| resourceName: "TestResource", | ||
| managementPermissionName: "ManagementPerm", | ||
| parentName: null, | ||
| displayName: "F:New Resource Permission" | ||
| ) | ||
| }; | ||
|
|
||
| // Act | ||
| await _cache.FillAsync(new List<PermissionGroupDefinitionRecord>(), permissionRecords2); | ||
|
|
||
| // Assert | ||
| var resourcePermissions = _cache.GetResourcePermissions(); | ||
| resourcePermissions.Count.ShouldBe(1); | ||
| resourcePermissions.First().Name.ShouldBe("NewResourcePerm"); | ||
| _cache.GetResourcePermissionOrNull("TestResource", "OldResourcePerm").ShouldBeNull(); | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.