mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-04-24 14:08:44 -04:00
Test RequiresElevationHandler for all roles
This commit is contained in:
parent
8d06d0dbdf
commit
ef75455178
1 changed files with 38 additions and 0 deletions
|
@ -0,0 +1,38 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Security.Claims;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Jellyfin.Api.Auth.RequiresElevationPolicy;
|
||||||
|
using Jellyfin.Api.Constants;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Jellyfin.Api.Tests.Auth.RequiresElevationPolicy
|
||||||
|
{
|
||||||
|
public class RequiresElevationHandlerTests
|
||||||
|
{
|
||||||
|
private readonly RequiresElevationHandler _sut;
|
||||||
|
|
||||||
|
public RequiresElevationHandlerTests()
|
||||||
|
{
|
||||||
|
_sut = new RequiresElevationHandler();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(UserRoles.Administrator, true)]
|
||||||
|
[InlineData(UserRoles.User, false)]
|
||||||
|
[InlineData(UserRoles.Guest, false)]
|
||||||
|
public async Task ShouldHandleRolesCorrectly(string role, bool shouldSucceed)
|
||||||
|
{
|
||||||
|
var requirements = new List<IAuthorizationRequirement> {new RequiresElevationRequirement()};
|
||||||
|
|
||||||
|
var claims = new[] {new Claim(ClaimTypes.Role, role)};
|
||||||
|
var identity = new ClaimsIdentity(claims);
|
||||||
|
var user = new ClaimsPrincipal(identity);
|
||||||
|
|
||||||
|
var context = new AuthorizationHandlerContext(requirements, user, null);
|
||||||
|
|
||||||
|
await _sut.HandleAsync(context);
|
||||||
|
Assert.Equal(shouldSucceed, context.HasSucceeded);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue