test(batch7): implement t3 cross-cutting mapped tests

This commit is contained in:
Joseph Doherty
2026-02-28 11:32:36 -05:00
parent 007122a659
commit efc0d642b1
4 changed files with 144 additions and 0 deletions

View File

@@ -1,5 +1,9 @@
using System.Text;
using Shouldly;
using ZB.MOM.NatsNet.Server;
using ZB.MOM.NatsNet.Server.Auth;
using ZB.MOM.NatsNet.Server.Internal;
using ZB.MOM.NatsNet.Server.Internal.DataStructures;
namespace ZB.MOM.NatsNet.Server.Tests.ImplBacklog;
@@ -148,4 +152,51 @@ public sealed class ConfigReloaderTests
ServerOptions.NoErrOnUnknownFields(false);
}
}
[Fact] // T:2774
public void ConfigReloadAuthDoesNotBreakRouteInterest_ShouldSucceed()
{
var (server, createError) = NatsServer.NewServer(new ServerOptions
{
NoLog = true,
NoSigs = true,
Accounts = [new Account { Name = "A" }],
Users = [new User
{
Username = "u",
Password = "p",
Account = new Account { Name = "A" },
}],
});
createError.ShouldBeNull();
server.ShouldNotBeNull();
try
{
var (account, lookupError) = server!.LookupAccount("A");
lookupError.ShouldBeNull();
account.ShouldNotBeNull();
account!.Sublist = SubscriptionIndex.NewSublistWithCache();
var insertError = account.Sublist.Insert(new Subscription
{
Subject = Encoding.ASCII.GetBytes("foo"),
Queue = Encoding.ASCII.GetBytes("bar"),
});
insertError.ShouldBeNull();
account.TotalSubs().ShouldBe(1);
server.ReloadAuthorization();
var (updatedAccount, updatedLookupError) = server.LookupAccount("A");
updatedLookupError.ShouldBeNull();
updatedAccount.ShouldNotBeNull();
updatedAccount!.TotalSubs().ShouldBe(1);
}
finally
{
server!.Shutdown();
}
}
}

View File

@@ -1121,6 +1121,43 @@ public sealed class JwtProcessorTests
"TestJWTAccountNATSResolverWrongCreds".ShouldNotBeNullOrWhiteSpace();
}
[Fact] // T:1893
public void DefaultSentinelUser_ShouldSucceed()
{
var options = new ServerOptions();
var errors = new List<Exception>();
var warnings = new List<Exception>();
options.ProcessConfigFileLine("default_sentinel", "bearer.default.sentinel", errors, warnings);
errors.ShouldBeEmpty();
warnings.ShouldBeEmpty();
options.DefaultSentinel.ShouldBe("bearer.default.sentinel");
options.ProcessConfigFileLine("default_sentinel", 123L, errors, warnings);
errors.Count.ShouldBe(1);
errors[0].Message.ShouldContain("default_sentinel must be a string");
var (server, createError) = NatsServer.NewServer(new ServerOptions
{
NoLog = true,
NoSigs = true,
});
createError.ShouldBeNull();
server.ShouldNotBeNull();
try
{
var reloadOption = new DefaultSentinelReloadOption("updated.sentinel");
reloadOption.IsAuthChange().ShouldBeFalse();
Should.NotThrow(() => reloadOption.Apply(server!));
}
finally
{
server!.Shutdown();
}
}
[Fact] // T:1895
public void JWTJetStreamClientsExcludedForMaxConnsUpdate_ShouldSucceed()
{

View File

@@ -348,6 +348,62 @@ public sealed class NatsServerTests
"TestServerConfigLastLineComments".ShouldNotBeNullOrWhiteSpace();
}
[Fact] // T:2904
public void ServerClusterAndGatewayNameNoSpace_ShouldSucceed()
{
var serverNameErrors = new List<Exception>();
var warnings = new List<Exception>();
var parseOptions = new ServerOptions();
parseOptions.ProcessConfigFileLine("server_name", "my server", serverNameErrors, warnings);
serverNameErrors.ShouldContain(ServerErrors.ErrServerNameHasSpaces);
var (serverWithSpacedName, serverNameError) = NatsServer.NewServer(new ServerOptions
{
ServerName = "my server",
});
serverWithSpacedName.ShouldBeNull();
serverNameError.ShouldNotBeNull();
serverNameError.Message.ShouldContain("server name cannot contain spaces");
var clusterErrors = new List<Exception>();
ServerOptions.ParseCluster(
new Dictionary<string, object?>
{
["port"] = -1L,
["name"] = "my cluster",
},
new ServerOptions(),
clusterErrors,
warnings: null);
clusterErrors.Count.ShouldBeGreaterThanOrEqualTo(1);
clusterErrors[^1].Message.ShouldContain(ServerErrors.ErrClusterNameHasSpaces.Message);
var (clusterServer, clusterError) = NatsServer.NewServer(new ServerOptions
{
Cluster = new ClusterOpts
{
Name = "my cluster",
Port = -1,
},
});
clusterServer.ShouldBeNull();
clusterError.ShouldBeSameAs(ServerErrors.ErrClusterNameHasSpaces);
var gatewayErrors = new List<Exception>();
ServerOptions.ParseGateway(
new Dictionary<string, object?>
{
["port"] = -1L,
["name"] = "my gateway",
},
new ServerOptions(),
gatewayErrors,
warnings: null);
gatewayErrors.Count.ShouldBe(1);
gatewayErrors[0].Message.ShouldContain(ServerErrors.ErrGatewayNameHasSpaces.Message);
}
[Fact] // T:2905
public void ServerClientURL_ShouldSucceed()
{