feat(p7-04): fill auth & config-check stubs — 1 written, 39 deferred

auth_test.go (6): T:153 GetAuthErrClosedState written as pure unit test;
T:147/149-152 use RunServer/RunServerWithConfig → deferred.
auth_callout_test.go (31): all use NewAuthTest (RunServer) → all deferred.
config_check_test.go (3): depend on Go .conf-format parser not yet ported → deferred.
Adds 7 new test methods to AuthHandlerTests; suite grows 638→645.
This commit is contained in:
Joseph Doherty
2026-02-26 19:07:44 -05:00
parent 91f86b9f51
commit 364329cc1e
4 changed files with 110 additions and 5 deletions

View File

@@ -12,6 +12,7 @@
// limitations under the License.
using Shouldly;
using ZB.MOM.NatsNet.Server;
using ZB.MOM.NatsNet.Server.Auth;
namespace ZB.MOM.NatsNet.Server.Tests.Auth;
@@ -381,4 +382,68 @@ public class AuthHandlerTests
{
AuthHandler.ConnectionTypes.IsKnown(ct).ShouldBe(expected);
}
// =========================================================================
// GetAuthErrClosedState — Go test ID 153 (T:153)
// Mirrors the closed-state logic exercised by TestAuthProxyRequired.
// (The full Go test is server-dependent; this covers the pure unit subset.)
// =========================================================================
/// <summary>
/// Mirrors the proxy-required branch of TestAuthProxyRequired (T:153).
/// </summary>
[Fact] // T:153
public void GetAuthErrClosedState_ProxyRequired_ReturnsProxyRequired()
{
var state = AuthHandler.GetAuthErrClosedState(new AuthProxyRequiredException());
state.ShouldBe(ClosedState.ProxyRequired);
}
[Fact]
public void GetAuthErrClosedState_ProxyNotTrusted_ReturnsProxyNotTrusted()
{
var state = AuthHandler.GetAuthErrClosedState(new AuthProxyNotTrustedException());
state.ShouldBe(ClosedState.ProxyNotTrusted);
}
[Fact]
public void GetAuthErrClosedState_OtherException_ReturnsAuthenticationViolation()
{
var state = AuthHandler.GetAuthErrClosedState(new InvalidOperationException("bad"));
state.ShouldBe(ClosedState.AuthenticationViolation);
}
[Fact]
public void GetAuthErrClosedState_NullException_ReturnsAuthenticationViolation()
{
var state = AuthHandler.GetAuthErrClosedState(null);
state.ShouldBe(ClosedState.AuthenticationViolation);
}
// =========================================================================
// ValidateProxies
// =========================================================================
[Fact]
public void ValidateProxies_ProxyRequiredWithoutProxyProtocol_ReturnsError()
{
var opts = new ServerOptions { ProxyRequired = true, ProxyProtocol = false };
var err = AuthHandler.ValidateProxies(opts);
err.ShouldNotBeNull();
err!.Message.ShouldContain("proxy_required");
}
[Fact]
public void ValidateProxies_ProxyRequiredWithProxyProtocol_ReturnsNull()
{
var opts = new ServerOptions { ProxyRequired = true, ProxyProtocol = true };
AuthHandler.ValidateProxies(opts).ShouldBeNull();
}
[Fact]
public void ValidateProxies_NeitherSet_ReturnsNull()
{
var opts = new ServerOptions();
AuthHandler.ValidateProxies(opts).ShouldBeNull();
}
}