Authenticates the scan progress hub connections

This commit is contained in:
BinaryAlley committed 2026-09-03 12:51:35 -07:00
1 parent f882f9192f
commit 44d37d71e2
3 files changed
+78 -61

No files matched your search

@@ -4,6 +4,7 @@ using Microsoft.AspNetCore.SignalR;
using NSubstitute;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Security.Claims;
using System.Threading;
using System.Threading.Tasks;
#endregion
@@ -17,9 +18,9 @@ namespace Lumina.Infrastructure.UnitTests.Core.MediaLibrary.Management.Scanning.
public class MediaLibraryScanProgressHubTests
{
[Fact]
public async Task SubscribeToScan_WhenCalled_ShouldAddTheConnectionToTheScanGroup()
public async Task SubscribeToScan_WhenCalled_ShouldAddTheConnectionToTheGroupOfTheAuthenticatedUser()
{
// Arrange
// Arrange.
MediaLibraryScanProgressHub sut = new();
HubCallerContext context = Substitute.For<HubCallerContext>();
context.ConnectionId.Returns("connection-1");
@@ -28,11 +29,14 @@ public class MediaLibraryScanProgressHubTests
sut.Groups = groupManager;
Guid scanId = Guid.NewGuid();
Guid userId = Guid.NewGuid();
// The user is always taken from the authenticated connection, never from the client.
ClaimsPrincipal user = new(new ClaimsIdentity([new Claim(ClaimTypes.NameIdentifier, userId.ToString())]));
context.User.Returns(user);
// Act
await sut.SubscribeToScan(scanId, userId);
// Act.
await sut.SubscribeToScan(scanId);
// Assert
// Assert.
await groupManager.Received(1).AddToGroupAsync("connection-1", $"{scanId}-{userId}", CancellationToken.None);
}
}