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.
This commit is contained in:
@@ -14,7 +14,7 @@ using ZB.MOM.WW.ScadaBridge.CentralUI.Auth;
|
||||
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Auth;
|
||||
|
||||
/// <summary>
|
||||
/// Regression tests for CentralUI-017. <c>POST /auth/logout</c> called
|
||||
/// Regression tests for the logout CSRF fix. <c>POST /auth/logout</c> called
|
||||
/// <c>.DisableAntiforgery()</c> and a plain <c>GET /logout</c> route also
|
||||
/// signed the user out — either could be triggered cross-site to forcibly log
|
||||
/// a user out. Logout is a state-changing authenticated action and must be
|
||||
@@ -48,6 +48,7 @@ public class AuthEndpointsCsrfTests
|
||||
e.RoutePattern.RawText == pattern &&
|
||||
(e.Metadata.GetMetadata<HttpMethodMetadata>()?.HttpMethods.Contains(method) ?? false));
|
||||
|
||||
/// <summary>Verifies that the logout POST route does not disable antiforgery validation.</summary>
|
||||
[Fact]
|
||||
public void PostAuthLogout_DoesNotDisableAntiforgery()
|
||||
{
|
||||
@@ -63,6 +64,7 @@ public class AuthEndpointsCsrfTests
|
||||
"POST /auth/logout must keep antiforgery validation enabled.");
|
||||
}
|
||||
|
||||
/// <summary>Verifies that the state-changing GET logout route has been removed.</summary>
|
||||
[Fact]
|
||||
public void GetLogout_StateChangingRoute_IsRemoved()
|
||||
{
|
||||
@@ -72,6 +74,8 @@ public class AuthEndpointsCsrfTests
|
||||
Assert.Null(getLogout);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that a login POST with a valid antiforgery token authenticates the user and sets the session cookie.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task PostAuthLogin_ValidTokenAuthenticatesAndSetsCookie()
|
||||
{
|
||||
@@ -105,6 +109,8 @@ public class AuthEndpointsCsrfTests
|
||||
Assert.Contains(context.Response.Headers.SetCookie, value => value!.StartsWith(".AspNetCore.Cookies="));
|
||||
}
|
||||
|
||||
/// <summary>Verifies that a login POST with a missing antiforgery token is rejected before any credential lookup occurs.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task PostAuthLogin_MissingTokenRejectsBeforeCredentialLookup()
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@ using ZB.MOM.WW.ScadaBridge.CentralUI.Auth;
|
||||
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Auth;
|
||||
|
||||
/// <summary>
|
||||
/// Regression tests for CentralUI-020. The Blazor circuit's
|
||||
/// Regression tests for session-expiry detection. The Blazor circuit's
|
||||
/// <c>CookieAuthenticationStateProvider</c> serves a frozen constructor-time
|
||||
/// principal, so <c>SessionExpiry</c> could never observe a server-side cookie
|
||||
/// expiry by polling the auth state. The fix adds <c>GET /auth/ping</c>, an
|
||||
@@ -43,6 +43,7 @@ public class AuthPingEndpointTests
|
||||
e.RoutePattern.RawText == pattern &&
|
||||
(e.Metadata.GetMetadata<HttpMethodMetadata>()?.HttpMethods.Contains(method) ?? false));
|
||||
|
||||
/// <summary>Verifies that the GET route for the auth ping endpoint is mapped.</summary>
|
||||
[Fact]
|
||||
public void AuthPing_GetRoute_IsMapped()
|
||||
{
|
||||
@@ -50,6 +51,8 @@ public class AuthPingEndpointTests
|
||||
Assert.NotNull(ping);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that an anonymous user receives a 401 response from the auth ping endpoint.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task AuthPing_AnonymousUser_Returns401()
|
||||
{
|
||||
@@ -63,6 +66,8 @@ public class AuthPingEndpointTests
|
||||
Assert.Equal(StatusCodes.Status401Unauthorized, context.Response.StatusCode);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that an authenticated user receives a 200 response from the auth ping endpoint.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task AuthPing_AuthenticatedUser_Returns200()
|
||||
{
|
||||
@@ -78,6 +83,7 @@ public class AuthPingEndpointTests
|
||||
Assert.Equal(StatusCodes.Status200OK, context.Response.StatusCode);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that the auth ping endpoint returns a status code instead of redirecting through the cookie middleware.</summary>
|
||||
[Fact]
|
||||
public void AuthPing_DoesNotTriggerCookieRedirect()
|
||||
{
|
||||
|
||||
@@ -14,6 +14,8 @@ namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Auth;
|
||||
|
||||
public class CircuitRevocationRegressionTests
|
||||
{
|
||||
/// <summary>Verifies that an explicit server auto-login does not remap the synthetic cookie principal.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task ExplicitServerAutoLogin_DoesNotRemapSyntheticCookiePrincipal()
|
||||
{
|
||||
@@ -38,6 +40,8 @@ public class CircuitRevocationRegressionTests
|
||||
await mapper.DidNotReceive().MapAsync(Arg.Any<IReadOnlyList<string>>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
/// <summary>Verifies that the same circuit rechecks role mapping and site scope after a grant is revoked.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task SameCircuit_RechecksMappingAndScope_AfterGrantRevocation()
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@ using ZB.MOM.WW.ScadaBridge.Security;
|
||||
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Auth;
|
||||
|
||||
/// <summary>
|
||||
/// Regression tests for CentralUI-024. Ten components each copy-pasted a
|
||||
/// Regression tests for the shared claim lookups. Ten components each copy-pasted a
|
||||
/// <c>GetCurrentUserAsync</c> helper using the magic string
|
||||
/// <c>FindFirst("Username")</c>, and <c>NavMenu</c>/<c>Dashboard</c> used
|
||||
/// <c>FindFirst("DisplayName")</c>. A rename of the claim type in
|
||||
@@ -20,6 +20,7 @@ public class ClaimsPrincipalExtensionsTests
|
||||
private static ClaimsPrincipal Principal(params Claim[] claims)
|
||||
=> new(new ClaimsIdentity(claims, authenticationType: "TestCookie"));
|
||||
|
||||
/// <summary>Verifies that the username lookup resolves the claim the JWT token service issues.</summary>
|
||||
[Fact]
|
||||
public void GetUsername_ResolvesTheJwtTokenServiceUsernameClaim()
|
||||
{
|
||||
@@ -29,6 +30,7 @@ public class ClaimsPrincipalExtensionsTests
|
||||
Assert.Equal("alice", principal.GetUsername());
|
||||
}
|
||||
|
||||
/// <summary>Verifies that the username lookup falls back to unknown when the claim is absent.</summary>
|
||||
[Fact]
|
||||
public void GetUsername_FallsBackToUnknown_WhenClaimAbsent()
|
||||
{
|
||||
@@ -37,6 +39,7 @@ public class ClaimsPrincipalExtensionsTests
|
||||
Assert.Equal(ClaimsPrincipalExtensions.UnknownUser, principal.GetUsername());
|
||||
}
|
||||
|
||||
/// <summary>Verifies that the display-name lookup resolves the claim the JWT token service issues.</summary>
|
||||
[Fact]
|
||||
public void GetDisplayName_ResolvesTheJwtTokenServiceDisplayNameClaim()
|
||||
{
|
||||
@@ -46,12 +49,15 @@ public class ClaimsPrincipalExtensionsTests
|
||||
Assert.Equal("Alice Anderson", principal.GetDisplayName());
|
||||
}
|
||||
|
||||
/// <summary>Verifies that the display-name lookup returns null when the claim is absent.</summary>
|
||||
[Fact]
|
||||
public void GetDisplayName_IsNull_WhenClaimAbsent()
|
||||
{
|
||||
Assert.Null(Principal().GetDisplayName());
|
||||
}
|
||||
|
||||
/// <summary>Verifies that the current-username lookup reads the username from the authentication state.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task GetCurrentUsernameAsync_ReadsUsernameFromAuthState()
|
||||
{
|
||||
@@ -63,6 +69,7 @@ public class ClaimsPrincipalExtensionsTests
|
||||
Assert.Equal("bob", await provider.GetCurrentUsernameAsync());
|
||||
}
|
||||
|
||||
/// <summary>Verifies that the username lookup follows a rename of the claim type in the JWT token service.</summary>
|
||||
[Fact]
|
||||
public void Username_LookupTracksAJwtTokenServiceRename()
|
||||
{
|
||||
@@ -81,7 +88,10 @@ public class ClaimsPrincipalExtensionsTests
|
||||
private sealed class StubAuthStateProvider : AuthenticationStateProvider
|
||||
{
|
||||
private readonly AuthenticationState _state;
|
||||
/// <summary>Initializes the provider with a fixed authentication state.</summary>
|
||||
/// <param name="state">The authentication state to return.</param>
|
||||
public StubAuthStateProvider(AuthenticationState state) => _state = state;
|
||||
/// <inheritdoc />
|
||||
public override Task<AuthenticationState> GetAuthenticationStateAsync()
|
||||
=> Task.FromResult(_state);
|
||||
}
|
||||
|
||||
+7
-1
@@ -5,7 +5,7 @@ using ZB.MOM.WW.ScadaBridge.CentralUI.Auth;
|
||||
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Auth;
|
||||
|
||||
/// <summary>
|
||||
/// Regression tests for CentralUI-004. The provider used to read
|
||||
/// Regression tests for the cookie authentication state provider. The provider used to read
|
||||
/// <see cref="IHttpContextAccessor.HttpContext"/> on every call; once the Blazor
|
||||
/// circuit is established that context is gone, so later re-evaluations saw an
|
||||
/// unauthenticated principal. The provider must snapshot the principal once at
|
||||
@@ -21,6 +21,8 @@ public class CookieAuthenticationStateProviderTests
|
||||
return new ClaimsPrincipal(identity);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that the provider returns the authenticated user while the HTTP context is present.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task GetAuthenticationStateAsync_ReturnsAuthenticatedUser_WhenHttpContextPresent()
|
||||
{
|
||||
@@ -36,6 +38,8 @@ public class CookieAuthenticationStateProviderTests
|
||||
Assert.Equal("alice", state.User.Identity?.Name);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that the provider still returns the user after the HTTP context is gone.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task GetAuthenticationStateAsync_StillReturnsUser_AfterHttpContextIsGone()
|
||||
{
|
||||
@@ -57,6 +61,8 @@ public class CookieAuthenticationStateProviderTests
|
||||
Assert.Equal("bob", state.User.Identity?.Name);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that the provider returns the same user across calls and ignores a stale foreign HTTP context.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task GetAuthenticationStateAsync_IsStableAcrossCalls_IgnoringStaleForeignContext()
|
||||
{
|
||||
|
||||
+7
@@ -20,6 +20,9 @@ namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Auth;
|
||||
|
||||
public class ParkedMessagesMutationRegressionTests : BunitContext
|
||||
{
|
||||
/// <summary>Verifies that a retry for a site with a non-numeric identifier is relayed only while the user's current site grant allows it.</summary>
|
||||
/// <param name="revoke"><c>true</c> to revoke the user's site grant before retrying, <c>false</c> to keep it.</param>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Theory]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
@@ -69,7 +72,9 @@ public class ParkedMessagesMutationRegressionTests : BunitContext
|
||||
|
||||
private sealed class MutableAuth(string siteId) : AuthenticationStateProvider
|
||||
{
|
||||
/// <summary>Gets or sets the site identifier carried in the user's site-scope claim.</summary>
|
||||
public string SiteId { get; set; } = siteId;
|
||||
/// <inheritdoc />
|
||||
public override Task<AuthenticationState> GetAuthenticationStateAsync() => Task.FromResult(new AuthenticationState(
|
||||
new ClaimsPrincipal(new ClaimsIdentity(new[] {
|
||||
new Claim(JwtTokenService.UsernameClaimType, "operator"),
|
||||
@@ -80,6 +85,8 @@ public class ParkedMessagesMutationRegressionTests : BunitContext
|
||||
|
||||
private sealed class ReplyActor : ReceiveActor
|
||||
{
|
||||
/// <summary>Initializes the actor with the queue that records relayed retry requests.</summary>
|
||||
/// <param name="dispatched">The queue that receives each relayed retry envelope.</param>
|
||||
public ReplyActor(ConcurrentQueue<SiteEnvelope> dispatched)
|
||||
{
|
||||
Receive<SiteEnvelope>(envelope =>
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Auth;
|
||||
|
||||
public class RoutePolicyCoverageTests
|
||||
{
|
||||
/// <summary>Verifies that every routable component has its reviewed authorization policy, including the external secrets pages.</summary>
|
||||
[Fact]
|
||||
public void EveryRoutableComponent_HasItsReviewedPolicy_IncludingExternalSecrets()
|
||||
{
|
||||
|
||||
@@ -7,19 +7,21 @@ using ZB.MOM.WW.ScadaBridge.CentralUI.Components.Shared;
|
||||
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Auth;
|
||||
|
||||
/// <summary>
|
||||
/// Regression tests for CentralUI-020 and CentralUI-025. <c>SessionExpiry</c>
|
||||
/// Regression tests for the session-expiry redirect. <c>SessionExpiry</c>
|
||||
/// used to poll the Blazor <c>AuthenticationStateProvider</c>, which (via
|
||||
/// <c>CookieAuthenticationStateProvider</c>) serves a frozen constructor-time
|
||||
/// principal — so the polled state could never become "expired" and the
|
||||
/// idle-logout redirect never fired. The component now polls the server
|
||||
/// <c>GET /auth/ping</c> endpoint, which reflects the live cookie session: a
|
||||
/// 401 response triggers a redirect to <c>/login</c>. These tests exercise that
|
||||
/// redirect path directly (CentralUI-025: the path was previously untested).
|
||||
/// redirect path directly (the path was previously untested).
|
||||
/// </summary>
|
||||
public class SessionExpiryComponentTests : BunitContext
|
||||
{
|
||||
private const string ModulePath = "./_content/ZB.MOM.WW.ScadaBridge.CentralUI/js/session-expiry.js";
|
||||
|
||||
/// <summary>Verifies that an expired session redirects to the login page.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task CheckSession_ExpiredSession_RedirectsToLogin()
|
||||
{
|
||||
@@ -35,6 +37,8 @@ public class SessionExpiryComponentTests : BunitContext
|
||||
Assert.EndsWith("/login", nav.Uri);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that a live session does not redirect.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task CheckSession_LiveSession_DoesNotRedirect()
|
||||
{
|
||||
@@ -52,6 +56,8 @@ public class SessionExpiryComponentTests : BunitContext
|
||||
Assert.DoesNotContain("/login", nav.Uri);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that a transient network failure does not redirect.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task CheckSession_TransientNetworkFailure_DoesNotRedirect()
|
||||
{
|
||||
@@ -69,6 +75,8 @@ public class SessionExpiryComponentTests : BunitContext
|
||||
Assert.Equal(before, nav.Uri);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that checking the session on the login page neither pings the server nor redirects.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task CheckSession_OnLoginPage_DoesNotPingOrRedirect()
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@ using ZB.MOM.WW.ScadaBridge.CentralUI.Auth;
|
||||
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Auth;
|
||||
|
||||
/// <summary>
|
||||
/// Regression tests for CentralUI-005. <c>AuthEndpoints</c> previously stamped a
|
||||
/// Regression tests for session expiry. <c>AuthEndpoints</c> previously stamped a
|
||||
/// fixed <c>expires_at = UtcNow + 30 min</c> claim and a 30-minute absolute cookie
|
||||
/// <c>ExpiresUtc</c> with no sliding refresh, contradicting the documented
|
||||
/// "sliding refresh, 30-minute idle timeout" policy. The login handler must now
|
||||
@@ -14,6 +14,7 @@ namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Auth;
|
||||
/// </summary>
|
||||
public class SessionExpiryPolicyTests
|
||||
{
|
||||
/// <summary>Verifies that the sign-in properties do not impose a fixed absolute expiry.</summary>
|
||||
[Fact]
|
||||
public void BuildSignInProperties_DoesNotSetFixedAbsoluteExpiry()
|
||||
{
|
||||
@@ -25,6 +26,7 @@ public class SessionExpiryPolicyTests
|
||||
Assert.Null(props.ExpiresUtc);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that the sign-in properties request a persistent cookie.</summary>
|
||||
[Fact]
|
||||
public void BuildSignInProperties_IsPersistent()
|
||||
{
|
||||
@@ -33,6 +35,7 @@ public class SessionExpiryPolicyTests
|
||||
Assert.True(props.IsPersistent);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that the sign-in properties allow a sliding refresh of the cookie.</summary>
|
||||
[Fact]
|
||||
public void BuildSignInProperties_AllowsSlidingRefresh()
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@ using ZB.MOM.WW.ScadaBridge.Security;
|
||||
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Auth;
|
||||
|
||||
/// <summary>
|
||||
/// Regression tests for CentralUI-002. Site-scoped Deployment permissions are
|
||||
/// Regression tests for site-scoped permissions. Site-scoped Deployment permissions are
|
||||
/// written as <c>SiteId</c> claims at login but were never read — Deployment
|
||||
/// pages listed and acted on every site. <see cref="SiteScopeService"/> is the
|
||||
/// shared helper that reads those claims; these tests pin its behaviour.
|
||||
@@ -17,7 +17,10 @@ public class SiteScopeServiceTests
|
||||
private sealed class StubAuthStateProvider : AuthenticationStateProvider
|
||||
{
|
||||
private readonly ClaimsPrincipal _user;
|
||||
/// <summary>Initializes a new instance of the <c>StubAuthStateProvider</c> class.</summary>
|
||||
/// <param name="user">The user.</param>
|
||||
public StubAuthStateProvider(ClaimsPrincipal user) => _user = user;
|
||||
/// <inheritdoc />
|
||||
public override Task<AuthenticationState> GetAuthenticationStateAsync()
|
||||
=> Task.FromResult(new AuthenticationState(_user));
|
||||
}
|
||||
@@ -34,6 +37,8 @@ public class SiteScopeServiceTests
|
||||
private static List<Site> Sites(params int[] ids)
|
||||
=> ids.Select(id => new Site($"Site{id}", $"SITE-{id}") { Id = id }).ToList();
|
||||
|
||||
/// <summary>Verifies that a deployer with no site claims is treated as system-wide.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task DeploymentUserWithNoSiteClaims_IsSystemWide()
|
||||
{
|
||||
@@ -43,6 +48,8 @@ public class SiteScopeServiceTests
|
||||
Assert.Empty(await svc.PermittedSiteIdsAsync());
|
||||
}
|
||||
|
||||
/// <summary>Verifies that filtering sites for a system-wide user returns every site.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task SystemWideUser_FilterSites_ReturnsAllSites()
|
||||
{
|
||||
@@ -53,6 +60,8 @@ public class SiteScopeServiceTests
|
||||
Assert.Equal(new[] { 1, 2, 3 }, filtered.Select(s => s.Id));
|
||||
}
|
||||
|
||||
/// <summary>Verifies that filtering sites for a scoped user returns only the permitted sites.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task ScopedUser_FilterSites_ReturnsOnlyPermittedSites()
|
||||
{
|
||||
@@ -64,6 +73,8 @@ public class SiteScopeServiceTests
|
||||
Assert.Equal(new[] { 1, 3 }, filtered.Select(s => s.Id).OrderBy(x => x));
|
||||
}
|
||||
|
||||
/// <summary>Verifies that a scoped user is allowed access only to the sites they were granted.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task ScopedUser_IsSiteAllowed_OnlyForGrantedSites()
|
||||
{
|
||||
@@ -73,6 +84,8 @@ public class SiteScopeServiceTests
|
||||
Assert.False(await svc.IsSiteAllowedAsync(6));
|
||||
}
|
||||
|
||||
/// <summary>Verifies that a scoped user is not system-wide and reports its permitted site ids.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task ScopedUser_IsNotSystemWide_AndReportsItsPermittedIds()
|
||||
{
|
||||
@@ -82,6 +95,8 @@ public class SiteScopeServiceTests
|
||||
Assert.Equal(new[] { 7, 9 }, (await svc.PermittedSiteIdsAsync()).OrderBy(x => x));
|
||||
}
|
||||
|
||||
/// <summary>Verifies that a system-wide user is allowed access to any site.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task SystemWideUser_IsSiteAllowed_ForAnySite()
|
||||
{
|
||||
@@ -99,6 +114,8 @@ public class SiteScopeServiceTests
|
||||
// could act fleet-wide through the CLI/HTTP surface while the UI hid the same
|
||||
// sites. The UI was the side that disagreed with the documented rule.
|
||||
|
||||
/// <summary>Verifies that an administrator carrying site claims is still system-wide.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task AdministratorWithSiteClaims_IsSystemWide()
|
||||
{
|
||||
@@ -107,6 +124,8 @@ public class SiteScopeServiceTests
|
||||
Assert.True(await svc.IsSystemWideAsync());
|
||||
}
|
||||
|
||||
/// <summary>Verifies that filtering sites for an administrator with site claims returns every site.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task AdministratorWithSiteClaims_FilterSites_ReturnsAllSites()
|
||||
{
|
||||
@@ -117,6 +136,8 @@ public class SiteScopeServiceTests
|
||||
Assert.Equal(new[] { 1, 2, 3 }, filtered.Select(s => s.Id));
|
||||
}
|
||||
|
||||
/// <summary>Verifies that an administrator with site claims is allowed access to sites outside those claims.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task AdministratorWithSiteClaims_IsSiteAllowed_ForSitesOutsideTheClaims()
|
||||
{
|
||||
@@ -125,6 +146,8 @@ public class SiteScopeServiceTests
|
||||
Assert.True(await svc.IsSiteAllowedAsync(2));
|
||||
}
|
||||
|
||||
/// <summary>Verifies that an administrator with site claims reports no permitted site ids.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task AdministratorWithSiteClaims_ReportsNoPermittedIds()
|
||||
{
|
||||
@@ -136,6 +159,9 @@ public class SiteScopeServiceTests
|
||||
Assert.Empty(await svc.PermittedSiteIdsAsync());
|
||||
}
|
||||
|
||||
/// <summary>Verifies that the administrator role match ignores case.</summary>
|
||||
/// <param name="role">The role.</param>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Theory]
|
||||
[InlineData("administrator")]
|
||||
[InlineData("ADMINISTRATOR")]
|
||||
@@ -150,6 +176,8 @@ public class SiteScopeServiceTests
|
||||
Assert.True(await svc.IsSystemWideAsync());
|
||||
}
|
||||
|
||||
/// <summary>Verifies that a designer with site claims remains scoped to those sites.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task DesignerWithSiteClaims_IsStillScoped()
|
||||
{
|
||||
@@ -172,6 +200,8 @@ public class SiteScopeServiceTests
|
||||
private static ClaimsPrincipal Principal(params Claim[] claims)
|
||||
=> new(new ClaimsIdentity(claims, authenticationType: "TestCookie"));
|
||||
|
||||
/// <summary>Verifies that resolving an administrator yields a system-wide scope with an empty site set.</summary>
|
||||
/// <returns>The result.</returns>
|
||||
[Fact]
|
||||
public void Resolve_Administrator_IsSystemWideWithAnEmptySet()
|
||||
{
|
||||
@@ -184,6 +214,8 @@ public class SiteScopeServiceTests
|
||||
Assert.Empty(sites);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that resolving a principal with site claims yields the scoped site set.</summary>
|
||||
/// <returns>The result.</returns>
|
||||
[Fact]
|
||||
public void Resolve_SiteClaims_YieldTheScopedSet()
|
||||
{
|
||||
@@ -194,6 +226,8 @@ public class SiteScopeServiceTests
|
||||
Assert.Equal([1, 3], sites.OrderBy(id => id));
|
||||
}
|
||||
|
||||
/// <summary>Verifies that resolving a principal with no site claims yields a system-wide scope.</summary>
|
||||
/// <returns>The result.</returns>
|
||||
[Fact]
|
||||
public void Resolve_NoSiteClaims_IsSystemWide()
|
||||
{
|
||||
@@ -203,6 +237,8 @@ public class SiteScopeServiceTests
|
||||
Assert.Empty(sites);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that resolving an unauthenticated principal yields a scope with no permitted sites.</summary>
|
||||
/// <returns>The result.</returns>
|
||||
[Fact]
|
||||
public void Resolve_UnauthenticatedPrincipal_IsScopedToNothing()
|
||||
{
|
||||
@@ -213,6 +249,8 @@ public class SiteScopeServiceTests
|
||||
Assert.Empty(sites);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that the synchronous resolve produces the same result as the async path.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task Resolve_AgreesWithTheAsyncPath()
|
||||
{
|
||||
|
||||
@@ -22,6 +22,9 @@ namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Auth;
|
||||
|
||||
public class UiAuditRegressionTests : BunitContext
|
||||
{
|
||||
/// <summary>Verifies that creating an LDAP mapping from the UI persists its audit row with the generated mapping id, or rolls back when the audit write fails.</summary>
|
||||
/// <param name="failAudit">Whether the audit write is made to fail.</param>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Theory]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
@@ -90,6 +93,7 @@ public class UiAuditRegressionTests : BunitContext
|
||||
|
||||
private sealed class StaticAuth(System.Security.Claims.ClaimsPrincipal principal) : AuthenticationStateProvider
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override Task<AuthenticationState> GetAuthenticationStateAsync() => Task.FromResult(new AuthenticationState(principal));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user