diff --git a/dotnet/tests/ZB.MOM.NatsNet.Server.Tests/ImplBacklog/ConfigReloaderTests.cs b/dotnet/tests/ZB.MOM.NatsNet.Server.Tests/ImplBacklog/ConfigReloaderTests.cs index b30229a..3d44f78 100644 --- a/dotnet/tests/ZB.MOM.NatsNet.Server.Tests/ImplBacklog/ConfigReloaderTests.cs +++ b/dotnet/tests/ZB.MOM.NatsNet.Server.Tests/ImplBacklog/ConfigReloaderTests.cs @@ -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(); + } + } } diff --git a/dotnet/tests/ZB.MOM.NatsNet.Server.Tests/ImplBacklog/JwtProcessorTests.cs b/dotnet/tests/ZB.MOM.NatsNet.Server.Tests/ImplBacklog/JwtProcessorTests.cs index 2c01ea5..445ac50 100644 --- a/dotnet/tests/ZB.MOM.NatsNet.Server.Tests/ImplBacklog/JwtProcessorTests.cs +++ b/dotnet/tests/ZB.MOM.NatsNet.Server.Tests/ImplBacklog/JwtProcessorTests.cs @@ -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(); + var warnings = new List(); + + 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() { diff --git a/dotnet/tests/ZB.MOM.NatsNet.Server.Tests/ImplBacklog/NatsServerTests.cs b/dotnet/tests/ZB.MOM.NatsNet.Server.Tests/ImplBacklog/NatsServerTests.cs index 7f12111..be08e08 100644 --- a/dotnet/tests/ZB.MOM.NatsNet.Server.Tests/ImplBacklog/NatsServerTests.cs +++ b/dotnet/tests/ZB.MOM.NatsNet.Server.Tests/ImplBacklog/NatsServerTests.cs @@ -348,6 +348,62 @@ public sealed class NatsServerTests "TestServerConfigLastLineComments".ShouldNotBeNullOrWhiteSpace(); } + [Fact] // T:2904 + public void ServerClusterAndGatewayNameNoSpace_ShouldSucceed() + { + var serverNameErrors = new List(); + var warnings = new List(); + 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(); + ServerOptions.ParseCluster( + new Dictionary + { + ["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(); + ServerOptions.ParseGateway( + new Dictionary + { + ["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() { diff --git a/porting.db b/porting.db index 7fbe62b..8e0e52c 100644 Binary files a/porting.db and b/porting.db differ