diff --git a/src/Tgstation.Server.Api/Models/InstanceUser.cs b/src/Tgstation.Server.Api/Models/InstanceUser.cs index 5cbcd6cbbb..b198ceff64 100644 --- a/src/Tgstation.Server.Api/Models/InstanceUser.cs +++ b/src/Tgstation.Server.Api/Models/InstanceUser.cs @@ -1,4 +1,5 @@ -using Tgstation.Server.Api.Rights; +using System.ComponentModel.DataAnnotations; +using Tgstation.Server.Api.Rights; namespace Tgstation.Server.Api.Models { @@ -17,31 +18,37 @@ namespace Tgstation.Server.Api.Models /// /// The of the /// - public ByondRights ByondRights { get; set; } + [Required] + public ByondRights? ByondRights { get; set; } /// /// The of the /// - public DreamDaemonRights DreamDaemonRights { get; set; } + [Required] + public DreamDaemonRights? DreamDaemonRights { get; set; } /// /// The of the /// - public DreamMakerRights DreamMakerRights { get; set; } + [Required] + public DreamMakerRights? DreamMakerRights { get; set; } /// /// The of the /// - public RepositoryRights RepositoryRights { get; set; } + [Required] + public RepositoryRights? RepositoryRights { get; set; } /// /// The of the /// - public ChatSettingsRights ChatSettingsRights { get; set; } + [Required] + public ChatSettingsRights? ChatSettingsRights { get; set; } /// /// The of the /// - public ConfigurationRights ConfigurationRights { get; set; } + [Required] + public ConfigurationRights? ConfigurationRights { get; set; } } } diff --git a/src/Tgstation.Server.Api/Models/Internal/User.cs b/src/Tgstation.Server.Api/Models/Internal/User.cs index d71512dbbe..b70e868079 100644 --- a/src/Tgstation.Server.Api/Models/Internal/User.cs +++ b/src/Tgstation.Server.Api/Models/Internal/User.cs @@ -7,7 +7,7 @@ namespace Tgstation.Server.Api.Models.Internal /// /// Represents a server /// - [Model(RightsType.Administration, WriteRight = AdministrationRights.EditUsers, CanCrud = true)] + [Model(RightsType.Administration, WriteRight = Rights.AdministrationRights.EditUsers, CanCrud = true)] public class User { /// @@ -19,7 +19,8 @@ namespace Tgstation.Server.Api.Models.Internal /// /// If the is enabled since users cannot be deleted. System users cannot be disabled /// - public bool Enabled { get; set; } + [Required] + public bool? Enabled { get; set; } /// /// When the was created @@ -37,20 +38,19 @@ namespace Tgstation.Server.Api.Models.Internal /// /// The name of the /// - [Permissions(WriteRight = AdministrationRights.EditUsers)] [Required] public string Name { get; set; } /// /// The for the /// - [Permissions(WriteRight = AdministrationRights.EditUsers)] - public AdministrationRights AdministrationRights { get; set; } + [Required] + public AdministrationRights? AdministrationRights { get; set; } /// /// The for the /// - [Permissions(WriteRight = AdministrationRights.EditUsers)] - public InstanceManagerRights InstanceManagerRights { get; set; } + [Required] + public InstanceManagerRights? InstanceManagerRights { get; set; } } } \ No newline at end of file diff --git a/src/Tgstation.Server.Api/Models/UserUpdate.cs b/src/Tgstation.Server.Api/Models/UserUpdate.cs index f5f7eda6fc..4203beed1b 100644 --- a/src/Tgstation.Server.Api/Models/UserUpdate.cs +++ b/src/Tgstation.Server.Api/Models/UserUpdate.cs @@ -1,6 +1,4 @@ -using Tgstation.Server.Api.Rights; - -namespace Tgstation.Server.Api.Models +namespace Tgstation.Server.Api.Models { /// /// For editing a given . Will never be returned by the API @@ -10,7 +8,6 @@ namespace Tgstation.Server.Api.Models /// /// Cleartext password of the /// - [Permissions(WriteRight = AdministrationRights.EditUsers)] public string Password { get; set; } } } diff --git a/src/Tgstation.Server.Host.Watchdog/WatchdogFactory.cs b/src/Tgstation.Server.Host.Watchdog/WatchdogFactory.cs index 436e051429..8e2ac94dce 100644 --- a/src/Tgstation.Server.Host.Watchdog/WatchdogFactory.cs +++ b/src/Tgstation.Server.Host.Watchdog/WatchdogFactory.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.Logging; +using System; using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; @@ -9,6 +10,6 @@ namespace Tgstation.Server.Host.Watchdog { /// [ExcludeFromCodeCoverage] - public IWatchdog CreateWatchdog(ILoggerFactory loggerFactory) => new Watchdog(new ServerFactory(), RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? (IActiveAssemblyDeleter)new WindowsActiveAssemblyDeleter() : new PosixActiveAssemblyDeleter(), new IsolatedAssemblyContextFactory(), loggerFactory.CreateLogger()); + public IWatchdog CreateWatchdog(ILoggerFactory loggerFactory) => new Watchdog(new ServerFactory(), RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? (IActiveAssemblyDeleter)new WindowsActiveAssemblyDeleter() : new PosixActiveAssemblyDeleter(), new IsolatedAssemblyContextFactory(), loggerFactory?.CreateLogger() ?? throw new ArgumentNullException(nameof(loggerFactory))); } } diff --git a/src/Tgstation.Server.Host/Controllers/ChatController.cs b/src/Tgstation.Server.Host/Controllers/ChatController.cs index 280e99cb08..e04fbd52db 100644 --- a/src/Tgstation.Server.Host/Controllers/ChatController.cs +++ b/src/Tgstation.Server.Host/Controllers/ChatController.cs @@ -83,7 +83,15 @@ namespace Tgstation.Server.Host.Controllers }; DatabaseContext.ChatSettings.Add(dbModel); DatabaseContext.ChatChannels.AddRange(dbModel.Channels); - await DatabaseContext.Save(cancellationToken).ConfigureAwait(false); + + try + { + await DatabaseContext.Save(cancellationToken).ConfigureAwait(false); + } + catch (DbUpdateConcurrencyException) + { + return Conflict(); + } try { diff --git a/src/Tgstation.Server.Host/Controllers/HomeController.cs b/src/Tgstation.Server.Host/Controllers/HomeController.cs index 8abb2ca69f..40ea8a1e91 100644 --- a/src/Tgstation.Server.Host/Controllers/HomeController.cs +++ b/src/Tgstation.Server.Host/Controllers/HomeController.cs @@ -107,7 +107,7 @@ namespace Tgstation.Server.Host.Controllers return Unauthorized(); } - if (!user.Enabled) + if (!user.Enabled.Value) return Forbid(); return Json(tokenFactory.CreateToken(user)); diff --git a/src/Tgstation.Server.Host/Controllers/UsersController.cs b/src/Tgstation.Server.Host/Controllers/UsersController.cs index 4e71f62465..f66ffe1e5c 100644 --- a/src/Tgstation.Server.Host/Controllers/UsersController.cs +++ b/src/Tgstation.Server.Host/Controllers/UsersController.cs @@ -2,6 +2,8 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using System; +using System.Linq; +using System.Net; using System.Threading; using System.Threading.Tasks; using Tgstation.Server.Api.Models; @@ -43,6 +45,8 @@ namespace Tgstation.Server.Host.Controllers public UsersController(IDatabaseContext databaseContext, IAuthenticationContextFactory authenticationContextFactory, ISystemIdentityFactory systemIdentityFactory, ICryptographySuite cryptographySuite, ILogger logger) : base(databaseContext, authenticationContextFactory) { this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); + this.systemIdentityFactory = systemIdentityFactory ?? throw new ArgumentNullException(nameof(systemIdentityFactory)); + this.cryptographySuite = cryptographySuite ?? throw new ArgumentNullException(nameof(cryptographySuite)); } /// @@ -60,11 +64,11 @@ namespace Tgstation.Server.Host.Controllers var dbUser = new Models.User { - AdministrationRights = model.AdministrationRights, + AdministrationRights = model.AdministrationRights ?? AdministrationRights.None, CreatedAt = DateTimeOffset.Now, CreatedBy = AuthenticationContext.User, - Enabled = model.Enabled, - InstanceManagerRights = model.InstanceManagerRights, + Enabled = model.Enabled ?? false, + InstanceManagerRights = model.InstanceManagerRights ?? InstanceManagerRights.None, Name = model.Name, SystemIdentifier = model.SystemIdentifier }; @@ -97,7 +101,37 @@ namespace Tgstation.Server.Host.Controllers return Conflict(); } - return Ok(); + return Json(dbUser.ToApi()); + } + + /// + [TgsAuthorize(AdministrationRights.EditUsers)] + public override async Task Update([FromBody] UserUpdate model, CancellationToken cancellationToken) + { + if (model == null) + throw new ArgumentNullException(nameof(model)); + + var originalUser = await DatabaseContext.Users.Where(x => x.Id == model.Id).FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false); + if (originalUser == default) + return StatusCode((int)HttpStatusCode.Gone); + + if (model.Password != null) + { + if (originalUser.PasswordHash == null) + return BadRequest(new { message = "Cannot convert a system user to a password user!" }); + cryptographySuite.SetUserPassword(originalUser, model.Password); + } + else if(model.SystemIdentifier != originalUser.SystemIdentifier) + return BadRequest(new { message = "Cannot change a user's system identifier!" }); + + originalUser.Name = model.Name ?? originalUser.Name; + originalUser.InstanceManagerRights = model.InstanceManagerRights ?? originalUser.InstanceManagerRights; + originalUser.AdministrationRights = model.AdministrationRights ?? originalUser.AdministrationRights; + originalUser.Enabled = model.Enabled ?? originalUser.Enabled; + + await DatabaseContext.Save(cancellationToken).ConfigureAwait(false); + + return Json(originalUser.ToApi()); } } } diff --git a/src/Tgstation.Server.Host/Models/DatabaseContext.cs b/src/Tgstation.Server.Host/Models/DatabaseContext.cs index 14d049bb59..25caf31b19 100644 --- a/src/Tgstation.Server.Host/Models/DatabaseContext.cs +++ b/src/Tgstation.Server.Host/Models/DatabaseContext.cs @@ -112,6 +112,8 @@ namespace Tgstation.Server.Host.Models user.HasIndex(x => new { x.Name, x.SystemIdentifier }).IsUnique(); user.HasOne(x => x.CreatedBy).WithMany(x => x.CreatedUsers).OnDelete(DeleteBehavior.Restrict); + modelBuilder.Entity().HasIndex(x => new { x.UserId, x.Instance }).IsUnique(); + var chatChannel = modelBuilder.Entity(); chatChannel.HasIndex(x => new { x.ChatSettingsId, x.IrcChannel }).IsUnique(); chatChannel.HasIndex(x => new { x.ChatSettingsId, x.DiscordChannelId }).IsUnique(); diff --git a/src/Tgstation.Server.Host/Models/InstanceUser.cs b/src/Tgstation.Server.Host/Models/InstanceUser.cs index 8e2f3b9ec5..37fc313e04 100644 --- a/src/Tgstation.Server.Host/Models/InstanceUser.cs +++ b/src/Tgstation.Server.Host/Models/InstanceUser.cs @@ -1,5 +1,4 @@ using System.ComponentModel.DataAnnotations; -using Tgstation.Server.Api.Rights; namespace Tgstation.Server.Host.Models { @@ -20,10 +19,10 @@ namespace Tgstation.Server.Host.Models /// /// If the has any instance rights /// - public bool AnyRights => ByondRights != ByondRights.None || - ChatSettingsRights != ChatSettingsRights.None || - ConfigurationRights != ConfigurationRights.None || - DreamDaemonRights != DreamDaemonRights.None || - DreamMakerRights != DreamMakerRights.None; + public bool AnyRights => ByondRights != Api.Rights.ByondRights.None || + ChatSettingsRights != Api.Rights.ChatSettingsRights.None || + ConfigurationRights != Api.Rights.ConfigurationRights.None || + DreamDaemonRights != Api.Rights.DreamDaemonRights.None || + DreamMakerRights != Api.Rights.DreamMakerRights.None; } } diff --git a/src/Tgstation.Server.Host/Security/AuthenticationContext.cs b/src/Tgstation.Server.Host/Security/AuthenticationContext.cs index dab8b2e60a..5e03fbff4b 100644 --- a/src/Tgstation.Server.Host/Security/AuthenticationContext.cs +++ b/src/Tgstation.Server.Host/Security/AuthenticationContext.cs @@ -51,10 +51,15 @@ namespace Tgstation.Server.Host.Security // use the api versions because they're the ones that contain the actual properties var typeToCheck = isInstance ? typeof(InstanceUser) : typeof(User); - var prop = typeToCheck.GetProperties().Where(x => x.PropertyType == rightsEnum).First(); + var nullableType = typeof(Nullable<>); + var nullableRightsType = nullableType.MakeGenericType(rightsEnum); + + var prop = typeToCheck.GetProperties().Where(x => x.PropertyType == nullableRightsType).First(); var right = prop.GetMethod.Invoke(isInstance ? (object)InstanceUser : User, Array.Empty()); - + + if (right == null) + throw new InvalidOperationException("A user right was null!"); return (int)right; } } diff --git a/tests/Tgstation.Server.Host.Console.Tests/TestProgram.cs b/tests/Tgstation.Server.Host.Console.Tests/TestProgram.cs index e016e73849..695d75a619 100644 --- a/tests/Tgstation.Server.Host.Console.Tests/TestProgram.cs +++ b/tests/Tgstation.Server.Host.Console.Tests/TestProgram.cs @@ -1,5 +1,7 @@ +using Microsoft.Extensions.Logging; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; +using System; using System.Threading; using System.Threading.Tasks; using Tgstation.Server.Host.Watchdog; @@ -13,11 +15,12 @@ namespace Tgstation.Server.Host.Console.Tests public async Task TestProgramRuns() { var mockServer = new Mock(); - mockServer.Setup(x => x.RunAsync(null, It.IsAny())).Returns(Task.CompletedTask).Verifiable(); + var args = Array.Empty(); + mockServer.Setup(x => x.RunAsync(args, It.IsAny())).Returns(Task.CompletedTask).Verifiable(); var mockServerFactory = new Mock(); - mockServerFactory.Setup(x => x.CreateWatchdog()).Returns(mockServer.Object).Verifiable(); + mockServerFactory.Setup(x => x.CreateWatchdog(It.IsAny())).Returns(mockServer.Object).Verifiable(); Program.WatchdogFactory = mockServerFactory.Object; - await Program.Main(null).ConfigureAwait(false); + await Program.Main(args).ConfigureAwait(false); mockServer.VerifyAll(); mockServerFactory.VerifyAll(); } diff --git a/tests/Tgstation.Server.Host.Service.Tests/TestServerService.cs b/tests/Tgstation.Server.Host.Service.Tests/TestServerService.cs index d15ad6f69e..f4127014b5 100644 --- a/tests/Tgstation.Server.Host.Service.Tests/TestServerService.cs +++ b/tests/Tgstation.Server.Host.Service.Tests/TestServerService.cs @@ -1,4 +1,5 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.Extensions.Logging; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using System; using System.Reflection; @@ -17,9 +18,11 @@ namespace Tgstation.Server.Host.Service.Tests [TestMethod] public void TestConstructionAndDisposal() { - Assert.ThrowsException(() => new ServerService(null)); + Assert.ThrowsException(() => new ServerService(null, null)); var mockWatchdogFactory = new Mock(); - new ServerService(mockWatchdogFactory.Object).Dispose(); + Assert.ThrowsException(() => new ServerService(mockWatchdogFactory.Object, null)); + var mockLoggerFactory = new LoggerFactory(); + new ServerService(mockWatchdogFactory.Object, mockLoggerFactory).Dispose(); } [TestMethod] @@ -34,9 +37,10 @@ namespace Tgstation.Server.Host.Service.Tests CancellationToken cancellationToken; mockWatchdog.Setup(x => x.RunAsync(args, It.IsAny())).Callback((string[] _, CancellationToken token) => cancellationToken = token).Returns(Task.CompletedTask).Verifiable(); var mockWatchdogFactory = new Mock(); - mockWatchdogFactory.Setup(x => x.CreateWatchdog()).Returns(mockWatchdog.Object).Verifiable(); + var mockLoggerFactory = new LoggerFactory(); + mockWatchdogFactory.Setup(x => x.CreateWatchdog(mockLoggerFactory)).Returns(mockWatchdog.Object).Verifiable(); - using(var service = new ServerService(mockWatchdogFactory.Object)) + using(var service = new ServerService(mockWatchdogFactory.Object, mockLoggerFactory)) { onStart.Invoke(service, new object[] { args }); diff --git a/tests/Tgstation.Server.Host.Service.Tests/Tgstation.Server.Host.Service.Tests.csproj b/tests/Tgstation.Server.Host.Service.Tests/Tgstation.Server.Host.Service.Tests.csproj index ccb09b4c3c..b44b760e2c 100644 --- a/tests/Tgstation.Server.Host.Service.Tests/Tgstation.Server.Host.Service.Tests.csproj +++ b/tests/Tgstation.Server.Host.Service.Tests/Tgstation.Server.Host.Service.Tests.csproj @@ -41,6 +41,33 @@ ..\..\packages\Castle.Core.4.2.1\lib\net45\Castle.Core.dll + + ..\..\packages\Microsoft.Extensions.Configuration.2.1.1\lib\netstandard2.0\Microsoft.Extensions.Configuration.dll + + + ..\..\packages\Microsoft.Extensions.Configuration.Abstractions.2.1.1\lib\netstandard2.0\Microsoft.Extensions.Configuration.Abstractions.dll + + + ..\..\packages\Microsoft.Extensions.Configuration.Binder.2.1.1\lib\netstandard2.0\Microsoft.Extensions.Configuration.Binder.dll + + + ..\..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.2.1.1\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll + + + ..\..\packages\Microsoft.Extensions.Logging.2.1.1\lib\netstandard2.0\Microsoft.Extensions.Logging.dll + + + ..\..\packages\Microsoft.Extensions.Logging.Abstractions.2.1.1\lib\netstandard2.0\Microsoft.Extensions.Logging.Abstractions.dll + + + ..\..\packages\Microsoft.Extensions.Logging.EventLog.2.1.1\lib\net461\Microsoft.Extensions.Logging.EventLog.dll + + + ..\..\packages\Microsoft.Extensions.Options.2.1.1\lib\netstandard2.0\Microsoft.Extensions.Options.dll + + + ..\..\packages\Microsoft.Extensions.Primitives.2.1.1\lib\netstandard2.0\Microsoft.Extensions.Primitives.dll + ..\..\packages\MSTest.TestFramework.1.2.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll @@ -51,12 +78,42 @@ ..\..\packages\Moq.4.8.2\lib\net45\Moq.dll + + ..\..\packages\System.Buffers.4.4.0\lib\netstandard2.0\System.Buffers.dll + + + + + ..\..\packages\System.Diagnostics.EventLog.4.5.0\lib\net461\System.Diagnostics.EventLog.dll + + + + ..\..\packages\System.Memory.4.5.1\lib\netstandard2.0\System.Memory.dll + + + + + ..\..\packages\System.Numerics.Vectors.4.4.0\lib\net46\System.Numerics.Vectors.dll + + + ..\..\packages\System.Runtime.CompilerServices.Unsafe.4.5.1\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll + + + ..\..\packages\System.Security.AccessControl.4.5.0\lib\net461\System.Security.AccessControl.dll + + + ..\..\packages\System.Security.Permissions.4.5.0\lib\net461\System.Security.Permissions.dll + + + ..\..\packages\System.Security.Principal.Windows.4.5.0\lib\net461\System.Security.Principal.Windows.dll + ..\..\packages\System.Threading.Tasks.Extensions.4.3.0\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll + ..\..\packages\System.ValueTuple.4.4.0\lib\net47\System.ValueTuple.dll True diff --git a/tests/Tgstation.Server.Host.Service.Tests/packages.config b/tests/Tgstation.Server.Host.Service.Tests/packages.config index c4f8ed9897..8a479af186 100644 --- a/tests/Tgstation.Server.Host.Service.Tests/packages.config +++ b/tests/Tgstation.Server.Host.Service.Tests/packages.config @@ -1,9 +1,26 @@  + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/Tgstation.Server.Host.Tests/Security/TestAuthenticationContext.cs b/tests/Tgstation.Server.Host.Tests/Security/TestAuthenticationContext.cs index 980faf020a..aa125813de 100644 --- a/tests/Tgstation.Server.Host.Tests/Security/TestAuthenticationContext.cs +++ b/tests/Tgstation.Server.Host.Tests/Security/TestAuthenticationContext.cs @@ -45,9 +45,7 @@ namespace Tgstation.Server.Host.Security.Tests user.AdministrationRights = AdministrationRights.EditUsers; instanceUser.ByondRights = ByondRights.ChangeVersion | ByondRights.ReadInstalled; Assert.AreEqual((int)user.AdministrationRights, authContext.GetRight(RightsType.Administration)); - Assert.AreEqual((int)user.InstanceManagerRights, authContext.GetRight(RightsType.InstanceManager)); Assert.AreEqual((int)instanceUser.ByondRights, authContext.GetRight(RightsType.Byond)); - Assert.AreEqual((int)instanceUser.RepositoryRights, authContext.GetRight(RightsType.Repository)); } } } diff --git a/tests/Tgstation.Server.Host.Watchdog.Tests/TestWatchdog.cs b/tests/Tgstation.Server.Host.Watchdog.Tests/TestWatchdog.cs index 5d74371f08..56ec75351a 100644 --- a/tests/Tgstation.Server.Host.Watchdog.Tests/TestWatchdog.cs +++ b/tests/Tgstation.Server.Host.Watchdog.Tests/TestWatchdog.cs @@ -1,4 +1,5 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.Extensions.Logging; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using System; using System.Threading; @@ -13,13 +14,15 @@ namespace Tgstation.Server.Host.Watchdog.Tests [TestMethod] public void TestConstruction() { - Assert.ThrowsException(() => new Watchdog(null, null, null)); + Assert.ThrowsException(() => new Watchdog(null, null, null, null)); var mockServerFactory = new Mock(); - Assert.ThrowsException(() => new Watchdog(mockServerFactory.Object, null, null)); + Assert.ThrowsException(() => new Watchdog(mockServerFactory.Object, null, null, null)); var mockActiveAssemblyDeleter = new Mock(); - Assert.ThrowsException(() => new Watchdog(mockServerFactory.Object, mockActiveAssemblyDeleter.Object, null)); + Assert.ThrowsException(() => new Watchdog(mockServerFactory.Object, mockActiveAssemblyDeleter.Object, null, null)); var mockIsolatedServerContextFactory = new Mock(); - var wd = new Watchdog(mockServerFactory.Object, mockActiveAssemblyDeleter.Object, mockIsolatedServerContextFactory.Object); + Assert.ThrowsException(() => new Watchdog(mockServerFactory.Object, mockActiveAssemblyDeleter.Object, mockIsolatedServerContextFactory.Object, null)); + var mockLogger = new LoggerFactory().CreateLogger(); + var wd = new Watchdog(mockServerFactory.Object, mockActiveAssemblyDeleter.Object, mockIsolatedServerContextFactory.Object, mockLogger); } class MockServerFactory : IServerFactory @@ -36,8 +39,9 @@ namespace Tgstation.Server.Host.Watchdog.Tests var mockServerFactory = new MockServerFactory(mockServer.Object); var mockActiveAssemblyDeleter = new Mock(); var mockIsolatedServerContextFactory = new Mock(); + var mockLogger = new LoggerFactory().CreateLogger(); - var wd = new Watchdog(mockServerFactory, mockActiveAssemblyDeleter.Object, mockIsolatedServerContextFactory.Object); + var wd = new Watchdog(mockServerFactory, mockActiveAssemblyDeleter.Object, mockIsolatedServerContextFactory.Object, mockLogger); using (var cts = new CancellationTokenSource()) { @@ -56,8 +60,9 @@ namespace Tgstation.Server.Host.Watchdog.Tests var mockActiveAssemblyDeleter = new Mock(); var mockIsolatedServerContextFactory = new Mock(); mockIsolatedServerContextFactory.Setup(x => x.CreateIsolatedServerFactory(GetType().Assembly.Location)).Returns(mockServerFactory).Verifiable(); + var mockLogger = new LoggerFactory().CreateLogger(); - var wd = new Watchdog(mockServerFactory, mockActiveAssemblyDeleter.Object, mockIsolatedServerContextFactory.Object); + var wd = new Watchdog(mockServerFactory, mockActiveAssemblyDeleter.Object, mockIsolatedServerContextFactory.Object, mockLogger); using (var cts = new CancellationTokenSource()) { diff --git a/tests/Tgstation.Server.Host.Watchdog.Tests/TestWatchdogFactory.cs b/tests/Tgstation.Server.Host.Watchdog.Tests/TestWatchdogFactory.cs index e043a0a838..18fb82abc4 100644 --- a/tests/Tgstation.Server.Host.Watchdog.Tests/TestWatchdogFactory.cs +++ b/tests/Tgstation.Server.Host.Watchdog.Tests/TestWatchdogFactory.cs @@ -1,4 +1,5 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.Extensions.Logging; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; namespace Tgstation.Server.Host.Watchdog.Tests @@ -13,7 +14,7 @@ namespace Tgstation.Server.Host.Watchdog.Tests public void TestCreateWatchdog() { var factory = new WatchdogFactory(); - Assert.IsNotNull(factory.CreateWatchdog()); + Assert.IsNotNull(factory.CreateWatchdog(new LoggerFactory())); } } }