feat(alarms): AlarmAcknowledgeRequest carries OperatorUser; Galaxy/ScriptedAlarmSource honor it [H6b]
This commit is contained in:
@@ -129,6 +129,37 @@ public sealed class ScriptedAlarmSourceTests
|
||||
state.LastAckComment.ShouldBe("ack via opcua");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that AcknowledgeAsync honors a supplied authenticated principal
|
||||
/// (<see cref="AlarmAcknowledgeRequest.OperatorUser"/>) and falls back to
|
||||
/// <c>"opcua-client"</c> only when none is supplied.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task ScriptedAlarmSource_uses_supplied_principal_else_default()
|
||||
{
|
||||
var (engine, source, up) = await BuildAsync();
|
||||
using var _e = engine;
|
||||
using var _s = source;
|
||||
|
||||
// Supplied principal -> honored.
|
||||
up.Push("Temp", 150);
|
||||
await Task.Delay(200);
|
||||
await source.AcknowledgeAsync([new AlarmAcknowledgeRequest(
|
||||
"Plant/Line1", "Plant/Line1::HighTemp", "ack as bob", "bob")],
|
||||
TestContext.Current.CancellationToken);
|
||||
engine.GetState("Plant/Line1::HighTemp")!.LastAckUser.ShouldBe("bob");
|
||||
|
||||
// No principal -> default audit identity.
|
||||
up.Push("Temp", 50);
|
||||
await Task.Delay(200);
|
||||
up.Push("Temp", 150);
|
||||
await Task.Delay(200);
|
||||
await source.AcknowledgeAsync([new AlarmAcknowledgeRequest(
|
||||
"Plant/Line1", "Plant/Line1::HighTemp", "ack anon", null)],
|
||||
TestContext.Current.CancellationToken);
|
||||
engine.GetState("Plant/Line1::HighTemp")!.LastAckUser.ShouldBe("opcua-client");
|
||||
}
|
||||
|
||||
/// <summary>Verifies that null arguments are rejected.</summary>
|
||||
[Fact]
|
||||
public async Task Null_arguments_rejected()
|
||||
|
||||
@@ -210,6 +210,26 @@ public sealed class GalaxyDriverAlarmSourceTests
|
||||
ack.Calls[0].AlarmRef.ShouldBe("Tank01.Level.HiHi");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that AcknowledgeAsync forwards the request's authenticated principal
|
||||
/// (<see cref="AlarmAcknowledgeRequest.OperatorUser"/>) to the acknowledger so the
|
||||
/// gateway records WHO acked, rather than the generic empty-string fallback.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task AcknowledgeAsync_forwards_OperatorUser()
|
||||
{
|
||||
var feed = new FakeAlarmFeed();
|
||||
var ack = new RecordingAcknowledger();
|
||||
using var driver = NewDriver(feed, ack);
|
||||
|
||||
await driver.AcknowledgeAsync(
|
||||
[new AlarmAcknowledgeRequest("src", "Obj.Alarm", "cmt", "alice")],
|
||||
CancellationToken.None);
|
||||
|
||||
ack.Calls.ShouldHaveSingleItem();
|
||||
ack.Calls[0].Operator.ShouldBe("alice");
|
||||
}
|
||||
|
||||
/// <summary>Verifies that AcknowledgeAsync throws NotSupportedException without an acknowledger.</summary>
|
||||
[Fact]
|
||||
public async Task AcknowledgeAsync_throws_NotSupported_without_acknowledger()
|
||||
|
||||
Reference in New Issue
Block a user