SessionManagerTests.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using System;
  2. using System.Threading.Tasks;
  3. using Jellyfin.Database.Implementations.Entities;
  4. using MediaBrowser.Controller;
  5. using MediaBrowser.Controller.Configuration;
  6. using MediaBrowser.Controller.Devices;
  7. using MediaBrowser.Controller.Drawing;
  8. using MediaBrowser.Controller.Dto;
  9. using MediaBrowser.Controller.Events;
  10. using MediaBrowser.Controller.Library;
  11. using MediaBrowser.Controller.Session;
  12. using Microsoft.Extensions.Hosting;
  13. using Microsoft.Extensions.Logging.Abstractions;
  14. using Moq;
  15. using Xunit;
  16. namespace Jellyfin.Server.Implementations.Tests.SessionManager;
  17. public class SessionManagerTests
  18. {
  19. [Theory]
  20. [InlineData("", typeof(ArgumentException))]
  21. [InlineData(null, typeof(ArgumentNullException))]
  22. public async Task GetAuthorizationToken_Should_ThrowException(string? deviceId, Type exceptionType)
  23. {
  24. await using var sessionManager = new Emby.Server.Implementations.Session.SessionManager(
  25. NullLogger<Emby.Server.Implementations.Session.SessionManager>.Instance,
  26. Mock.Of<IEventManager>(),
  27. Mock.Of<IUserDataManager>(),
  28. Mock.Of<IServerConfigurationManager>(),
  29. Mock.Of<ILibraryManager>(),
  30. Mock.Of<IUserManager>(),
  31. Mock.Of<IMusicManager>(),
  32. Mock.Of<IDtoService>(),
  33. Mock.Of<IImageProcessor>(),
  34. Mock.Of<IServerApplicationHost>(),
  35. Mock.Of<IDeviceManager>(),
  36. Mock.Of<IMediaSourceManager>(),
  37. Mock.Of<IHostApplicationLifetime>());
  38. await Assert.ThrowsAsync(exceptionType, () => sessionManager.GetAuthorizationToken(
  39. new User("test", "default", "default"),
  40. deviceId,
  41. "app_name",
  42. "0.0.0",
  43. "device_name"));
  44. }
  45. [Theory]
  46. [MemberData(nameof(AuthenticateNewSessionInternal_Exception_TestData))]
  47. public async Task AuthenticateNewSessionInternal_Should_ThrowException(AuthenticationRequest authenticationRequest, Type exceptionType)
  48. {
  49. await using var sessionManager = new Emby.Server.Implementations.Session.SessionManager(
  50. NullLogger<Emby.Server.Implementations.Session.SessionManager>.Instance,
  51. Mock.Of<IEventManager>(),
  52. Mock.Of<IUserDataManager>(),
  53. Mock.Of<IServerConfigurationManager>(),
  54. Mock.Of<ILibraryManager>(),
  55. Mock.Of<IUserManager>(),
  56. Mock.Of<IMusicManager>(),
  57. Mock.Of<IDtoService>(),
  58. Mock.Of<IImageProcessor>(),
  59. Mock.Of<IServerApplicationHost>(),
  60. Mock.Of<IDeviceManager>(),
  61. Mock.Of<IMediaSourceManager>(),
  62. Mock.Of<IHostApplicationLifetime>());
  63. await Assert.ThrowsAsync(exceptionType, () => sessionManager.AuthenticateNewSessionInternal(authenticationRequest, false));
  64. }
  65. public static TheoryData<AuthenticationRequest, Type> AuthenticateNewSessionInternal_Exception_TestData()
  66. {
  67. var data = new TheoryData<AuthenticationRequest, Type>
  68. {
  69. {
  70. new AuthenticationRequest { App = string.Empty, DeviceId = "device_id", DeviceName = "device_name", AppVersion = "app_version" },
  71. typeof(ArgumentException)
  72. },
  73. {
  74. new AuthenticationRequest { App = null, DeviceId = "device_id", DeviceName = "device_name", AppVersion = "app_version" },
  75. typeof(ArgumentNullException)
  76. },
  77. {
  78. new AuthenticationRequest { App = "app_name", DeviceId = string.Empty, DeviceName = "device_name", AppVersion = "app_version" },
  79. typeof(ArgumentException)
  80. },
  81. {
  82. new AuthenticationRequest { App = "app_name", DeviceId = null, DeviceName = "device_name", AppVersion = "app_version" },
  83. typeof(ArgumentNullException)
  84. },
  85. {
  86. new AuthenticationRequest { App = "app_name", DeviceId = "device_id", DeviceName = string.Empty, AppVersion = "app_version" },
  87. typeof(ArgumentException)
  88. },
  89. {
  90. new AuthenticationRequest { App = "app_name", DeviceId = "device_id", DeviceName = null, AppVersion = "app_version" },
  91. typeof(ArgumentNullException)
  92. },
  93. {
  94. new AuthenticationRequest { App = "app_name", DeviceId = "device_id", DeviceName = "device_name", AppVersion = string.Empty },
  95. typeof(ArgumentException)
  96. },
  97. {
  98. new AuthenticationRequest { App = "app_name", DeviceId = "device_id", DeviceName = "device_name", AppVersion = null },
  99. typeof(ArgumentNullException)
  100. }
  101. };
  102. return data;
  103. }
  104. }