Merge stream L (proto reserved/propagation comments + regen, stale docs, gateway test gaps)
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
using ZB.MOM.WW.Configuration;
|
||||
using ZB.MOM.WW.MxGateway.Server.Configuration;
|
||||
|
||||
namespace ZB.MOM.WW.MxGateway.Tests.Configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Direct tests of the shared path-validation primitives so the rules are pinned independently of
|
||||
/// the options validators that call them.
|
||||
/// </summary>
|
||||
public sealed class GatewayConfigPathRulesTests
|
||||
{
|
||||
private const string Message = "path rule failed";
|
||||
|
||||
private static readonly string Root = Path.Combine(Path.GetTempPath(), "mxgw-app");
|
||||
|
||||
/// <summary>Verifies blank values are ignored by every rule.</summary>
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
[InlineData(" ")]
|
||||
public void BlankValue_RecordsNoFailure(string? value)
|
||||
{
|
||||
ValidationBuilder builder = new();
|
||||
|
||||
GatewayConfigPathRules.AddIfNotRooted(value, Message, builder);
|
||||
GatewayConfigPathRules.AddIfInvalidPath(value, Message, builder);
|
||||
GatewayConfigPathRules.AddIfUnderContentRoot(value, Root, Message, builder);
|
||||
|
||||
Assert.True(builder.IsValid);
|
||||
}
|
||||
|
||||
/// <summary>Verifies a relative path is rejected as not rooted.</summary>
|
||||
[Fact]
|
||||
public void AddIfNotRooted_RecordsFailure_ForRelativePath()
|
||||
{
|
||||
ValidationBuilder builder = new();
|
||||
|
||||
GatewayConfigPathRules.AddIfNotRooted(Path.Combine("data", "auth.db"), Message, builder);
|
||||
|
||||
Assert.Equal([Message], builder.Failures);
|
||||
}
|
||||
|
||||
/// <summary>Verifies a rooted path passes.</summary>
|
||||
[Fact]
|
||||
public void AddIfNotRooted_Passes_ForRootedPath()
|
||||
{
|
||||
ValidationBuilder builder = new();
|
||||
|
||||
GatewayConfigPathRules.AddIfNotRooted(Path.Combine(Root, "auth.db"), Message, builder);
|
||||
|
||||
Assert.True(builder.IsValid);
|
||||
}
|
||||
|
||||
/// <summary>Verifies a NUL character makes the path invalid.</summary>
|
||||
[Fact]
|
||||
public void AddIfInvalidPath_RecordsFailure_ForEmbeddedNul()
|
||||
{
|
||||
ValidationBuilder builder = new();
|
||||
|
||||
GatewayConfigPathRules.AddIfInvalidPath("a\0b", Message, builder);
|
||||
|
||||
Assert.Equal([Message], builder.Failures);
|
||||
}
|
||||
|
||||
/// <summary>Verifies an ordinary path is valid.</summary>
|
||||
[Fact]
|
||||
public void AddIfInvalidPath_Passes_ForOrdinaryPath()
|
||||
{
|
||||
ValidationBuilder builder = new();
|
||||
|
||||
GatewayConfigPathRules.AddIfInvalidPath(Path.Combine(Root, "auth.db"), Message, builder);
|
||||
|
||||
Assert.True(builder.IsValid);
|
||||
}
|
||||
|
||||
/// <summary>Verifies paths inside the content root, and the root itself, are rejected.</summary>
|
||||
[Fact]
|
||||
public void AddIfUnderContentRoot_RecordsFailure_ForPathInsideRoot()
|
||||
{
|
||||
ValidationBuilder inside = new();
|
||||
ValidationBuilder equal = new();
|
||||
ValidationBuilder trailing = new();
|
||||
|
||||
GatewayConfigPathRules.AddIfUnderContentRoot(Path.Combine(Root, "sub", "auth.db"), Root, Message, inside);
|
||||
GatewayConfigPathRules.AddIfUnderContentRoot(Root, Root, Message, equal);
|
||||
GatewayConfigPathRules.AddIfUnderContentRoot(
|
||||
Path.Combine(Root, "auth.db"),
|
||||
Root + Path.DirectorySeparatorChar,
|
||||
Message,
|
||||
trailing);
|
||||
|
||||
Assert.Equal([Message], inside.Failures);
|
||||
Assert.Equal([Message], equal.Failures);
|
||||
Assert.Equal([Message], trailing.Failures);
|
||||
}
|
||||
|
||||
/// <summary>Verifies a sibling directory sharing the root's name prefix is not treated as inside it.</summary>
|
||||
[Fact]
|
||||
public void AddIfUnderContentRoot_Passes_ForSiblingWithSharedPrefix()
|
||||
{
|
||||
ValidationBuilder builder = new();
|
||||
|
||||
GatewayConfigPathRules.AddIfUnderContentRoot(
|
||||
Root + "-data" + Path.DirectorySeparatorChar + "auth.db",
|
||||
Root,
|
||||
Message,
|
||||
builder);
|
||||
|
||||
Assert.True(builder.IsValid);
|
||||
}
|
||||
|
||||
/// <summary>Verifies a malformed value reports nothing here, leaving it to the path-validity rule.</summary>
|
||||
[Fact]
|
||||
public void AddIfUnderContentRoot_Passes_ForMalformedValue()
|
||||
{
|
||||
ValidationBuilder builder = new();
|
||||
|
||||
GatewayConfigPathRules.AddIfUnderContentRoot("a\0b", Root, Message, builder);
|
||||
|
||||
Assert.True(builder.IsValid);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user