fix(opcuaclient): keep the configured IPv6 zone index through the endpoint rewrite (#819)
.NET's Uri parses a zone ([fe80::1%eth0]) but drops it from Host, Authority, AbsoluteUri and ToString(); only DnsSafeHost/IdnHost carry it. The shared OpcUaEndpointUrlRewriter rebuilt the URL through UriBuilder, so the zone was lost and link-local endpoints were unroutable. The SDK dials new Uri(EndpointUrl).IdnHost (TcpByteTransport -> DnsEndPoint), which keeps it, so splicing the zone back into the string is enough. Kept verbatim (%eth0, %4, or RFC 6874 %25eth0) so the session dials exactly what GetEndpoints reached. Applies to the driver, the AdminUI browser and the Client CLI/UI (all share the rewriter).
This commit is contained in:
+37
@@ -94,6 +94,43 @@ public sealed class OpcUaClientEndpointRewriteTests
|
||||
.ShouldBe("opc.tcp://[fd00::1]:54840/OtOpcUa");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gitea #819 — a configured IPv6 zone index survives the rewrite verbatim. .NET's <see cref="Uri"/> drops it from
|
||||
/// every re-serialisation (Host, Authority, AbsoluteUri, ToString), so before #819 a link-local endpoint came out
|
||||
/// zone-less and unroutable.
|
||||
/// </summary>
|
||||
[Theory]
|
||||
[InlineData("opc.tcp://[fe80::1%eth0]:4841", "opc.tcp://[fe80::1%eth0]:4841/OtOpcUa")]
|
||||
[InlineData("opc.tcp://[fe80::1%4]:4841/", "opc.tcp://[fe80::1%4]:4841/OtOpcUa")]
|
||||
// RFC 6874's encoded delimiter is kept as written, not normalised: the session dials what GetEndpoints reached.
|
||||
[InlineData("opc.tcp://[fe80::1%25eth0]:4841", "opc.tcp://[fe80::1%25eth0]:4841/OtOpcUa")]
|
||||
// Port-less configured URL: the advertised port is kept, the zone still is.
|
||||
[InlineData("opc.tcp://[fe80::1%eth0]", "opc.tcp://[fe80::1%eth0]:4840/OtOpcUa")]
|
||||
public void An_IPv6_zone_index_on_the_configured_host_is_preserved(string configured, string expected)
|
||||
{
|
||||
OpcUaEndpointUrlRewriter.Rewrite("opc.tcp://internal-host:4840/OtOpcUa", configured).ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_zone_index_reaches_the_host_the_SDK_dials()
|
||||
{
|
||||
// The SDK's TCP transport connects to new Uri(EndpointDescription.EndpointUrl).IdnHost (ConfiguredEndpoint
|
||||
// re-parses the string), so the zone must survive into that accessor — and the advertised path with it.
|
||||
var rewritten = OpcUaEndpointUrlRewriter.Rewrite(
|
||||
"opc.tcp://[fe80::9]:4840/Ua", "opc.tcp://[fe80::1%eth0]:4841");
|
||||
var endpoint = new ConfiguredEndpoint(null, new EndpointDescription { EndpointUrl = rewritten }, EndpointConfiguration.Create());
|
||||
endpoint.EndpointUrl!.IdnHost.ShouldBe("fe80::1%eth0");
|
||||
endpoint.EndpointUrl.Port.ShouldBe(4841);
|
||||
endpoint.EndpointUrl.AbsolutePath.ShouldBe("/Ua");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_zone_matching_no_op_returns_the_advertised_string_verbatim()
|
||||
{
|
||||
OpcUaEndpointUrlRewriter.Rewrite("opc.tcp://[fe80::1%eth0]:4840/Ua", "opc.tcp://[fe80::1%eth0]:4840/")
|
||||
.ShouldBe("opc.tcp://[fe80::1%eth0]:4840/Ua");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void An_IPv6_advertised_host_is_replaced_by_a_configured_name()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user