You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.7 KiB
72 lines
2.7 KiB
5 years ago
|
using System.Collections.Generic;
|
||
|
using System.Threading.Tasks;
|
||
|
using AutoFixture;
|
||
|
using AutoFixture.AutoMoq;
|
||
2 years ago
|
using Jellyfin.Api.Auth.FirstTimeSetupPolicy;
|
||
5 years ago
|
using Jellyfin.Api.Constants;
|
||
|
using MediaBrowser.Common.Configuration;
|
||
4 years ago
|
using MediaBrowser.Controller.Library;
|
||
5 years ago
|
using Microsoft.AspNetCore.Authorization;
|
||
4 years ago
|
using Microsoft.AspNetCore.Http;
|
||
5 years ago
|
using Moq;
|
||
|
using Xunit;
|
||
|
|
||
2 years ago
|
namespace Jellyfin.Api.Tests.Auth.FirstTimeSetupPolicy
|
||
5 years ago
|
{
|
||
2 years ago
|
public class FirstTimeSetupHandlerTests
|
||
5 years ago
|
{
|
||
|
private readonly Mock<IConfigurationManager> _configurationManagerMock;
|
||
|
private readonly List<IAuthorizationRequirement> _requirements;
|
||
2 years ago
|
private readonly FirstTimeSetupHandler _firstTimeSetupHandler;
|
||
4 years ago
|
private readonly Mock<IUserManager> _userManagerMock;
|
||
|
private readonly Mock<IHttpContextAccessor> _httpContextAccessor;
|
||
5 years ago
|
|
||
2 years ago
|
public FirstTimeSetupHandlerTests()
|
||
5 years ago
|
{
|
||
|
var fixture = new Fixture().Customize(new AutoMoqCustomization());
|
||
|
_configurationManagerMock = fixture.Freeze<Mock<IConfigurationManager>>();
|
||
2 years ago
|
_requirements = new List<IAuthorizationRequirement> { new FirstTimeSetupRequirement() };
|
||
4 years ago
|
_userManagerMock = fixture.Freeze<Mock<IUserManager>>();
|
||
|
_httpContextAccessor = fixture.Freeze<Mock<IHttpContextAccessor>>();
|
||
5 years ago
|
|
||
2 years ago
|
_firstTimeSetupHandler = fixture.Create<FirstTimeSetupHandler>();
|
||
5 years ago
|
}
|
||
|
|
||
|
[Theory]
|
||
|
[InlineData(UserRoles.Administrator)]
|
||
|
[InlineData(UserRoles.Guest)]
|
||
|
[InlineData(UserRoles.User)]
|
||
|
public async Task ShouldSucceedIfStartupWizardIncomplete(string userRole)
|
||
|
{
|
||
4 years ago
|
TestHelpers.SetupConfigurationManager(_configurationManagerMock, false);
|
||
4 years ago
|
var claims = TestHelpers.SetupUser(
|
||
4 years ago
|
_userManagerMock,
|
||
|
_httpContextAccessor,
|
||
4 years ago
|
userRole);
|
||
4 years ago
|
|
||
|
var context = new AuthorizationHandlerContext(_requirements, claims, null);
|
||
5 years ago
|
|
||
2 years ago
|
await _firstTimeSetupHandler.HandleAsync(context);
|
||
5 years ago
|
Assert.True(context.HasSucceeded);
|
||
|
}
|
||
|
|
||
|
[Theory]
|
||
|
[InlineData(UserRoles.Administrator, true)]
|
||
|
[InlineData(UserRoles.Guest, false)]
|
||
|
[InlineData(UserRoles.User, false)]
|
||
|
public async Task ShouldRequireAdministratorIfStartupWizardComplete(string userRole, bool shouldSucceed)
|
||
|
{
|
||
4 years ago
|
TestHelpers.SetupConfigurationManager(_configurationManagerMock, true);
|
||
4 years ago
|
var claims = TestHelpers.SetupUser(
|
||
4 years ago
|
_userManagerMock,
|
||
|
_httpContextAccessor,
|
||
4 years ago
|
userRole);
|
||
4 years ago
|
|
||
|
var context = new AuthorizationHandlerContext(_requirements, claims, null);
|
||
5 years ago
|
|
||
2 years ago
|
await _firstTimeSetupHandler.HandleAsync(context);
|
||
5 years ago
|
Assert.Equal(shouldSucceed, context.HasSucceeded);
|
||
|
}
|
||
|
}
|
||
|
}
|