aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Jellyfin.Api.Tests/Controllers/DynamicHlsControllerTests.cs29
-rw-r--r--tests/Jellyfin.Server.Implementations.Tests/Security/AuthenticationManagerTests.cs80
2 files changed, 109 insertions, 0 deletions
diff --git a/tests/Jellyfin.Api.Tests/Controllers/DynamicHlsControllerTests.cs b/tests/Jellyfin.Api.Tests/Controllers/DynamicHlsControllerTests.cs
index 5f5f273f12..a9f85739bc 100644
--- a/tests/Jellyfin.Api.Tests/Controllers/DynamicHlsControllerTests.cs
+++ b/tests/Jellyfin.Api.Tests/Controllers/DynamicHlsControllerTests.cs
@@ -3,6 +3,7 @@ using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Api.Controllers;
using MediaBrowser.Controller.MediaEncoding;
+using MediaBrowser.Model.Entities;
using Microsoft.Extensions.Logging.Abstractions;
using Xunit;
@@ -11,6 +12,34 @@ namespace Jellyfin.Api.Tests.Controllers
public class DynamicHlsControllerTests
{
[Theory]
+ [InlineData(8, 1, "smpte2084", false, "hvc1")]
+ [InlineData(8, 1, "smpte2084", true, "hvc1")]
+ [InlineData(8, 2, "bt709", false, "hvc1")]
+ [InlineData(8, 4, "arib-std-b67", false, "hvc1")]
+ [InlineData(8, 6, "smpte2084", false, "hvc1")]
+ [InlineData(5, 0, "smpte2084", false, "dvh1")]
+ [InlineData(7, 6, "smpte2084", false, "dvh1")]
+ [InlineData(null, null, "smpte2084", false, "dvh1")]
+ public void GetDolbyVisionHevcCodecTag_SelectsTagForProfile(int? profile, int? compatibilityId, string transfer, bool hdr10Plus, string expected)
+ {
+ var stream = new MediaStream
+ {
+ Codec = "hevc",
+ Type = MediaStreamType.Video,
+ RpuPresentFlag = 1,
+ BlPresentFlag = 1,
+ ColorSpace = "bt2020nc",
+ ColorPrimaries = "bt2020",
+ ColorTransfer = transfer,
+ DvProfile = profile,
+ DvBlSignalCompatibilityId = compatibilityId,
+ Hdr10PlusPresentFlag = hdr10Plus
+ };
+
+ Assert.Equal(expected, DynamicHlsController.GetDolbyVisionHevcCodecTag(stream));
+ }
+
+ [Theory]
[MemberData(nameof(GetSegmentLengths_Success_TestData))]
public void GetSegmentLengths_Success(long runtimeTicks, int segmentlength, double[] expected)
{
diff --git a/tests/Jellyfin.Server.Implementations.Tests/Security/AuthenticationManagerTests.cs b/tests/Jellyfin.Server.Implementations.Tests/Security/AuthenticationManagerTests.cs
new file mode 100644
index 0000000000..e46b88c67e
--- /dev/null
+++ b/tests/Jellyfin.Server.Implementations.Tests/Security/AuthenticationManagerTests.cs
@@ -0,0 +1,80 @@
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+using Jellyfin.Database.Implementations;
+using Jellyfin.Database.Implementations.Locking;
+using Jellyfin.Database.Providers.Sqlite;
+using Jellyfin.Server.Implementations.Security;
+using Microsoft.Data.Sqlite;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Logging.Abstractions;
+using Moq;
+using Xunit;
+
+namespace Jellyfin.Server.Implementations.Tests.Security
+{
+ public sealed class AuthenticationManagerTests : IDisposable
+ {
+ private readonly SqliteConnection _connection;
+ private readonly DbContextOptions<JellyfinDbContext> _dbOptions;
+ private readonly AuthenticationManager _authenticationManager;
+
+ public AuthenticationManagerTests()
+ {
+ _connection = new SqliteConnection("Data Source=:memory:");
+ _connection.Open();
+
+ _dbOptions = new DbContextOptionsBuilder<JellyfinDbContext>()
+ .UseSqlite(_connection)
+ .Options;
+
+ // Create the schema
+ using var ctx = CreateDbContext();
+ ctx.Database.EnsureCreated();
+
+ var factory = new Mock<IDbContextFactory<JellyfinDbContext>>();
+ factory.Setup(f => f.CreateDbContext()).Returns(CreateDbContext);
+ factory.Setup(f => f.CreateDbContextAsync(It.IsAny<CancellationToken>()))
+ .ReturnsAsync(CreateDbContext);
+
+ _authenticationManager = new AuthenticationManager(factory.Object);
+ }
+
+ public void Dispose()
+ {
+ _connection.Dispose();
+ }
+
+ private JellyfinDbContext CreateDbContext()
+ {
+ return new JellyfinDbContext(
+ _dbOptions,
+ NullLogger<JellyfinDbContext>.Instance,
+ new SqliteDatabaseProvider(null!, NullLogger<SqliteDatabaseProvider>.Instance),
+ new NoLockBehavior(NullLogger<NoLockBehavior>.Instance));
+ }
+
+ [Fact]
+ public async Task CreateApiKey_ReturnsInfoMatchingStoredKey()
+ {
+ var created = await _authenticationManager.CreateApiKey("test-app");
+
+ Assert.Equal("test-app", created.AppName);
+ Assert.False(string.IsNullOrEmpty(created.AccessToken));
+
+ var keys = await _authenticationManager.GetApiKeys();
+ var stored = Assert.Single(keys);
+ Assert.Equal(created.AppName, stored.AppName);
+ Assert.Equal(created.AccessToken, stored.AccessToken);
+ }
+
+ [Fact]
+ public async Task CreateApiKey_WithMultipleKeys_ReturnsDistinctTokens()
+ {
+ var first = await _authenticationManager.CreateApiKey("app1");
+ var second = await _authenticationManager.CreateApiKey("app2");
+
+ Assert.NotEqual(first.AccessToken, second.AccessToken);
+ }
+ }
+}