b36c8d8716
GrpcDataConnection implements IDataHistoryService (explicitly; ReadHistoryAsync/ReleaseHistoryAsync avoid an overload clash with ReadAsync): the capabilities probe always asks for history, other calls send it only when the selected endpoint advertised it; per-call deadline min(remaining, HistoryTimeoutMilliseconds); FAILED_PRECONDITION/UNIMPLEMENTED => BadHistoryOperationUnsupported; chunks assembled within the request budget (BadTooManyOperations past it); page tokens wrapped with the issuing endpoint + serving incarnation so a resumed read never moves; release forwarded. The deployment lease gates history on the row's HistoryRead bit and carries HistoryTimeout. Decoded capabilities drop HistoryRead without the history field. X0 tests that used bit 32 as the unknown bit now use a still-reserved bit.
519 lines
22 KiB
C#
519 lines
22 KiB
C#
using System.Text;
|
|
using System.Text.Json.Nodes;
|
|
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.Configuration.Entities;
|
|
using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections;
|
|
using ZB.MOM.WW.OtOpcUa.Runtime.Drivers;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Runtime.Tests.DataConnections;
|
|
|
|
[Trait("Category", "Unit")]
|
|
[Trait("Feature", "GrpcData")]
|
|
[Trait("Phase", "P02")]
|
|
public sealed class GrpcDataArtifactReadTests
|
|
{
|
|
private const string NodeA = "node-a";
|
|
private const string NodeB = "node-b";
|
|
|
|
[Theory]
|
|
[InlineData("{}")]
|
|
[InlineData(
|
|
"{\"Clusters\":[{\"ClusterId\":\"local\"}],\"Nodes\":[{\"NodeId\":\"node-a\",\"ClusterId\":\"local\",\"Enabled\":true}]}"
|
|
)]
|
|
[InlineData("{\"UnknownFutureArray\":[{\"Enabled\":true}]}")]
|
|
public void Old_artifacts_without_new_arrays_have_no_enabled_data_surface(string json)
|
|
{
|
|
using var parsed = DeploymentArtifact.Open(Encoding.UTF8.GetBytes(json));
|
|
|
|
parsed.ParseDataConnections(NodeA).ShouldBeEmpty();
|
|
parsed.ParseDataExports(NodeA).ShouldBeEmpty();
|
|
parsed.ParseRemoteNamespaceMappings(NodeA).ShouldBeEmpty();
|
|
}
|
|
|
|
[Fact]
|
|
public void A_only_peer_mount_is_not_returned_to_its_same_cluster_target_B()
|
|
{
|
|
using var parsed = DeploymentArtifact.Open(Blob(Fixture()));
|
|
|
|
var connection = parsed.ParseDataConnections(NodeA).ShouldHaveSingleItem();
|
|
connection.TargetMode.ShouldBe(DataTargetMode.Node);
|
|
connection.ExpectedNodeId.ShouldBe(NodeB);
|
|
connection.ExpectedClusterId.ShouldBe("local");
|
|
parsed
|
|
.ParseRemoteNamespaceMappings(NodeA)
|
|
.ShouldHaveSingleItem()
|
|
.RemoteNamespaceMappingId.ShouldBe("mapping-a");
|
|
parsed.ParseDataConnections(NodeB).ShouldBeEmpty();
|
|
parsed.ParseRemoteNamespaceMappings(NodeB).ShouldBeEmpty();
|
|
// B still owns the local export catalog; import consumer scope must not suppress it.
|
|
parsed.ParseDataExports(NodeB).ShouldHaveSingleItem().DataExportId.ShouldBe("export-a");
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(false)]
|
|
[InlineData(true)]
|
|
public void Unknown_node_never_inherits_a_single_clusters_new_data_surface(bool omitNodes)
|
|
{
|
|
var root = Fixture();
|
|
if (omitNodes)
|
|
root.Remove("Nodes");
|
|
using var parsed = DeploymentArtifact.Open(Blob(root));
|
|
|
|
parsed.ParseDataConnections("unlisted").ShouldBeEmpty();
|
|
parsed.ParseDataExports("unlisted").ShouldBeEmpty();
|
|
parsed.ParseRemoteNamespaceMappings("unlisted").ShouldBeEmpty();
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("node-disabled")]
|
|
[InlineData("node-maintenance")]
|
|
[InlineData("cluster-disabled")]
|
|
public void Ineligible_node_or_owner_cluster_has_no_new_data_surface(string state)
|
|
{
|
|
var root = Fixture();
|
|
if (state == "node-disabled")
|
|
root["Nodes"]![0]!["Enabled"] = false;
|
|
if (state == "node-maintenance")
|
|
root["Nodes"]![0]!["MaintenanceMode"] = true;
|
|
if (state == "cluster-disabled")
|
|
root["Clusters"]![0]!["Enabled"] = false;
|
|
using var parsed = DeploymentArtifact.Open(Blob(root));
|
|
|
|
parsed.ParseDataConnections(NodeA).ShouldBeEmpty();
|
|
parsed.ParseDataExports(NodeA).ShouldBeEmpty();
|
|
parsed.ParseRemoteNamespaceMappings(NodeA).ShouldBeEmpty();
|
|
}
|
|
|
|
[Fact]
|
|
public void Owner_cluster_filters_connections_mappings_and_origin_local_exports()
|
|
{
|
|
var root = Fixture();
|
|
root["Clusters"]!
|
|
.AsArray()
|
|
.Add(
|
|
JsonNode.Parse(
|
|
"""{"ClusterId":"other","Name":"Other","Enterprise":"ent","Site":"site","RedundancyMode":0,"CreatedBy":"test","Enabled":true}"""
|
|
)
|
|
);
|
|
root["Nodes"]!
|
|
.AsArray()
|
|
.Add(
|
|
JsonNode.Parse(
|
|
"""{"NodeId":"node-c","ClusterId":"other","Host":"node-c","ApplicationUri":"urn:node-c","CreatedBy":"test","Enabled":true}"""
|
|
)
|
|
);
|
|
root["RawFolders"]!
|
|
.AsArray()
|
|
.Add(
|
|
JsonNode.Parse(
|
|
"""{"RawFolderId":"other-root","ClusterId":"other","Name":"Other"}"""
|
|
)
|
|
);
|
|
var foreignConnection = root["DataConnections"]![0]!.DeepClone();
|
|
foreignConnection["DataConnectionId"] = "connection-other";
|
|
foreignConnection["ClusterId"] = "other";
|
|
foreignConnection["SecretScopeClusterId"] = "other";
|
|
foreignConnection["ConsumerNodeIds"] = new JsonArray("node-c");
|
|
root["DataConnections"]!.AsArray().Add(foreignConnection);
|
|
var foreignMapping = root["RemoteNamespaceMappings"]![0]!.DeepClone();
|
|
foreignMapping["RemoteNamespaceMappingId"] = "mapping-other";
|
|
foreignMapping["ClusterId"] = "other";
|
|
foreignMapping["DataConnectionId"] = "connection-other";
|
|
foreignMapping["LocalParentId"] = "other-root";
|
|
foreignMapping["ConsumerNodeIds"] = new JsonArray("node-c");
|
|
root["RemoteNamespaceMappings"]!.AsArray().Add(foreignMapping);
|
|
var foreignExport = root["DataExports"]![0]!.DeepClone();
|
|
foreignExport["DataExportId"] = "export-other";
|
|
foreignExport["ClusterId"] = "other";
|
|
foreignExport["RootEntityId"] = "other-root";
|
|
root["DataExports"]!.AsArray().Add(foreignExport);
|
|
using var parsed = DeploymentArtifact.Open(Blob(root));
|
|
|
|
parsed
|
|
.ParseDataConnections(NodeA)
|
|
.Select(x => x.DataConnectionId)
|
|
.ShouldBe(["connection-a"]);
|
|
parsed
|
|
.ParseRemoteNamespaceMappings(NodeA)
|
|
.Select(x => x.RemoteNamespaceMappingId)
|
|
.ShouldBe(["mapping-a"]);
|
|
parsed.ParseDataExports(NodeA).Select(x => x.DataExportId).ShouldBe(["export-a"]);
|
|
parsed
|
|
.ParseDataExports("node-c")
|
|
.ShouldHaveSingleItem()
|
|
.DataExportId.ShouldBe("export-other");
|
|
}
|
|
|
|
[Fact]
|
|
public void Disabled_rows_are_retained_within_scope_for_generation_reconciliation()
|
|
{
|
|
var root = Fixture();
|
|
root["DataConnections"]![0]!["Enabled"] = false;
|
|
root["DataExports"]![0]!["Enabled"] = false;
|
|
root["RemoteNamespaceMappings"]![0]!["Enabled"] = false;
|
|
using var parsed = DeploymentArtifact.Open(Blob(root));
|
|
|
|
parsed.ParseDataConnections(NodeA).ShouldHaveSingleItem().Enabled.ShouldBeFalse();
|
|
parsed.ParseDataExports(NodeA).ShouldHaveSingleItem().Enabled.ShouldBeFalse();
|
|
parsed.ParseRemoteNamespaceMappings(NodeA).ShouldHaveSingleItem().Enabled.ShouldBeFalse();
|
|
parsed.ParseDataConnections(NodeB).ShouldBeEmpty();
|
|
parsed.ParseRemoteNamespaceMappings(NodeB).ShouldBeEmpty();
|
|
}
|
|
|
|
[Fact]
|
|
public void Omitted_enabled_flags_never_enable_new_configuration_implicitly()
|
|
{
|
|
var root = Fixture();
|
|
root["DataConnections"]![0]!.AsObject().Remove("Enabled");
|
|
root["DataExports"]![0]!.AsObject().Remove("Enabled");
|
|
root["RemoteNamespaceMappings"]![0]!.AsObject().Remove("Enabled");
|
|
using var parsed = DeploymentArtifact.Open(Blob(root));
|
|
|
|
parsed.ParseDataConnections(NodeA).ShouldHaveSingleItem().Enabled.ShouldBeFalse();
|
|
parsed.ParseDataExports(NodeA).ShouldHaveSingleItem().Enabled.ShouldBeFalse();
|
|
parsed.ParseRemoteNamespaceMappings(NodeA).ShouldHaveSingleItem().Enabled.ShouldBeFalse();
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("ConsumerNodeIds", "[]")]
|
|
[InlineData("ConsumerNodeIds", "null")]
|
|
[InlineData("ConsumerNodeIds", "\"node-a\"")]
|
|
[InlineData("TargetMode", "0")]
|
|
[InlineData("TargetMode", "999")]
|
|
[InlineData("ExpectedNodeId", "null")]
|
|
[InlineData("ExpectedNodeId", "\"node-a\"")]
|
|
[InlineData("SecretReference", "\"\"")]
|
|
[InlineData("SecretScopeClusterId", "\"foreign\"")]
|
|
[InlineData("Endpoints", "null")]
|
|
[InlineData("Endpoints", "[\"http://node-b:7443\"]")]
|
|
[InlineData("AllowedOperations", "0")]
|
|
[InlineData("MaxBatchItems", "0")]
|
|
[InlineData("Revision", "0")]
|
|
public void Malformed_enabled_connection_fails_closed_with_row_diagnostics(
|
|
string field,
|
|
string value
|
|
)
|
|
{
|
|
var root = Fixture();
|
|
root["DataConnections"]![0]![field] = JsonNode.Parse(value);
|
|
using var parsed = DeploymentArtifact.Open(Blob(root));
|
|
|
|
var error = Should.Throw<InvalidDataException>(() => parsed.ParseDataConnections(NodeA));
|
|
|
|
error.Message.ShouldContain("connection-a");
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("Realm", "0")]
|
|
[InlineData("RemoteRealm", "2")]
|
|
[InlineData("DataConnectionId", "\"missing-connection\"")]
|
|
[InlineData("LocalParentId", "\"missing-parent\"")]
|
|
[InlineData("ConsumerNodeIds", "[\"node-a\",\"node-b\"]")]
|
|
[InlineData("AllowedOperations", "8")]
|
|
[InlineData("MaxProjectionNodes", "0")]
|
|
[InlineData("Revision", "0")]
|
|
public void Malformed_enabled_mapping_is_not_installed_with_inferred_permissions(
|
|
string field,
|
|
string value
|
|
)
|
|
{
|
|
var root = Fixture();
|
|
root["RemoteNamespaceMappings"]![0]![field] = JsonNode.Parse(value);
|
|
using var parsed = DeploymentArtifact.Open(Blob(root));
|
|
|
|
var error = Should.Throw<InvalidDataException>(() =>
|
|
parsed.ParseRemoteNamespaceMappings(NodeA)
|
|
);
|
|
|
|
error.Message.ShouldContain("mapping-a");
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("PrincipalId", "\"\"")]
|
|
[InlineData("Realm", "0")]
|
|
[InlineData("RootEntityId", "\"missing-origin\"")]
|
|
[InlineData("RootKind", "\"RemoteNamespaceMapping\"")]
|
|
[InlineData("Revision", "0")]
|
|
public void Malformed_enabled_export_cannot_become_a_broad_or_reexport_grant(
|
|
string field,
|
|
string value
|
|
)
|
|
{
|
|
var root = Fixture();
|
|
root["DataExports"]![0]![field] = JsonNode.Parse(value);
|
|
using var parsed = DeploymentArtifact.Open(Blob(root));
|
|
|
|
var error = Should.Throw<InvalidDataException>(() => parsed.ParseDataExports(NodeA));
|
|
|
|
error.Message.ShouldContain("export-a");
|
|
}
|
|
|
|
[Trait("Phase", "X0")]
|
|
// X0 (plan section 4.3): an operation bit this build does not understand, e.g. one a newer central authored, is
|
|
// TOLERATED at the parse seam and grants nothing downstream. Before X0 it failed the whole row closed (and with it
|
|
// the snapshot). Only the understood subset is validated; an all-unknown row parses and is inert.
|
|
[Theory]
|
|
[InlineData(1073741824, 0)]
|
|
[InlineData(5 | 1073741824, 5)]
|
|
[InlineData(5 | 64, 5)] // 64 (AlarmSubscribe) is still reserved; 32 became understood in H2
|
|
[InlineData(5 | 32 | 64, 5 | 32)]
|
|
public void Unknown_operation_bit_on_a_connection_or_export_parses_and_grants_nothing(int authored, int understood)
|
|
{
|
|
var root = Fixture();
|
|
root["DataConnections"]![0]!["AllowedOperations"] = authored;
|
|
root["DataExports"]![0]!["AllowedOperations"] = authored;
|
|
using var parsed = DeploymentArtifact.Open(Blob(root));
|
|
|
|
var connection = parsed.ParseDataConnections(NodeA).ShouldHaveSingleItem();
|
|
var export = parsed.ParseDataExports(NodeA).ShouldHaveSingleItem();
|
|
connection.AllowedOperations.ShouldBe((DataOperations)authored, "rows are returned as authored");
|
|
(connection.AllowedOperations & DataOperationSets.Understood).ShouldBe((DataOperations)understood);
|
|
(export.AllowedOperations & DataOperationSets.Understood).ShouldBe((DataOperations)understood);
|
|
(DataOperationSets.Understood & (DataOperations)1073741824).ShouldBe(DataOperations.None, "the bit is never granted");
|
|
}
|
|
|
|
[Fact]
|
|
public void Missing_connection_array_does_not_leave_an_enabled_orphan_mount()
|
|
{
|
|
var root = Fixture();
|
|
root.Remove("DataConnections");
|
|
using var parsed = DeploymentArtifact.Open(Blob(root));
|
|
|
|
var error = Should.Throw<InvalidDataException>(() =>
|
|
parsed.ParseRemoteNamespaceMappings(NodeA)
|
|
);
|
|
|
|
error.Message.ShouldContain("mapping-a");
|
|
}
|
|
|
|
[Fact]
|
|
public void Presented_credentials_are_rejected_without_echoing_them_in_artifact_diagnostics()
|
|
{
|
|
const string presentedSecret = "presented-key-never-log-this";
|
|
var root = Fixture();
|
|
root["DataConnections"]![0]!["Endpoints"] = new JsonArray(
|
|
"https://peer:" + presentedSecret + "@node-b:7443"
|
|
);
|
|
using var parsed = DeploymentArtifact.Open(Blob(root));
|
|
|
|
var error = Should.Throw<InvalidDataException>(() => parsed.ParseDataConnections(NodeA));
|
|
|
|
error.Message.ShouldContain("connection-a");
|
|
error.Message.ShouldNotContain(presentedSecret);
|
|
}
|
|
|
|
[Fact]
|
|
public void New_projections_are_materialized_and_survive_document_disposal()
|
|
{
|
|
IReadOnlyList<DataConnection> connections;
|
|
IReadOnlyList<DataExport> exports;
|
|
IReadOnlyList<RemoteNamespaceMapping> mappings;
|
|
var root = Fixture();
|
|
root["RemoteNamespaceMappings"]![0]!["ExpectedValueKind"] = (int)DataValueKind.Array;
|
|
root["RemoteNamespaceMappings"]![0]!["ExpectedArrayElementKind"] = (int)
|
|
DataValueKind.UInt64;
|
|
using (var parsed = DeploymentArtifact.Open(Blob(root)))
|
|
{
|
|
connections = parsed.ParseDataConnections(NodeA);
|
|
exports = parsed.ParseDataExports(NodeA);
|
|
mappings = parsed.ParseRemoteNamespaceMappings(NodeA);
|
|
}
|
|
|
|
connections.ShouldHaveSingleItem().Endpoints.ShouldBe(["https://node-b:7443"]);
|
|
connections[0].ConsumerNodeIds.ShouldBe([NodeA]);
|
|
connections[0].SecretReference.ShouldBe("secret:data/upstream");
|
|
exports.ShouldHaveSingleItem().RootEntityId.ShouldBe("local-root");
|
|
mappings.ShouldHaveSingleItem().RemoteIdentifier.ShouldBe("origin-root");
|
|
mappings[0].WriteThrough.ShouldBeFalse();
|
|
mappings[0].ExpectedValueKind.ShouldBe(DataValueKind.Array);
|
|
mappings[0].ExpectedArrayElementKind.ShouldBe(DataValueKind.UInt64);
|
|
}
|
|
|
|
[Fact]
|
|
public void Static_facades_preserve_the_strict_scoped_projection()
|
|
{
|
|
var blob = Blob(Fixture());
|
|
|
|
DeploymentArtifact
|
|
.ParseDataConnections(blob, NodeA)
|
|
.ShouldHaveSingleItem()
|
|
.DataConnectionId.ShouldBe("connection-a");
|
|
DeploymentArtifact
|
|
.ParseDataExports(blob, NodeA)
|
|
.ShouldHaveSingleItem()
|
|
.DataExportId.ShouldBe("export-a");
|
|
DeploymentArtifact
|
|
.ParseRemoteNamespaceMappings(blob, NodeA)
|
|
.ShouldHaveSingleItem()
|
|
.RemoteNamespaceMappingId.ShouldBe("mapping-a");
|
|
DeploymentArtifact.ParseDataConnections(blob, "unlisted").ShouldBeEmpty();
|
|
DeploymentArtifact.ParseDataExports(blob, "unlisted").ShouldBeEmpty();
|
|
DeploymentArtifact.ParseRemoteNamespaceMappings(blob, "unlisted").ShouldBeEmpty();
|
|
|
|
var root = Fixture();
|
|
root["DataConnections"]![0]!["SecretReference"] = "";
|
|
Should
|
|
.Throw<InvalidDataException>(() =>
|
|
DeploymentArtifact.ParseDataConnections(Blob(root), NodeA)
|
|
)
|
|
.Message.ShouldContain("connection-a");
|
|
}
|
|
|
|
[Fact]
|
|
public void Foreign_projected_mapping_cannot_be_used_as_a_remote_root()
|
|
{
|
|
var root = Fixture();
|
|
root["DataConnections"]![0]!["ExpectedClusterId"] = "remote";
|
|
var foreign = root["RemoteNamespaceMappings"]![0]!.DeepClone();
|
|
foreign["ClusterId"] = "remote";
|
|
foreign["RemoteNamespaceMappingId"] = "origin-root";
|
|
root["RemoteNamespaceMappings"]!.AsArray().Add(foreign);
|
|
using var parsed = DeploymentArtifact.Open(Blob(root));
|
|
Should
|
|
.Throw<InvalidDataException>(() => parsed.ParseRemoteNamespaceMappings(NodeA))
|
|
.Message.ShouldContain("mapping-a");
|
|
}
|
|
|
|
[Fact]
|
|
public void Null_topology_rows_fail_closed_as_invalid_data()
|
|
{
|
|
var root = Fixture();
|
|
root["Nodes"]!.AsArray().Add((JsonNode?)null);
|
|
using var parsed = DeploymentArtifact.Open(Blob(root));
|
|
Should.Throw<InvalidDataException>(() => parsed.ParseDataConnections(NodeA));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("DataConnections", "DataConnectionId", "missing")]
|
|
[InlineData("DataConnections", "DataConnectionId", "null")]
|
|
[InlineData("DataConnections", "DataConnectionId", "blank")]
|
|
[InlineData("DataExports", "DataExportId", "missing")]
|
|
[InlineData("DataExports", "DataExportId", "null")]
|
|
[InlineData("DataExports", "DataExportId", "blank")]
|
|
[InlineData("RemoteNamespaceMappings", "RemoteNamespaceMappingId", "missing")]
|
|
[InlineData("RemoteNamespaceMappings", "RemoteNamespaceMappingId", "null")]
|
|
[InlineData("RemoteNamespaceMappings", "RemoteNamespaceMappingId", "blank")]
|
|
public void Enabled_rows_require_logical_ids(string collection, string field, string shape)
|
|
{
|
|
var root = Fixture();
|
|
var row = root[collection]![0]!.AsObject();
|
|
if (shape == "missing")
|
|
row.Remove(field);
|
|
else if (shape == "null")
|
|
row[field] = null;
|
|
else
|
|
row[field] = " ";
|
|
using var parsed = DeploymentArtifact.Open(Blob(root));
|
|
var error = Should.Throw<InvalidDataException>(() =>
|
|
{
|
|
if (collection == "DataConnections")
|
|
parsed.ParseDataConnections(NodeA);
|
|
else if (collection == "DataExports")
|
|
parsed.ParseDataExports(NodeA);
|
|
else
|
|
parsed.ParseRemoteNamespaceMappings(NodeA);
|
|
});
|
|
error.Message.ShouldContain("<unknown>");
|
|
}
|
|
|
|
[Fact]
|
|
public void Null_id_cannot_hide_other_invalid_connection_fields()
|
|
{
|
|
var root = Fixture();
|
|
root["DataConnections"]![0]!["DataConnectionId"] = null;
|
|
root["DataConnections"]![0]!["TargetMode"] = 0;
|
|
using var parsed = DeploymentArtifact.Open(Blob(root));
|
|
Should
|
|
.Throw<InvalidDataException>(() => parsed.ParseDataConnections(NodeA))
|
|
.Message.ShouldContain("<unknown>");
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("DataConnections", "DataConnectionId")]
|
|
[InlineData("DataExports", "DataExportId")]
|
|
[InlineData("RemoteNamespaceMappings", "RemoteNamespaceMappingId")]
|
|
public void Lowercase_enabled_with_null_id_is_rejected(string collection, string idName)
|
|
{
|
|
var root = Fixture();
|
|
var row = root[collection]![0]!.AsObject();
|
|
row.Remove("Enabled");
|
|
row["enabled"] = true;
|
|
row[idName] = null;
|
|
using var parsed = DeploymentArtifact.Open(Blob(root));
|
|
Should.Throw<InvalidDataException>(() => ReadCollection(parsed, collection));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("DataConnections", "DataConnectionId", "dataConnectionId")]
|
|
[InlineData("DataExports", "DataExportId", "dataExportId")]
|
|
[InlineData("RemoteNamespaceMappings", "RemoteNamespaceMappingId", "remoteNamespaceMappingId")]
|
|
public void Case_variant_shadow_id_is_rejected(string collection, string idName, string alias)
|
|
{
|
|
var root = Fixture();
|
|
root[collection]![0]!.AsObject().ContainsKey(idName).ShouldBeTrue();
|
|
root[collection]![0]![alias] = null;
|
|
using var parsed = DeploymentArtifact.Open(Blob(root));
|
|
Should.Throw<InvalidDataException>(() => ReadCollection(parsed, collection));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("DataConnections")]
|
|
[InlineData("DataExports")]
|
|
[InlineData("RemoteNamespaceMappings")]
|
|
public void Case_variant_owner_cannot_override_local_scope(string collection)
|
|
{
|
|
var root = Fixture();
|
|
root[collection]![0]!["clusterId"] = "foreign";
|
|
using var parsed = DeploymentArtifact.Open(Blob(root));
|
|
Should.Throw<InvalidDataException>(() => ReadCollection(parsed, collection));
|
|
}
|
|
|
|
private static void ReadCollection(ParsedDeploymentArtifact parsed, string collection)
|
|
{
|
|
if (collection == "DataConnections")
|
|
parsed.ParseDataConnections(NodeA);
|
|
else if (collection == "DataExports")
|
|
parsed.ParseDataExports(NodeA);
|
|
else
|
|
parsed.ParseRemoteNamespaceMappings(NodeA);
|
|
}
|
|
|
|
private static byte[] Blob(JsonObject root) => Encoding.UTF8.GetBytes(root.ToJsonString());
|
|
|
|
private static JsonObject Fixture() =>
|
|
JsonNode
|
|
.Parse(
|
|
"""
|
|
{
|
|
"Clusters": [{"ClusterId":"local","Name":"Local","Enterprise":"ent","Site":"site","RedundancyMode":0,"CreatedBy":"test","Enabled":true}],
|
|
"Nodes": [
|
|
{"NodeId":"node-a","ClusterId":"local","Host":"node-a","ApplicationUri":"urn:node-a","CreatedBy":"test","Enabled":true,"MaintenanceMode":false},
|
|
{"NodeId":"node-b","ClusterId":"local","Host":"node-b","ApplicationUri":"urn:node-b","CreatedBy":"test","Enabled":true,"MaintenanceMode":false}
|
|
],
|
|
"RawFolders": [{"RawFolderId":"local-root","ClusterId":"local","Name":"Local"}],
|
|
"DataConnections": [{
|
|
"DataConnectionId":"connection-a","ClusterId":"local","Revision":3,"Enabled":true,
|
|
"ConsumerNodeIds":["node-a"],"TargetMode":1,"Consistency":1,
|
|
"ExpectedClusterId":"local","ExpectedNodeId":"node-b","EligibleTargetNodeIds":[],
|
|
"Endpoints":["https://node-b:7443"],"SecretReference":"secret:data/upstream",
|
|
"SecretScopeClusterId":"local","AllowedOperations":5
|
|
}],
|
|
"DataExports": [{
|
|
"DataExportId":"export-a","ClusterId":"local","Revision":4,"Enabled":true,
|
|
"Realm":1,"RootKind":"RawFolder","RootEntityId":"local-root",
|
|
"PrincipalId":"peer","AllowedOperations":5
|
|
}],
|
|
"RemoteNamespaceMappings": [{
|
|
"RemoteNamespaceMappingId":"mapping-a","ClusterId":"local","DataConnectionId":"connection-a",
|
|
"Revision":5,"Enabled":true,"ConsumerNodeIds":["node-a"],"Realm":1,"RemoteRealm":1,
|
|
"LocalParentKind":"RawFolder","LocalParentId":"local-root","BranchName":"Remote",
|
|
"RemoteRootEntityId":"origin-root","RemoteNamespaceUri":"https://zb.com/otopcua/raw","RemoteIdentifierKind":"string",
|
|
"RemoteIdentifier":"origin-root","AllowedOperations":1,"WriteThrough":false
|
|
}]
|
|
}
|
|
"""
|
|
)!
|
|
.AsObject();
|
|
}
|