fix(secrets-ui): align fields, confirmation lifecycle and list recovery

This commit is contained in:
Joseph Doherty
2026-11-13 17:02:22 -05:00
parent cb424a0ce7
commit 510d15d546
64 changed files with 4376 additions and 97 deletions
@@ -0,0 +1,7 @@
<!DOCTYPE html>
<html lang="en"><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width,initial-scale=1" /><base href="/" />
<link rel="stylesheet" href="/fixture-bootstrap/bootstrap.min.css" />
<ThemeHead /><title>Secrets synthetic acceptance fixture</title>
<style>body{margin:0}.fixture-main{padding:1.5rem;max-width:92rem;margin:auto;min-width:0}.fixture-note{font-size:.85rem;color:var(--ink-muted)}.fixture-transform{transform:translateZ(0)}.visually-hidden{position:absolute!important;width:1px;height:1px;overflow:hidden;clip:rect(0,0,0,0)}</style>
<HeadOutlet @rendermode="InteractiveServer" /></head><body><div class="fixture-main fixture-transform"><p class="fixture-note">Synthetic local fixture · bootstrap · No production data or services</p>
<Routes @rendermode="InteractiveServer" /></div><ThemeScripts /><script src="/_framework/blazor.web.js"></script></body></html>
@@ -0,0 +1,6 @@
<ErrorBoundary><div data-fixture-ready="@(_ready ? "true" : "false")">@ChildContent</div></ErrorBoundary>
@code {
[Parameter] public RenderFragment? ChildContent { get; set; }
private bool _ready;
protected override void OnAfterRender(bool firstRender) { if (firstRender) { _ready = true; StateHasChanged(); } }
}
@@ -0,0 +1,3 @@
@page "/admin/secrets"
@attribute [Authorize(Policy = SecretsAuthorization.ManagePolicy)]
<PageErrorBoundary><SecretsPage /></PageErrorBoundary>
@@ -0,0 +1 @@
<Router AppAssembly="typeof(App).Assembly"><Found Context="routeData"><AuthorizeRouteView RouteData="routeData"><NotAuthorized><p role="status">Synthetic principal is not authorized.</p></NotAuthorized></AuthorizeRouteView></Found><NotFound><p>Fixture route not found.</p></NotFound></Router>
@@ -0,0 +1,9 @@
@using Microsoft.AspNetCore.Components
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.AspNetCore.Authorization
@using static Microsoft.AspNetCore.Components.Web.RenderMode
@using ZB.MOM.WW.Theme
@using ZB.MOM.WW.Secrets.Ui
@using SecretsUiFixture.Components
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup><TargetFramework>net10.0</TargetFramework><ImplicitUsings>enable</ImplicitUsings><Nullable>enable</Nullable><RootNamespace>SecretsUiFixture</RootNamespace><OtOpcUaRoot Condition="'$(OtOpcUaRoot)' == ''">/Users/dohertj2/Desktop/OtOpcUa</OtOpcUaRoot></PropertyGroup>
<ItemGroup>
<ProjectReference Condition="'$(SecretsUiPackageVersion)' == ''" Include="../../../../../../ZB.MOM.WW.Secrets/src/ZB.MOM.WW.Secrets.Ui/ZB.MOM.WW.Secrets.Ui.csproj" />
<PackageReference Condition="'$(SecretsUiPackageVersion)' != ''" Include="ZB.MOM.WW.Secrets.Ui" Version="$(SecretsUiPackageVersion)" />
<PackageReference Include="ZB.MOM.WW.Theme" Version="1.0.0" />
<Compile Include="../shared/*.cs" Link="%(Filename)%(Extension)" />
<Compile Include="../../../../../../ZB.MOM.WW.Secrets/tests/ZB.MOM.WW.Secrets.Ui.Tests/Fakes/FakeCipher.cs" Link="Fakes/FakeCipher.cs" />
<Compile Include="../../../../../../ZB.MOM.WW.Secrets/tests/ZB.MOM.WW.Secrets.Ui.Tests/Fakes/RecordingSecretStore.cs" Link="Fakes/RecordingSecretStore.cs" />
<Compile Include="../../../../../../ZB.MOM.WW.Secrets/tests/ZB.MOM.WW.Secrets.Ui.Tests/Fakes/RecordingCacheInvalidator.cs" Link="Fakes/RecordingCacheInvalidator.cs" />
<Compile Include="../../../../../../ZB.MOM.WW.Secrets/tests/ZB.MOM.WW.Secrets.Ui.Tests/Fakes/CapturingAuditWriter.cs" Link="Fakes/CapturingAuditWriter.cs" />
</ItemGroup></Project>
@@ -0,0 +1,7 @@
<!DOCTYPE html>
<html lang="en"><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width,initial-scale=1" /><base href="/" />
<ThemeHead /><title>Secrets synthetic acceptance fixture</title>
<style>body{margin:0}.fixture-main{padding:1.5rem;max-width:92rem;margin:auto;min-width:0}.fixture-note{font-size:.85rem;color:var(--ink-muted)}.fixture-transform{transform:translateZ(0)}.visually-hidden{position:absolute!important;width:1px;height:1px;overflow:hidden;clip:rect(0,0,0,0)}</style>
<HeadOutlet /></head><body><div class="fixture-main fixture-transform"><p class="fixture-note">Synthetic local fixture · perpage · No production data or services</p>
<Routes /></div><ThemeScripts /><script src="/_framework/blazor.web.js"></script></body></html>
@@ -0,0 +1,6 @@
<ErrorBoundary><div data-fixture-ready="@(_ready ? "true" : "false")">@ChildContent</div></ErrorBoundary>
@code {
[Parameter] public RenderFragment? ChildContent { get; set; }
private bool _ready;
protected override void OnAfterRender(bool firstRender) { if (firstRender) { _ready = true; StateHasChanged(); } }
}
@@ -0,0 +1 @@
<Router AppAssembly="typeof(App).Assembly"><Found Context="routeData"><AuthorizeRouteView RouteData="routeData"><NotAuthorized><p role="status">Synthetic principal is not authorized.</p></NotAuthorized></AuthorizeRouteView></Found><NotFound><p>Fixture route not found.</p></NotFound></Router>
@@ -0,0 +1,9 @@
@using Microsoft.AspNetCore.Components
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.AspNetCore.Authorization
@using static Microsoft.AspNetCore.Components.Web.RenderMode
@using ZB.MOM.WW.Theme
@using ZB.MOM.WW.Secrets.Ui
@using SecretsUiFixture.Components
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup><TargetFramework>net10.0</TargetFramework><ImplicitUsings>enable</ImplicitUsings><Nullable>enable</Nullable><RootNamespace>SecretsUiFixture</RootNamespace><OtOpcUaRoot Condition="'$(OtOpcUaRoot)' == ''">/Users/dohertj2/Desktop/OtOpcUa</OtOpcUaRoot></PropertyGroup>
<ItemGroup>
<ProjectReference Condition="'$(SecretsUiPackageVersion)' == ''" Include="../../../../../../ZB.MOM.WW.Secrets/src/ZB.MOM.WW.Secrets.Ui/ZB.MOM.WW.Secrets.Ui.csproj" />
<PackageReference Condition="'$(SecretsUiPackageVersion)' != ''" Include="ZB.MOM.WW.Secrets.Ui" Version="$(SecretsUiPackageVersion)" />
<PackageReference Include="ZB.MOM.WW.Theme" Version="1.0.0" />
<Compile Include="../shared/*.cs" Link="%(Filename)%(Extension)" />
<Compile Include="../../../../../../ZB.MOM.WW.Secrets/tests/ZB.MOM.WW.Secrets.Ui.Tests/Fakes/FakeCipher.cs" Link="Fakes/FakeCipher.cs" />
<Compile Include="../../../../../../ZB.MOM.WW.Secrets/tests/ZB.MOM.WW.Secrets.Ui.Tests/Fakes/RecordingSecretStore.cs" Link="Fakes/RecordingSecretStore.cs" />
<Compile Include="../../../../../../ZB.MOM.WW.Secrets/tests/ZB.MOM.WW.Secrets.Ui.Tests/Fakes/RecordingCacheInvalidator.cs" Link="Fakes/RecordingCacheInvalidator.cs" />
<Compile Include="../../../../../../ZB.MOM.WW.Secrets/tests/ZB.MOM.WW.Secrets.Ui.Tests/Fakes/CapturingAuditWriter.cs" Link="Fakes/CapturingAuditWriter.cs" />
<RazorComponent Include="$(OtOpcUaRoot)/src/Server/ZB.MOM.WW.OtOpcUa.AdminUI/Components/Pages/SecretsAdmin.razor" Link="Components/Pages/SecretsAdmin.razor" />
</ItemGroup></Project>
@@ -0,0 +1,38 @@
using System.Security.Claims;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.WebUtilities;
using ZB.MOM.WW.Secrets.Ui;
namespace SecretsUiFixture;
internal sealed class SyntheticAuthentication(NavigationManager navigation) : AuthenticationStateProvider
{
public override Task<AuthenticationState> GetAuthenticationStateAsync()
{
var query = QueryHelpers.ParseQuery(new Uri(navigation.Uri).Query);
string role = query.TryGetValue("role", out var value) ? value.ToString() : "reveal";
return Task.FromResult(new AuthenticationState(SyntheticIdentity.ForRole(role)));
}
}
internal sealed record FaultSettings(bool List = false, bool Write = false, bool Audit = false, int DelayMs = 0);
internal static class SyntheticIdentity
{
internal static ClaimsPrincipal ForRole(string role)
{
var claims = new List<Claim> { new(ClaimTypes.Name, "synthetic-reviewer") };
if (role == "manage") claims.Add(new(ClaimTypes.Role, SecretsAuthorization.ManageRole));
if (role == "reveal") claims.Add(new(ClaimTypes.Role, SecretsAuthorization.RevealRole));
return new ClaimsPrincipal(new ClaimsIdentity(claims, "local-synthetic-fixture"));
}
}
internal sealed class SyntheticHandler(Microsoft.Extensions.Options.IOptionsMonitor<Microsoft.AspNetCore.Authentication.AuthenticationSchemeOptions> options,
ILoggerFactory logger, System.Text.Encodings.Web.UrlEncoder encoder)
: Microsoft.AspNetCore.Authentication.AuthenticationHandler<Microsoft.AspNetCore.Authentication.AuthenticationSchemeOptions>(options, logger, encoder)
{
protected override Task<Microsoft.AspNetCore.Authentication.AuthenticateResult> HandleAuthenticateAsync()
{
string role = Request.Query.TryGetValue("role", out var value) ? value.ToString() : "reveal";
return Task.FromResult(Microsoft.AspNetCore.Authentication.AuthenticateResult.Success(
new Microsoft.AspNetCore.Authentication.AuthenticationTicket(SyntheticIdentity.ForRole(role), Scheme.Name)));
}
}
@@ -0,0 +1,48 @@
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.Extensions.FileProviders;
using SecretsUiFixture;
using SecretsUiFixture.Components;
using ZB.MOM.WW.Audit;
using ZB.MOM.WW.Secrets.Abstractions;
using ZB.MOM.WW.Secrets.Ui;
using ZB.MOM.WW.Secrets.Ui.Tests.Fakes;
using ZB.MOM.WW.Theme;
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.UseStaticWebAssets();
builder.Services.AddRazorComponents().AddInteractiveServerComponents();
builder.Services.AddDataProtection().UseEphemeralDataProtectionProvider();
builder.Services.AddAuthentication("synthetic").AddScheme<Microsoft.AspNetCore.Authentication.AuthenticationSchemeOptions, SyntheticHandler>("synthetic", _ => { });
builder.Services.AddAuthorization(options => options.AddSecretsAuthorization());
builder.Services.AddCascadingAuthenticationState();
builder.Services.AddScoped<AuthenticationStateProvider, SyntheticAuthentication>();
var store = new RecordingSecretStore();
var cipher = new FakeCipher();
var audit = new CapturingAuditWriter();
foreach (string name in new[] { "app/alpha", "app/bravo", "app/" + new string('x', 160) })
store.Seed(cipher.Encrypt(new SecretName(name), "synthetic-fixture-value", SecretContentType.Text) with
{ Description = "Illustrative local metadata", UpdatedBy = "synthetic-reviewer", UpdatedUtc = DateTimeOffset.Parse("2026-11-13T12:00:00Z") });
builder.Services.AddSingleton<ISecretStore>(store);
builder.Services.AddSingleton<ISecretCipher>(cipher);
builder.Services.AddSingleton<IAuditWriter>(audit);
builder.Services.AddSingleton<ISecretCacheInvalidator>(new RecordingCacheInvalidator());
var app = builder.Build();
string bootstrap = builder.Configuration["Fixture:BootstrapRoot"] ?? "/Users/dohertj2/Desktop/ScadaBridge/src/ZB.MOM.WW.ScadaBridge.Host/wwwroot/lib/bootstrap/css";
if (Directory.Exists(bootstrap)) app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(bootstrap), RequestPath = "/fixture-bootstrap" });
app.UseStaticFiles();
app.UseAntiforgery();
app.MapGet("/fixture/provenance", () => new { purpose = "Loopback synthetic Secrets UI acceptance fixture; not a production host", theme = typeof(ThemeHead).Assembly.GetName().Version?.ToString(), ui = typeof(SecretsPage).Assembly.GetName().Version?.ToString(), store = "In-memory fake only; no keys, LDAP, SQL, network services or production credentials", bootstrap });
app.MapPost("/fixture/faults", (FaultSettings faults) =>
{
store.ListFault = faults.List ? new IOException("synthetic metadata outage") : null;
store.UpsertFault = faults.Write ? new IOException("synthetic write outage") : null;
store.DeleteFault = faults.Write ? new IOException("synthetic delete outage") : null;
audit.SuccessFault = faults.Audit ? new IOException("synthetic audit outage") : null;
int delay = Math.Clamp(faults.DelayMs, 0, 10000);
store.UpsertOverride = (_, ct) => Task.Delay(delay, ct);
store.DeleteOverride = (_, _, ct) => Task.Delay(delay, ct);
return Results.NoContent();
});
app.MapGet("/fixture/counts", () => new { lists = store.ListCalls, upserts = store.Upserts.Count, deletes = store.Deletes.Count, audits = audit.Events.Select(e => new { e.Action, e.Target, e.DetailsJson, e.Outcome }) });
app.MapRazorComponents<App>().AddInteractiveServerRenderMode();
app.Run();