test(ui): retain ScadaBridge synthetic consumer validation host

This commit is contained in:
Joseph Doherty
2026-11-13 19:43:32 -05:00
parent e61af09c2e
commit 3c1eada677
22 changed files with 579 additions and 0 deletions
@@ -0,0 +1,61 @@
using System.Security.Claims;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.Extensions.FileProviders;
using ScadaBridgeUiCanary.Components;
using ZB.MOM.WW.ScadaBridge.CentralUI.Components.Shared;
using ZB.MOM.WW.Theme;
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.UseStaticWebAssets();
builder.Services.AddRazorComponents().AddInteractiveServerComponents();
builder.Services.AddDataProtection().UseEphemeralDataProtectionProvider();
builder.Services.AddAuthorizationCore(options => ZB.MOM.WW.Secrets.Ui.SecretsAuthorization.AddSecretsAuthorization(options));
ZB.MOM.WW.ScadaBridge.Security.AuthorizationPolicies.AddScadaBridgeAuthorization(builder.Services);
builder.Services.AddCascadingAuthenticationState();
builder.Services.AddScoped<AuthenticationStateProvider, LocalAnonymousState>();
builder.Services.AddScoped<IDialogService, DialogService>();
builder.Services.AddSingleton(ReadOnlyFixtureProxy.EmptyReads<ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories.INotificationRepository>());
builder.Services.AddSingleton(ReadOnlyFixtureProxy.EmptyReads<ZB.MOM.WW.ScadaBridge.CentralUI.Services.ISchemaLibraryQueryService>());
builder.Services.AddScoped(_ => ReadOnlyFixtureProxy.EmptyReads<ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories.ISiteRepository>());
builder.Services.AddScoped(_ => ReadOnlyFixtureProxy.EmptyReads<ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories.ITemplateEngineRepository>());
builder.Services.AddScoped(_ => ReadOnlyFixtureProxy.EmptyReads<ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Security.IInboundApiKeyAdmin>("ListAsync"));
builder.Services.AddScoped(_ => ReadOnlyFixtureProxy.EmptyReads<ZB.MOM.WW.ScadaBridge.CentralUI.Services.IAuditLogQueryService>());
BatchThreeFixtures.Register(builder.Services);
SecretsCanaryFixtures.Register(builder.Services);
var app = builder.Build();
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(Path.Combine(
builder.Configuration["Canary:ScadaBridgeRoot"] ?? "/Users/dohertj2/Desktop/ScadaBridge",
"src/ZB.MOM.WW.ScadaBridge.Host/wwwroot"))
});
app.UseStaticFiles();
app.UseAntiforgery();
app.MapGet("/canary-provenance", () => new
{
purpose = "Disposable local component canary; not the complete ScadaBridge application",
themeAssembly = typeof(ThemeShell).Assembly.GetName().Version?.ToString(),
centralUiAssembly = typeof(DialogHost).Assembly.GetName().Version?.ToString(),
data = "Synthetic local only; no SQL, Akka, LDAP or fleet services registered",
source = "Authorized ScadaBridge checkout via project reference"
});
app.MapGet("/auth/ping", () => Results.Ok());
app.MapPost("/auth/activity", () => Results.NoContent());
app.MapPost("/auth/login", () => Results.StatusCode(405));
app.MapPost("/auth/logout", () => Results.StatusCode(405));
app.MapRazorComponents<App>().AddInteractiveServerRenderMode();
app.Run();
internal sealed class LocalAnonymousState(Microsoft.AspNetCore.Components.NavigationManager navigation) : AuthenticationStateProvider
{
public override Task<AuthenticationState> GetAuthenticationStateAsync()
{
// Fixture-only role selection. No real authentication endpoint or external identity is used.
var query = Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(new Uri(navigation.Uri).Query);
var roles = query.TryGetValue("role", out var value) ? value.ToString().Split(',') : [];
var claims = roles.Select(role => new Claim(ZB.MOM.WW.ScadaBridge.Security.JwtTokenService.RoleClaimType, role)).ToList();
claims.Add(new Claim(ZB.MOM.WW.ScadaBridge.Security.JwtTokenService.UsernameClaimType, "local synthetic identity"));
return Task.FromResult(new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity(claims, roles.Length > 0 ? "LocalFixture" : null))));
}
}