b104760b3a
Standardize role string VALUES on the canonical vocabulary
(Administrator/Designer/Deployer/Viewer; Operator/Engineer unused here):
Admin -> Administrator
Design -> Designer
Deployment -> Deployer
Audit -> Administrator (COLLAPSE; accepted privilege escalation)
AuditReadOnly-> Viewer (COLLAPSE; keeps audit-read, no export)
SoD: OperationalAuditRoles = { Administrator, Viewer },
AuditExportRoles = { Administrator }
so Viewer reads the audit log + nav but cannot bulk-export, while
Administrator does both + holds the full admin surface (the documented,
accepted auditor/admin SoD collapse).
Atomic move across every enforcement site:
- Roles constants; AuthorizationPolicies (RequireClaim values + SoD arrays +
honest XML-doc); RoleMapper Deployer check.
- ManagementActor.GetRequiredRole switch + the hard-coded site-scope
admin-bypass (now Roles.Administrator at all 6 sites). Site-scoping logic
is otherwise unchanged.
- DebugStreamHub Administrator/Deployer gates (Deployer kept case-sensitive).
- CentralUI BrowseService/BindingTester Designer guards; LdapMappingForm
dropdown now offers canonical values (incl. Viewer).
- Config-DB seed (LdapGroupMappings Id 1-4) + EF migration CanonicalizeRoles:
Id-keyed UpdateData for seed rows + idempotent raw catch-all UPDATEs for
operator-added rows. Down is lossy on the collapse (documented in-file).
No pending model changes.
Tests reworked to the collapsed model across Security/CentralUI/
ManagementService/ConfigurationDatabase/Integration suites, incl. explicit
Viewer-reads-not-exports and former-Audit-now-Administrator-escalation cases.
CHANGELOG: BREAKING security note documenting the canonicalization + SoD
collapse.
71 lines
2.6 KiB
C#
71 lines
2.6 KiB
C#
using System.Security.Claims;
|
|
using Bunit;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using NSubstitute;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Entities.ExternalSystems;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories;
|
|
using ZB.MOM.WW.ScadaBridge.Security;
|
|
using ExternalSystemForm = ZB.MOM.WW.ScadaBridge.CentralUI.Components.Pages.Design.ExternalSystemForm;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Design;
|
|
|
|
/// <summary>
|
|
/// Bundle D drill-in test (#23 M7-T12) for the External Systems edit page.
|
|
/// The page-header chip routes operators into the central Audit Log
|
|
/// pre-filtered by Target = external-system name. Create mode has nothing
|
|
/// to drill into yet, so the link is suppressed.
|
|
/// </summary>
|
|
public class ExternalSystemFormAuditDrillinTests : BunitContext
|
|
{
|
|
private readonly IExternalSystemRepository _repo = Substitute.For<IExternalSystemRepository>();
|
|
|
|
public ExternalSystemFormAuditDrillinTests()
|
|
{
|
|
Services.AddSingleton(_repo);
|
|
|
|
var claims = new[]
|
|
{
|
|
new Claim(JwtTokenService.UsernameClaimType, "tester"),
|
|
new Claim(JwtTokenService.RoleClaimType, "Designer"),
|
|
};
|
|
var user = new ClaimsPrincipal(new ClaimsIdentity(claims, "TestAuth"));
|
|
Services.AddSingleton<AuthenticationStateProvider>(new TestAuthStateProvider(user));
|
|
Services.AddAuthorizationCore();
|
|
AuthorizationPolicies.AddScadaBridgeAuthorization(Services);
|
|
}
|
|
|
|
[Fact]
|
|
public void EditPage_HasRecentAuditActivityLink_WithTargetEqualToSystemName()
|
|
{
|
|
_repo.GetExternalSystemByIdAsync(7, Arg.Any<CancellationToken>())
|
|
.Returns(new ExternalSystemDefinition("ERP-Alpha", "https://erp.example.test", "ApiKey")
|
|
{
|
|
Id = 7,
|
|
});
|
|
|
|
var cut = Render<ExternalSystemForm>(p => p.Add(c => c.Id, 7));
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
var link = cut.Find("a[data-test=\"audit-link\"]");
|
|
Assert.Equal("/audit/log?target=ERP-Alpha", link.GetAttribute("href"));
|
|
Assert.Contains("Recent audit activity", link.TextContent);
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void CreatePage_HasNoRecentAuditActivityLink()
|
|
{
|
|
// Create mode (Id is null) — there's no real external system to drill into,
|
|
// so the link must not render.
|
|
var cut = Render<ExternalSystemForm>();
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
Assert.Empty(cut.FindAll("a[data-test=\"audit-link\"]"));
|
|
});
|
|
}
|
|
}
|