mirror of https://github.com/abpframework/abp.git
4 changed files with 81 additions and 0 deletions
@ -0,0 +1,19 @@ |
|||
@page |
|||
@model Volo.Abp.AspNetCore.Mvc.Authorization.AuthTestPage |
|||
|
|||
@{ |
|||
Layout = null; |
|||
} |
|||
|
|||
<!DOCTYPE html> |
|||
|
|||
<html> |
|||
<head> |
|||
<title></title> |
|||
</head> |
|||
<body> |
|||
<div> |
|||
|
|||
</div> |
|||
</body> |
|||
</html> |
|||
@ -0,0 +1,18 @@ |
|||
using System; |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.Authorization |
|||
{ |
|||
[Authorize] |
|||
public class AuthTestPage : AbpPageModel |
|||
{ |
|||
public static Guid FakeUserId { get; } = Guid.NewGuid(); |
|||
|
|||
public ActionResult OnGet() |
|||
{ |
|||
return Content("OK"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,40 @@ |
|||
using System.Security.Claims; |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Volo.Abp.AspNetCore.TestBase; |
|||
using Volo.Abp.Autofac; |
|||
using Volo.Abp.MemoryDb; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.Security.Claims; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.Authorization |
|||
{ |
|||
[DependsOn( |
|||
typeof(AbpAspNetCoreTestBaseModule), |
|||
typeof(AbpMemoryDbTestModule), |
|||
typeof(AbpAspNetCoreMvcModule), |
|||
typeof(AbpAutofacModule) |
|||
)] |
|||
public class AuthTestPage_Tests: AspNetCoreMvcTestBase |
|||
{ |
|||
private readonly FakeUserClaims _fakeRequiredService; |
|||
|
|||
public AuthTestPage_Tests() |
|||
{ |
|||
_fakeRequiredService = GetRequiredService<FakeUserClaims>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Call_Simple_Authorized_Method_With_Authenticated_User() |
|||
{ |
|||
_fakeRequiredService.Claims.AddRange(new[] |
|||
{ |
|||
new Claim(AbpClaimTypes.UserId, AuthTestController.FakeUserId.ToString()) |
|||
}); |
|||
|
|||
var result = await GetResponseAsStringAsync("/Authorization/AuthTestPage"); |
|||
result.ShouldBe("OK"); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue