More user stuff, other fixes

This commit is contained in:
Cyberboss
2018-07-20 16:43:48 -04:00
parent 1701f318e5
commit 1af9644d73
17 changed files with 190 additions and 52 deletions
@@ -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
/// <summary>
/// The <see cref="Rights.ByondRights"/> of the <see cref="InstanceUser"/>
/// </summary>
public ByondRights ByondRights { get; set; }
[Required]
public ByondRights? ByondRights { get; set; }
/// <summary>
/// The <see cref="Rights.DreamDaemonRights"/> of the <see cref="InstanceUser"/>
/// </summary>
public DreamDaemonRights DreamDaemonRights { get; set; }
[Required]
public DreamDaemonRights? DreamDaemonRights { get; set; }
/// <summary>
/// The <see cref="Rights.DreamMakerRights"/> of the <see cref="InstanceUser"/>
/// </summary>
public DreamMakerRights DreamMakerRights { get; set; }
[Required]
public DreamMakerRights? DreamMakerRights { get; set; }
/// <summary>
/// The <see cref="Rights.RepositoryRights"/> of the <see cref="InstanceUser"/>
/// </summary>
public RepositoryRights RepositoryRights { get; set; }
[Required]
public RepositoryRights? RepositoryRights { get; set; }
/// <summary>
/// The <see cref="Rights.ChatSettingsRights"/> of the <see cref="InstanceUser"/>
/// </summary>
public ChatSettingsRights ChatSettingsRights { get; set; }
[Required]
public ChatSettingsRights? ChatSettingsRights { get; set; }
/// <summary>
/// The <see cref="Rights.ConfigurationRights"/> of the <see cref="InstanceUser"/>
/// </summary>
public ConfigurationRights ConfigurationRights { get; set; }
[Required]
public ConfigurationRights? ConfigurationRights { get; set; }
}
}
@@ -7,7 +7,7 @@ namespace Tgstation.Server.Api.Models.Internal
/// <summary>
/// Represents a server <see cref="User"/>
/// </summary>
[Model(RightsType.Administration, WriteRight = AdministrationRights.EditUsers, CanCrud = true)]
[Model(RightsType.Administration, WriteRight = Rights.AdministrationRights.EditUsers, CanCrud = true)]
public class User
{
/// <summary>
@@ -19,7 +19,8 @@ namespace Tgstation.Server.Api.Models.Internal
/// <summary>
/// If the <see cref="User"/> is enabled since users cannot be deleted. System users cannot be disabled
/// </summary>
public bool Enabled { get; set; }
[Required]
public bool? Enabled { get; set; }
/// <summary>
/// When the <see cref="User"/> was created
@@ -37,20 +38,19 @@ namespace Tgstation.Server.Api.Models.Internal
/// <summary>
/// The name of the <see cref="User"/>
/// </summary>
[Permissions(WriteRight = AdministrationRights.EditUsers)]
[Required]
public string Name { get; set; }
/// <summary>
/// The <see cref="Rights.AdministrationRights"/> for the <see cref="User"/>
/// </summary>
[Permissions(WriteRight = AdministrationRights.EditUsers)]
public AdministrationRights AdministrationRights { get; set; }
[Required]
public AdministrationRights? AdministrationRights { get; set; }
/// <summary>
/// The <see cref="Rights.InstanceManagerRights"/> for the <see cref="User"/>
/// </summary>
[Permissions(WriteRight = AdministrationRights.EditUsers)]
public InstanceManagerRights InstanceManagerRights { get; set; }
[Required]
public InstanceManagerRights? InstanceManagerRights { get; set; }
}
}
@@ -1,6 +1,4 @@
using Tgstation.Server.Api.Rights;
namespace Tgstation.Server.Api.Models
namespace Tgstation.Server.Api.Models
{
/// <summary>
/// For editing a given <see cref="User"/>. Will never be returned by the API
@@ -10,7 +8,6 @@ namespace Tgstation.Server.Api.Models
/// <summary>
/// Cleartext password of the <see cref="User"/>
/// </summary>
[Permissions(WriteRight = AdministrationRights.EditUsers)]
public string Password { get; set; }
}
}
@@ -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
{
/// <inheritdoc />
[ExcludeFromCodeCoverage]
public IWatchdog CreateWatchdog(ILoggerFactory loggerFactory) => new Watchdog(new ServerFactory(), RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? (IActiveAssemblyDeleter)new WindowsActiveAssemblyDeleter() : new PosixActiveAssemblyDeleter(), new IsolatedAssemblyContextFactory(), loggerFactory.CreateLogger<Watchdog>());
public IWatchdog CreateWatchdog(ILoggerFactory loggerFactory) => new Watchdog(new ServerFactory(), RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? (IActiveAssemblyDeleter)new WindowsActiveAssemblyDeleter() : new PosixActiveAssemblyDeleter(), new IsolatedAssemblyContextFactory(), loggerFactory?.CreateLogger<Watchdog>() ?? throw new ArgumentNullException(nameof(loggerFactory)));
}
}
@@ -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
{
@@ -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));
@@ -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<UsersController> 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));
}
/// <inheritdoc />
@@ -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());
}
/// <inheritdoc />
[TgsAuthorize(AdministrationRights.EditUsers)]
public override async Task<IActionResult> 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());
}
}
}
@@ -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<InstanceUser>().HasIndex(x => new { x.UserId, x.Instance }).IsUnique();
var chatChannel = modelBuilder.Entity<ChatChannel>();
chatChannel.HasIndex(x => new { x.ChatSettingsId, x.IrcChannel }).IsUnique();
chatChannel.HasIndex(x => new { x.ChatSettingsId, x.DiscordChannelId }).IsUnique();
@@ -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
/// <summary>
/// If the <see cref="InstanceUser"/> has any instance rights
/// </summary>
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;
}
}
@@ -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<object>());
if (right == null)
throw new InvalidOperationException("A user right was null!");
return (int)right;
}
}
@@ -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<IWatchdog>();
mockServer.Setup(x => x.RunAsync(null, It.IsAny<CancellationToken>())).Returns(Task.CompletedTask).Verifiable();
var args = Array.Empty<string>();
mockServer.Setup(x => x.RunAsync(args, It.IsAny<CancellationToken>())).Returns(Task.CompletedTask).Verifiable();
var mockServerFactory = new Mock<IWatchdogFactory>();
mockServerFactory.Setup(x => x.CreateWatchdog()).Returns(mockServer.Object).Verifiable();
mockServerFactory.Setup(x => x.CreateWatchdog(It.IsAny<ILoggerFactory>())).Returns(mockServer.Object).Verifiable();
Program.WatchdogFactory = mockServerFactory.Object;
await Program.Main(null).ConfigureAwait(false);
await Program.Main(args).ConfigureAwait(false);
mockServer.VerifyAll();
mockServerFactory.VerifyAll();
}
@@ -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<ArgumentNullException>(() => new ServerService(null));
Assert.ThrowsException<ArgumentNullException>(() => new ServerService(null, null));
var mockWatchdogFactory = new Mock<IWatchdogFactory>();
new ServerService(mockWatchdogFactory.Object).Dispose();
Assert.ThrowsException<ArgumentNullException>(() => 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<CancellationToken>())).Callback((string[] _, CancellationToken token) => cancellationToken = token).Returns(Task.CompletedTask).Verifiable();
var mockWatchdogFactory = new Mock<IWatchdogFactory>();
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 });
@@ -41,6 +41,33 @@
<Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\..\packages\Castle.Core.4.2.1\lib\net45\Castle.Core.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Configuration, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.Configuration.2.1.1\lib\netstandard2.0\Microsoft.Extensions.Configuration.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Configuration.Abstractions, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.Configuration.Abstractions.2.1.1\lib\netstandard2.0\Microsoft.Extensions.Configuration.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Configuration.Binder, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.Configuration.Binder.2.1.1\lib\netstandard2.0\Microsoft.Extensions.Configuration.Binder.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.2.1.1\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Logging, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.Logging.2.1.1\lib\netstandard2.0\Microsoft.Extensions.Logging.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Logging.Abstractions, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.Logging.Abstractions.2.1.1\lib\netstandard2.0\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Logging.EventLog, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.Logging.EventLog.2.1.1\lib\net461\Microsoft.Extensions.Logging.EventLog.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Options, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.Options.2.1.1\lib\netstandard2.0\Microsoft.Extensions.Options.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Primitives, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Extensions.Primitives.2.1.1\lib\netstandard2.0\Microsoft.Extensions.Primitives.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\MSTest.TestFramework.1.2.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
@@ -51,12 +78,42 @@
<HintPath>..\..\packages\Moq.4.8.2\lib\net45\Moq.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Buffers.4.4.0\lib\netstandard2.0\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Data.OracleClient" />
<Reference Include="System.Diagnostics.EventLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Diagnostics.EventLog.4.5.0\lib\net461\System.Diagnostics.EventLog.dll</HintPath>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.Memory, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Memory.4.5.1\lib\netstandard2.0\System.Memory.dll</HintPath>
</Reference>
<Reference Include="System.Net" />
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Numerics.Vectors.4.4.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Runtime.CompilerServices.Unsafe.4.5.1\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Security.AccessControl, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Security.AccessControl.4.5.0\lib\net461\System.Security.AccessControl.dll</HintPath>
</Reference>
<Reference Include="System.Security.Permissions, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Security.Permissions.4.5.0\lib\net461\System.Security.Permissions.dll</HintPath>
</Reference>
<Reference Include="System.Security.Principal.Windows, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Security.Principal.Windows.4.5.0\lib\net461\System.Security.Principal.Windows.dll</HintPath>
</Reference>
<Reference Include="System.ServiceProcess" />
<Reference Include="System.Threading.Tasks.Extensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Threading.Tasks.Extensions.4.3.0\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.Transactions" />
<Reference Include="System.ValueTuple">
<HintPath>..\..\packages\System.ValueTuple.4.4.0\lib\net47\System.ValueTuple.dll</HintPath>
<Private>True</Private>
@@ -1,9 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Castle.Core" version="4.2.1" targetFramework="net471" />
<package id="Microsoft.Extensions.Configuration" version="2.1.1" targetFramework="net471" />
<package id="Microsoft.Extensions.Configuration.Abstractions" version="2.1.1" targetFramework="net471" />
<package id="Microsoft.Extensions.Configuration.Binder" version="2.1.1" targetFramework="net471" />
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="2.1.1" targetFramework="net471" />
<package id="Microsoft.Extensions.Logging" version="2.1.1" targetFramework="net471" />
<package id="Microsoft.Extensions.Logging.Abstractions" version="2.1.1" targetFramework="net471" />
<package id="Microsoft.Extensions.Logging.EventLog" version="2.1.1" targetFramework="net471" />
<package id="Microsoft.Extensions.Options" version="2.1.1" targetFramework="net471" />
<package id="Microsoft.Extensions.Primitives" version="2.1.1" targetFramework="net471" />
<package id="Moq" version="4.8.2" targetFramework="net471" />
<package id="MSTest.TestAdapter" version="1.2.1" targetFramework="net471" />
<package id="MSTest.TestFramework" version="1.2.1" targetFramework="net471" />
<package id="System.Buffers" version="4.4.0" targetFramework="net471" />
<package id="System.Diagnostics.EventLog" version="4.5.0" targetFramework="net471" />
<package id="System.Memory" version="4.5.1" targetFramework="net471" />
<package id="System.Numerics.Vectors" version="4.4.0" targetFramework="net471" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.1" targetFramework="net471" />
<package id="System.Security.AccessControl" version="4.5.0" targetFramework="net471" />
<package id="System.Security.Permissions" version="4.5.0" targetFramework="net471" />
<package id="System.Security.Principal.Windows" version="4.5.0" targetFramework="net471" />
<package id="System.Threading.Tasks.Extensions" version="4.3.0" targetFramework="net471" />
<package id="System.ValueTuple" version="4.4.0" targetFramework="net471" />
</packages>
@@ -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));
}
}
}
@@ -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<ArgumentNullException>(() => new Watchdog(null, null, null));
Assert.ThrowsException<ArgumentNullException>(() => new Watchdog(null, null, null, null));
var mockServerFactory = new Mock<IServerFactory>();
Assert.ThrowsException<ArgumentNullException>(() => new Watchdog(mockServerFactory.Object, null, null));
Assert.ThrowsException<ArgumentNullException>(() => new Watchdog(mockServerFactory.Object, null, null, null));
var mockActiveAssemblyDeleter = new Mock<IActiveAssemblyDeleter>();
Assert.ThrowsException<ArgumentNullException>(() => new Watchdog(mockServerFactory.Object, mockActiveAssemblyDeleter.Object, null));
Assert.ThrowsException<ArgumentNullException>(() => new Watchdog(mockServerFactory.Object, mockActiveAssemblyDeleter.Object, null, null));
var mockIsolatedServerContextFactory = new Mock<IIsolatedAssemblyContextFactory>();
var wd = new Watchdog(mockServerFactory.Object, mockActiveAssemblyDeleter.Object, mockIsolatedServerContextFactory.Object);
Assert.ThrowsException<ArgumentNullException>(() => new Watchdog(mockServerFactory.Object, mockActiveAssemblyDeleter.Object, mockIsolatedServerContextFactory.Object, null));
var mockLogger = new LoggerFactory().CreateLogger<Watchdog>();
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<IActiveAssemblyDeleter>();
var mockIsolatedServerContextFactory = new Mock<IIsolatedAssemblyContextFactory>();
var mockLogger = new LoggerFactory().CreateLogger<Watchdog>();
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<IActiveAssemblyDeleter>();
var mockIsolatedServerContextFactory = new Mock<IIsolatedAssemblyContextFactory>();
mockIsolatedServerContextFactory.Setup(x => x.CreateIsolatedServerFactory(GetType().Assembly.Location)).Returns(mockServerFactory).Verifiable();
var mockLogger = new LoggerFactory().CreateLogger<Watchdog>();
var wd = new Watchdog(mockServerFactory, mockActiveAssemblyDeleter.Object, mockIsolatedServerContextFactory.Object);
var wd = new Watchdog(mockServerFactory, mockActiveAssemblyDeleter.Object, mockIsolatedServerContextFactory.Object, mockLogger);
using (var cts = new CancellationTokenSource())
{
@@ -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()));
}
}
}