fix(accounts): restore AccountSecurity.CurrentAlgorithm after each test case

AccountPasswordTests mutates the process-wide AccountSecurity.CurrentAlgorithm
static in every test case and never restored it. The class shares the
"Sequential UOContent Tests" collection with ~45 other test classes;
DisableParallelization serialises them but gives no isolation between classes,
so whichever algorithm a case last set leaked into whatever ran next. Nothing
reads CurrentAlgorithm elsewhere today, but Tasks 6 and 7 add rehash tests to
this same file that will.

Capture the ambient algorithm in the constructor and restore it via
IDisposable so xUnit's per-test-case construct/dispose cycle resets it
automatically -- tests added later to this file inherit the restoration
without having to opt in.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Kamron Batman 2026-08-07 16:33:18 -07:00
parent 970cd42699
commit 1b0bdcf609

View file

@ -1,3 +1,4 @@
using System;
using Server.Accounting;
using Server.Accounting.Security;
using Xunit;
@ -5,10 +6,19 @@ using Xunit;
namespace Server.Tests.Accounting;
[Collection("Sequential UOContent Tests")]
public class AccountPasswordTests
public class AccountPasswordTests : IDisposable
{
private const string Password = "hunter2";
// AccountSecurity.CurrentAlgorithm is process-wide static state, shared with every other
// class in the "Sequential UOContent Tests" collection. xUnit constructs/disposes this class
// once per test case, so capturing and restoring it here means every case -- current and any
// added later to this file -- starts from and leaves behind the ambient value, instead of
// bleeding whatever algorithm it last set into the rest of the collection.
private readonly PasswordProtectionAlgorithm _originalAlgorithm = AccountSecurity.CurrentAlgorithm;
public void Dispose() => AccountSecurity.CurrentAlgorithm = _originalAlgorithm;
[Theory]
[InlineData(PasswordProtectionAlgorithm.SHA1)]
[InlineData(PasswordProtectionAlgorithm.SHA2)]