* Avoid null endpoint DTO metadata in tests * Enforce console logs hub read permission * Remove unused console logs hub import * Support mapped endpoint metadata in auth tests * Reduce console log capture throughput impact * Address Copilot console logs review * Refactor task scheduling to support tenant-level background work and enhance logging functionality. * Introduce ConsoleStreamHook for stdout/stderr tee and enhance logging validation. Adjust test cases and startup warnings for distributed lock provider usage. * Refactor console logging pipeline with capture optimization and new ConsoleLogsHost; update tests accordingly. * Add Ansi SGR parser for console logs and associated unit tests * Remove ANSI color renderings and parsers; integrate ConsoleLogScopeAccessor for improved logging context with workflow instance ID support. * Address console logs code quality feedback * Address PR review feedback * Preserve console logs extension points * Stabilize console logs host lifecycle * Address final automated review comments * Tighten console log capture shutdown * Address console log review feedback * Address follow-up review feedback * Cover final review feedback * Avoid recursive console provider initialization * Guard console host lease shutdown * Preserve console log scope and provider lifetime * Correlate console log scope fallback * Tighten console scope correlation * Expose host services during provider construction * Redact ANSI-normalized console lines
68 lines
1.7 KiB
C#
68 lines
1.7 KiB
C#
using Elsa.Diagnostics.ConsoleLogs.Services;
|
|
|
|
namespace Elsa.Diagnostics.ConsoleLogs.UnitTests.Redaction;
|
|
|
|
public class ConsoleLogRedactorTests
|
|
{
|
|
private readonly ConsoleLogRedactor _redactor = new(Microsoft.Extensions.Options.Options.Create(new ConsoleLogsOptions()));
|
|
|
|
[Fact]
|
|
public void Redact_MasksSensitiveLineText()
|
|
{
|
|
var line = CreateLine(string.Concat("Authorization: ", "Bearer ", "sample-token"));
|
|
|
|
var redacted = _redactor.Redact(line);
|
|
|
|
Assert.Equal("Authorization: [Redacted]", redacted.Text);
|
|
}
|
|
|
|
[Fact]
|
|
public void Redact_MasksSensitiveLineTextSplitByAnsi()
|
|
{
|
|
var line = CreateLine("to\u001b[31mken=sample-token");
|
|
|
|
var redacted = _redactor.Redact(line);
|
|
|
|
Assert.Equal("[Redacted]", redacted.Text);
|
|
}
|
|
|
|
[Fact]
|
|
public void Redact_PreservesAnsiWhenLineTextIsNotSensitive()
|
|
{
|
|
var line = CreateLine("\u001b[31mhello\u001b[0m");
|
|
|
|
var redacted = _redactor.Redact(line);
|
|
|
|
Assert.Equal("\u001b[31mhello\u001b[0m", redacted.Text);
|
|
}
|
|
|
|
[Fact]
|
|
public void Redact_MasksSensitiveSourceMetadata()
|
|
{
|
|
var line = CreateLine("hello") with
|
|
{
|
|
Source = CreateSource() with
|
|
{
|
|
Metadata = new Dictionary<string, string?> { ["apiKey"] = "secret-value" }
|
|
}
|
|
};
|
|
|
|
var redacted = _redactor.Redact(line);
|
|
|
|
Assert.Equal("[Redacted]", redacted.Source.Metadata["apiKey"]);
|
|
}
|
|
|
|
private static ConsoleLogLine CreateLine(string text) => new()
|
|
{
|
|
Text = text,
|
|
Source = CreateSource()
|
|
};
|
|
|
|
private static ConsoleLogSource CreateSource() => new()
|
|
{
|
|
Id = "source",
|
|
DisplayName = "source",
|
|
MachineName = "machine"
|
|
};
|
|
}
|