Files
lmxopcua/tests/Server/ZB.MOM.WW.OtOpcUa.Host.Tests/DataConnections/GrpcDataScopeActivationTests.cs
T

27 lines
1.6 KiB
C#

using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Host.Configuration;
using static ZB.MOM.WW.OtOpcUa.Host.Tests.DataConnections.GrpcDataSecretProvisioningTests;
namespace ZB.MOM.WW.OtOpcUa.Host.Tests.DataConnections;
[Trait("Feature", "GrpcData"), Trait("Phase", "P07")]
public sealed class GrpcDataScopeActivationTests
{
[Fact]
public async Task Activation_persists_identical_scope_to_credentials_and_trust()
{
var ct = TestContext.Current.CancellationToken; var store = new MemoryStore(); var cipher = new TestCipher(); var changes = new DataConnectionSecretChangeHandler();
var p = new DataConnectionSecretProvisioner(store, cipher, new NoopInvalidator(), changes, "pair", "node");
var trust = new DataConnectionTrustPolicyStore(store, cipher, changes, "pair", "node");
var activator = new DataConnectionScopeActivator(p, trust);
await activator.SetScopeAsync(1, new Dictionary<string, string> { ["link"] = "secret:data/key" }, ct);
await p.ApplyAsync(new("pair", "node", 1, [new("link", "secret:data/key", "bearer", false)], 1), ct);
await trust.SetAsync("LINK", 1, [], 1, ct);
await activator.SetScopeAsync(2, new Dictionary<string, string>(), ct);
(await new DataConnectionCredentialResolver(store, cipher, "pair", "node").ResolveAsync("link", ct)).ShouldBeNull();
await Should.ThrowAsync<InvalidOperationException>(() => trust.SetAsync("link", 2, [], 1, ct));
await Should.ThrowAsync<InvalidOperationException>(() => activator.SetScopeAsync(1, new Dictionary<string, string> { ["link"] = "secret:data/key" }, ct));
}
}