78 lines
3.5 KiB
C#
78 lines
3.5 KiB
C#
using Bunit;
|
|
using Bunit.TestDoubles;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.AdminUI.Components.Layout;
|
|
using ZB.MOM.WW.OtOpcUa.AdminUI.Components.Shared;
|
|
using ZB.MOM.WW.OtOpcUa.Security.Auth;
|
|
using ZB.MOM.WW.Secrets.Ui;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.Pages;
|
|
|
|
/// <summary>Real rail destinations retain their route-policy visibility.</summary>
|
|
[Trait("Category", "Unit")]
|
|
public sealed class NavigationPolicyRenderTests : BunitContext
|
|
{
|
|
[Theory]
|
|
[InlineData(false, false)]
|
|
[InlineData(true, false)]
|
|
[InlineData(true, true)]
|
|
public void Navigation_UsesDestinationPolicies(bool editor, bool administrator)
|
|
{
|
|
var auth = this.AddAuthorization();
|
|
auth.SetAuthorized("fixture");
|
|
var policies = new List<string> { AdminUiPolicies.AuthenticatedRead };
|
|
if (editor) policies.Add(AdminUiPolicies.ConfigEditor);
|
|
if (administrator) policies.AddRange([AdminUiPolicies.FleetAdmin, SecretsAuthorization.ManagePolicy]);
|
|
auth.SetPolicies(policies.ToArray());
|
|
var cut = Render<MainLayout>();
|
|
foreach (var path in new[] { "/fleet", "/hosts", "/clusters", "/certificates", "/script-log", "/alerts" })
|
|
cut.FindAll($"a[href='{path}']").Count.ShouldBe(1, path);
|
|
foreach (var path in new[] { "/raw", "/uns", "/scripts", "/deployments" })
|
|
cut.FindAll($"a[href='{path}']").Count.ShouldBe(editor ? 1 : 0, path);
|
|
foreach (var path in new[] { "/role-grants", "/apikeys", "/admin/secrets" })
|
|
cut.FindAll($"a[href='{path}']").Count.ShouldBe(administrator ? 1 : 0, path);
|
|
}
|
|
|
|
[Fact]
|
|
public void RetiredNamespaces_AreAbsentFromOrdinaryClusterNavigation()
|
|
{
|
|
var cut = Render<ClusterNav>(p => p.Add(x => x.ClusterId,"C1").Add(x => x.ActiveTab,"overview"));
|
|
cut.FindAll("a[href$='/namespaces']").ShouldBeEmpty();
|
|
cut.Find("a[href='/clusters/C1']").GetAttribute("aria-current").ShouldBe("page");
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(false)]
|
|
[InlineData(true)]
|
|
public void CompatibilityAndHome_OfferOnlyAuthorizedAuthoring(bool editor)
|
|
{
|
|
var auth = this.AddAuthorization();
|
|
auth.SetAuthorized("fixture");
|
|
auth.SetPolicies(editor
|
|
? [AdminUiPolicies.AuthenticatedRead, AdminUiPolicies.ConfigEditor]
|
|
: [AdminUiPolicies.AuthenticatedRead]);
|
|
var home = Render<ZB.MOM.WW.OtOpcUa.AdminUI.Components.Pages.Home>();
|
|
home.FindAll("h1").Count.ShouldBe(1);
|
|
home.Find("a[href='/fleet']").ShouldNotBeNull();
|
|
home.FindAll("a[href='/raw']").Count.ShouldBe(editor ? 1 : 0);
|
|
home.FindAll("a[href='/uns']").Count.ShouldBe(editor ? 1 : 0);
|
|
var compatibility = Render<ZB.MOM.WW.OtOpcUa.AdminUI.Components.Pages.Clusters.ClusterNamespaces>(p => p.Add(x => x.ClusterId, "C1"));
|
|
compatibility.FindAll("h1").Count.ShouldBe(1);
|
|
compatibility.FindAll("a[href='/raw']").Count.ShouldBe(editor ? 1 : 0);
|
|
compatibility.FindAll("a[href='/uns']").Count.ShouldBe(editor ? 1 : 0);
|
|
}
|
|
|
|
[Fact]
|
|
public void SecretsPolicy_IsIndependentOfFleetAdministration()
|
|
{
|
|
var auth = this.AddAuthorization();
|
|
auth.SetAuthorized("fixture");
|
|
auth.SetPolicies(AdminUiPolicies.AuthenticatedRead, SecretsAuthorization.ManagePolicy);
|
|
var cut = Render<MainLayout>();
|
|
cut.Find("a[href='/admin/secrets']").ShouldNotBeNull();
|
|
cut.FindAll("a[href='/role-grants'],a[href='/apikeys']").ShouldBeEmpty();
|
|
}
|
|
}
|