Replaces the plugin template with a working plugin that lets several users share one viewing account while keeping their individual watched lists accurate. Three pieces: - Auto-creating groups. Logging in as "alice+bob" with any named member's own password provisions the shared account and signs you in. Verified against 10.11.5: AuthenticateUser offers unmatched usernames to every enabled provider and re-queries afterwards, which is the hook this relies on. Gated on a real member password so knowing two usernames is not enough to create an account. - Multi-password authentication. IRequiresResolvedUser hands us the resolved shared account; each member's live stored hash is checked via ICryptoProvider.Verify. Deliberately avoids re-entering UserManager.AuthenticateUser, which would trip every member's failed-attempt counter whenever a different member's password matched. - One-way played-state sync. Shared account to members only, filtered to PlaybackFinished/TogglePlayed/Import so playback progress ticks are ignored. No loop guard needed: member writes carry a non-shared id. Membership is stored as user IDs rather than re-parsed from the username, so shared accounts can be renamed freely. The +/name collision resolves itself because Jellyfin only consults the plugin when no local user matches the typed name. Targets Jellyfin 10.11.x / net9.0. Adds Gitea CI (test, build, release), a builder image, and 34 tests covering the auth and sync rules.
75 lines
2.5 KiB
C#
75 lines
2.5 KiB
C#
using System;
|
|
using System.IO;
|
|
using Jellyfin.Plugin.WatchedTogether.Configuration;
|
|
using MediaBrowser.Common.Configuration;
|
|
using MediaBrowser.Model.Serialization;
|
|
using Moq;
|
|
using Xunit;
|
|
|
|
namespace Jellyfin.Plugin.WatchedTogether.Tests;
|
|
|
|
/// <summary>
|
|
/// Marks tests that read or write the process-wide <see cref="Plugin.Instance"/>, so xUnit runs
|
|
/// them serially rather than letting parallel classes clobber each other's configuration.
|
|
/// </summary>
|
|
[CollectionDefinition(nameof(PluginTestContext))]
|
|
public class PluginTestCollection : ICollectionFixture<object>
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Constructs a real <see cref="Plugin"/> backed by a temporary directory so that services reading
|
|
/// <see cref="Plugin.Instance"/> have configuration to work with, and cleans up afterwards.
|
|
/// </summary>
|
|
public sealed class PluginTestContext : IDisposable
|
|
{
|
|
private readonly string _configDirectory;
|
|
|
|
private PluginTestContext(Plugin plugin, string configDirectory)
|
|
{
|
|
Plugin = plugin;
|
|
_configDirectory = configDirectory;
|
|
}
|
|
|
|
public Plugin Plugin { get; }
|
|
|
|
public PluginConfiguration Configuration => Plugin.Configuration;
|
|
|
|
public static PluginTestContext Create()
|
|
{
|
|
var dir = Path.Combine(Path.GetTempPath(), "wt-tests-" + Guid.NewGuid().ToString("N"));
|
|
Directory.CreateDirectory(dir);
|
|
|
|
// BasePlugin<T> derives its data folder from PluginsPath and its config file from
|
|
// PluginConfigurationsPath, so both must resolve to a real directory.
|
|
var paths = new Mock<IApplicationPaths>();
|
|
paths.SetupGet(p => p.PluginConfigurationsPath).Returns(dir);
|
|
paths.SetupGet(p => p.PluginsPath).Returns(dir);
|
|
|
|
// BasePlugin persists configuration through the serializer; a stub keeps tests off disk
|
|
// while still letting UpdateConfiguration succeed.
|
|
var serializer = new Mock<IXmlSerializer>();
|
|
serializer.Setup(s => s.DeserializeFromFile(It.IsAny<Type>(), It.IsAny<string>()))
|
|
.Returns(new PluginConfiguration());
|
|
|
|
var plugin = new Plugin(paths.Object, serializer.Object);
|
|
|
|
return new PluginTestContext(plugin, dir);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
try
|
|
{
|
|
if (Directory.Exists(_configDirectory))
|
|
{
|
|
Directory.Delete(_configDirectory, recursive: true);
|
|
}
|
|
}
|
|
catch (IOException)
|
|
{
|
|
// A leftover temp directory is not worth failing a test over.
|
|
}
|
|
}
|
|
}
|