diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataComposedBrowseWireTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataComposedBrowseWireTests.cs index 91996b623..1b211ae7d 100644 --- a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataComposedBrowseWireTests.cs +++ b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataComposedBrowseWireTests.cs @@ -362,7 +362,7 @@ public sealed partial class GrpcDataConfiguredDiscoveryWireTests bool restrictToPlant = false, Action? onPublished = null, bool mountAtRealmRoot = false, long maxUnaryBytes = 8_000_000, bool allowWrite = false, IGrpcDataAdapterConnectionSource? connectionSource = null, int? staleTimeoutMilliseconds = null, Func? renewalSinkFactory = null, - Action? onCoordinator = null, int? localPermissions = null) + Action? onCoordinator = null, int? localPermissions = null, bool allowHistory = false) { var ct = TestContext.Current.CancellationToken; var pki = Path.Combine(Path.GetTempPath(), $"composed-projection-{Guid.NewGuid():N}"); @@ -400,6 +400,7 @@ public sealed partial class GrpcDataConfiguredDiscoveryWireTests if (mountAtRealmRoot) { mapping.LocalParentKind = "Cluster"; mapping.LocalParentId = "cluster"; } mapping.AllowedOperations |= DataOperations.Read | DataOperations.Metadata; if (allowWrite) { mapping.AllowedOperations |= DataOperations.Write; mapping.WriteThrough = true; } + if (allowHistory) mapping.AllowedOperations |= DataOperations.HistoryRead; placements.Stage(attempt, [mapping], [Connection()]); coordinator.Complete(attempt, true).ShouldBeTrue(); var manager = started.Server.NodeManager!; diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataProjectedHistoryRefusalTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataProjectedHistoryRefusalTests.cs new file mode 100644 index 000000000..2a82ab6b9 --- /dev/null +++ b/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataProjectedHistoryRefusalTests.cs @@ -0,0 +1,39 @@ +using Opc.Ua; +using Opc.Ua.Client; +using Shouldly; +using Xunit; + +namespace ZB.MOM.WW.OtOpcUa.Runtime.Tests.DataConnections; + +public sealed partial class GrpcDataConfiguredDiscoveryWireTests +{ + /// + /// H2 review 7: DataOperationPolicy now maps OPC UA HistoryRead to the mapping's HistoryRead bit, so a mapped + /// HistoryRead is AUTHORISABLE before H3 projects history. Pin that a projected node with the mapping bit AND a local + /// HistoryRead grant still answers a clean refusal — never data, never a fault — until H3. + /// + [Fact(Timeout = 90000)] + [Trait("Phase", "H2")] + public async Task HistoryRead_on_a_projected_node_stays_a_clean_refusal_until_H3() + { + using var origin = new LocalDataFixture(servingGeneration: 1); + await WithComposedServer(origin, origin.Raw, async (session, _, _, _, _, _, anchor) => + { + var client = (SessionClient)session; + await BrowseAll(client, anchor, 1); + var details = new ReadRawModifiedDetails + { + StartTime = DateTime.UtcNow.AddHours(-1), EndTime = DateTime.UtcNow, NumValuesPerNode = 10, + IsReadModified = false, ReturnBounds = false, + }; + var response = await client.HistoryReadAsync(new RequestHeader(), new ExtensionObject(details), TimestampsToReturn.Both, false, + [new HistoryReadValueId { NodeId = anchor }], TestContext.Current.CancellationToken); + var result = response.Results.ToArray()!.Single(); + // Pinned: the projected variable carries no HistoryRead access-level bit, so the SDK refuses before any history code. + result.StatusCode.Code.ShouldBe(StatusCodes.BadHistoryOperationUnsupported.Code); + (result.HistoryData.IsNull || ExtensionObject.ToEncodeable(result.HistoryData) is not HistoryData { DataValues.Count: > 0 }) + .ShouldBeTrue("no data is served from a projected node before H3"); + result.ContinuationPoint.IsEmpty.ShouldBeTrue(); + }, localPermissions: 15, allowHistory: true); + } +}