test(server): cover GatewayConfigPathRules, DashboardRedactor, EventSubscriberReplayAttachment
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
using ZB.MOM.WW.MxGateway.Server.Dashboard;
|
||||
using ZB.MOM.WW.MxGateway.Server.Diagnostics;
|
||||
|
||||
namespace ZB.MOM.WW.MxGateway.Tests.Dashboard;
|
||||
|
||||
/// <summary>Tests for <see cref="DashboardRedactor"/>.</summary>
|
||||
public sealed class DashboardRedactorTests
|
||||
{
|
||||
/// <summary>Verifies null, empty and whitespace values pass through unchanged.</summary>
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
public void Redact_ReturnsBlankValueUnchanged(string? value)
|
||||
{
|
||||
Assert.Equal(value, DashboardRedactor.Redact(value));
|
||||
}
|
||||
|
||||
/// <summary>Verifies harmless text is returned unchanged.</summary>
|
||||
[Fact]
|
||||
public void Redact_ReturnsOrdinaryTextUnchanged()
|
||||
{
|
||||
Assert.Equal("Session opened for Plant1", DashboardRedactor.Redact("Session opened for Plant1"));
|
||||
}
|
||||
|
||||
/// <summary>Verifies text containing a sensitive marker is replaced whole, case-insensitively.</summary>
|
||||
[Theory]
|
||||
[InlineData("apikey=abc")]
|
||||
[InlineData("API_KEY abc")]
|
||||
[InlineData("Authorization: Basic abc")]
|
||||
[InlineData("user credential rejected")]
|
||||
[InlineData("bad Password supplied")]
|
||||
[InlineData("client SECRET")]
|
||||
[InlineData("hub Token minted")]
|
||||
public void Redact_ReplacesTextContainingSensitiveMarker(string value)
|
||||
{
|
||||
Assert.Equal(GatewayLogRedactor.RedactedValue, DashboardRedactor.Redact(value));
|
||||
}
|
||||
|
||||
/// <summary>Verifies a gateway API key goes through client-identity redaction and its secret never survives.</summary>
|
||||
[Fact]
|
||||
public void Redact_DelegatesGatewayKeysToClientIdentityRedaction()
|
||||
{
|
||||
const string Value = "Bearer mxgw_dev_topsecretvalue";
|
||||
|
||||
string? result = DashboardRedactor.Redact(Value);
|
||||
|
||||
Assert.Equal(GatewayLogRedactor.RedactClientIdentity(Value), result);
|
||||
Assert.DoesNotContain("topsecretvalue", result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user