87 lines
5.2 KiB
C#
87 lines
5.2 KiB
C#
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.Configuration.Entities;
|
|
using ZB.MOM.WW.OtOpcUa.Configuration.Validation;
|
|
using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Configuration.Tests.DataConnections;
|
|
|
|
/// <summary>
|
|
/// X0 grow site: authoring keeps rejecting the reserved bits until the phase that implements each one, so central
|
|
/// cannot hand a node a grant it does not implement. Only the node-side re-validation of a deployed artifact tolerates them.
|
|
/// </summary>
|
|
[Trait("Category", "Unit"), Trait("Feature", "GrpcData"), Trait("Phase", "X0")]
|
|
public sealed class GrpcDataReservedOperationAuthoringTests
|
|
{
|
|
// H2 implemented 32 (HistoryRead), A2a 64 (AlarmSubscribe), A2b 128/256 (AlarmAcknowledge/AlarmConfirm): authoring accepts
|
|
// them (GrpcDataHistoryConfigurationTests, GrpcDataConditionConfigurationTests). 512 (AlarmShelve) stays reserved.
|
|
public static TheoryData<int> ReservedBits => new(512);
|
|
|
|
[Theory]
|
|
[MemberData(nameof(ReservedBits))]
|
|
public void Authoring_rejects_a_reserved_bit_on_connections_exports_and_mappings(int bit)
|
|
{
|
|
var errors = DataConnectionValidator.Validate(Snapshot(DataOperations.Read | (DataOperations)bit));
|
|
errors.ShouldContain(x => x.Code == "DataConnectionOperationsInvalid" && x.Context == "connection");
|
|
errors.ShouldContain(x => x.Code == "DataExportOperationsInvalid" && x.Context == "export");
|
|
errors.ShouldContain(x => x.Code == "DataMappingOperationsInvalid" && x.Context == "mapping");
|
|
}
|
|
|
|
[Fact]
|
|
public void Authoring_accepts_the_v1_set_unchanged()
|
|
{
|
|
var errors = DataConnectionValidator.Validate(Snapshot(DataOperations.Read));
|
|
errors.ShouldNotContain(x => x.Code.EndsWith("OperationsInvalid", StringComparison.Ordinal));
|
|
DataOperationSets.V1.ShouldBe(DataOperations.Browse | DataOperations.Metadata | DataOperations.Read | DataOperations.Write | DataOperations.Subscribe);
|
|
}
|
|
|
|
[Theory]
|
|
[MemberData(nameof(ReservedBits))]
|
|
public void Deployed_revalidation_ignores_reserved_bits_but_keeps_every_other_operation_rule(int bit)
|
|
{
|
|
DataConnectionValidator.ValidateDeployed(Snapshot(DataOperations.Read | (DataOperations)bit))
|
|
.ShouldNotContain(x => x.Code.EndsWith("OperationsInvalid", StringComparison.Ordinal));
|
|
// Still rejected node-side: an empty grant, and a mapping wider than its connection in UNDERSTOOD bits.
|
|
DataConnectionValidator.ValidateDeployed(Snapshot(DataOperations.None))
|
|
.ShouldContain(x => x.Code == "DataConnectionOperationsInvalid");
|
|
var wider = Snapshot(DataOperations.Read | (DataOperations)bit);
|
|
wider.RemoteNamespaceMappings[0].AllowedOperations = DataOperations.Read | DataOperations.Subscribe;
|
|
DataConnectionValidator.ValidateDeployed(wider).ShouldContain(x => x.Code == "DataMappingOperationsInvalid");
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(1 << 10)]
|
|
[InlineData(1 << 30)]
|
|
public void Any_bit_outside_v1_is_rejected_at_authoring_and_tolerated_on_a_deployed_artifact(int bit)
|
|
{
|
|
// Authoring rejects anything outside V1. A deployed artifact may come from a newer central that defines bits this
|
|
// build has never heard of (not only the X0 reservation), so node-side re-validation ignores them; consumers mask
|
|
// them away (GrpcDataArtifactReadTests / GrpcDataUnknownOperationToleranceTests pin "parses, grants nothing").
|
|
var authored = DataConnectionValidator.Validate(Snapshot(DataOperations.Read | (DataOperations)bit));
|
|
authored.ShouldContain(x => x.Code == "DataConnectionOperationsInvalid");
|
|
authored.ShouldContain(x => x.Code == "DataExportOperationsInvalid");
|
|
DataConnectionValidator.ValidateDeployed(Snapshot(DataOperations.Read | (DataOperations)bit))
|
|
.ShouldNotContain(x => x.Code.EndsWith("OperationsInvalid", StringComparison.Ordinal));
|
|
// An all-unknown row is non-empty, so it is not an error; it simply grants nothing downstream.
|
|
DataConnectionValidator.ValidateDeployed(Snapshot((DataOperations)bit))
|
|
.ShouldNotContain(x => x.Code == "DataConnectionOperationsInvalid" || x.Code == "DataExportOperationsInvalid");
|
|
}
|
|
|
|
internal static DraftSnapshot Snapshot(DataOperations operations) => new()
|
|
{
|
|
GenerationId = 1, ClusterId = "local",
|
|
DataConnections = [new DataConnection
|
|
{
|
|
DataConnectionId = "connection", ClusterId = "local", Revision = 1, Enabled = true, AllowedOperations = operations,
|
|
ConsumerNodeIds = [], EligibleTargetNodeIds = [], Endpoints = ["https://origin.example:7443"],
|
|
MaxMessageBytes = 1, MaxBatchItems = 1, MaxPageItems = 1, MaxStreams = 1, MaxMonitoredItems = 1, MaxPendingBytes = 1, TimeoutMilliseconds = 1,
|
|
}],
|
|
DataExports = [new DataExport { DataExportId = "export", ClusterId = "local", Enabled = true, AllowedOperations = operations, PrincipalId = "p", Revision = 1 }],
|
|
RemoteNamespaceMappings = [new RemoteNamespaceMapping
|
|
{
|
|
RemoteNamespaceMappingId = "mapping", ClusterId = "local", DataConnectionId = "connection", Enabled = true,
|
|
AllowedOperations = operations, ConsumerNodeIds = [], Revision = 1,
|
|
}],
|
|
};
|
|
}
|