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("synthetic", _ => { }); builder.Services.AddAuthorization(options => options.AddSecretsAuthorization()); builder.Services.AddCascadingAuthenticationState(); builder.Services.AddScoped(); 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', 400) }) store.Seed(cipher.Encrypt(new SecretName(name), name.Length > 100 ? new string('s', 800) : "synthetic-fixture-value", SecretContentType.Text) with { Description = "Illustrative local metadata", KekId = name.Length > 100 ? "synthetic-kek-" + new string('k', 100) : "fake-kek", UpdatedBy = name.Length > 100 ? "synthetic-reviewer-" + new string('u', 100) : "synthetic-reviewer", UpdatedUtc = DateTimeOffset.Parse("2026-11-13T12:00:00Z") }); builder.Services.AddSingleton(store); builder.Services.AddSingleton(cipher); builder.Services.AddSingleton(audit); builder.Services.AddSingleton(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.BeforeGetAsync = (_, ct) => Task.Delay(Math.Clamp(faults.ReadDelayMs, 0, 10000), ct); store.UpsertOverride = (_, ct) => Task.Delay(delay, ct); store.DeleteOverride = (_, _, ct) => Task.Delay(delay, ct); return Results.NoContent(); }); app.MapGet("/fixture/counts", () => new { gets = store.Gets.Count, 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().AddInteractiveServerRenderMode(); app.Run();