453ec7358d
Code-review fixes: CompositeAuditWriter re-throws OperationCanceledException (honors cancellation) + evt null-guard; RedactingAuditWriter evt null-guard; added marker-longer-than-max and cancellation-propagation regression tests.
27 lines
974 B
C#
27 lines
974 B
C#
namespace ZB.MOM.WW.Audit.Tests;
|
|
|
|
public class RedactingAuditWriterTests
|
|
{
|
|
private sealed class CapturingWriter : IAuditWriter
|
|
{
|
|
public AuditEvent? Last;
|
|
public Task WriteAsync(AuditEvent evt, CancellationToken ct = default) { Last = evt; return Task.CompletedTask; }
|
|
}
|
|
private sealed class StampRedactor : IAuditRedactor
|
|
{
|
|
public AuditEvent Apply(AuditEvent rawEvent) => rawEvent with { DetailsJson = "redacted" };
|
|
}
|
|
|
|
private static AuditEvent Evt() => new() { EventId = Guid.NewGuid(), OccurredAtUtc = DateTimeOffset.UtcNow,
|
|
Actor = "a", Action = "x", Outcome = AuditOutcome.Success, DetailsJson = "secret" };
|
|
|
|
[Fact]
|
|
public async Task Inner_writer_receives_the_redacted_event()
|
|
{
|
|
var inner = new CapturingWriter();
|
|
var sut = new RedactingAuditWriter(new StampRedactor(), inner);
|
|
await sut.WriteAsync(Evt());
|
|
Assert.Equal("redacted", inner.Last!.DetailsJson);
|
|
}
|
|
}
|