3773509888
A-3: UnsTreeService pre-checks sibling (cluster,area,line) names on create/update/import, catches DbUpdateException, validates column lengths. A-4: blank ack password keeps the stored one; first-time blank refused. A-6: BrowseSessionReaper drains sessions in a finally on shutdown. A-7: node flushes response headers; central treats them as established; deadline warning throttled. A-9: key delete always reloads and names leftover ack secrets when cleanup fails. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
125 lines
5.0 KiB
C#
125 lines
5.0 KiB
C#
using Bunit;
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.AdminUI.ApiKeyAck;
|
|
using ZB.MOM.WW.OtOpcUa.AdminUI.Components.Pages;
|
|
using ZB.MOM.WW.OtOpcUa.Configuration.Entities;
|
|
using ZB.MOM.WW.OtOpcUa.Core.Authorization;
|
|
using ZB.MOM.WW.OtOpcUa.Driver.Galaxy.Config;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.Pages;
|
|
|
|
/// <summary>
|
|
/// #997 A-9: deleting a key removed the row, then cleared its Galaxy ack identity, then reloaded - all in one
|
|
/// <c>try</c>. A Secrets-store failure in the middle skipped the reload (the page kept listing a key that no
|
|
/// longer exists, with live buttons) and left the ack secrets behind with no way to find them.
|
|
/// </summary>
|
|
[Trait("Category", "Unit")]
|
|
public sealed class ApiKeysDeleteTests : BunitContext
|
|
{
|
|
private const string KeyId = "0a1b2c3d4e5f6071";
|
|
|
|
public ApiKeysDeleteTests()
|
|
{
|
|
JSInterop.Setup<bool>("otDialog.activate", _ => true).SetResult(true);
|
|
JSInterop.SetupVoid("otDialog.update", _ => true).SetVoidResult();
|
|
JSInterop.SetupVoid("otDialog.deactivate", _ => true).SetVoidResult();
|
|
Services.AddSingleton<AuthenticationStateProvider>(new FakeAuth());
|
|
}
|
|
|
|
private IRenderedComponent<ApiKeys> RenderPage(FakeKeys keys, FakeAck ack)
|
|
{
|
|
Services.AddSingleton<IApiKeyAdminService>(keys);
|
|
Services.AddSingleton<IApiKeyGalaxyAckIdentityService>(ack);
|
|
return Render<ApiKeys>();
|
|
}
|
|
|
|
private static void DeleteAndConfirm(IRenderedComponent<ApiKeys> cut)
|
|
{
|
|
cut.Find("table button.btn-outline-danger").Click();
|
|
cut.Find(".modal-footer .btn-danger").Click();
|
|
}
|
|
|
|
[Fact]
|
|
public void A_failing_ack_cleanup_still_reloads_the_list_and_names_the_leftover_secrets()
|
|
{
|
|
var keys = new FakeKeys();
|
|
var ack = new FakeAck { ThrowOnClear = true };
|
|
var cut = RenderPage(keys, ack);
|
|
cut.Markup.ShouldContain(KeyId);
|
|
|
|
DeleteAndConfirm(cut);
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
cut.FindAll("table").ShouldBeEmpty("the deleted key must no longer be listed");
|
|
var alert = cut.Find(".alert-danger").TextContent;
|
|
alert.ShouldContain(GalaxyAckIdentitySecrets.UserSecretName(KeyId));
|
|
alert.ShouldContain(GalaxyAckIdentitySecrets.PasswordSecretName(KeyId));
|
|
alert.ShouldContain("secret store unavailable");
|
|
});
|
|
keys.DeleteCalls.ShouldBe(1);
|
|
}
|
|
|
|
/// <summary>Positive control: with a healthy Secrets store the same flow lists nothing and shows no error.</summary>
|
|
[Fact]
|
|
public void A_clean_delete_reloads_the_list_and_shows_no_error()
|
|
{
|
|
var keys = new FakeKeys();
|
|
var ack = new FakeAck();
|
|
var cut = RenderPage(keys, ack);
|
|
|
|
DeleteAndConfirm(cut);
|
|
|
|
cut.WaitForAssertion(() => cut.FindAll("table").ShouldBeEmpty());
|
|
cut.FindAll(".alert-danger").ShouldBeEmpty();
|
|
ack.ClearCalls.ShouldBe(1);
|
|
}
|
|
|
|
private sealed class FakeKeys : IApiKeyAdminService
|
|
{
|
|
private readonly List<ApiKey> _rows =
|
|
[
|
|
new() { ApiKeyId = KeyId, Name = "ScadaBridge", SecretHash = "x", Principal = "sb", Enabled = true, CreatedUtc = DateTime.UtcNow },
|
|
];
|
|
|
|
public int DeleteCalls { get; private set; }
|
|
public Task<IReadOnlyList<ApiKey>> ListAsync(CancellationToken ct) => Task.FromResult<IReadOnlyList<ApiKey>>(_rows.ToList());
|
|
public Task<string> CreateAsync(string name, string principal, DateTime? expiresUtc, string? notes, CancellationToken ct) => throw new NotSupportedException();
|
|
public Task SetEnabledAsync(string apiKeyId, bool enabled, CancellationToken ct) => throw new NotSupportedException();
|
|
public Task DeleteAsync(string apiKeyId, CancellationToken ct)
|
|
{
|
|
DeleteCalls++;
|
|
_rows.RemoveAll(r => r.ApiKeyId == apiKeyId);
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
|
|
private sealed class FakeAck : IApiKeyGalaxyAckIdentityService
|
|
{
|
|
public bool ThrowOnClear { get; init; }
|
|
public int ClearCalls { get; private set; }
|
|
|
|
public Task<IReadOnlyDictionary<string, string>> ListAsync(CancellationToken ct) =>
|
|
Task.FromResult<IReadOnlyDictionary<string, string>>(new Dictionary<string, string>());
|
|
|
|
public Task SetAsync(string apiKeyId, string user, string? domain, string? password, string actor, CancellationToken ct) =>
|
|
throw new NotSupportedException();
|
|
|
|
public Task ClearAsync(string apiKeyId, string actor, CancellationToken ct)
|
|
{
|
|
ClearCalls++;
|
|
return ThrowOnClear ? throw new InvalidOperationException("secret store unavailable") : Task.CompletedTask;
|
|
}
|
|
}
|
|
|
|
private sealed class FakeAuth : AuthenticationStateProvider
|
|
{
|
|
public override Task<AuthenticationState> GetAuthenticationStateAsync() =>
|
|
Task.FromResult(new AuthenticationState(new System.Security.Claims.ClaimsPrincipal(
|
|
new System.Security.Claims.ClaimsIdentity("test"))));
|
|
}
|
|
}
|