test(secrets): migrate UI fixtures to bUnit 2.7.2

This commit is contained in:
Joseph Doherty
2026-11-13 14:41:17 -05:00
parent 9bda64ec4b
commit f96104245e
27 changed files with 2438 additions and 58 deletions
+4 -5
View File
@@ -90,11 +90,10 @@
ASP.NET Core version into the graph. -->
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="10.0.7" />
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
<PackageVersion Include="bunit" Version="1.40.0" />
<!-- Transitive security pin (scadaproj#24): bunit 1.40.0 pulls AngleSharp 1.2.0 (NU1902,
GHSA-pgww-w46g-26qg). bUnit 2.x removes RenderComponent/AddTestAuthorization, so pin the
parser instead (same version Theme resolves via bUnit 2.7.2). -->
<PackageVersion Include="AngleSharp" Version="1.5.0" />
<PackageVersion Include="bunit" Version="2.7.2" />
<!-- Test-only patched parser, consumed by an explicit UI test reference. The shared
bUnit 2.7.2 render/query/event probe validates the 1.5.2 combination. -->
<PackageVersion Include="AngleSharp" Version="1.5.2" />
</ItemGroup>
</Project>
@@ -15,7 +15,7 @@ namespace ZB.MOM.WW.Secrets.Ui.Tests;
/// audit shared one try, so a throwing audit sink turned a real rotation into "Unable to rotate the
/// secret.", a <c>Failure</c> audit row, and a resolver still serving the old plaintext.
/// </summary>
public sealed class AuditFailureAfterCommitTests : TestContext
public sealed class AuditFailureAfterCommitTests : BunitContext
{
private (RecordingSecretStore Store, CapturingAuditWriter Audit, RecordingCacheInvalidator Cache) Register()
{
@@ -27,7 +27,7 @@ public sealed class AuditFailureAfterCommitTests : TestContext
Services.AddSingleton<ISecretCipher>(new FakeCipher());
Services.AddSingleton<ISecretCacheInvalidator>(cache);
var auth = this.AddTestAuthorization();
var auth = this.AddAuthorization();
auth.SetAuthorized("carol");
auth.SetPolicies(SecretsAuthorization.ManagePolicy);
return (store, audit, cache);
@@ -40,7 +40,7 @@ public sealed class AuditFailureAfterCommitTests : TestContext
var name = new SecretName("db/central");
bool saved = false;
var cut = RenderComponent<SecretEditor>(p => p
var cut = Render<SecretEditor>(p => p
.Add(c => c.ExistingName, name)
.Add(c => c.OnSaved, () => saved = true));
cut.Find("[data-testid=secret-value]").Change("new-value");
@@ -59,7 +59,7 @@ public sealed class AuditFailureAfterCommitTests : TestContext
var (store, audit, cache) = Register();
bool saved = false;
var cut = RenderComponent<SecretEditor>(p => p.Add(c => c.OnSaved, () => saved = true));
var cut = Render<SecretEditor>(p => p.Add(c => c.OnSaved, () => saved = true));
cut.Find("[data-testid=secret-name]").Change("app/thing");
cut.Find("[data-testid=secret-value]").Change("v");
cut.Find("[data-testid=editor-submit]").Click();
@@ -78,7 +78,7 @@ public sealed class AuditFailureAfterCommitTests : TestContext
var name = new SecretName("db/central");
bool deleted = false;
var cut = RenderComponent<ConfirmDeleteModal>(p => p
var cut = Render<ConfirmDeleteModal>(p => p
.Add(c => c.Visible, true)
.Add(c => c.Name, name)
.Add(c => c.OnDeleted, () => deleted = true));
@@ -17,7 +17,7 @@ namespace ZB.MOM.WW.Secrets.Ui.Tests;
/// definitions in <see cref="SecretsAuthorization.AddSecretsAuthorization"/> are pinned (the bUnit
/// tests elsewhere use <c>SetPolicies</c>, which bypasses them).
/// </summary>
public class ComponentAuthorizationTests : TestContext
public class ComponentAuthorizationTests : BunitContext
{
private const string PlainValue = "the-plaintext-value-42";
@@ -29,7 +29,7 @@ public class ComponentAuthorizationTests : TestContext
Services.AddSingleton<ISecretStore>(store);
Services.AddSingleton<IAuditWriter>(audit);
Services.AddSingleton<ISecretCipher>(cipher);
var auth = this.AddTestAuthorization();
var auth = this.AddAuthorization();
auth.SetAuthorized("eve");
auth.SetPolicies(grantedPolicies);
return (store, audit, cipher);
@@ -46,7 +46,7 @@ public class ComponentAuthorizationTests : TestContext
Revision = 1, CreatedUtc = DateTimeOffset.UnixEpoch, UpdatedUtc = DateTimeOffset.UnixEpoch,
});
var cut = RenderComponent<RevealButton>(p => p.Add(c => c.Name, name));
var cut = Render<RevealButton>(p => p.Add(c => c.Name, name));
cut.Find("button.reveal-secret").Click();
Assert.DoesNotContain(PlainValue, cut.Markup);
@@ -64,7 +64,7 @@ public class ComponentAuthorizationTests : TestContext
Revision = 1, CreatedUtc = DateTimeOffset.UnixEpoch, UpdatedUtc = DateTimeOffset.UnixEpoch,
});
var cut = RenderComponent<RevealButton>(p => p.Add(c => c.Name, name));
var cut = Render<RevealButton>(p => p.Add(c => c.Name, name));
cut.Find("button.reveal-secret").Click();
Assert.Contains(PlainValue, cut.Markup);
@@ -75,7 +75,7 @@ public class ComponentAuthorizationTests : TestContext
{
var (store, audit, _) = Setup(/* no policies */);
var cut = RenderComponent<SecretEditor>(p => p.Add(c => c.OnSaved, () => { }));
var cut = Render<SecretEditor>(p => p.Add(c => c.OnSaved, () => { }));
cut.Find("[data-testid=secret-name]").Change("app/thing");
cut.Find("[data-testid=secret-value]").Change("v");
cut.Find("[data-testid=editor-submit]").Click();
@@ -96,7 +96,7 @@ public class ComponentAuthorizationTests : TestContext
});
bool deleted = false;
var cut = RenderComponent<ConfirmDeleteModal>(p => p
var cut = Render<ConfirmDeleteModal>(p => p
.Add(c => c.Visible, true)
.Add(c => c.Name, name)
.Add(c => c.OnDeleted, () => deleted = true));
@@ -8,7 +8,7 @@ using ZB.MOM.WW.Secrets.Ui.Tests.Fakes;
namespace ZB.MOM.WW.Secrets.Ui.Tests;
public class ConfirmDeleteModalTests : TestContext
public class ConfirmDeleteModalTests : BunitContext
{
[Fact]
public void ConfirmDeleteModal_IsInPageModal_NoJsDialog()
@@ -23,12 +23,12 @@ public class ConfirmDeleteModalTests : TestContext
Services.AddSingleton<IAuditWriter>(audit);
var name = new SecretName("db/primary");
var auth = this.AddTestAuthorization();
var auth = this.AddAuthorization();
auth.SetAuthorized("carol");
auth.SetPolicies(SecretsAuthorization.ManagePolicy);
bool deleted = false;
var cut = RenderComponent<ConfirmDeleteModal>(p => p
var cut = Render<ConfirmDeleteModal>(p => p
.Add(c => c.Visible, true)
.Add(c => c.Name, name)
.Add(c => c.OnDeleted, () => deleted = true));
@@ -63,12 +63,12 @@ public class ConfirmDeleteModalTests : TestContext
Services.AddSingleton<IAuditWriter>(audit);
var name = new SecretName("db/primary");
var auth = this.AddTestAuthorization();
var auth = this.AddAuthorization();
auth.SetAuthorized("carol");
auth.SetPolicies(SecretsAuthorization.ManagePolicy);
bool cancelled = false;
var cut = RenderComponent<ConfirmDeleteModal>(p => p
var cut = Render<ConfirmDeleteModal>(p => p
.Add(c => c.Visible, true)
.Add(c => c.Name, name)
.Add(c => c.OnCancelled, () => cancelled = true));
@@ -92,12 +92,12 @@ public class ConfirmDeleteModalTests : TestContext
Services.AddSingleton<IAuditWriter>(audit);
var name = new SecretName("db/primary");
var auth = this.AddTestAuthorization();
var auth = this.AddAuthorization();
auth.SetAuthorized("carol");
auth.SetPolicies(SecretsAuthorization.ManagePolicy);
bool deleted = false;
var cut = RenderComponent<ConfirmDeleteModal>(p => p
var cut = Render<ConfirmDeleteModal>(p => p
.Add(c => c.Visible, true)
.Add(c => c.Name, name)
.Add(c => c.OnDeleted, () => deleted = true));
@@ -127,9 +127,9 @@ public class ConfirmDeleteModalTests : TestContext
Services.AddSingleton<IAuditWriter>(audit);
var name = new SecretName("db/primary");
this.AddTestAuthorization().SetAuthorized("carol");
this.AddAuthorization().SetAuthorized("carol");
var cut = RenderComponent<ConfirmDeleteModal>(p => p
var cut = Render<ConfirmDeleteModal>(p => p
.Add(c => c.Visible, false)
.Add(c => c.Name, name));
@@ -182,9 +182,9 @@ public class ConfirmDeleteModalTests : TestContext
{
Services.AddSingleton<ISecretStore>(new RecordingSecretStore());
Services.AddSingleton<IAuditWriter>(new CapturingAuditWriter());
this.AddTestAuthorization().SetAuthorized("carol");
this.AddAuthorization().SetAuthorized("carol");
return RenderComponent<ConfirmDeleteModal>(p => p
return Render<ConfirmDeleteModal>(p => p
.Add(c => c.Visible, true)
.Add(c => c.Name, new SecretName("db/primary")));
}
@@ -13,7 +13,7 @@ namespace ZB.MOM.WW.Secrets.Ui.Tests;
/// Secrets-015: a reveal whose audit write fails must not show the plaintext (fail closed), and the
/// failure must be logged — actor and name, never the value.
/// </summary>
public class RevealAuditFailureTests : TestContext
public class RevealAuditFailureTests : BunitContext
{
private const string PlainValue = "the-plaintext-value-42";
@@ -39,7 +39,7 @@ public class RevealAuditFailureTests : TestContext
Services.AddSingleton<IAuditWriter>(audit);
Services.AddSingleton<ISecretCipher>(new FakeCipher());
Services.AddSingleton<ILogger<RevealButton>>(logger);
var auth = this.AddTestAuthorization();
var auth = this.AddAuthorization();
auth.SetAuthorized("mallory");
auth.SetPolicies(SecretsAuthorization.RevealPolicy);
@@ -51,7 +51,7 @@ public class RevealAuditFailureTests : TestContext
UpdatedUtc = DateTimeOffset.UnixEpoch,
});
var cut = RenderComponent<RevealButton>(p => p.Add(c => c.Name, name));
var cut = Render<RevealButton>(p => p.Add(c => c.Name, name));
cut.Find("button.reveal-secret").Click();
Assert.DoesNotContain(PlainValue, cut.Markup);
@@ -8,7 +8,7 @@ using ZB.MOM.WW.Secrets.Ui.Tests.Fakes;
namespace ZB.MOM.WW.Secrets.Ui.Tests;
public class RevealButtonTests : TestContext
public class RevealButtonTests : BunitContext
{
private const string PlainValue = "the-plaintext-value-42";
@@ -38,11 +38,11 @@ public class RevealButtonTests : TestContext
var name = new SecretName("api/token");
store.Seed(Row(name, PlainValue));
var auth = this.AddTestAuthorization();
var auth = this.AddAuthorization();
auth.SetAuthorized("carol");
auth.SetPolicies(SecretsAuthorization.RevealPolicy);
var cut = RenderComponent<RevealButton>(p => p.Add(c => c.Name, name));
var cut = Render<RevealButton>(p => p.Add(c => c.Name, name));
// The value is NOT present before the reveal click.
Assert.DoesNotContain(PlainValue, cut.Markup);
@@ -68,11 +68,11 @@ public class RevealButtonTests : TestContext
var (_, audit, _) = RegisterServices();
var name = new SecretName("api/missing");
var auth = this.AddTestAuthorization();
var auth = this.AddAuthorization();
auth.SetAuthorized("carol");
auth.SetPolicies(SecretsAuthorization.RevealPolicy);
var cut = RenderComponent<RevealButton>(p => p.Add(c => c.Name, name));
var cut = Render<RevealButton>(p => p.Add(c => c.Name, name));
cut.Find("button.reveal-secret").Click();
@@ -93,11 +93,11 @@ public class RevealButtonTests : TestContext
store.Seed(Row(name, PlainValue));
cipher.FailDecrypt = true;
var auth = this.AddTestAuthorization();
var auth = this.AddAuthorization();
auth.SetAuthorized("carol");
auth.SetPolicies(SecretsAuthorization.RevealPolicy);
var cut = RenderComponent<RevealButton>(p => p.Add(c => c.Name, name));
var cut = Render<RevealButton>(p => p.Add(c => c.Name, name));
// The click must not throw into the Blazor event pipeline.
cut.Find("button.reveal-secret").Click();
@@ -13,7 +13,7 @@ namespace ZB.MOM.WW.Secrets.Ui.Tests;
/// description, content type) and audit the overwrite as <c>secret.add</c>. A live row is refused;
/// a tombstoned one is restored only on a second, deliberate submit of the same name.
/// </summary>
public class SecretEditorAddExistingTests : TestContext
public class SecretEditorAddExistingTests : BunitContext
{
private (RecordingSecretStore Store, CapturingAuditWriter Audit, FakeCipher Cipher) Setup()
{
@@ -23,7 +23,7 @@ public class SecretEditorAddExistingTests : TestContext
Services.AddSingleton<ISecretStore>(store);
Services.AddSingleton<IAuditWriter>(audit);
Services.AddSingleton<ISecretCipher>(cipher);
var auth = this.AddTestAuthorization();
var auth = this.AddAuthorization();
auth.SetAuthorized("carol");
auth.SetPolicies(SecretsAuthorization.ManagePolicy);
return (store, audit, cipher);
@@ -41,7 +41,7 @@ public class SecretEditorAddExistingTests : TestContext
private IRenderedComponent<SecretEditor> FillAdd(string name, string value)
{
var cut = RenderComponent<SecretEditor>(p => p.Add(c => c.OnSaved, () => { }));
var cut = Render<SecretEditor>(p => p.Add(c => c.OnSaved, () => { }));
cut.Find("[data-testid=secret-name]").Change(name);
cut.Find("[data-testid=secret-value]").Change(value);
return cut;
@@ -9,7 +9,7 @@ using ZB.MOM.WW.Secrets.Ui.Tests.Fakes;
namespace ZB.MOM.WW.Secrets.Ui.Tests;
public class SecretEditorTests : TestContext
public class SecretEditorTests : BunitContext
{
private const string EnteredValue = "sup3r-s3cret-value!";
@@ -28,11 +28,11 @@ public class SecretEditorTests : TestContext
public void SecretEditor_Add_EncryptsAndUpserts()
{
var (store, audit, cipher) = RegisterServices();
var auth = this.AddTestAuthorization();
var auth = this.AddAuthorization();
auth.SetAuthorized("carol");
auth.SetPolicies(SecretsAuthorization.ManagePolicy);
var cut = RenderComponent<SecretEditor>(p => p
var cut = Render<SecretEditor>(p => p
.Add(c => c.OnSaved, () => { }));
// The value control is a masked password input.
@@ -72,11 +72,11 @@ public class SecretEditorTests : TestContext
{
var (store, audit, cipher) = RegisterServices();
var name = new SecretName("db/primary");
var auth = this.AddTestAuthorization();
var auth = this.AddAuthorization();
auth.SetAuthorized("dave");
auth.SetPolicies(SecretsAuthorization.ManagePolicy);
var cut = RenderComponent<SecretEditor>(p => p
var cut = Render<SecretEditor>(p => p
.Add(c => c.ExistingName, name)
.Add(c => c.OnSaved, () => { }));
@@ -115,11 +115,11 @@ public class SecretEditorTests : TestContext
};
store.Seed(existing);
var auth = this.AddTestAuthorization();
var auth = this.AddAuthorization();
auth.SetAuthorized("dave");
auth.SetPolicies(SecretsAuthorization.ManagePolicy);
var cut = RenderComponent<SecretEditor>(p => p
var cut = Render<SecretEditor>(p => p
.Add(c => c.ExistingName, name)
.Add(c => c.OnSaved, () => { }));
@@ -145,11 +145,11 @@ public class SecretEditorTests : TestContext
var (store, audit, _) = RegisterServices();
store.UpsertFault = new MasterKeyUnavailableException("KEK unavailable.");
var auth = this.AddTestAuthorization();
var auth = this.AddAuthorization();
auth.SetAuthorized("carol");
auth.SetPolicies(SecretsAuthorization.ManagePolicy);
var cut = RenderComponent<SecretEditor>(p => p
var cut = Render<SecretEditor>(p => p
.Add(c => c.OnSaved, () => { }));
cut.Find("[data-testid=secret-name]").Change("app/thing");
@@ -8,7 +8,7 @@ using ZB.MOM.WW.Secrets.Ui.Tests.Fakes;
namespace ZB.MOM.WW.Secrets.Ui.Tests;
public class SecretsListTests : TestContext
public class SecretsListTests : BunitContext
{
private static readonly SecretMetadata SecretOne = new()
{
@@ -47,11 +47,11 @@ public class SecretsListTests : TestContext
public void Renders_Metadata_ForEachSecret()
{
RegisterStore(SecretOne, SecretTwo);
var auth = this.AddTestAuthorization();
var auth = this.AddAuthorization();
auth.SetAuthorized("alice");
auth.SetPolicies(SecretsAuthorization.ManagePolicy);
var cut = RenderComponent<SecretsList>();
var cut = Render<SecretsList>();
var markup = cut.Markup;
Assert.Contains("db/primary", markup);
@@ -67,11 +67,11 @@ public class SecretsListTests : TestContext
public void RevealButton_Hidden_WithoutRevealPolicy()
{
RegisterStore(SecretOne, SecretTwo);
var auth = this.AddTestAuthorization();
var auth = this.AddAuthorization();
auth.SetAuthorized("alice");
auth.SetPolicies(SecretsAuthorization.ManagePolicy);
var cut = RenderComponent<SecretsList>();
var cut = Render<SecretsList>();
Assert.Empty(cut.FindAll("button.reveal-secret"));
Assert.DoesNotContain("Reveal", cut.Markup);
@@ -81,11 +81,11 @@ public class SecretsListTests : TestContext
public void RevealButton_Shown_WithRevealPolicy()
{
RegisterStore(SecretOne, SecretTwo);
var auth = this.AddTestAuthorization();
var auth = this.AddAuthorization();
auth.SetAuthorized("carol");
auth.SetPolicies(SecretsAuthorization.ManagePolicy, SecretsAuthorization.RevealPolicy);
var cut = RenderComponent<SecretsList>();
var cut = Render<SecretsList>();
// One reveal affordance per secret row.
Assert.Equal(2, cut.FindAll("button.reveal-secret").Count);
@@ -95,11 +95,11 @@ public class SecretsListTests : TestContext
public void EmptyList_ShowsEmptyState()
{
RegisterStore();
var auth = this.AddTestAuthorization();
var auth = this.AddAuthorization();
auth.SetAuthorized("alice");
auth.SetPolicies(SecretsAuthorization.ManagePolicy);
var cut = RenderComponent<SecretsList>();
var cut = Render<SecretsList>();
Assert.Contains("No secrets", cut.Markup);
}
@@ -6,6 +6,7 @@
<ItemGroup>
<PackageReference Include="bunit" />
<PackageReference Include="AngleSharp" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />