mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-29 15:11:53 +08:00
# Description The CTT AliasName conformance units skip or fail against the ConsoleReferenceServer. `AliasName Base` skips with *"No instance of AliasNameType has been found in the address space"*; `Category Tags`, `Category Topics` and `Hierarchy` fail. Part 17 support landed in #3779, but aliases live only inside the `IAliasNameStore` — nothing is browsable, no `AliasNameCategoryType` is nested under another, and the Topics aliases point at the Server object rather than at a `PublishedDataSetType` instance. Part 17 §6.2 clients — the CTT among them — discover aliases by browsing, not only by calling `FindAlias`. This PR materializes the store contents as real nodes and fills the three gaps. ### SDK — `Opc.Ua.Server` * **`DiagnosticsNodeManager.MaterializeRegisteredAliasNameNodesAsync`** (new, opt-in) walks every registered `IAliasNameStore` and creates one `AliasNameType` instance per alias — BrowseName carrying the alias name, `AliasFor` references to its targets, and the inverse `HasAlias` reference on each local target (via `externalReferences`, since targets usually live in another node manager) — plus an `AliasNameCategoryType` instance for every store category the standard NodeSet does not already ship. Categories whose NodeId belongs to another node manager are skipped, so an `AliasNameNodeManager` that also registers its store with the server-wide registry does not get its NodeIds claimed twice. Opt-in: servers that only need the well-known `FindAlias` to answer from their store pay nothing. The nodes are a snapshot taken at address-space creation — later mutations change what `FindAlias` returns but do not add or remove nodes. * **Optional Part 17 methods on the well-known categories.** The same pass instantiates whatever a category declares through `AliasNameCapabilities`: `FindAliasVerbose` (§6.3.3), `AddAliasesToCategory` (§6.3.4), `DeleteAliasesFromCategory` (§6.3.5) and `LastChange` (§6.3.1). Mutations require a `SecurityAdmin` caller on a `SignAndEncrypt` channel; the gate previously private to `AliasNameNodeManager` moved to `AliasNameMethodDispatcher` so both paths share one implementation. * **`LastChange`** is now tracked per category rather than only for the standard `Aliases` node, and the duplicated seeding logic collapsed into one helper. ### Reference server * A nested **`Devices`** category under `TagVariables` holds `Pump1_Status` and `Heater_Power`. `FindAlias` on `TagVariables` still returns all six names through subtree recursion, while `FindAlias` on `Devices` returns exactly two — which is what the Hierarchy unit checks. * `ReferenceServerConfigurationNodeManager` creates three **`PublishedDataSet` instances** under `PublishedDataSets` (`i=17371`) and the Topics aliases now target them, satisfying the *"is a Dataset"* check. These are address-space instances only — no PubSub runtime is added, and the CTT only inspects the target's type definition. ## Note for reviewers — the reserved NodeIds The optional children are created at the NodeIds the OPC Foundation reserves for them (`Aliases.FindAliasVerbose` = `i=24054`, `TagVariables.LastChange` = `i=32854`, …). Those identifiers are allocated in `StandardTypes.csv` but are **not** declared in the ModelDesign and **not** present in the published NodeSet, because the standard address space does not instantiate optional children. The source generator therefore emits no parent-to-instance mapping and no `MethodIds` constants for them, so `DiagnosticsNodeManager.ReservedChildIds` supplies the nine method ids and the two missing `LastChange` ids explicitly, each traceable to its registry row. The 18 argument-property ids do have generated `VariableIds` constants and are referenced through those. I deliberately did **not** "fix" this by declaring the children in `tools/Opc.Ua.SourceGeneration.Core/Design/StandardTypes.xml`: that file is a verbatim copy of upstream `UA-ModelCompiler/Design.v105/StandardTypes.xml` (the only differences today are upstream being newer), so a local edit is lost on the next sync and the NodeIds would silently revert to factory-minted ones. `docs/AliasNames.md` records this. Worth raising upstream separately: `StandardTypes.csv` allocates `Aliases_FindAliasVerbose` and siblings while the ModelDesign never declares those children, so the ModelCompiler cannot emit ids it has itself reserved. If that is ever reconciled, `ReservedChildIds` becomes redundant and deletes cleanly. ## Related Issues - Fixes #4012 ## Checklist - [x] I have signed the [CLA](https://opcfoundation.org/license/cla/ContributorLicenseAgreementv1.0.pdf) and read the [CONTRIBUTING](https://github.com/OPCFoundation/UA-.NETStandard/blob/master/CONTRIBUTING.md) doc. - [x] I have added tests that prove my fix is effective or that my feature works and increased code coverage. - [x] I have added all necessary documentation. - [x] I have verified that my changes do not introduce (new) build or analyzer warnings. - [ ] I ran **all** tests locally using the **UA.slnx** solution against at least .net **framework** and .net **10**, and all passed. — **not done: verified on net8.0 only** (Server 4710, InformationModel 1099, Core 4443, plus the client and features alias suites; AOT build clean). Needs a run against net framework and net10 before this leaves draft. - [ ] I fixed **all** failing and flaky tests in the CI pipelines and **all** CodeQL warnings. - [ ] I have addressed **all** PR feedback received. ### Tests `tests/Opc.Ua.InformationModel.Tests/Aliasname*Tests.cs` mirror the four CTT conformance units and no longer `Assert.Ignore` where the CTT reported failures — the alias suite is 37 tests with no skips. New `AliasnameOptionalMethodsTests` covers the optional methods, their reserved NodeIds, the anonymous-caller denial, an add/find/delete round trip and `LastChange` advancing on mutation. One pre-existing test changed premise: `EnumerateSubCategoriesAsyncOnLeafReturnsEmptyAsync` asserted that `TagVariables` has no sub-categories, which this PR deliberately makes false. It now targets `Topics` (still a leaf) and a new test guards the nesting. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: romanett <7413710+romanett@users.noreply.github.com> Co-authored-by: marcschier <11168470+marcschier@users.noreply.github.com>
451 lines
21 KiB
C#
451 lines
21 KiB
C#
/* ========================================================================
|
|
* Copyright (c) 2005-2025 The OPC Foundation, Inc. All rights reserved.
|
|
*
|
|
* OPC Foundation MIT License 1.00
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person
|
|
* obtaining a copy of this software and associated documentation
|
|
* files (the "Software"), to deal in the Software without
|
|
* restriction, including without limitation the rights to use,
|
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the
|
|
* Software is furnished to do so, subject to the following
|
|
* conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be
|
|
* included in all copies or substantial portions of the Software.
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
*
|
|
* The complete license agreement can be found here:
|
|
* http://opcfoundation.org/License/MIT/1.00/
|
|
* ======================================================================*/
|
|
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using NUnit.Framework;
|
|
using Opc.Ua.Client.TestFramework;
|
|
using static Opc.Ua.InformationModel.Tests.AliasNameTestHelpers;
|
|
|
|
// Conformance tests use inline literal arrays as expected-value
|
|
// assertions; the per-call allocation cost is irrelevant for tests
|
|
// and keeping the literal adjacent to the assertion improves readability.
|
|
#pragma warning disable CA1861 // Avoid constant arrays as arguments
|
|
|
|
namespace Opc.Ua.InformationModel.Tests
|
|
{
|
|
/// <summary>
|
|
/// compliance tests for AliasName Base.
|
|
/// </summary>
|
|
[TestFixture]
|
|
[Category("Conformance")]
|
|
[Category("AliasName")]
|
|
public class AliasnameBaseTests : TestFixture
|
|
{
|
|
[Description("Verify that the type system includes the AliasNameType, the AliasNameCategoryType and the assocated Datatype AliasNameDataType and the AliasFor Reference type.")]
|
|
[Test]
|
|
public async Task TypeSystemDefinesAliasNameTypesAsync()
|
|
{
|
|
(NodeId id, string expected)[] cases =
|
|
[
|
|
(AliasNameTypeNodeId, "AliasNameType"),
|
|
(AliasNameCategoryTypeNodeId, "AliasNameCategoryType"),
|
|
(AliasNameDataTypeNodeId, "AliasNameDataType"),
|
|
(AliasForNodeId, "AliasFor")
|
|
];
|
|
|
|
foreach ((NodeId id, string expected) in cases)
|
|
{
|
|
DataValue dv = await ReadAttributeAsync(
|
|
Session, id, Attributes.BrowseName).ConfigureAwait(false);
|
|
Assert.That(StatusCode.IsGood(dv.StatusCode), Is.True,
|
|
$"BrowseName of {id} should be readable.");
|
|
QualifiedName name = dv.GetValue<QualifiedName>(default);
|
|
Assert.That(name, Is.Not.Null);
|
|
Assert.That(name.Name, Is.EqualTo(expected),
|
|
$"NodeId {id} should have BrowseName '{expected}'.");
|
|
}
|
|
}
|
|
|
|
[Description("Browse the Objects Folder for 'Aliases'")]
|
|
[Test]
|
|
public async Task ObjectsFolderContainsAliasesObjectAsync()
|
|
{
|
|
DataValue dv = await ReadAttributeAsync(
|
|
Session, AliasesNodeId, Attributes.BrowseName).ConfigureAwait(false);
|
|
Assert.That(StatusCode.IsGood(dv.StatusCode), Is.True,
|
|
"Aliases (i=23470) BrowseName should be readable.");
|
|
QualifiedName name = dv.GetValue<QualifiedName>(default);
|
|
Assert.That(name.Name, Is.EqualTo("Aliases"));
|
|
|
|
// The Aliases object is reachable from the Objects folder via
|
|
// the standard Server hierarchy (Objects → Server → ... or
|
|
// Objects → Aliases). Walk the Objects folder hierarchy and
|
|
// confirm the Aliases object is reachable from it.
|
|
DataValue parent = await ReadAttributeAsync(
|
|
Session, AliasesNodeId, Attributes.NodeId).ConfigureAwait(false);
|
|
Assert.That(StatusCode.IsGood(parent.StatusCode), Is.True);
|
|
|
|
IList<ReferenceDescription> objectChildren = await BrowseChildrenAsync(
|
|
Session, ObjectIds.ObjectsFolder).ConfigureAwait(false);
|
|
Assert.That(objectChildren, Is.Not.Empty,
|
|
"Objects folder should expose at least one child.");
|
|
}
|
|
|
|
[Description("Browse the Hiearchy under object.")]
|
|
[Test]
|
|
public async Task AliasesHierarchyCanBeBrowsedAsync()
|
|
{
|
|
IList<ReferenceDescription> children =
|
|
await BrowseChildrenAsync(Session, AliasesNodeId).ConfigureAwait(false);
|
|
|
|
int categoryCount = 0;
|
|
foreach (ReferenceDescription child in children)
|
|
{
|
|
var typeDef = ExpandedNodeId.ToNodeId(
|
|
child.TypeDefinition, Session.NamespaceUris);
|
|
if (typeDef == AliasNameCategoryTypeNodeId)
|
|
{
|
|
categoryCount++;
|
|
}
|
|
}
|
|
|
|
Assert.That(categoryCount, Is.GreaterThanOrEqualTo(1),
|
|
"Aliases (i=23470) should expose at least one AliasNameCategory child.");
|
|
}
|
|
|
|
[Description("Verify the address space contains at least one AliasNameType instance with an association to a Node.")]
|
|
[Test]
|
|
public async Task AddressSpaceContainsAliasNameInstanceAsync()
|
|
{
|
|
// The AliasName Base conformance unit is skipped entirely when
|
|
// no AliasNameType instance can be found, so walk the Aliases
|
|
// hierarchy and require one that aliases an actual node.
|
|
var pending = new Queue<NodeId>();
|
|
pending.Enqueue(AliasesNodeId);
|
|
|
|
int aliasInstances = 0;
|
|
int aliasesWithTarget = 0;
|
|
|
|
while (pending.Count > 0)
|
|
{
|
|
NodeId current = pending.Dequeue();
|
|
IList<ReferenceDescription> children =
|
|
await BrowseChildrenAsync(Session, current).ConfigureAwait(false);
|
|
|
|
foreach (ReferenceDescription child in children)
|
|
{
|
|
var typeDef = ExpandedNodeId.ToNodeId(
|
|
child.TypeDefinition, Session.NamespaceUris);
|
|
var childId = ExpandedNodeId.ToNodeId(
|
|
child.NodeId, Session.NamespaceUris);
|
|
|
|
if (typeDef == AliasNameCategoryTypeNodeId)
|
|
{
|
|
pending.Enqueue(childId);
|
|
continue;
|
|
}
|
|
if (typeDef != AliasNameTypeNodeId)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
aliasInstances++;
|
|
Assert.That(child.BrowseName.Name, Is.Not.Null.And.Not.Empty,
|
|
"An AliasName instance carries its alias in the BrowseName.");
|
|
|
|
IList<ReferenceDescription> targets = await BrowseChildrenAsync(
|
|
Session, childId, AliasForNodeId).ConfigureAwait(false);
|
|
if (targets.Count > 0)
|
|
{
|
|
aliasesWithTarget++;
|
|
}
|
|
}
|
|
}
|
|
|
|
Assert.That(aliasInstances, Is.GreaterThan(0),
|
|
"The address space should contain at least one AliasNameType instance.");
|
|
Assert.That(aliasesWithTarget, Is.GreaterThan(0),
|
|
"At least one AliasName instance should have an AliasFor association to a Node.");
|
|
}
|
|
|
|
[Description("Call the FindAlias method on the Aliases object, passing in the string name part of the name of an AliasName instance. Pass in the AliasFor Reference type.")]
|
|
[Test]
|
|
public async Task FindAliasByExactNameAsync()
|
|
{
|
|
(NodeId category, NodeId method) = await FindCategoryAsync(
|
|
Session, "TagVariables").ConfigureAwait(false);
|
|
|
|
CallMethodResult result = await CallFindAliasAsync(
|
|
Session, category, method, "TIC101_Setpoint", AliasForNodeId)
|
|
.ConfigureAwait(false);
|
|
|
|
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True,
|
|
$"FindAlias should succeed: {result.StatusCode}");
|
|
|
|
IList<AliasRecord> records = DecodeAliasResults(Session, result);
|
|
Assert.That(records, Has.Count.EqualTo(1));
|
|
Assert.That(records[0].AliasName.Name, Is.EqualTo("TIC101_Setpoint"));
|
|
Assert.That(records[0].ReferencedNodes, Is.Not.Empty);
|
|
}
|
|
|
|
[Description("Call the FindAlias method on the Aliases object, passing in the string name part of the name of an AliasName instance, prefaced with a "%". Pass in the AliasFor Reference type.")]
|
|
[Test]
|
|
public async Task FindAliasWithPercentPrefixWildcardAsync()
|
|
{
|
|
(NodeId category, NodeId method) = await FindCategoryAsync(
|
|
Session, "TagVariables").ConfigureAwait(false);
|
|
|
|
CallMethodResult result = await CallFindAliasAsync(
|
|
Session, category, method, "%101_Setpoint", AliasForNodeId)
|
|
.ConfigureAwait(false);
|
|
|
|
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
|
|
IList<AliasRecord> records = DecodeAliasResults(Session, result);
|
|
Assert.That(records.Select(r => r.AliasName.Name),
|
|
Is.EquivalentTo(["TIC101_Setpoint"]));
|
|
}
|
|
|
|
[Description("Call the FindAlias method on the Aliases object, passing in the string name part of the name of an AliasName instance, with a "%" replacing any character in the name. Pass in the A")]
|
|
[Test]
|
|
public async Task FindAliasWithPercentMidWildcardAsync()
|
|
{
|
|
(NodeId category, NodeId method) = await FindCategoryAsync(
|
|
Session, "TagVariables").ConfigureAwait(false);
|
|
|
|
CallMethodResult result = await CallFindAliasAsync(
|
|
Session, category, method, "TIC%PV", AliasForNodeId)
|
|
.ConfigureAwait(false);
|
|
|
|
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
|
|
IList<AliasRecord> records = DecodeAliasResults(Session, result);
|
|
Assert.That(records.Select(r => r.AliasName.Name),
|
|
Is.EquivalentTo(["TIC101_PV"]));
|
|
}
|
|
|
|
[Description("Call the FindAlias method on the Aliases object, passing in the string name part of the name of an AliasName instance, replace the first character with a "_". Pass in the AliasFor")]
|
|
[Test]
|
|
public async Task FindAliasWithUnderscorePrefixWildcardAsync()
|
|
{
|
|
(NodeId category, NodeId method) = await FindCategoryAsync(
|
|
Session, "TagVariables").ConfigureAwait(false);
|
|
|
|
// '_' matches exactly one character — replace the leading 'T'.
|
|
CallMethodResult result = await CallFindAliasAsync(
|
|
Session, category, method, "_IC101_Setpoint", AliasForNodeId)
|
|
.ConfigureAwait(false);
|
|
|
|
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
|
|
IList<AliasRecord> records = DecodeAliasResults(Session, result);
|
|
Assert.That(records.Select(r => r.AliasName.Name),
|
|
Is.EquivalentTo(["TIC101_Setpoint"]));
|
|
}
|
|
|
|
[Description("Call the FindAlias method on the Aliases object, passing in the string name part of the name of an AliasName instance, with a "_" replacing any character in the name. Pass in the A")]
|
|
[Test]
|
|
public async Task FindAliasWithUnderscoreMidWildcardAsync()
|
|
{
|
|
(NodeId category, NodeId method) = await FindCategoryAsync(
|
|
Session, "TagVariables").ConfigureAwait(false);
|
|
|
|
// Replace the 'e' in 'Setpoint' with '_' (single-char wildcard).
|
|
CallMethodResult result = await CallFindAliasAsync(
|
|
Session, category, method, "TIC101_S_tpoint", AliasForNodeId)
|
|
.ConfigureAwait(false);
|
|
|
|
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
|
|
IList<AliasRecord> records = DecodeAliasResults(Session, result);
|
|
Assert.That(records.Select(r => r.AliasName.Name),
|
|
Is.EquivalentTo(["TIC101_Setpoint"]));
|
|
}
|
|
|
|
[Description("Call the FindAlias method on the Aliases object, passing in the string name part of the name of an AliasName instance, enclose the first character with "[]". Pass in the AliasFor R")]
|
|
[Test]
|
|
public async Task FindAliasWithBracketCharacterClassAsync()
|
|
{
|
|
(NodeId category, NodeId method) = await FindCategoryAsync(
|
|
Session, "TagVariables").ConfigureAwait(false);
|
|
|
|
// [T] matches a single 'T' — should match TIC101_Setpoint exactly.
|
|
CallMethodResult result = await CallFindAliasAsync(
|
|
Session, category, method, "[T]IC101_Setpoint", AliasForNodeId)
|
|
.ConfigureAwait(false);
|
|
|
|
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
|
|
IList<AliasRecord> records = DecodeAliasResults(Session, result);
|
|
Assert.That(records.Select(r => r.AliasName.Name),
|
|
Is.EquivalentTo(["TIC101_Setpoint"]));
|
|
}
|
|
|
|
[Description("Call the FindAlias method on the Aliases object, passing in the string name part of the name of an AliasName instance, enclose the first character with "[]" include the letters ABC")]
|
|
[Test]
|
|
public async Task FindAliasWithBracketCharacterRangeAsync()
|
|
{
|
|
(NodeId category, NodeId method) = await FindCategoryAsync(
|
|
Session, "TagVariables").ConfigureAwait(false);
|
|
|
|
// [TF] matches a single 'T' or 'F' as the first character —
|
|
// should match TIC101_*, FIC202_Flow.
|
|
CallMethodResult result = await CallFindAliasAsync(
|
|
Session, category, method, "[TF]IC%", AliasForNodeId)
|
|
.ConfigureAwait(false);
|
|
|
|
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
|
|
IList<AliasRecord> records = DecodeAliasResults(Session, result);
|
|
Assert.That(records.Select(r => r.AliasName.Name),
|
|
Is.EquivalentTo(
|
|
[
|
|
"TIC101_Setpoint",
|
|
"TIC101_PV",
|
|
"FIC202_Flow"
|
|
]));
|
|
}
|
|
|
|
[Description("Call the FindAlias method on the Aliases object, passing in the string name part of the name of an AliasName instance, enclose the first character with "[^]" (the ^ is before the c")]
|
|
[Test]
|
|
public async Task FindAliasWithNegatedBracketCharacterClassAsync()
|
|
{
|
|
(NodeId category, NodeId method) = await FindCategoryAsync(
|
|
Session, "TagVariables").ConfigureAwait(false);
|
|
|
|
// OPC UA Like-pattern uses '[!P]' for negation (Part 4).
|
|
// Should match every TagVariables alias that does NOT start with 'P'.
|
|
CallMethodResult result = await CallFindAliasAsync(
|
|
Session, category, method, "[!P]%", AliasForNodeId)
|
|
.ConfigureAwait(false);
|
|
|
|
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True);
|
|
IList<AliasRecord> records = DecodeAliasResults(Session, result);
|
|
string[] names = [.. records.Select(r => r.AliasName.Name)];
|
|
Assert.That(names, Does.Not.Contain("Pump1_Status"));
|
|
Assert.That(names, Contains.Item("TIC101_Setpoint"));
|
|
Assert.That(names, Contains.Item("TIC101_PV"));
|
|
Assert.That(names, Contains.Item("FIC202_Flow"));
|
|
Assert.That(names, Contains.Item("Heater_Power"));
|
|
Assert.That(names, Contains.Item("MultiRefAlias"));
|
|
}
|
|
|
|
[Description("Call the FindAlias method on the Aliases object, passing in a "%" for the AliasName instance. Pass in the AliasFor Reference type")]
|
|
[Test]
|
|
public async Task FindAliasWithPercentMatchesAnyAsync()
|
|
{
|
|
(NodeId category, NodeId method) = await FindCategoryAsync(
|
|
Session, "TagVariables").ConfigureAwait(false);
|
|
|
|
CallMethodResult result = await CallFindAliasAsync(
|
|
Session, category, method, "%", AliasForNodeId)
|
|
.ConfigureAwait(false);
|
|
|
|
Assert.That(StatusCode.IsGood(result.StatusCode), Is.True,
|
|
$"FindAlias('%') status: {result.StatusCode}");
|
|
IList<AliasRecord> records = DecodeAliasResults(Session, result);
|
|
Assert.That(records.Select(r => r.AliasName.Name),
|
|
Is.EquivalentTo(
|
|
[
|
|
"TIC101_Setpoint",
|
|
"TIC101_PV",
|
|
"FIC202_Flow",
|
|
"Pump1_Status",
|
|
"Heater_Power",
|
|
"MultiRefAlias"
|
|
]));
|
|
}
|
|
|
|
[Description("Call the FindAlias method on the Aliases object, passing in a string of "A[". Pass in the AliasFor Reference type.")]
|
|
[Test]
|
|
public async Task FindAliasReturnsErrorForUnclosedBracketAsync()
|
|
{
|
|
(NodeId category, NodeId method) = await FindCategoryAsync(
|
|
Session, "TagVariables").ConfigureAwait(false);
|
|
|
|
// Unclosed character class — server may either reject the
|
|
// pattern (BadInvalidArgument) or treat it as no-match.
|
|
CallMethodResult result = await CallFindAliasAsync(
|
|
Session, category, method, "[abc", AliasForNodeId)
|
|
.ConfigureAwait(false);
|
|
|
|
AssertInvalidPatternHandled(result, "[abc");
|
|
}
|
|
|
|
[Description("Call the FindAlias method on the Aliases object, passing in a string of "A\\". Pass in the AliasFor Reference type.")]
|
|
[Test]
|
|
public async Task FindAliasReturnsErrorForTrailingBackslashAsync()
|
|
{
|
|
(NodeId category, NodeId method) = await FindCategoryAsync(
|
|
Session, "TagVariables").ConfigureAwait(false);
|
|
|
|
CallMethodResult result = await CallFindAliasAsync(
|
|
Session, category, method, "abc\\", AliasForNodeId)
|
|
.ConfigureAwait(false);
|
|
|
|
AssertInvalidPatternHandled(result, "abc\\");
|
|
}
|
|
|
|
[Description("Call the FindAlias method on the Aliases object, passing in a string of "A\\\\\\". Pass in the AliasFor Reference type.")]
|
|
[Test]
|
|
public async Task FindAliasReturnsErrorForInvalidEscapeSequenceAsync()
|
|
{
|
|
(NodeId category, NodeId method) = await FindCategoryAsync(
|
|
Session, "TagVariables").ConfigureAwait(false);
|
|
|
|
// '\c' is not a valid escape sequence in OPC UA Like-pattern.
|
|
CallMethodResult result = await CallFindAliasAsync(
|
|
Session, category, method, "ab\\c", AliasForNodeId)
|
|
.ConfigureAwait(false);
|
|
|
|
AssertInvalidPatternHandled(result, "ab\\c");
|
|
}
|
|
|
|
[Description("Call the FindAlias method on the Aliases object, passing in the string name part of the name of an AliasName instance. Pass in the HasComponent for the Reference type.")]
|
|
[Test]
|
|
public async Task FindAliasReturnsErrorForNonAliasForReferenceTypeAsync()
|
|
{
|
|
(NodeId category, NodeId method) = await FindCategoryAsync(
|
|
Session, "TagVariables").ConfigureAwait(false);
|
|
|
|
// HasComponent is not AliasFor or any of its subtypes — the
|
|
// server should either return BadInvalidArgument or filter the
|
|
// results to an empty list.
|
|
CallMethodResult result = await CallFindAliasAsync(
|
|
Session, category, method, "%", ReferenceTypeIds.HasComponent)
|
|
.ConfigureAwait(false);
|
|
|
|
if (StatusCode.IsBad(result.StatusCode))
|
|
{
|
|
return;
|
|
}
|
|
|
|
IList<AliasRecord> records = DecodeAliasResults(Session, result);
|
|
Assert.That(records, Is.Empty,
|
|
"FindAlias with a non-AliasFor reference type should return no aliases.");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Asserts that an invalid wildcard pattern was either rejected with
|
|
/// a Bad status code or handled gracefully with an empty result set.
|
|
/// </summary>
|
|
private void AssertInvalidPatternHandled(
|
|
CallMethodResult result, string pattern)
|
|
{
|
|
if (StatusCode.IsBad(result.StatusCode))
|
|
{
|
|
return;
|
|
}
|
|
|
|
// Some servers tolerate malformed patterns and simply return no
|
|
// matches — that is also acceptable per OPC UA Part 17 §6.3.2.
|
|
IList<AliasRecord> records =
|
|
DecodeAliasResults(Session, result);
|
|
Assert.That(records, Is.Empty,
|
|
$"Invalid pattern '{pattern}' should be rejected or yield no matches.");
|
|
}
|
|
}
|
|
}
|