feat(heidenhain): read-only, credential and endpoint deploy gates + TagConfig inspector (#803)

- HeidenhainDeployChecks (wired into DraftValidator): HeidenhainTagWritable refuses a
  ReadWrite access level on any Heidenhain tag, so no node is ever advertised writable;
  HeidenhainCredentialPersisted refuses a literal password in DriverConfig/DeviceConfig
  (only blank / secret: / env: references; the value is never echoed);
  HeidenhainConfigInvalid for out-of-range settings or a tagged device without an endpoint.
- EquipmentTagConfigInspector maps Heidenhain to HeidenhainTagDefinitionFactory.Inspect.
- Driver validates only devices that carry tags (an unconfigured default Device1 no longer
  faults the driver).
This commit is contained in:
Joseph Doherty
2026-11-10 23:10:36 -05:00
parent d50ee809e3
commit 2b45694f91
7 changed files with 185 additions and 9 deletions
@@ -0,0 +1,78 @@
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;
namespace ZB.MOM.WW.OtOpcUa.Configuration.Tests;
/// <summary>lmxopcua#803: the Heidenhain read-only, credential and endpoint deploy gates.</summary>
[Trait("Category", "Unit")]
public sealed class DraftValidatorHeidenhainTests
{
private static DriverInstance Driver(string config = "{}", string type = "Heidenhain") => new()
{
DriverInstanceId = "hh", ClusterId = "c", Name = "hh", DriverType = type, DriverConfig = config,
};
private static Device Dev(string config = """{"Host":"10.0.0.5"}""") => new()
{
DeviceId = "d1", DriverInstanceId = "hh", Name = "dev1", DeviceConfig = config,
};
private static Tag T(TagAccessLevel access) => new()
{
TagId = "t1", DeviceId = "d1", Name = "ExecState", DataType = "Int32", AccessLevel = access,
TagConfig = """{"address":"Status/ExecutionState"}""",
};
private static IReadOnlyList<ValidationError> Validate(DriverInstance d, Device dev, params Tag[] tags) =>
DraftValidator.Validate(new DraftSnapshot
{
GenerationId = 1, ClusterId = "c", DriverInstances = [d], Devices = [dev], Tags = tags,
});
[Fact]
public void A_read_only_tag_on_a_configured_control_is_valid()
=> Validate(Driver(), Dev(), T(TagAccessLevel.Read)).ShouldNotContain(e => e.Code.StartsWith("Heidenhain", StringComparison.Ordinal));
[Fact]
public void A_ReadWrite_tag_is_refused_so_no_node_is_ever_writable()
{
var e = Validate(Driver(), Dev(), T(TagAccessLevel.ReadWrite)).Single(x => x.Code == HeidenhainDeployChecks.WritableCode);
e.Context.ShouldBe("t1");
e.Message.ShouldContain("read-only");
}
[Theory]
[InlineData("""{"Access":{"InspectPassword":"hunter2"}}""", "{\"Host\":\"10.0.0.5\"}")]
[InlineData("{}", """{"Host":"10.0.0.5","DncPassword":"hunter2"}""")]
public void A_literal_password_is_refused_without_echoing_it(string driverConfig, string deviceConfig)
{
var errors = Validate(Driver(driverConfig), Dev(deviceConfig), T(TagAccessLevel.Read));
errors.ShouldContain(e => e.Code == HeidenhainDeployChecks.CredentialCode);
errors.ShouldAllBe(e => !e.Message.Contains("hunter2"));
}
[Fact]
public void Secret_and_env_references_are_accepted()
=> Validate(Driver("""{"Access":{"InspectPassword":"secret:lsv2/inspect","DncPassword":"env:LSV2_DNC"}}"""), Dev(), T(TagAccessLevel.Read))
.ShouldNotContain(e => e.Code.StartsWith("Heidenhain", StringComparison.Ordinal));
[Fact]
public void A_device_with_tags_but_no_endpoint_is_refused_while_an_empty_device_is_not()
{
Validate(Driver(), Dev("{}"), T(TagAccessLevel.Read)).ShouldContain(e => e.Code == HeidenhainDeployChecks.ConfigCode && e.Context == "d1");
Validate(Driver(), Dev("{}")).ShouldNotContain(e => e.Code.StartsWith("Heidenhain", StringComparison.Ordinal));
}
[Fact]
public void Out_of_range_settings_are_refused()
=> Validate(Driver("""{"Polling":{"MaxAlarms":999}}"""), Dev(), T(TagAccessLevel.Read))
.ShouldContain(e => e.Code == HeidenhainDeployChecks.ConfigCode);
[Fact]
public void Other_drivers_are_unaffected()
=> Validate(Driver("""{"Access":{"InspectPassword":"x"}}""", type: "Modbus"), Dev(), T(TagAccessLevel.ReadWrite))
.ShouldNotContain(e => e.Code.StartsWith("Heidenhain", StringComparison.Ordinal));
}