Files
lmxopcua/tests/Core/ZB.MOM.WW.OtOpcUa.Configuration.Tests/DataConnections/GrpcDataExportRootValidationTests.cs
T
Joseph Doherty bddf3724f8 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.
2026-12-01 19:32:14 -05:00

68 lines
4.2 KiB
C#

using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Configuration.Entities;
using ZB.MOM.WW.OtOpcUa.Configuration.Enums;
using ZB.MOM.WW.OtOpcUa.Configuration.Validation;
using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections;
namespace ZB.MOM.WW.OtOpcUa.Configuration.Tests.DataConnections;
/// <summary>
/// #942: an export rooted at an alarm-bearing raw tag (or a UNS reference to one) grants nothing — the tag is an
/// unsupported value node (#917) and its condition placements sit under its folder / the referencing equipment. The
/// authoring + deploy-gate validator refuses such a root; node-side re-validation of a deployed artifact tolerates it.
/// </summary>
[Trait("Category", "Unit"), Trait("Feature", "GrpcData")]
public sealed class GrpcDataExportRootValidationTests
{
private const string AlarmConfig = "{\"alarm\":{\"alarmType\":\"AlarmCondition\",\"severity\":700}}";
private const string Code = "DataExportRootAlarmBearing";
[Theory]
[InlineData(DataRealm.Raw, "RawTag", "alarm-tag")]
[InlineData(DataRealm.Uns, "UnsTagReference", "ref-alarm")]
public void An_export_rooted_at_an_alarm_bearing_tag_is_refused_at_authoring_and_the_deploy_gate(DataRealm realm, string kind, string id)
{
var draft = Snapshot(realm, kind, id);
var error = DataConnectionValidator.Validate(draft).ShouldHaveSingleItem();
error.Code.ShouldBe(Code);
error.Context.ShouldBe("export");
DraftValidator.Validate(draft).ShouldContain(x => x.Code == Code && x.Context == "export");
// Node-side re-validation of an already-deployed artifact stays tolerant (a refusal there would fail the whole set).
DataConnectionValidator.ValidateDeployed(draft).ShouldNotContain(x => x.Code == Code);
}
[Theory]
[InlineData(DataRealm.Raw, "RawTag", "plain-tag")]
[InlineData(DataRealm.Uns, "UnsTagReference", "ref-plain")]
[InlineData(DataRealm.Raw, "RawDevice", "device")]
[InlineData(DataRealm.Uns, "Equipment", "eq")]
public void A_value_tag_or_a_container_holding_the_alarm_is_still_a_valid_root(DataRealm realm, string kind, string id) =>
DataConnectionValidator.Validate(Snapshot(realm, kind, id)).ShouldBeEmpty();
[Fact]
public void A_disabled_export_is_not_checked() =>
DataConnectionValidator.Validate(Snapshot(DataRealm.Raw, "RawTag", "alarm-tag", enabled: false)).ShouldBeEmpty();
private static DraftSnapshot Snapshot(DataRealm realm, string rootKind, string rootId, bool enabled = true) => new()
{
GenerationId = 1, ClusterId = "local",
ServerClusters = [new() { ClusterId = "local", Name = "Local", Enterprise = "E", Site = "S", CreatedBy = "test", RedundancyMode = RedundancyMode.None }],
RawFolders = [new() { RawFolderId = "folder", ClusterId = "local", Name = "Plant" }],
DriverInstances = [new() { DriverInstanceId = "driver", ClusterId = "local", RawFolderId = "folder", Name = "Driver", DriverType = "Modbus", DriverConfig = "{}" }],
Devices = [new() { DeviceId = "device", DriverInstanceId = "driver", Name = "Device", DeviceConfig = "{}" }],
Tags = [new() { TagId = "plain-tag", DeviceId = "device", Name = "Speed", DataType = "Int32", AccessLevel = TagAccessLevel.Read, TagConfig = "{}" },
new() { TagId = "alarm-tag", DeviceId = "device", Name = "OverTemp", DataType = "Boolean", AccessLevel = TagAccessLevel.Read, TagConfig = AlarmConfig }],
UnsAreas = [new() { UnsAreaId = "area", ClusterId = "local", Name = "Area" }],
UnsLines = [new() { UnsLineId = "line", UnsAreaId = "area", Name = "Line" }],
Equipment = [new() { EquipmentId = "eq", UnsLineId = "line", Name = "Filler", MachineCode = "E1" }],
UnsTagReferences = [new() { UnsTagReferenceId = "ref-plain", EquipmentId = "eq", TagId = "plain-tag" },
new() { UnsTagReferenceId = "ref-alarm", EquipmentId = "eq", TagId = "alarm-tag" }],
DataExports = [new DataExport
{
DataExportId = "export", ClusterId = "local", Enabled = enabled, Revision = 1, Realm = realm, RootKind = rootKind,
RootEntityId = rootId, PrincipalId = "peer", AllowedOperations = DataOperations.Browse | DataOperations.Read,
}],
};
}