|
|
|
@ -9,16 +9,33 @@ namespace Volo.Abp.Authorization
|
|
|
|
|
public class Authorization_Tests : AuthorizationTestBase
|
|
|
|
|
{
|
|
|
|
|
private readonly IMyAuthorizedService1 _myAuthorizedService1;
|
|
|
|
|
private readonly IMySimpleAuthorizedService _simpleAuthorizedService;
|
|
|
|
|
private readonly IMyAuthorizedServiceWithRole _myAuthorizedServiceWithRole;
|
|
|
|
|
private readonly IPermissionDefinitionManager _permissionDefinitionManager;
|
|
|
|
|
|
|
|
|
|
public Authorization_Tests()
|
|
|
|
|
{
|
|
|
|
|
_myAuthorizedService1 = GetRequiredService<IMyAuthorizedService1>();
|
|
|
|
|
_simpleAuthorizedService = GetRequiredService<IMySimpleAuthorizedService>();
|
|
|
|
|
_myAuthorizedServiceWithRole = GetRequiredService<IMyAuthorizedServiceWithRole>();
|
|
|
|
|
_permissionDefinitionManager = GetRequiredService<IPermissionDefinitionManager>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task Should_Not_Allow_To_Call_Authorized_Method_For_Anonymous_User()
|
|
|
|
|
{
|
|
|
|
|
await Assert.ThrowsAsync<AbpAuthorizationException>(async () =>
|
|
|
|
|
{
|
|
|
|
|
await _simpleAuthorizedService.ProtectedByClassAsync();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task Should_Allow_To_Call_Anonymous_Method_For_Anonymous_User()
|
|
|
|
|
{
|
|
|
|
|
(await _simpleAuthorizedService.AnonymousAsync()).ShouldBe(42);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task Should_Not_Allow_To_Call_Method_If_Has_No_Permission_ProtectedByClass()
|
|
|
|
|
{
|
|
|
|
|