using System.Runtime.CompilerServices; using System.Security.Claims; using Microsoft.AspNetCore.Components.Authorization; using ZB.MOM.WW.MxGateway.Server.Dashboard; using ZB.MOM.WW.MxGateway.Server.Security.Authentication; using ZB.MOM.WW.MxGateway.Server.Security.Authorization; internal sealed class StubSnapshotService : IDashboardSnapshotService { /// public DashboardSnapshot GetSnapshot() => new( GeneratedAt: DateTimeOffset.UnixEpoch, GatewayStartedAt: DateTimeOffset.UnixEpoch, GatewayUptime: TimeSpan.Zero, GatewayStatus: "Healthy", GatewayVersion: "test", Sessions: [], Workers: [], Metrics: [], Faults: [], ApiKeys: [ new DashboardApiKeySummary( KeyId: "synthetic-tagged", DisplayName: "Tags only", Scopes: new HashSet(StringComparer.Ordinal), Constraints: ApiKeyConstraints.Empty with { DashboardTags = ["team-a", "team-b"] }, CreatedUtc: DateTimeOffset.UnixEpoch, LastUsedUtc: null, RevokedUtc: null), new DashboardApiKeySummary( KeyId: "synthetic-plain", DisplayName: "Unconstrained", Scopes: new HashSet(StringComparer.Ordinal), Constraints: ApiKeyConstraints.Empty, CreatedUtc: DateTimeOffset.UnixEpoch, LastUsedUtc: null, RevokedUtc: null), ], Configuration: null!, Galaxy: null!); /// public IAsyncEnumerable WatchSnapshotsAsync(CancellationToken cancellationToken) => new IdleSnapshotFeed().WatchAsync(cancellationToken); } // Parks until the page is disposed, so the base page's watch loop neither spins nor pushes a // second snapshot mid-render. internal sealed class IdleSnapshotFeed : IDashboardSnapshotFeed { /// public async IAsyncEnumerable WatchAsync( [EnumeratorCancellation] CancellationToken cancellationToken) { await Task.Delay(Timeout.Infinite, cancellationToken).ConfigureAwait(false); yield break; } } // Grants management so the create dialog is reachable; no test here exercises a mutation. internal sealed class ManagingApiKeyService : IDashboardApiKeyManagementService { /// public bool CanManage(ClaimsPrincipal user) => true; /// public Task CreateAsync( ClaimsPrincipal user, DashboardApiKeyManagementRequest request, CancellationToken cancellationToken) => Task.FromResult(DashboardApiKeyManagementResult.Fail("not exercised")); /// public Task RevokeAsync( ClaimsPrincipal user, string keyId, CancellationToken cancellationToken) => Task.FromResult(DashboardApiKeyManagementResult.Fail("not exercised")); /// public Task RotateAsync( ClaimsPrincipal user, string keyId, CancellationToken cancellationToken) => Task.FromResult(DashboardApiKeyManagementResult.Fail("not exercised")); /// public Task DeleteAsync( ClaimsPrincipal user, string keyId, CancellationToken cancellationToken) => Task.FromResult(DashboardApiKeyManagementResult.Fail("not exercised")); } internal sealed class StubAuthenticationStateProvider : AuthenticationStateProvider { /// public override Task GetAuthenticationStateAsync() => Task.FromResult(new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity( [new Claim(ClaimTypes.Name, "admin-user"), new Claim(ClaimTypes.Role, DashboardRoles.Admin)], authenticationType: "test", nameType: ClaimTypes.Name, roleType: ClaimTypes.Role)))); }