fix(dataconn): #941 #942 #943 consumer skips unmaterialisable browse items, gate refuses alarm-bearing export roots, no existence oracle
#941: RemoteNamespaceResolver now skips an origin browse item this build cannot materialise (NodeKind not Folder/Variable/Tag, or a value/array-element kind with no OPC UA built-in type: Guid, Bytes) instead of failing the whole page, so one UnsupportedVariable no longer makes the folder BadNoCommunication. Malformed items of a supported kind still fail closed. New real-SDK wire tests: an injected unmaterialisable child (4 kinds) is skipped across BrowseNext pages, and an empty Complete=false origin page is paged through. #942: DataConnectionValidator (authoring + DraftValidator deploy gate, not node-side ValidateDeployed) refuses DataExportRootAlarmBearing: an export rooted at an alarm-bearing RawTag (grants nothing) or at a UnsTagReference to one (no UNS node, so the node's catalog compile throws and refuses the whole export set). #943: GetMetadata, Read, Subscribe and condition-item admission answer an address outside every export of the principal as NotFound, identical to a missing one (LocalExportCatalog.DisclosesAddress replaces ContainsAddress). Denied stays for addresses inside a grant. Browse, Write, HistoryRead and condition methods were already uniform.
This commit is contained in:
+113
@@ -0,0 +1,113 @@
|
||||
using Opc.Ua;
|
||||
using Opc.Ua.Client;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections;
|
||||
using ZB.MOM.WW.OtOpcUa.Runtime.DataConnections;
|
||||
using DataBrowseRequest = ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections.BrowseRequest;
|
||||
using DataReadRequest = ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections.ReadRequest;
|
||||
using DataReadResult = ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections.ReadResult;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Runtime.Tests.DataConnections;
|
||||
|
||||
/// <summary>
|
||||
/// #941: the consumer's browse path (resolver → applier → node manager → real SDK Browse/BrowseNext) tolerates what an
|
||||
/// origin may legitimately send — a child of a kind this build cannot materialise is skipped instead of failing the
|
||||
/// whole folder, and an empty <c>Complete = false</c> page (the origin's name filter can produce one) is paged through.
|
||||
/// </summary>
|
||||
public sealed partial class GrpcDataConfiguredDiscoveryWireTests
|
||||
{
|
||||
[Theory(Timeout = 90000)]
|
||||
[InlineData("UnsupportedVariable", DataValueKind.Null)] // a pre-#917 origin's alarm-bearing / unsupported value node
|
||||
[InlineData("Method", DataValueKind.Null)] // a node kind a newer origin might add
|
||||
[InlineData("Variable", DataValueKind.Guid)] // a value kind the consumer has no OPC UA type for
|
||||
[InlineData("Variable", DataValueKind.Bytes)]
|
||||
public async Task A_child_of_an_unmaterialisable_kind_is_skipped_not_the_whole_folder_941(string nodeKind, DataValueKind valueKind)
|
||||
{
|
||||
using var origin = new LocalDataFixture(additionalRawNodes: 2, servingGeneration: 1);
|
||||
var connections = new TamperingConnections(origin) { InjectKind = (nodeKind, valueKind) };
|
||||
await WithComposedServer(origin, origin.Root, async (session, _, _, _, _, _, anchor) =>
|
||||
{
|
||||
// Page size 2: each origin page is one real child plus the injected one, so every page mixes the two.
|
||||
var children = await BrowseAll((SessionClient)session, anchor, 2);
|
||||
children.Select(x => x.BrowseName.Name).Order(StringComparer.Ordinal).ShouldBe(["Speed", "Speed0", "Speed1"]);
|
||||
children.ShouldAllBe(x => x.NodeClass == NodeClass.Variable);
|
||||
connections.Injected.ShouldBeGreaterThan(0, "the origin page carried the unmaterialisable item");
|
||||
}, connectionSource: connections);
|
||||
}
|
||||
|
||||
[Fact(Timeout = 90000)]
|
||||
public async Task An_empty_incomplete_origin_page_is_paged_through_by_sdk_BrowseNext_941()
|
||||
{
|
||||
using var origin = new LocalDataFixture(additionalRawNodes: 2, servingGeneration: 1);
|
||||
var connections = new TamperingConnections(origin) { EmptyFirstPage = true };
|
||||
await WithComposedServer(origin, origin.Root, async (session, _, _, _, _, _, anchor) =>
|
||||
{
|
||||
var children = await BrowseAll((SessionClient)session, anchor, 1);
|
||||
children.Select(x => x.BrowseName.Name).Order(StringComparer.Ordinal).ShouldBe(["Speed", "Speed0", "Speed1"]);
|
||||
connections.EmptyPagesServed.ShouldBeGreaterThan(0, "the origin served an empty Complete=false page");
|
||||
}, connectionSource: connections);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wraps the origin's direct connection and rewrites Browse answers: <see cref="InjectKind"/> adds one item of that
|
||||
/// kind to every Good page of the root's children; <see cref="EmptyFirstPage"/> answers the first page of every
|
||||
/// browse with no items, <c>Complete = false</c> and a token that resumes at the origin's real first page.
|
||||
/// </summary>
|
||||
private sealed class TamperingConnections(LocalDataFixture peer) : IGrpcDataAdapterConnectionSource
|
||||
{
|
||||
private const string ResumeToken = "resume-at-first-page";
|
||||
private int _injected, _empty;
|
||||
internal (string NodeKind, DataValueKind ValueKind)? InjectKind { get; init; }
|
||||
internal bool EmptyFirstPage { get; init; }
|
||||
internal int Injected => Volatile.Read(ref _injected);
|
||||
internal int EmptyPagesServed => Volatile.Read(ref _empty);
|
||||
|
||||
public ValueTask<IGrpcDataAdapterConnectionLease?> AcquireAsync(string connectionId, CancellationToken cancellationToken) =>
|
||||
ValueTask.FromResult<IGrpcDataAdapterConnectionLease?>(connectionId == "link" ? new Lease(new Connection(peer.Connection(), this)) : null);
|
||||
|
||||
private sealed class Lease(IDataConnection connection) : IGrpcDataAdapterConnectionLease
|
||||
{
|
||||
public IDataConnection Connection => connection;
|
||||
public CancellationToken CancellationToken => CancellationToken.None;
|
||||
public ValueTask DisposeAsync() => connection.DisposeAsync();
|
||||
}
|
||||
|
||||
private sealed class Connection(IDataConnection inner, TamperingConnections owner) : IDataConnection
|
||||
{
|
||||
public DataTarget Target => inner.Target;
|
||||
public TimeProvider Clock => inner.Clock;
|
||||
public Task<DataCapabilities> GetCapabilitiesAsync(DataBudget budget, CancellationToken cancellationToken) => inner.GetCapabilitiesAsync(budget, cancellationToken);
|
||||
public async Task<DataBrowseBranch> BrowseAsync(DataBrowseRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (owner.EmptyFirstPage && request.Continuation is null)
|
||||
{
|
||||
var real = await inner.BrowseAsync(request, cancellationToken);
|
||||
if (real.Status != DataItemStatus.Good) return real;
|
||||
Interlocked.Increment(ref owner._empty);
|
||||
return real with { Items = [], Complete = false, Continuation = ResumeToken };
|
||||
}
|
||||
if (request.Continuation == ResumeToken) request = request with { Continuation = null };
|
||||
if (owner.InjectKind is not { } kind || request.Budget.MaxItems < 2) return await inner.BrowseAsync(request, cancellationToken);
|
||||
// Leave room for the injected item so the page stays within the consumer's item budget.
|
||||
var branch = await inner.BrowseAsync(request with { Budget = request.Budget with { MaxItems = request.Budget.MaxItems - 1 } }, cancellationToken);
|
||||
if (branch.Status != DataItemStatus.Good || branch.Items.Count == 0) return branch;
|
||||
var template = branch.Items[0];
|
||||
var identifier = request.Parent.Address.Identifier + "/Ghost" + branch.Items.Count;
|
||||
var ghost = template with
|
||||
{
|
||||
View = template.View with { Address = template.View.Address with { Identifier = identifier }, Subject = identifier },
|
||||
BrowseName = "Ghost" + branch.Items.Count, NodeKind = kind.NodeKind, ValueKind = kind.ValueKind,
|
||||
ValueRank = -1, Dimensions = [], ArrayElementKind = null, Writable = false, History = null,
|
||||
};
|
||||
Interlocked.Increment(ref owner._injected);
|
||||
return branch with { Items = [ghost, .. branch.Items] };
|
||||
}
|
||||
public Task<IReadOnlyList<DataItemResult<DataMetadata>>> GetMetadataAsync(MetadataRequest request, CancellationToken cancellationToken) => inner.GetMetadataAsync(request, cancellationToken);
|
||||
public Task<IReadOnlyList<DataReadResult>> ReadAsync(DataReadRequest request, CancellationToken cancellationToken) => inner.ReadAsync(request, cancellationToken);
|
||||
public Task<IReadOnlyList<WriteItemResult>> WriteAsync(WriteBatch request, CancellationToken cancellationToken) => inner.WriteAsync(request, cancellationToken);
|
||||
public Task<IDataSubscription> SubscribeAsync(CancellationToken cancellationToken) => inner.SubscribeAsync(cancellationToken);
|
||||
public ValueTask DisposeAsync() => inner.DisposeAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
+26
@@ -448,5 +448,31 @@ public sealed class GrpcDataConditionPlacementTests
|
||||
return (snapshot, rawPaths.ToArray(), drivers.Select(x => x.DriverInstanceId).ToArray(), expected);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// #942: why the deploy gate refuses an export rooted at an alarm-bearing tag (<c>DataExportRootAlarmBearing</c>).
|
||||
/// Rooted at the raw tag it compiles but grants nothing — no condition (the placement's parent is the tag's folder)
|
||||
/// and no value (an unsupported node). Rooted at a UNS reference to it, the origin has no node (#896) and the catalog
|
||||
/// compile refuses the whole export set. The authoring validator now names both; the node-side compile is unchanged.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void An_export_rooted_at_an_alarm_bearing_tag_grants_nothing_and_is_refused_by_the_gate_942()
|
||||
{
|
||||
using var fixture = new LocalDataFixture();
|
||||
var b = Fixed();
|
||||
var rawTag = With(b, exports: [.. b.DataExports, Export("tag-root", DataRealm.Raw, "tag-peer", rootKind: "RawTag", rootId: "alarm-tag")]);
|
||||
var catalog = LocalExportCatalog.Compile(rawTag, fixture.Serving, fixture.Activation.CaptureAuthority());
|
||||
var root = catalog.Nodes.Single(n => n.EntityKind == "RawTag" && n.EntityId == "alarm-tag").Metadata.View;
|
||||
catalog.ListConditions("tag-peer", root, DataOperations.Subscribe, ConditionKeys.FromSecret(Secret)).ShouldBeEmpty();
|
||||
catalog.Nodes.Single(n => n.EntityId == "alarm-tag").Supported.ShouldBeFalse();
|
||||
DataConnectionValidator.Validate(rawTag).ShouldContain(x => x.Code == "DataExportRootAlarmBearing" && x.Context == "tag-root");
|
||||
|
||||
var unsRef = With(b, exports: [.. b.DataExports, Export("ref-root", DataRealm.Uns, "ref-peer", rootKind: "UnsTagReference", rootId: "ref-alarm-1")]);
|
||||
Should.Throw<ArgumentException>(() => LocalExportCatalog.Compile(unsRef, fixture.Serving, fixture.Activation.CaptureAuthority()));
|
||||
DataConnectionValidator.Validate(unsRef).ShouldContain(x => x.Code == "DataExportRootAlarmBearing" && x.Context == "ref-root");
|
||||
|
||||
// Control: the base draft (exports rooted at the realm / an equipment) is not refused.
|
||||
DataConnectionValidator.Validate(b).ShouldNotContain(x => x.Code == "DataExportRootAlarmBearing");
|
||||
}
|
||||
|
||||
private static string Json<T>(T value) => JsonSerializer.Serialize(value);
|
||||
}
|
||||
|
||||
+15
@@ -467,6 +467,21 @@ public sealed class GrpcDataConditionStreamTests
|
||||
(await denied.ReadAckAsync()).Items.ShouldHaveSingleItem().Status.ShouldBe(DataItemStatus.Denied);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// #943: a peer granted only a UNS export cannot learn which raw roots exist through condition-item admission — an
|
||||
/// existing raw folder and a missing raw address are both NotFound; the granted UNS root is admitted (control).
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void A_condition_root_outside_the_grant_is_answered_like_a_missing_one_943()
|
||||
{
|
||||
using var f = new ConditionFixture(conditions: 1, unsPrincipal: true);
|
||||
var missing = f.Root with { Address = f.Root.Address with { Identifier = "Nope" }, Subject = "Nope" };
|
||||
f.Services.AuthorizeConditionItem(f.Context, f.Target, f.Root, out _).ShouldBe(DataItemStatus.NotFound);
|
||||
f.Services.AuthorizeConditionItem(f.Context, f.Target, missing, out _).ShouldBe(DataItemStatus.NotFound);
|
||||
f.Services.AuthorizeConditionItem(f.Context, f.Target, f.UnsRoot, out var authority).ShouldBe(DataItemStatus.Good);
|
||||
authority.ShouldNotBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task An_incomplete_snapshot_is_retaken_complete_once_the_apply_completes()
|
||||
{
|
||||
|
||||
+56
-1
@@ -83,6 +83,60 @@ public sealed class GrpcDataLocalConnectionTests
|
||||
result[1].Value.ShouldBeNull();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// #943: a peer granted only a UNS export cannot probe guessed Raw-realm addresses and learn which exist —
|
||||
/// GetMetadata, Read, Subscribe and condition-item admission answer an existing raw tag outside its grant exactly
|
||||
/// like a missing one (<c>NotFound</c>). Positive control: the granted UNS view still answers Good, so the refusal
|
||||
/// is the grant, not a broken fixture.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task Addresses_outside_the_grant_are_answered_like_missing_ones_943()
|
||||
{
|
||||
using var fixture = new LocalDataFixture(nestedUnsCatalog: true, unsOnlyExport: true);
|
||||
await using var connection = fixture.Connection();
|
||||
fixture.Catalog.Nodes.ShouldContain(n => n.Metadata.View == fixture.Raw, "the raw tag exists at the origin");
|
||||
var missing = fixture.Raw with { Address = fixture.Raw.Address with { Identifier = "Plant/Driver/Device/Nope" }, Subject = "Plant/Driver/Device/Nope" };
|
||||
var ct = TestContext.Current.CancellationToken;
|
||||
|
||||
var metadata = await connection.GetMetadataAsync(new([fixture.Raw, missing, fixture.Root, fixture.Uns], LocalDataFixture.Budget), ct);
|
||||
metadata.Select(x => x.Status).ShouldBe([DataItemStatus.NotFound, DataItemStatus.NotFound, DataItemStatus.NotFound, DataItemStatus.Good]);
|
||||
metadata.Take(3).ShouldAllBe(x => x.Value == null && x.Lease == null);
|
||||
|
||||
fixture.Publish(7);
|
||||
var reads = await connection.ReadAsync(new([new("existing", fixture.Raw, null), new("missing", missing, null),
|
||||
new("granted", fixture.Uns, null)], LocalDataFixture.Budget), ct);
|
||||
try
|
||||
{
|
||||
reads.Select(x => x.Status).ShouldBe([DataItemStatus.NotFound, DataItemStatus.NotFound, DataItemStatus.Good]);
|
||||
reads.Take(2).ShouldAllBe(x => x.Readiness == DataReadiness.Unavailable && x.Sample == null);
|
||||
}
|
||||
finally { foreach (var read in reads) read.Dispose(); }
|
||||
|
||||
var target = new DataTarget(DataTargetMode.Node, "cluster", fixture.Serving.NodeId);
|
||||
fixture.Services.AuthorizeSubscription(fixture.Context, target, fixture.Raw, out _).ShouldBe(DataItemStatus.NotFound);
|
||||
fixture.Services.AuthorizeSubscription(fixture.Context, target, missing, out _).ShouldBe(DataItemStatus.NotFound);
|
||||
fixture.Services.AuthorizeSubscription(fixture.Context, target, fixture.Uns, out var granted).ShouldBe(DataItemStatus.Good);
|
||||
granted.ShouldNotBeNull();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// #943: inside the grant a refusal still says Denied (the peer already sees the node), so the fix does not blur a
|
||||
/// misconfigured export into "missing": a view whose address is granted but whose claimed mapping fields do not match
|
||||
/// the origin node is Denied, not NotFound.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task A_mismatched_view_of_a_granted_address_is_still_denied_943()
|
||||
{
|
||||
using var fixture = new LocalDataFixture();
|
||||
await using var connection = fixture.Connection();
|
||||
var mapped = fixture.Raw with { MappingId = "m", MappingRevision = 1 };
|
||||
var metadata = await connection.GetMetadataAsync(new([mapped], LocalDataFixture.Budget), TestContext.Current.CancellationToken);
|
||||
metadata.ShouldHaveSingleItem().Status.ShouldBe(DataItemStatus.Denied);
|
||||
var reads = await connection.ReadAsync(new([new("mapped", mapped, null)], LocalDataFixture.Budget), TestContext.Current.CancellationToken);
|
||||
using var read = reads.ShouldHaveSingleItem();
|
||||
read.Status.ShouldBe(DataItemStatus.Denied);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Browse_continuation_is_bound_to_the_original_query_and_retains_bounded_scan_progress()
|
||||
{
|
||||
@@ -174,7 +228,7 @@ internal sealed class LocalDataFixture : IDisposable
|
||||
Func<DataAuthenticatedContext, IDataWriteService>? writes = null, bool denyReadExport = false,
|
||||
ManualTimeProvider? clock = null, string servingNode = "node-a", string servingIncarnation = "serving-1",
|
||||
IOriginHistoryPort? history = null, DataValueKind rawValueKind = DataValueKind.Int32, int maxBatchItems = 100,
|
||||
string? siblingPattern = null)
|
||||
string? siblingPattern = null, bool unsOnlyExport = false)
|
||||
{
|
||||
if (clock is not null) Clock = clock;
|
||||
Serving = Serving with { NodeId = servingNode, Incarnation = servingIncarnation, Role = role, ServingGeneration = servingGeneration };
|
||||
@@ -241,6 +295,7 @@ internal sealed class LocalDataFixture : IDisposable
|
||||
new() { ClusterId = "cluster", Kind = NodeHierarchyKind.Raw, Segments = ["Plant", name] }, Root, Ticket.Key, Supported: supported));
|
||||
}
|
||||
Catalog = new LocalExportCatalog("cluster", Serving, Activation.CaptureAuthority(), nodes,
|
||||
unsOnlyExport ? [new() { DataExportId = "uns-export", ClusterId = "cluster", Enabled = true, Realm = DataRealm.Uns, RootKind = nestedUnsCatalog ? "UnsArea" : "UnsTagReference", RootEntityId = nestedUnsCatalog ? "area" : "reference", PrincipalId = "peer", AllowedOperations = operations }] :
|
||||
[new() { DataExportId = "raw-export", ClusterId = "cluster", Enabled = true, Realm = DataRealm.Raw, RootKind = "RawFolder", RootEntityId = "folder", PrincipalId = "peer", AllowedOperations = operations },
|
||||
new() { DataExportId = "uns-export", ClusterId = "cluster", Enabled = true, Realm = DataRealm.Uns, RootKind = nestedUnsCatalog ? "UnsArea" : "UnsTagReference", RootEntityId = nestedUnsCatalog ? "area" : "reference", PrincipalId = "peer", AllowedOperations = operations }]);
|
||||
var limits = new DataLimits(100, maxBatchItems, 1_000_000, 100, 10, 1_000_000, TimeSpan.FromSeconds(15), TimeSpan.FromHours(1), TimeSpan.FromMinutes(1));
|
||||
|
||||
Reference in New Issue
Block a user