Files
ScadaBridge/tests/ZB.MOM.WW.ScadaBridge.CentralUI.Tests/Services/AuthorizedManualFailoverTests.cs
T
Joseph Doherty 513fa1aa16 docs(tests): fix CommentChecker findings across tests/ — 13,392 → 0 (repo-wide scan clean)
Comment/XML-doc changes only:
- add summaries to ~10k test methods, fixtures, fakes and helpers
  (+ <param> on theories, <returns> on async Task methods,
  <inheritdoc/> on interface implementations the checker can resolve)
- strip ~2.6k project-tracking references (WP*, P*-*, row-NN, Task N,
  #NN, Component-0NN) from comments, keeping the explanatory text;
  reword false positives in comments only
- real docs on fakes implementing BCL/library interfaces
  (IDisposable, ILogger, IOptionsMonitor, IAsyncLifetime)
- reword the last 5 src/ false positives (CWE-1236, failures-1,
  year-0001, M365)

Only non-comment edits: four one-line nested classes split across lines
so members can carry docs. Build 0 errors / 0 warnings.
2026-10-07 15:05:49 -04:00

31 lines
1.6 KiB
C#

using System.Security.Claims;
using Microsoft.AspNetCore.Components.Authorization;
using NSubstitute;
using ZB.MOM.WW.ScadaBridge.CentralUI.Services;
using ZB.MOM.WW.ScadaBridge.Security;
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Services;
public class AuthorizedManualFailoverTests
{
/// <summary>Verifies that an administrator whose role has been revoked cannot dispatch a manual failover to central or a site.</summary>
/// <param name="site">True to target a site failover, or false to target the central cluster.</param>
/// <returns>A task that represents the asynchronous operation.</returns>
[Theory]
[InlineData(false)]
[InlineData(true)]
public async Task RevokedAdmin_CannotDispatchCentralOrSite(bool site)
{
var auth = Substitute.For<AuthenticationStateProvider>();
var identity = new ClaimsIdentity([new Claim(JwtTokenService.RoleClaimType, Roles.Administrator)], "test");
auth.GetAuthenticationStateAsync().Returns(new AuthenticationState(new ClaimsPrincipal(identity)));
var backend = Substitute.For<IManualFailoverService>();
var service = new AuthorizedManualFailoverService(auth, backend);
identity.RemoveClaim(identity.FindFirst(JwtTokenService.RoleClaimType)!);
if (site) await Assert.ThrowsAsync<UnauthorizedAccessException>(() => service.FailOverSiteAsync("plant"));
else await Assert.ThrowsAsync<UnauthorizedAccessException>(() => service.FailOverCentralAsync());
await backend.DidNotReceiveWithAnyArgs().FailOverCentralAsync(default!);
await backend.DidNotReceiveWithAnyArgs().FailOverSiteAsync(default!, default!);
}
}