mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-06-03 14:28:46 +01:00
Merge remote-tracking branch 'jellyfin/master' into emby-namig-nullable
This commit is contained in:
@@ -8,6 +8,7 @@ using Jellyfin.Api.Auth;
|
||||
using Jellyfin.Api.Constants;
|
||||
using Jellyfin.Data.Entities;
|
||||
using Jellyfin.Data.Enums;
|
||||
using MediaBrowser.Controller.Authentication;
|
||||
using MediaBrowser.Controller.Net;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -68,14 +69,14 @@ namespace Jellyfin.Api.Tests.Auth
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HandleAuthenticateAsyncShouldFailOnSecurityException()
|
||||
public async Task HandleAuthenticateAsyncShouldFailOnAuthenticationException()
|
||||
{
|
||||
var errorMessage = _fixture.Create<string>();
|
||||
|
||||
_jellyfinAuthServiceMock.Setup(
|
||||
a => a.Authenticate(
|
||||
It.IsAny<HttpRequest>()))
|
||||
.Throws(new SecurityException(errorMessage));
|
||||
.Throws(new AuthenticationException(errorMessage));
|
||||
|
||||
var authenticateResult = await _sut.AuthenticateAsync();
|
||||
|
||||
@@ -128,6 +129,7 @@ namespace Jellyfin.Api.Tests.Auth
|
||||
var authorizationInfo = _fixture.Create<AuthorizationInfo>();
|
||||
authorizationInfo.User = _fixture.Create<User>();
|
||||
authorizationInfo.User.SetPermission(PermissionKind.IsAdministrator, isAdmin);
|
||||
authorizationInfo.IsApiKey = false;
|
||||
|
||||
_jellyfinAuthServiceMock.Setup(
|
||||
a => a.Authenticate(
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoFixture" Version="4.13.0" />
|
||||
<PackageReference Include="AutoFixture.AutoMoq" Version="4.13.0" />
|
||||
<PackageReference Include="AutoFixture.Xunit2" Version="4.13.0" />
|
||||
<PackageReference Include="AutoFixture" Version="4.14.0" />
|
||||
<PackageReference Include="AutoFixture.AutoMoq" Version="4.14.0" />
|
||||
<PackageReference Include="AutoFixture.Xunit2" Version="4.14.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.1.9" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="3.1.9" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace Jellyfin.Api.Tests
|
||||
{
|
||||
new Claim(ClaimTypes.Role, role),
|
||||
new Claim(ClaimTypes.Name, "jellyfin"),
|
||||
new Claim(InternalClaimTypes.UserId, Guid.Empty.ToString("N", CultureInfo.InvariantCulture)),
|
||||
new Claim(InternalClaimTypes.UserId, Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture)),
|
||||
new Claim(InternalClaimTypes.DeviceId, Guid.Empty.ToString("N", CultureInfo.InvariantCulture)),
|
||||
new Claim(InternalClaimTypes.Device, "test"),
|
||||
new Claim(InternalClaimTypes.Client, "test"),
|
||||
|
||||
@@ -11,82 +11,82 @@ namespace Jellyfin.Common.Tests.Json
|
||||
[Fact]
|
||||
public static void Deserialize_String_Valid_Success()
|
||||
{
|
||||
var desiredValue = new GenericBodyModel<string>
|
||||
var desiredValue = new GenericBodyArrayModel<string>
|
||||
{
|
||||
Value = new[] { "a", "b", "c" }
|
||||
};
|
||||
|
||||
var options = new JsonSerializerOptions();
|
||||
var value = JsonSerializer.Deserialize<GenericBodyModel<string>>(@"{ ""Value"": ""a,b,c"" }", options);
|
||||
var value = JsonSerializer.Deserialize<GenericBodyArrayModel<string>>(@"{ ""Value"": ""a,b,c"" }", options);
|
||||
Assert.Equal(desiredValue.Value, value?.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void Deserialize_String_Space_Valid_Success()
|
||||
{
|
||||
var desiredValue = new GenericBodyModel<string>
|
||||
var desiredValue = new GenericBodyArrayModel<string>
|
||||
{
|
||||
Value = new[] { "a", "b", "c" }
|
||||
};
|
||||
|
||||
var options = new JsonSerializerOptions();
|
||||
var value = JsonSerializer.Deserialize<GenericBodyModel<string>>(@"{ ""Value"": ""a, b, c"" }", options);
|
||||
var value = JsonSerializer.Deserialize<GenericBodyArrayModel<string>>(@"{ ""Value"": ""a, b, c"" }", options);
|
||||
Assert.Equal(desiredValue.Value, value?.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void Deserialize_GenericCommandType_Valid_Success()
|
||||
{
|
||||
var desiredValue = new GenericBodyModel<GeneralCommandType>
|
||||
var desiredValue = new GenericBodyArrayModel<GeneralCommandType>
|
||||
{
|
||||
Value = new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown }
|
||||
};
|
||||
|
||||
var options = new JsonSerializerOptions();
|
||||
options.Converters.Add(new JsonStringEnumConverter());
|
||||
var value = JsonSerializer.Deserialize<GenericBodyModel<GeneralCommandType>>(@"{ ""Value"": ""MoveUp,MoveDown"" }", options);
|
||||
var value = JsonSerializer.Deserialize<GenericBodyArrayModel<GeneralCommandType>>(@"{ ""Value"": ""MoveUp,MoveDown"" }", options);
|
||||
Assert.Equal(desiredValue.Value, value?.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void Deserialize_GenericCommandType_Space_Valid_Success()
|
||||
{
|
||||
var desiredValue = new GenericBodyModel<GeneralCommandType>
|
||||
var desiredValue = new GenericBodyArrayModel<GeneralCommandType>
|
||||
{
|
||||
Value = new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown }
|
||||
};
|
||||
|
||||
var options = new JsonSerializerOptions();
|
||||
options.Converters.Add(new JsonStringEnumConverter());
|
||||
var value = JsonSerializer.Deserialize<GenericBodyModel<GeneralCommandType>>(@"{ ""Value"": ""MoveUp, MoveDown"" }", options);
|
||||
var value = JsonSerializer.Deserialize<GenericBodyArrayModel<GeneralCommandType>>(@"{ ""Value"": ""MoveUp, MoveDown"" }", options);
|
||||
Assert.Equal(desiredValue.Value, value?.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void Deserialize_String_Array_Valid_Success()
|
||||
{
|
||||
var desiredValue = new GenericBodyModel<string>
|
||||
var desiredValue = new GenericBodyArrayModel<string>
|
||||
{
|
||||
Value = new[] { "a", "b", "c" }
|
||||
};
|
||||
|
||||
var options = new JsonSerializerOptions();
|
||||
var value = JsonSerializer.Deserialize<GenericBodyModel<string>>(@"{ ""Value"": [""a"",""b"",""c""] }", options);
|
||||
var value = JsonSerializer.Deserialize<GenericBodyArrayModel<string>>(@"{ ""Value"": [""a"",""b"",""c""] }", options);
|
||||
Assert.Equal(desiredValue.Value, value?.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void Deserialize_GenericCommandType_Array_Valid_Success()
|
||||
{
|
||||
var desiredValue = new GenericBodyModel<GeneralCommandType>
|
||||
var desiredValue = new GenericBodyArrayModel<GeneralCommandType>
|
||||
{
|
||||
Value = new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown }
|
||||
};
|
||||
|
||||
var options = new JsonSerializerOptions();
|
||||
options.Converters.Add(new JsonStringEnumConverter());
|
||||
var value = JsonSerializer.Deserialize<GenericBodyModel<GeneralCommandType>>(@"{ ""Value"": [""MoveUp"", ""MoveDown""] }", options);
|
||||
var value = JsonSerializer.Deserialize<GenericBodyArrayModel<GeneralCommandType>>(@"{ ""Value"": [""MoveUp"", ""MoveDown""] }", options);
|
||||
Assert.Equal(desiredValue.Value, value?.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Jellyfin.Common.Tests.Models;
|
||||
using MediaBrowser.Model.Session;
|
||||
using Xunit;
|
||||
|
||||
namespace Jellyfin.Common.Tests.Json
|
||||
{
|
||||
public static class JsonCommaDelimitedIReadOnlyListTests
|
||||
{
|
||||
[Fact]
|
||||
public static void Deserialize_String_Valid_Success()
|
||||
{
|
||||
var desiredValue = new GenericBodyIReadOnlyListModel<string>
|
||||
{
|
||||
Value = new[] { "a", "b", "c" }
|
||||
};
|
||||
|
||||
var options = new JsonSerializerOptions();
|
||||
var value = JsonSerializer.Deserialize<GenericBodyIReadOnlyListModel<string>>(@"{ ""Value"": ""a,b,c"" }", options);
|
||||
Assert.Equal(desiredValue.Value, value?.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void Deserialize_String_Space_Valid_Success()
|
||||
{
|
||||
var desiredValue = new GenericBodyIReadOnlyListModel<string>
|
||||
{
|
||||
Value = new[] { "a", "b", "c" }
|
||||
};
|
||||
|
||||
var options = new JsonSerializerOptions();
|
||||
var value = JsonSerializer.Deserialize<GenericBodyIReadOnlyListModel<string>>(@"{ ""Value"": ""a, b, c"" }", options);
|
||||
Assert.Equal(desiredValue.Value, value?.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void Deserialize_GenericCommandType_Valid_Success()
|
||||
{
|
||||
var desiredValue = new GenericBodyIReadOnlyListModel<GeneralCommandType>
|
||||
{
|
||||
Value = new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown }
|
||||
};
|
||||
|
||||
var options = new JsonSerializerOptions();
|
||||
options.Converters.Add(new JsonStringEnumConverter());
|
||||
var value = JsonSerializer.Deserialize<GenericBodyIReadOnlyListModel<GeneralCommandType>>(@"{ ""Value"": ""MoveUp,MoveDown"" }", options);
|
||||
Assert.Equal(desiredValue.Value, value?.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void Deserialize_GenericCommandType_Space_Valid_Success()
|
||||
{
|
||||
var desiredValue = new GenericBodyIReadOnlyListModel<GeneralCommandType>
|
||||
{
|
||||
Value = new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown }
|
||||
};
|
||||
|
||||
var options = new JsonSerializerOptions();
|
||||
options.Converters.Add(new JsonStringEnumConverter());
|
||||
var value = JsonSerializer.Deserialize<GenericBodyIReadOnlyListModel<GeneralCommandType>>(@"{ ""Value"": ""MoveUp, MoveDown"" }", options);
|
||||
Assert.Equal(desiredValue.Value, value?.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void Deserialize_String_Array_Valid_Success()
|
||||
{
|
||||
var desiredValue = new GenericBodyIReadOnlyListModel<string>
|
||||
{
|
||||
Value = new[] { "a", "b", "c" }
|
||||
};
|
||||
|
||||
var options = new JsonSerializerOptions();
|
||||
var value = JsonSerializer.Deserialize<GenericBodyIReadOnlyListModel<string>>(@"{ ""Value"": [""a"",""b"",""c""] }", options);
|
||||
Assert.Equal(desiredValue.Value, value?.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void Deserialize_GenericCommandType_Array_Valid_Success()
|
||||
{
|
||||
var desiredValue = new GenericBodyIReadOnlyListModel<GeneralCommandType>
|
||||
{
|
||||
Value = new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown }
|
||||
};
|
||||
|
||||
var options = new JsonSerializerOptions();
|
||||
options.Converters.Add(new JsonStringEnumConverter());
|
||||
var value = JsonSerializer.Deserialize<GenericBodyIReadOnlyListModel<GeneralCommandType>>(@"{ ""Value"": [""MoveUp"", ""MoveDown""] }", options);
|
||||
Assert.Equal(desiredValue.Value, value?.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ namespace Jellyfin.Common.Tests.Models
|
||||
/// The generic body model.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The value type.</typeparam>
|
||||
public class GenericBodyModel<T>
|
||||
public class GenericBodyArrayModel<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the value.
|
||||
@@ -17,4 +17,4 @@ namespace Jellyfin.Common.Tests.Models
|
||||
[JsonConverter(typeof(JsonCommaDelimitedArrayConverterFactory))]
|
||||
public T[] Value { get; set; } = default!;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json.Serialization;
|
||||
using MediaBrowser.Common.Json.Converters;
|
||||
|
||||
namespace Jellyfin.Common.Tests.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// The generic body <c>IReadOnlyList</c> model.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The value type.</typeparam>
|
||||
public class GenericBodyIReadOnlyListModel<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the value.
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(JsonCommaDelimitedArrayConverterFactory))]
|
||||
public IReadOnlyList<T> Value { get; set; } = default!;
|
||||
}
|
||||
}
|
||||
@@ -14,8 +14,8 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoFixture" Version="4.13.0" />
|
||||
<PackageReference Include="AutoFixture.AutoMoq" Version="4.13.0" />
|
||||
<PackageReference Include="AutoFixture" Version="4.14.0" />
|
||||
<PackageReference Include="AutoFixture.AutoMoq" Version="4.14.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
|
||||
<PackageReference Include="Moq" Version="4.14.7" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
|
||||
Reference in New Issue
Block a user