mirror of https://github.com/abpframework/abp.git
committed by
GitHub
24 changed files with 300 additions and 34 deletions
@ -0,0 +1,15 @@ |
|||||
|
namespace Volo.Abp.Authorization |
||||
|
{ |
||||
|
public static class AbpAuthorizationErrorCodes |
||||
|
{ |
||||
|
public const string GivenPolicyHasNotGranted = "Volo.Authorization:010001"; |
||||
|
|
||||
|
public const string GivenPolicyHasNotGrantedWithPolicyName = "Volo.Authorization:010002"; |
||||
|
|
||||
|
public const string GivenPolicyHasNotGrantedForGivenResource = "Volo.Authorization:010003"; |
||||
|
|
||||
|
public const string GivenRequirementHasNotGrantedForGivenResource = "Volo.Authorization:010004"; |
||||
|
|
||||
|
public const string GivenRequirementsHasNotGrantedForGivenResource = "Volo.Authorization:010005"; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
using Volo.Abp.Localization; |
||||
|
|
||||
|
namespace Volo.Abp.Authorization.Localization |
||||
|
{ |
||||
|
[LocalizationResourceName("AbpAuthorization")] |
||||
|
public class AbpAuthorizationResource |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
{ |
||||
|
"culture": "en", |
||||
|
"texts": { |
||||
|
"Volo.Authorization:010001": "Authorization failed! Given policy has not granted.", |
||||
|
"Volo.Authorization:010002": "Authorization failed! Given policy has not granted: {PolicyName}", |
||||
|
"Volo.Authorization:010003": "Authorization failed! Given policy has not granted for given resource: {ResourceName}", |
||||
|
"Volo.Authorization:010004": "Authorization failed! Given requirement has not granted for given resource: {ResourceName}", |
||||
|
"Volo.Authorization:010005": "Authorization failed! Given requirements has not granted for given resource: {ResourceName}" |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
{ |
||||
|
"culture": "tr", |
||||
|
"texts": { |
||||
|
"Volo.Authorization:010001": "Yetkilendirme başarısız oldu! Verilen politika verilmemiştir.", |
||||
|
"Volo.Authorization:010002": "Yetkilendirme başarısız oldu! Verilen politika vermedi: {PolicyName}", |
||||
|
"Volo.Authorization:010003": "Yetkilendirme başarısız oldu! Verilen politika, verilen kaynak için verilmemiştir: {ResourceName}", |
||||
|
"Volo.Authorization:010004": "Yetkilendirme başarısız oldu! Belirtilen kaynak için verilen şart verilmedi {ResourceName}", |
||||
|
"Volo.Authorization:010005": "Yetkilendirme başarısız oldu! Verilen gereksinimler, verilen kaynak için verilmemiştir: {ResourceName}" |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
{ |
||||
|
"culture": "zh-Hans", |
||||
|
"texts": { |
||||
|
"Volo.Authorization:010001": "授权失败! 提供的策略尚未授予.", |
||||
|
"Volo.Authorization:010002": "授权失败! 提供的策略尚未授予: {PolicyName}", |
||||
|
"Volo.Authorization:010003": "授权失败! 提供的策略未授予提供的资源: {ResourceName}", |
||||
|
"Volo.Authorization:010004": "授权失败! 提供的要求未授予提供的资源: {ResourceName}", |
||||
|
"Volo.Authorization:010005": "授权失败! 提供的要求未授予提供的资源: {ResourceName}" |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
namespace Volo.Abp.Features |
||||
|
{ |
||||
|
public static class AbpFeatureErrorCodes |
||||
|
{ |
||||
|
public const string FeatureIsNotEnabled = "Volo.Feature:010001"; |
||||
|
|
||||
|
public const string AllOfTheseFeaturesMustBeEnabled = "Volo.Feature:010002"; |
||||
|
|
||||
|
public const string AtLeastOneOfTheseFeaturesMustBeEnabled = "Volo.Feature:010003"; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
using Volo.Abp.Localization; |
||||
|
|
||||
|
namespace Volo.Abp.Features.Localization |
||||
|
{ |
||||
|
[LocalizationResourceName("AbpFeature")] |
||||
|
public class AbpFeatureResource |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,8 @@ |
|||||
|
{ |
||||
|
"culture": "en", |
||||
|
"texts": { |
||||
|
"Volo.Feature:010001": "Feature is not enabled: {FeatureName}", |
||||
|
"Volo.Feature:010002": "Required features are not enabled. All of these features must be enabled: {FeatureNames}", |
||||
|
"Volo.Feature:010003": "Required features are not enabled. At least one of these features must be enabled: {FeatureNames}" |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,8 @@ |
|||||
|
{ |
||||
|
"culture": "tr", |
||||
|
"texts": { |
||||
|
"Volo.Feature:010001": "Özellik etkinleştirilmedi: {FeatureName}", |
||||
|
"Volo.Feature:010002": "Gerekli özellikler etkinleştirilmedi. Bu özelliklerin tümü etkinleştirilmelidir: {FeatureNames}", |
||||
|
"Volo.Feature:010003": "Gerekli özellikler etkinleştirilmedi. Bu özelliklerden en az birinin etkinleştirilmesi gerekir: {FeatureNames}" |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,8 @@ |
|||||
|
{ |
||||
|
"culture": "zh-Hans", |
||||
|
"texts": { |
||||
|
"Volo.Feature:010001": "功能未启用: {FeatureName}", |
||||
|
"Volo.Feature:010002": "必要的功能未启用. 这些功能需要启用: {FeatureNames}", |
||||
|
"Volo.Feature:010003": "必要的功能未启用. 需要启用这些功能中的一项:{FeatureNames}" |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,49 @@ |
|||||
|
using Shouldly; |
||||
|
using Volo.Abp.AspNetCore.ExceptionHandling; |
||||
|
using Volo.Abp.Authorization; |
||||
|
using Volo.Abp.Localization; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Microsoft.AspNetCore.Authorization |
||||
|
{ |
||||
|
public class AbpAuthorizationServiceExtensions_Tests : AuthorizationTestBase |
||||
|
{ |
||||
|
private readonly IExceptionToErrorInfoConverter _exceptionToErrorInfoConverter; |
||||
|
|
||||
|
public AbpAuthorizationServiceExtensions_Tests() |
||||
|
{ |
||||
|
_exceptionToErrorInfoConverter = GetRequiredService<IExceptionToErrorInfoConverter>(); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Test_AbpAuthorizationException_Localization() |
||||
|
{ |
||||
|
using (CultureHelper.Use("zh-Hans")) |
||||
|
{ |
||||
|
var exception = new AbpAuthorizationException(code: AbpAuthorizationErrorCodes.GivenPolicyHasNotGranted); |
||||
|
var errorInfo = _exceptionToErrorInfoConverter.Convert(exception, false); |
||||
|
errorInfo.Message.ShouldBe("授权失败! 提供的策略尚未授予."); |
||||
|
|
||||
|
exception = new AbpAuthorizationException(code: AbpAuthorizationErrorCodes.GivenPolicyHasNotGrantedWithPolicyName) |
||||
|
.WithData("PolicyName", "my_policy_name"); |
||||
|
errorInfo = _exceptionToErrorInfoConverter.Convert(exception, false); |
||||
|
errorInfo.Message.ShouldBe("授权失败! 提供的策略尚未授予: my_policy_name"); |
||||
|
|
||||
|
exception = new AbpAuthorizationException(code: AbpAuthorizationErrorCodes.GivenPolicyHasNotGrantedForGivenResource) |
||||
|
.WithData("ResourceName", "my_resource_name"); |
||||
|
errorInfo = _exceptionToErrorInfoConverter.Convert(exception, false); |
||||
|
errorInfo.Message.ShouldBe("授权失败! 提供的策略未授予提供的资源: my_resource_name"); |
||||
|
|
||||
|
exception = new AbpAuthorizationException(code: AbpAuthorizationErrorCodes.GivenRequirementHasNotGrantedForGivenResource) |
||||
|
.WithData("ResourceName", "my_resource_name"); |
||||
|
errorInfo = _exceptionToErrorInfoConverter.Convert(exception, false); |
||||
|
errorInfo.Message.ShouldBe("授权失败! 提供的要求未授予提供的资源: my_resource_name"); |
||||
|
|
||||
|
exception = new AbpAuthorizationException(code: AbpAuthorizationErrorCodes.GivenRequirementsHasNotGrantedForGivenResource) |
||||
|
.WithData("ResourceName", "my_resource_name"); |
||||
|
errorInfo = _exceptionToErrorInfoConverter.Convert(exception, false); |
||||
|
errorInfo.Message.ShouldBe("授权失败! 提供的要求未授予提供的资源: my_resource_name"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,40 @@ |
|||||
|
using Shouldly; |
||||
|
using Volo.Abp.AspNetCore.ExceptionHandling; |
||||
|
using Volo.Abp.Authorization; |
||||
|
using Volo.Abp.Localization; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Volo.Abp.Features |
||||
|
{ |
||||
|
public class FeatureCheckerExtensions_Tests : FeatureTestBase |
||||
|
{ |
||||
|
private readonly IExceptionToErrorInfoConverter _exceptionToErrorInfoConverter; |
||||
|
|
||||
|
public FeatureCheckerExtensions_Tests() |
||||
|
{ |
||||
|
_exceptionToErrorInfoConverter = GetRequiredService<IExceptionToErrorInfoConverter>(); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Test_AbpAuthorizationException_Localization() |
||||
|
{ |
||||
|
using (CultureHelper.Use("zh-Hans")) |
||||
|
{ |
||||
|
var exception = new AbpAuthorizationException(code: AbpFeatureErrorCodes.FeatureIsNotEnabled) |
||||
|
.WithData("FeatureName", "my_feature_name"); |
||||
|
var errorInfo = _exceptionToErrorInfoConverter.Convert(exception, false); |
||||
|
errorInfo.Message.ShouldBe("功能未启用: my_feature_name"); |
||||
|
|
||||
|
exception = new AbpAuthorizationException(code: AbpFeatureErrorCodes.AllOfTheseFeaturesMustBeEnabled) |
||||
|
.WithData("FeatureNames", "my_feature_name, my_feature_name2"); |
||||
|
errorInfo = _exceptionToErrorInfoConverter.Convert(exception, false); |
||||
|
errorInfo.Message.ShouldBe("必要的功能未启用. 这些功能需要启用: my_feature_name, my_feature_name2"); |
||||
|
|
||||
|
exception = new AbpAuthorizationException(code: AbpFeatureErrorCodes.AtLeastOneOfTheseFeaturesMustBeEnabled) |
||||
|
.WithData("FeatureNames", "my_feature_name, my_feature_name2"); |
||||
|
errorInfo = _exceptionToErrorInfoConverter.Convert(exception, false); |
||||
|
errorInfo.Message.ShouldBe("必要的功能未启用. 需要启用这些功能中的一项:my_feature_name, my_feature_name2"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue