diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Web.OpenIddict/Handlers/ServerValidationTokenCheckIdentitySession.cs b/aspnet-core/modules/account/LINGYUN.Abp.Account.Web.OpenIddict/Handlers/ServerValidationTokenCheckIdentitySession.cs index 2577ff084..66ae8ad68 100644 --- a/aspnet-core/modules/account/LINGYUN.Abp.Account.Web.OpenIddict/Handlers/ServerValidationTokenCheckIdentitySession.cs +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Web.OpenIddict/Handlers/ServerValidationTokenCheckIdentitySession.cs @@ -34,7 +34,7 @@ public class ServerValidationTokenCheckIdentitySession : IOpenIddictServerHandle public async virtual ValueTask HandleAsync(OpenIddictServerEvents.ValidateTokenContext context) { - Logger.LogDebug("Server Validate Token: {endpointType} - {requestUri}", context.EndpointType, context.RequestUri); + Logger.LogDebug("Server Validate Token: {endpointType} - {requestPath}", context.EndpointType, context.RequestUri?.AbsolutePath); if (context.Principal == null || context.Principal.Identity?.IsAuthenticated == false) { diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Web.OpenIddict/Handlers/ValidationTokenCheckIdentitySession.cs b/aspnet-core/modules/account/LINGYUN.Abp.Account.Web.OpenIddict/Handlers/ValidationTokenCheckIdentitySession.cs index 8b127f26d..48063e0bd 100644 --- a/aspnet-core/modules/account/LINGYUN.Abp.Account.Web.OpenIddict/Handlers/ValidationTokenCheckIdentitySession.cs +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Web.OpenIddict/Handlers/ValidationTokenCheckIdentitySession.cs @@ -34,7 +34,7 @@ public class ValidationTokenCheckIdentitySession : IOpenIddictValidationHandler< public async virtual ValueTask HandleAsync(OpenIddictValidationEvents.ValidateTokenContext context) { - Logger.LogInformation("Validate Token: {endpointType} - {requestUri}", context.EndpointType, context.RequestUri); + Logger.LogDebug("Validate Token: {endpointType} - {requestPath}", context.EndpointType, context.RequestUri?.AbsolutePath); var tenantId = context.Principal?.FindTenantId(); using (CurrentTenant.Change(tenantId)) diff --git a/aspnet-core/modules/account/LINGYUN.Abp.Account.Web.OpenIddict/README.md b/aspnet-core/modules/account/LINGYUN.Abp.Account.Web.OpenIddict/README.md new file mode 100644 index 000000000..9413e65c6 --- /dev/null +++ b/aspnet-core/modules/account/LINGYUN.Abp.Account.Web.OpenIddict/README.md @@ -0,0 +1,5 @@ +# OpenIddict session validation diagnostics + +The server and validation handlers log the endpoint type and the request URI's absolute path at Debug level. URI query parameters, fragments and authority information are excluded from both the rendered message and structured URI fields, because requests such as SignalR connections can carry access tokens in their query strings. + +A missing request URI is logged as a null path. Session validation and rejection behavior remain the responsibility of the existing handlers. diff --git a/aspnet-core/modules/blob-management/LINGYUN.Abp.BlobManagement.Application/LINGYUN/Abp/BlobManagement/BlobContainerAppService.cs b/aspnet-core/modules/blob-management/LINGYUN.Abp.BlobManagement.Application/LINGYUN/Abp/BlobManagement/BlobContainerAppService.cs index 6c81a87c5..fa4f3ce68 100644 --- a/aspnet-core/modules/blob-management/LINGYUN.Abp.BlobManagement.Application/LINGYUN/Abp/BlobManagement/BlobContainerAppService.cs +++ b/aspnet-core/modules/blob-management/LINGYUN.Abp.BlobManagement.Application/LINGYUN/Abp/BlobManagement/BlobContainerAppService.cs @@ -1,4 +1,6 @@ using LINGYUN.Abp.BlobManagement.Dtos; +using LINGYUN.Abp.BlobManagement.Permissions; +using Microsoft.AspNetCore.Authorization; using Microsoft.Extensions.Options; using System; using System.Collections.Generic; @@ -7,10 +9,12 @@ using System.Linq.Expressions; using System.Threading.Tasks; using Volo.Abp; using Volo.Abp.Application.Dtos; +using Volo.Abp.Authorization; using Volo.Abp.Specifications; namespace LINGYUN.Abp.BlobManagement; +[Authorize] public class BlobContainerAppService : BlobManagementApplicationService, IBlobContainerAppService { private readonly AbpBlobManagementOptions _options; @@ -27,6 +31,7 @@ public class BlobContainerAppService : BlobManagementApplicationService, IBlobCo _options = options.Value; } + [Authorize(BlobManagementPermissionNames.BlobContainer.Create)] public async virtual Task CreateAsync(BlobContainerCreateDto input) { var blobContainer = await _blobManager.CreateContainerAsync(input.Name); @@ -34,6 +39,7 @@ public class BlobContainerAppService : BlobManagementApplicationService, IBlobCo return ObjectMapper.Map(blobContainer); } + [Authorize(BlobManagementPermissionNames.BlobContainer.Delete)] public async virtual Task DeleteAsync(Guid id) { var blobContainer = await _blobContainerRepository.GetAsync(id); @@ -50,6 +56,8 @@ public class BlobContainerAppService : BlobManagementApplicationService, IBlobCo public async virtual Task GetAsync(Guid id) { + await CheckReadPolicyAsync(); + var blobContainer = await _blobContainerRepository.GetAsync(id); return ObjectMapper.Map(blobContainer); @@ -57,6 +65,8 @@ public class BlobContainerAppService : BlobManagementApplicationService, IBlobCo public async virtual Task> GetListAsync(BlobContainerGetPagedListInput input) { + await CheckReadPolicyAsync(); + Expression> expression = x => x.Provider == _blobManager.GetBlobProvider(); if (!input.Filter.IsNullOrWhiteSpace()) @@ -73,4 +83,16 @@ public class BlobContainerAppService : BlobManagementApplicationService, IBlobCo return new PagedResultDto(totalCount, ObjectMapper.Map, List>(blobContainers)); } + + protected virtual async Task CheckReadPolicyAsync() + { + // File selection reads current-tenant containers without granting container administration. + // Blob.Default carries the native feature requirement; check the effective policies. + if (!await AuthorizationService.IsGrantedAnyAsync( + BlobManagementPermissionNames.BlobContainer.Default, + BlobManagementPermissionNames.Blob.Default)) + { + throw new AbpAuthorizationException(); + } + } } diff --git a/aspnet-core/modules/blob-management/LINGYUN.Abp.BlobManagement.Application/README.md b/aspnet-core/modules/blob-management/LINGYUN.Abp.BlobManagement.Application/README.md new file mode 100644 index 000000000..438beb3be --- /dev/null +++ b/aspnet-core/modules/blob-management/LINGYUN.Abp.BlobManagement.Application/README.md @@ -0,0 +1,14 @@ +# Blob container authorization + +Container operations require an authenticated caller. + +- Create and delete require the corresponding `AbpBlobManagement.BlobContainer.Create` and `AbpBlobManagement.BlobContainer.Delete` permissions. +- Get and list accept either `AbpBlobManagement.BlobContainer` or the effective `AbpBlobManagement.Blob` permission, so file selection remains available to authorized file users. +- The file permission includes the existing Blob feature requirement. Container management uses its own permission. +- Existing permission definitions determine tenant eligibility; repository filters continue to determine data scope. Static-container deletion protection also applies to authorized callers. + +Run the focused authorization tests from the repository root: + +```sh +dotnet test aspnet-core/tests/LINGYUN.Abp.BlobManagement.Application.Tests/LINGYUN.Abp.BlobManagement.Application.Tests.csproj +``` diff --git a/aspnet-core/modules/caching-management/LINGYUN.Abp.CachingManagement.StackExchangeRedis/LINGYUN/Abp/CachingManagement/StackExchangeRedis/StackExchangeRedisCacheManager.cs b/aspnet-core/modules/caching-management/LINGYUN.Abp.CachingManagement.StackExchangeRedis/LINGYUN/Abp/CachingManagement/StackExchangeRedis/StackExchangeRedisCacheManager.cs index 0c3f267c2..f7eb7c071 100644 --- a/aspnet-core/modules/caching-management/LINGYUN.Abp.CachingManagement.StackExchangeRedis/LINGYUN/Abp/CachingManagement/StackExchangeRedis/StackExchangeRedisCacheManager.cs +++ b/aspnet-core/modules/caching-management/LINGYUN.Abp.CachingManagement.StackExchangeRedis/LINGYUN/Abp/CachingManagement/StackExchangeRedis/StackExchangeRedisCacheManager.cs @@ -72,7 +72,7 @@ public class StackExchangeRedisCacheManager : ICacheManager, ISingletonDependenc // 缓存键名规则: InstanceName + (t + TenantId)(CurrentTenant.IsAvailable) + CacheItemName + KeyPrefix + Key // 缓存键名规则: InstanceName + (c:)(!CurrentTenant.IsAvailable) + CacheItemName + KeyPrefix + Key - var match = "*"; + var match = RedisCacheOptions.InstanceName ?? string.Empty; // abp* if (!RedisCacheOptions.InstanceName.IsNullOrWhiteSpace()) { @@ -82,7 +82,7 @@ public class StackExchangeRedisCacheManager : ICacheManager, ISingletonDependenc // abp*c:* if (CurrentTenant.IsAvailable) { - match += "t:" + CurrentTenant.Id.ToString() + "*"; + match += "t:" + CurrentTenant.Id.ToString() + ",c:*"; } else { @@ -152,6 +152,7 @@ public class StackExchangeRedisCacheManager : ICacheManager, ISingletonDependenc public async virtual Task GetValueAsync(string key, CancellationToken cancellationToken = default) { + CheckKey(key); long size = 0; var values = new Dictionary(); @@ -210,6 +211,7 @@ public class StackExchangeRedisCacheManager : ICacheManager, ISingletonDependenc public async virtual Task SetAsync(SetCacheRequest request, CancellationToken cancellationToken = default) { + CheckKey(request.Key); var cacheKey = request.Key; if (!RedisCacheOptions.InstanceName.IsNullOrWhiteSpace() && cacheKey.StartsWith(RedisCacheOptions.InstanceName)) { @@ -231,6 +233,7 @@ public class StackExchangeRedisCacheManager : ICacheManager, ISingletonDependenc public async virtual Task RefreshAsync(RefreshCacheRequest request, CancellationToken cancellationToken = default) { + CheckKey(request.Key); var cacheKey = request.Key; if (!RedisCacheOptions.InstanceName.IsNullOrWhiteSpace() && cacheKey.StartsWith(RedisCacheOptions.InstanceName)) { @@ -259,6 +262,11 @@ public class StackExchangeRedisCacheManager : ICacheManager, ISingletonDependenc public async virtual Task RemoveAsync(RemoveCacheRequest request, CancellationToken cancellationToken = default) { + foreach (var key in request.Keys) + { + CheckKey(key); + } + var cacheKeys = request.Keys.Select((cacheKey) => { if (!RedisCacheOptions.InstanceName.IsNullOrWhiteSpace() && cacheKey.StartsWith(RedisCacheOptions.InstanceName)) @@ -270,6 +278,20 @@ public class StackExchangeRedisCacheManager : ICacheManager, ISingletonDependenc await RedisCache.RemoveManyAsync(cacheKeys, cancellationToken); } + protected virtual void CheckKey(string key) + { + var prefix = RedisCacheOptions.InstanceName ?? string.Empty; + if (CurrentTenant.IsAvailable) + { + prefix += $"t:{CurrentTenant.Id},c:"; + } + + if (string.IsNullOrEmpty(key) || !key.StartsWith(prefix, StringComparison.Ordinal)) + { + throw new Volo.Abp.Authorization.AbpAuthorizationException("Cache key is outside the current scope."); + } + } + protected virtual ValueTask ConnectAsync(CancellationToken token = default) { return (ValueTask)ConnectAsyncMethod.Invoke(RedisCache, new object[] { token })!; diff --git a/aspnet-core/modules/caching-management/LINGYUN.Abp.CachingManagement.StackExchangeRedis/README.EN.md b/aspnet-core/modules/caching-management/LINGYUN.Abp.CachingManagement.StackExchangeRedis/README.EN.md index d0ed1282c..ba5533250 100644 --- a/aspnet-core/modules/caching-management/LINGYUN.Abp.CachingManagement.StackExchangeRedis/README.EN.md +++ b/aspnet-core/modules/caching-management/LINGYUN.Abp.CachingManagement.StackExchangeRedis/README.EN.md @@ -51,6 +51,8 @@ The module has built-in multi-tenancy support, automatically isolating cache dat * Key format with tenant: `{InstanceName}t:{TenantId}:{KeyPrefix}:{Key}` * Key format without tenant: `{InstanceName}c:{KeyPrefix}:{Key}` +Read, set, refresh and delete operations validate the Redis instance prefix and, for tenant requests, the complete tenant key prefix. Bulk deletion validates every key before deleting any entries. Host administrators can still manage cache entries within the configured instance. + ## More For more information, please refer to the following resources: diff --git a/aspnet-core/modules/caching-management/LINGYUN.Abp.CachingManagement.StackExchangeRedis/README.md b/aspnet-core/modules/caching-management/LINGYUN.Abp.CachingManagement.StackExchangeRedis/README.md index c246f7b62..0c136b4aa 100644 --- a/aspnet-core/modules/caching-management/LINGYUN.Abp.CachingManagement.StackExchangeRedis/README.md +++ b/aspnet-core/modules/caching-management/LINGYUN.Abp.CachingManagement.StackExchangeRedis/README.md @@ -51,6 +51,8 @@ Configure(options => * 有租户时的键格式:`{InstanceName}t:{TenantId}:{KeyPrefix}:{Key}` * 无租户时的键格式:`{InstanceName}c:{KeyPrefix}:{Key}` +读取、设置、刷新和删除操作都会校验键的 Redis 实例前缀;租户请求还必须匹配完整的租户键前缀。批量删除先校验全部键,再执行删除。平台管理员仍可管理当前实例范围内的缓存。 + ## 更多 有关更多信息,请参阅以下资源: diff --git a/aspnet-core/tests/LINGYUN.Abp.BlobManagement.Application.Tests/BlobContainerAuthorizationTests.cs b/aspnet-core/tests/LINGYUN.Abp.BlobManagement.Application.Tests/BlobContainerAuthorizationTests.cs new file mode 100644 index 000000000..7f1e4c288 --- /dev/null +++ b/aspnet-core/tests/LINGYUN.Abp.BlobManagement.Application.Tests/BlobContainerAuthorizationTests.cs @@ -0,0 +1,258 @@ +using System.Security.Claims; +using LINGYUN.Abp.BlobManagement.Dtos; +using LINGYUN.Abp.BlobManagement.Features; +using LINGYUN.Abp.BlobManagement.Permissions; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; +using NSubstitute; +using Volo.Abp; +using Volo.Abp.Authorization; +using Volo.Abp.Authorization.Permissions; +using Volo.Abp.Autofac; +using Volo.Abp.Features; +using Volo.Abp.Modularity; +using Volo.Abp.MultiTenancy; +using Volo.Abp.ObjectMapping; +using Volo.Abp.Security.Claims; +using Volo.Abp.Specifications; +using Xunit; + +namespace LINGYUN.Abp.BlobManagement; + +public class BlobContainerAuthorizationTests +{ + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task Anonymous_requests_are_rejected_before_container_access(bool isTenant) + { + using var application = await CreateApplicationAsync(); + var services = application.ServiceProvider; + using var tenant = services.GetRequiredService().Change(isTenant ? Guid.NewGuid() : null); + using var principal = services.GetRequiredService() + .Change(new ClaimsPrincipal(new ClaimsIdentity())); + var service = services.GetRequiredService(); + var state = services.GetRequiredService(); + + await Assert.ThrowsAsync(() => service.GetAsync(state.Container.Id)); + await Assert.ThrowsAsync(() => service.GetListAsync(new BlobContainerGetPagedListInput())); + await Assert.ThrowsAsync(() => service.CreateAsync(new BlobContainerCreateDto { Name = "media" })); + await Assert.ThrowsAsync(() => service.DeleteAsync(state.Container.Id)); + Assert.Empty(state.Repository.ReceivedCalls()); + Assert.Empty(state.Manager.ReceivedCalls()); + await application.ShutdownAsync(); + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task Authenticated_users_without_permissions_cannot_read_or_write(bool isTenant) + { + using var application = await CreateApplicationAsync(); + var services = application.ServiceProvider; + var tenantId = isTenant ? Guid.NewGuid() : (Guid?)null; + using var tenant = services.GetRequiredService().Change(tenantId); + using var principal = services.GetRequiredService().Change(Principal(tenantId)); + var service = services.GetRequiredService(); + var state = services.GetRequiredService(); + + await Assert.ThrowsAsync(() => service.GetAsync(state.Container.Id)); + await Assert.ThrowsAsync(() => service.GetListAsync(new BlobContainerGetPagedListInput())); + await Assert.ThrowsAsync(() => service.CreateAsync(new BlobContainerCreateDto { Name = "media" })); + await Assert.ThrowsAsync(() => service.DeleteAsync(state.Container.Id)); + Assert.Empty(state.Repository.ReceivedCalls()); + Assert.Empty(state.Manager.ReceivedCalls()); + await application.ShutdownAsync(); + } + + [Theory] + [InlineData(false, BlobManagementPermissionNames.BlobContainer.Default, false)] + [InlineData(true, BlobManagementPermissionNames.BlobContainer.Default, false)] + [InlineData(false, BlobManagementPermissionNames.Blob.Default, true)] + [InlineData(true, BlobManagementPermissionNames.Blob.Default, true)] + public async Task Container_management_or_effective_file_permission_allows_reads( + bool isTenant, string permission, bool blobEnabled) + { + using var application = await CreateApplicationAsync(); + var services = application.ServiceProvider; + var tenantId = isTenant ? Guid.NewGuid() : (Guid?)null; + using var tenant = services.GetRequiredService().Change(tenantId); + using var principal = services.GetRequiredService().Change(Principal(tenantId)); + var service = services.GetRequiredService(); + var state = services.GetRequiredService(); + state.Granted.Add(permission); + state.BlobEnabled = blobEnabled; + + Assert.Equal(state.Container.Id, (await service.GetAsync(state.Container.Id)).Id); + Assert.Single((await service.GetListAsync(new BlobContainerGetPagedListInput())).Items); + Assert.Equal(tenantId, services.GetRequiredService().Id); + await Assert.ThrowsAsync(() => service.CreateAsync(new BlobContainerCreateDto { Name = "media" })); + await Assert.ThrowsAsync(() => service.DeleteAsync(state.Container.Id)); + Assert.DoesNotContain(state.Manager.ReceivedCalls(), call => call.GetMethodInfo().Name != nameof(BlobManager.GetBlobProvider)); + await application.ShutdownAsync(); + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public async Task Disabled_file_feature_rejects_file_only_readers_before_repository_access(bool isTenant) + { + using var application = await CreateApplicationAsync(); + var services = application.ServiceProvider; + var tenantId = isTenant ? Guid.NewGuid() : (Guid?)null; + using var tenant = services.GetRequiredService().Change(tenantId); + using var principal = services.GetRequiredService().Change(Principal(tenantId)); + var service = services.GetRequiredService(); + var state = services.GetRequiredService(); + state.Granted.Add(BlobManagementPermissionNames.Blob.Default); + state.BlobEnabled = false; + + await Assert.ThrowsAsync(() => service.GetAsync(state.Container.Id)); + await Assert.ThrowsAsync(() => service.GetListAsync(new BlobContainerGetPagedListInput())); + Assert.Empty(state.Repository.ReceivedCalls()); + await application.ShutdownAsync(); + } + + [Theory] + [InlineData(false, BlobManagementPermissionNames.BlobContainer.Create)] + [InlineData(true, BlobManagementPermissionNames.BlobContainer.Create)] + [InlineData(false, BlobManagementPermissionNames.BlobContainer.Delete)] + [InlineData(true, BlobManagementPermissionNames.BlobContainer.Delete)] + public async Task Write_permissions_remain_independent(bool isTenant, string permission) + { + using var application = await CreateApplicationAsync(); + var services = application.ServiceProvider; + var tenantId = isTenant ? Guid.NewGuid() : (Guid?)null; + using var tenant = services.GetRequiredService().Change(tenantId); + using var principal = services.GetRequiredService().Change(Principal(tenantId)); + var service = services.GetRequiredService(); + var state = services.GetRequiredService(); + state.Granted.Add(permission); + + if (permission == BlobManagementPermissionNames.BlobContainer.Create) + { + Assert.Equal(state.Container.Id, + (await service.CreateAsync(new BlobContainerCreateDto { Name = "media" })).Id); + await Assert.ThrowsAsync(() => service.DeleteAsync(state.Container.Id)); + await state.Manager.Received(1).CreateContainerAsync("media"); + await state.Manager.DidNotReceive().DeleteContainerAsync(Arg.Any()); + } + else + { + await service.DeleteAsync(state.Container.Id); + await Assert.ThrowsAsync(() => service.CreateAsync(new BlobContainerCreateDto { Name = "media" })); + await state.Manager.Received(1).DeleteContainerAsync(state.Container); + await state.Manager.DidNotReceive().CreateContainerAsync(Arg.Any()); + } + await application.ShutdownAsync(); + } + + [Fact] + public async Task Authorized_delete_still_rejects_static_containers() + { + using var application = await CreateApplicationAsync(); + var services = application.ServiceProvider; + using var principal = services.GetRequiredService().Change(Principal(null)); + var service = services.GetRequiredService(); + var state = services.GetRequiredService(); + state.Granted.Add(BlobManagementPermissionNames.BlobContainer.Delete); + services.GetRequiredService>().Value.StaticContainers.Add(state.Container.Name); + + var error = await Assert.ThrowsAsync(() => service.DeleteAsync(state.Container.Id)); + Assert.Equal(BlobManagementErrorCodes.Container.DeleteWithStatic, error.Code); + await state.Manager.DidNotReceive().DeleteContainerAsync(Arg.Any()); + await application.ShutdownAsync(); + } + + private static async Task CreateApplicationAsync() + { + var application = await AbpApplicationFactory.CreateAsync(options => options.UseAutofac()); + await application.InitializeAsync(); + return application; + } + + private static ClaimsPrincipal Principal(Guid? tenantId) + { + var claims = new List { new(AbpClaimTypes.UserId, Guid.NewGuid().ToString()) }; + if (tenantId.HasValue) claims.Add(new Claim(AbpClaimTypes.TenantId, tenantId.Value.ToString())); + return new ClaimsPrincipal(new ClaimsIdentity(claims, "test")); + } +} + +public class ContainerAuthorizationState +{ + public HashSet Granted { get; } = new(StringComparer.Ordinal); + public bool BlobEnabled { get; set; } = true; + public BlobContainer Container { get; } = new TestContainer(); + public IBlobContainerRepository Repository { get; } = Substitute.For(); + public BlobManager Manager { get; } = Substitute.For( + new object?[] { null, null, null, null, null, null, null, null, null, null, null }); + public IObjectMapper Mapper { get; } = + Substitute.For>(); + + public ContainerAuthorizationState() + { + Repository.GetAsync(Container.Id, Arg.Any(), Arg.Any()).Returns(Container); + Repository.GetCountAsync(Arg.Any>(), Arg.Any()).Returns(1); + Repository.GetListAsync(Arg.Any>(), Arg.Any(), + Arg.Any(), Arg.Any(), Arg.Any()).Returns(new List { Container }); + Manager.GetBlobProvider().Returns("test-provider"); + Manager.CreateContainerAsync(Arg.Any()).Returns(Container); + Mapper.Map(Arg.Any()) + .Returns(call => new BlobContainerDto { Id = call.Arg().Id }); + Mapper.Map, List>(Arg.Any>()) + .Returns(new List { new() { Id = Container.Id } }); + Repository.ClearReceivedCalls(); + Manager.ClearReceivedCalls(); + } + + private sealed class TestContainer : BlobContainer + { + public TestContainer() + { + Id = Guid.NewGuid(); + Name = "media"; + SetProvider("test-provider"); + } + } +} + +[DependsOn(typeof(AbpAutofacModule), typeof(AbpAuthorizationModule), typeof(AbpFeaturesModule), typeof(AbpBlobManagementApplicationModule))] +public class ContainerAuthorizationTestModule : AbpModule +{ + public override void ConfigureServices(ServiceConfigurationContext context) + { + var state = new ContainerAuthorizationState(); + context.Services.AddSingleton(state); + context.Services.AddSingleton(state.Repository); + context.Services.AddSingleton(state.Manager); + context.Services.AddSingleton(state.Mapper); + context.Services.AddTransient(); + context.Services.AddTransient(); + var permissions = Substitute.For(); + permissions.IsGrantedAsync(Arg.Any(), Arg.Any(), Arg.Any()) + .Returns(call => state.Granted.Contains(call.ArgAt(0))); + permissions.IsGrantedAsync(Arg.Any(), Arg.Any(), Arg.Any()).Returns(call => + { + var result = new MultiplePermissionGrantResult(); + foreach (var name in call.ArgAt(0)) + result.Result.Add(name, state.Granted.Contains(name) ? PermissionGrantResult.Granted : PermissionGrantResult.Undefined); + return result; + }); + context.Services.AddSingleton(permissions); + var features = Substitute.For(); + features.GetOrNullAsync(Arg.Any(), Arg.Any(), Arg.Any()) + .Returns(call => call.ArgAt(0) == BlobManagementFeatureNames.Blob.Enable ? state.BlobEnabled.ToString() : null); + context.Services.AddSingleton(features); + Configure(options => + { + options.DefinitionProviders.Clear(); + options.DefinitionProviders.Add(); + }); + Configure(options => + { + options.DefinitionProviders.Clear(); + options.DefinitionProviders.Add(); + }); + } +}