test: verify live history authority and secure peer reactivation

This commit is contained in:
Joseph Doherty
2026-11-10 11:53:34 -05:00
parent da50123a2c
commit 1840b5ccf6
2 changed files with 175 additions and 0 deletions
@@ -1,4 +1,6 @@
using System.Text;
using System.Net;
using System.Collections.Concurrent;
using Microsoft.Extensions.Logging.Abstractions;
using Opc.Ua;
using Opc.Ua.Client;
@@ -29,6 +31,16 @@ public sealed class Sdk2TrustedChannelTests
(await session.ReadValueAsync(rig.Node(session), ct)).WrappedValue.GetInt32().ShouldBe(7);
(await rig.WriteAsync(session, 42, ct)).ShouldBe(StatusCodes.Good);
rig.Writes.ShouldBe(1, "a narrow grant with no application-wide roles must permit the write");
var observedPeer = rig.Peers.ShouldHaveSingleItem();
observedPeer.ShouldNotBeNull();
IPAddress.IsLoopback(observedPeer.Address).ShouldBeTrue();
observedPeer.Port.ShouldBe(0, "the public SDK evidence supplies an IP address, not an invented client port");
var originalSessionId = session.SessionId;
await session.ReconnectAsync(null, null, ct);
session.SessionId.ShouldBe(originalSessionId, "the test must reactivate the existing session on a new channel");
rig.Peers.Count.ShouldBe(2);
rig.Peers.Last().ShouldNotBeNull().Address.ShouldBe(observedPeer.Address);
(await session.ReadValueAsync(rig.Node(session), ct)).StatusCode.ShouldBe(StatusCodes.Good);
var identity = rig.Server.CurrentInstance.SessionManager.GetSessions().ShouldHaveSingleItem().EffectiveIdentity
.ShouldBeOfType<RoleCarryingUserIdentity>();
identity.Principal.ShouldBe(TrustedRig.Principal);
@@ -80,6 +92,7 @@ public sealed class Sdk2TrustedChannelTests
private int _port;
private int _writes;
private int _authCalls;
internal ConcurrentQueue<IPEndPoint?> Peers { get; } = new();
internal OtOpcUaSdkServer Server { get; private set; } = null!;
internal int Writes => Volatile.Read(ref _writes);
internal int AuthCalls => Volatile.Read(ref _authCalls);
@@ -204,6 +217,12 @@ public sealed class Sdk2TrustedChannelTests
new Dictionary<AclScopeRef, IReadOnlyList<NodeAclPath>>
{ [new(NodeAclScopeKind.RawDevice, "device")] = [new([NodeAclRealms.Raw, "Plant", "Device"])] });
public Task<OpcUaUserAuthResult> AuthenticateUserNameAsync(string username, string password, IPEndPoint? peer, CancellationToken ct)
{
Peers.Enqueue(peer is null ? null : new IPEndPoint(peer.Address, peer.Port));
return AuthenticateUserNameAsync(username, password, ct);
}
public Task<OpcUaUserAuthResult> AuthenticateUserNameAsync(string username, string password, CancellationToken ct)
{
Interlocked.Increment(ref _authCalls);