diff --git a/src/Tgstation.Server.Host/Components/Chat/Providers/IrcProvider.cs b/src/Tgstation.Server.Host/Components/Chat/Providers/IrcProvider.cs index b504ddf0be..000a6cc6fc 100644 --- a/src/Tgstation.Server.Host/Components/Chat/Providers/IrcProvider.cs +++ b/src/Tgstation.Server.Host/Components/Chat/Providers/IrcProvider.cs @@ -112,6 +112,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers { if (assemblyInformationProvider == null) throw new ArgumentNullException(nameof(assemblyInformationProvider)); + this.asyncDelayer = asyncDelayer ?? throw new ArgumentNullException(nameof(asyncDelayer)); var builder = chatBot.CreateConnectionStringBuilder(); @@ -123,7 +124,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers nickname = ircBuilder.Nickname; password = ircBuilder.Password; - passwordType = ircBuilder.PasswordType.Value; + passwordType = ircBuilder.PasswordType; client = new IrcFeatures { diff --git a/src/Tgstation.Server.Host/Controllers/ApiController.cs b/src/Tgstation.Server.Host/Controllers/ApiController.cs index 16cda75523..d1c9f9f0ea 100644 --- a/src/Tgstation.Server.Host/Controllers/ApiController.cs +++ b/src/Tgstation.Server.Host/Controllers/ApiController.cs @@ -408,12 +408,15 @@ namespace Tgstation.Server.Host.Controllers foreach (var finalResult in finalResults) resultTransformer(finalResult); + var carryTheOne = totalResults % pageSize != 0 + ? 1 + : 0; return Json( new PaginatedResponse { Content = finalResults, PageSize = pageSize, - TotalPages = (ushort)((totalResults / pageSize) + 1), + TotalPages = (ushort)(totalResults / pageSize) + carryTheOne, }); } } diff --git a/tests/Tgstation.Server.Host.Tests/Components/Chat/Providers/TestIrcProvider.cs b/tests/Tgstation.Server.Host.Tests/Components/Chat/Providers/TestIrcProvider.cs new file mode 100644 index 0000000000..68413a0809 --- /dev/null +++ b/tests/Tgstation.Server.Host.Tests/Components/Chat/Providers/TestIrcProvider.cs @@ -0,0 +1,49 @@ +using Microsoft.Extensions.Logging; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using System; +using System.Threading.Tasks; +using Tgstation.Server.Api.Models; +using Tgstation.Server.Host.Core; +using Tgstation.Server.Host.Jobs; +using Tgstation.Server.Host.Models; +using Tgstation.Server.Host.System; + +namespace Tgstation.Server.Host.Components.Chat.Providers.Tests +{ + [TestClass] + public sealed class TestIrcProvider + { + [TestMethod] + public async Task TestConstructionAndDisposal() + { + Assert.ThrowsException(() => new IrcProvider(null, null, null, null, null)); + var mockJobManager = new Mock(); + Assert.ThrowsException(() => new IrcProvider(mockJobManager.Object, null, null, null, null)); + var mockAss = new Mock(); + Assert.ThrowsException(() => new IrcProvider(mockJobManager.Object, mockAss.Object, null, null, null)); + var mockAsyncDelayer = new Mock(); + Assert.ThrowsException(() => new IrcProvider(mockJobManager.Object, mockAss.Object, mockAsyncDelayer.Object, null, null)); + var mockLogger = new Mock>(); + Assert.ThrowsException(() => new IrcProvider(mockJobManager.Object, mockAss.Object, mockAsyncDelayer.Object, mockLogger.Object, null)); + + var mockBot = new ChatBot + { + Name = "test", + Provider = ChatProvider.Irc + }; + + Assert.ThrowsException(() => new IrcProvider(mockJobManager.Object, mockAss.Object, mockAsyncDelayer.Object, mockLogger.Object, mockBot)); + + mockBot.ConnectionString = new IrcConnectionStringBuilder + { + Address = "localhost", + Nickname = "test", + UseSsl = true, + Port = 6667 + }.ToString(); + + await new IrcProvider(mockJobManager.Object, mockAss.Object, mockAsyncDelayer.Object, mockLogger.Object, mockBot).DisposeAsync(); + } + } +} diff --git a/tests/Tgstation.Server.Tests/InstanceManagerTest.cs b/tests/Tgstation.Server.Tests/InstanceManagerTest.cs index 14a50233c5..7aed5d0fe7 100644 --- a/tests/Tgstation.Server.Tests/InstanceManagerTest.cs +++ b/tests/Tgstation.Server.Tests/InstanceManagerTest.cs @@ -1,10 +1,17 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.IO; using System.Linq; +using System.Net; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Net.Mime; using System.Threading; using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Newtonsoft.Json; + +using Tgstation.Server.Api; using Tgstation.Server.Api.Models; using Tgstation.Server.Api.Models.Request; using Tgstation.Server.Api.Models.Response; @@ -18,14 +25,16 @@ namespace Tgstation.Server.Tests { public const string TestInstanceName = "IntegrationTestInstance"; + readonly IServerClient serverClient; readonly IInstanceManagerClient instanceManagerClient; readonly IUsersClient usersClient; readonly string testRootPath; - public InstanceManagerTest(IInstanceManagerClient instanceManagerClient, IUsersClient usersClient, string testRootPath) + public InstanceManagerTest(IServerClient serverClient, string testRootPath) { - this.instanceManagerClient = instanceManagerClient ?? throw new ArgumentNullException(nameof(instanceManagerClient)); - this.usersClient = usersClient ?? throw new ArgumentNullException(nameof(usersClient)); + this.serverClient = serverClient ?? throw new ArgumentNullException(nameof(serverClient)); + this.instanceManagerClient = serverClient.Instances; + this.usersClient = serverClient.Users; this.testRootPath = testRootPath ?? throw new ArgumentNullException(nameof(testRootPath)); } @@ -151,9 +160,45 @@ namespace Tgstation.Server.Tests }, cancellationToken), ErrorCode.InstanceRelocateOnline).ConfigureAwait(false); Assert.IsTrue(Directory.Exists(firstTest.Path)); + await RegressionTest1256(cancellationToken).ConfigureAwait(false); + return firstTest; } + async Task RegressionTest1256(CancellationToken cancellationToken) + { + var allInstances = await instanceManagerClient.List(null, cancellationToken).ConfigureAwait(false); + Assert.IsTrue(allInstances.Count <= 6, "Need less than or 6 instances at this point"); + + for (var I = allInstances.Count; I < 6; ++I) + await instanceManagerClient.CreateOrAttach(new InstanceCreateRequest + { + Name = $"RegressionTest1256-{I}", + Path = Path.Combine(testRootPath, Guid.NewGuid().ToString()), + }, cancellationToken).ConfigureAwait(false); + + var url = serverClient.Url; + var token = serverClient.Token.Bearer; + // check that 400s are returned appropriately + using var httpClient = new HttpClient(); + using (var request = new HttpRequestMessage(HttpMethod.Get, url.ToString() + Routes.ListRoute(Routes.InstanceManager).Substring(1) + "?pageSize=2")) + { + request.Headers.Accept.Clear(); + request.Headers.UserAgent.Add(new ProductInfoHeaderValue("RegressionTest1256", "1.0.0")); + request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(MediaTypeNames.Application.Json)); + request.Headers.Add(ApiHeaders.ApiVersionHeader, "Tgstation.Server.Api/" + ApiHeaders.Version); + request.Headers.Authorization = new AuthenticationHeaderValue(ApiHeaders.BearerAuthenticationScheme, token); + using var response = await httpClient.SendAsync(request, cancellationToken); + response.EnsureSuccessStatusCode(); + + var json = await response.Content.ReadAsStringAsync(); + var paginated = JsonConvert.DeserializeObject>(json); + + Assert.AreEqual(2, paginated.PageSize); + Assert.AreEqual(3, paginated.TotalPages); + } + } + public async Task RunPostTest(CancellationToken cancellationToken) { var instances = await instanceManagerClient.List(null, cancellationToken); diff --git a/tests/Tgstation.Server.Tests/IntegrationTest.cs b/tests/Tgstation.Server.Tests/IntegrationTest.cs index ff975168ad..2c1f446d9f 100644 --- a/tests/Tgstation.Server.Tests/IntegrationTest.cs +++ b/tests/Tgstation.Server.Tests/IntegrationTest.cs @@ -768,7 +768,7 @@ namespace Tgstation.Server.Tests var rootTest = FailFast(new RawRequestTests().Run(clientFactory, adminClient, cancellationToken)); var adminTest = FailFast(new AdministrationTest(adminClient.Administration).Run(cancellationToken)); var usersTest = FailFast(new UsersTest(adminClient).Run(cancellationToken)); - instance = await new InstanceManagerTest(adminClient.Instances, adminClient.Users, server.Directory).RunPreInstanceTest(cancellationToken); + instance = await new InstanceManagerTest(adminClient, server.Directory).RunPreInstanceTest(cancellationToken); Assert.IsTrue(Directory.Exists(instance.Path)); var instanceClient = adminClient.Instances.CreateClient(instance); @@ -885,7 +885,7 @@ namespace Tgstation.Server.Tests await new ChatTest(instanceClient.ChatBots, adminClient.Instances, instance).RunPostTest(cancellationToken); await repoTest; - await new InstanceManagerTest(adminClient.Instances, adminClient.Users, server.Directory).RunPostTest(cancellationToken); + await new InstanceManagerTest(adminClient, server.Directory).RunPostTest(cancellationToken); } } catch (ApiException ex)