Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Stack/Opc.Ua.Core/Types/Utils/RelativePath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,12 @@
{
element.ReferenceTypeName = new QualifiedName(qname.Name, (ushort)mappings[qname.NamespaceIndex]);
}
else
{
throw new ServiceResultException(
StatusCodes.BadIndexRangeInvalid,
Utils.Format("Cannot translate namespace index '{0}' to target namespace table.", qname.NamespaceIndex));

Check warning on line 361 in Stack/Opc.Ua.Core/Types/Utils/RelativePath.cs

View check run for this annotation

Codecov / codecov/patch

Stack/Opc.Ua.Core/Types/Utils/RelativePath.cs#L359-L361

Added lines #L359 - L361 were not covered by tests
}
}

qname = element.TargetName;
Expand All @@ -364,6 +370,12 @@
{
element.TargetName = new QualifiedName(qname.Name, (ushort)mappings[qname.NamespaceIndex]);
}
else
{
throw new ServiceResultException(
StatusCodes.BadIndexRangeInvalid,
Utils.Format("Cannot translate namespace index '{0}' to target namespace table.", qname.NamespaceIndex));

Check warning on line 377 in Stack/Opc.Ua.Core/Types/Utils/RelativePath.cs

View check run for this annotation

Codecov / codecov/patch

Stack/Opc.Ua.Core/Types/Utils/RelativePath.cs#L375-L377

Added lines #L375 - L377 were not covered by tests
}
}
}
}
Expand Down
49 changes: 49 additions & 0 deletions Tests/Opc.Ua.Core.Tests/Types/Utils/UtilsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,55 @@ public void RelativePathParseAlphanumericWithNamespaceIndexStringPath()
Assert.AreEqual(str, RelativePath.Parse(str, typeTable).Format(typeTable));
}

/// <summary>
/// Parse path string containing two Namespaces, translate indexes
/// </summary>
[Theory]
[TestCase("<#2:HasChild>", "<#3:HasChild>")]
[TestCase("<!2:HasChild>", "<!3:HasChild>")]
[TestCase(".2:NodeVersion", ".3:NodeVersion")]
[TestCase("/1:abc/2:def", "/1:abc/3:def")]
public void RelativePathParseTranslateNamespaceIndexReferenceType(string input, string output)
{
var currentTable = new NamespaceTable(new List<string>() { Namespaces.OpcUa, "1", Namespaces.OpcUaGds });
var targetTable = new NamespaceTable(new List<string>() { Namespaces.OpcUa, "1", "2", Namespaces.OpcUaGds });

TypeTable typeTable = new TypeTable(new NamespaceTable());
typeTable.AddReferenceSubtype(Opc.Ua.ReferenceTypeIds.HasChild, NodeId.Null, new QualifiedName("HasChild", 3));
Assert.AreEqual(output, RelativePath.Parse(input, typeTable, currentTable, targetTable).Format(typeTable));
}


/// <summary>
/// Parse path string containing two Namespaces with missing namespace indexes in either currentTable or targetTable.
/// </summary>
[Theory]
[TestCase(
new string[] { Namespaces.OpcUa, "2", Namespaces.OpcUaGds },
new string[] { Namespaces.OpcUa, "2", "3" },
"/1:abc/2:def"
)]
[TestCase(
new string[] { Namespaces.OpcUa, "2", Namespaces.OpcUaGds },
new string[] { Namespaces.OpcUa, "2", "3" },
"<#2:HasChild>"
)]
[TestCase(
new string[] { Namespaces.OpcUa, "2", Namespaces.OpcUaGds },
new string[] { Namespaces.OpcUa, "2", "3", "4", "5" },
"/1:abc/4:def"
)]
public void RelativePathParseInvalidNamespaceIndex(string[] currentNamespaces, string[] targetNamespaces, string path)
{
var currentTable = new NamespaceTable(new List<string>(currentNamespaces));
var targetTable = new NamespaceTable(new List<string>(targetNamespaces));

TypeTable typeTable = new TypeTable(new NamespaceTable());
var sre = Assert.Throws<ServiceResultException>(() => RelativePath.Parse(path, typeTable, currentTable, targetTable).Format(typeTable));
Assert.AreEqual((StatusCode)StatusCodes.BadIndexRangeInvalid, (StatusCode)sre.StatusCode);
}


/// <summary>
/// Validate that XmlDocument DtdProcessing is protected against
/// exponential entity expansion in this version of .NET.
Expand Down
Loading