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

30 lines
1.7 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 class GrpcDataSecretRotationTests
{
[Fact]
public async Task Rotation_retires_and_rejects_downgrade_and_wrong_node()
{
var ct = TestContext.Current.CancellationToken;
var store = new MemoryStore(); var cipher = new TestCipher(); var changes = new DataConnectionSecretChangeHandler();
var changed = new List<string>(); changes.ConnectionChanged += changed.Add;
var provisioner = new DataConnectionSecretProvisioner(store, cipher, new NoopInvalidator(), changes, "cluster", "node");
await provisioner.SetScopeAsync(1, new Dictionary<string, string> { ["c"] = "secret:data/key" }, ct);
DataConnectionCredentialBundle Bundle(long version, string node) => new("cluster", node, version, [new("c", "secret:data/key", "value" + version, false)], ScopeVersion: 1);
await provisioner.ApplyAsync(Bundle(1, "node"), ct);
await provisioner.ApplyAsync(Bundle(2, "node"), ct);
await Should.ThrowAsync<InvalidOperationException>(() => provisioner.ApplyAsync(Bundle(1, "node"), ct));
await Should.ThrowAsync<InvalidOperationException>(() => provisioner.ApplyAsync(Bundle(3, "other"), ct));
var credential = await new DataConnectionCredentialResolver(store, cipher, "cluster", "node").ResolveAsync("c", ct);
credential.ShouldNotBeNull(); credential.Value.ShouldBe("value2"); credential.Version.ShouldBe(2);
changed.Count.ShouldBe(2);
}
}