From a013a1faf005b067c07c0ba09ca1d1208bb847ff Mon Sep 17 00:00:00 2001 From: RaidMax Date: Wed, 17 Jun 2020 15:20:07 -0500 Subject: [PATCH] prevent ability to kick users of same rank --- SharedLibraryCore/PartialEntities/EFClient.cs | 4 +- Tests/ApplicationTests/ClientTests.cs | 70 +++++++++++++++++++ 2 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 Tests/ApplicationTests/ClientTests.cs diff --git a/SharedLibraryCore/PartialEntities/EFClient.cs b/SharedLibraryCore/PartialEntities/EFClient.cs index e9a87cfe3..c39656a82 100644 --- a/SharedLibraryCore/PartialEntities/EFClient.cs +++ b/SharedLibraryCore/PartialEntities/EFClient.cs @@ -317,7 +317,7 @@ namespace SharedLibraryCore.Database.Models /// /// reason to kick for /// client performing the kick - public GameEvent Kick(String kickReason, EFClient sender) + public GameEvent Kick(string kickReason, EFClient sender) { var e = new GameEvent() { @@ -330,7 +330,7 @@ namespace SharedLibraryCore.Database.Models }; // enforce level restrictions - if (Level > sender.Level) + if (sender.Level <= Level) { e.FailReason = GameEvent.EventFailReason.Permission; } diff --git a/Tests/ApplicationTests/ClientTests.cs b/Tests/ApplicationTests/ClientTests.cs new file mode 100644 index 000000000..4a2949680 --- /dev/null +++ b/Tests/ApplicationTests/ClientTests.cs @@ -0,0 +1,70 @@ +using ApplicationTests.Fixtures; +using FakeItEasy; +using IW4MAdmin; +using Microsoft.Extensions.DependencyInjection; +using NUnit.Framework; +using SharedLibraryCore; +using SharedLibraryCore.Database.Models; +using System; +using System.Collections.Generic; +using System.Text; + +namespace ApplicationTests +{ + [TestFixture] + public class ClientTests + { + private IServiceProvider serviceProvider; + + [SetUp] + public void Setup() + { + serviceProvider = new ServiceCollection() + .BuildBase() + .BuildServiceProvider(); + } + + #region KICK + [Test] + public void Test_Kick_Happy() + { + var server = serviceProvider.GetRequiredService(); + var target = ClientGenerators.CreateBasicClient(server); + var origin = ClientGenerators.CreateBasicClient(server); + origin.Level = EFClient.Permission.Owner; + + var result = target.Kick("test", origin); + + Assert.False(result.Failed); + Assert.AreEqual(EFClient.ClientState.Disconnecting, target.State); + } + + [Test] + public void Test_Kick_FailSamePermission() + { + var server = serviceProvider.GetRequiredService(); + var target = ClientGenerators.CreateBasicClient(server); + var origin = ClientGenerators.CreateBasicClient(server); + + var result = target.Kick("test", origin); + + Assert.True(result.Failed); + Assert.AreEqual(GameEvent.EventFailReason.Permission, result.FailReason); + } + + [Test] + public void Test_Kick_FailLessPermission() + { + var server = serviceProvider.GetRequiredService(); + var target = ClientGenerators.CreateBasicClient(server); + var origin = ClientGenerators.CreateBasicClient(server); + target.Level = EFClient.Permission.Owner; + + var result = target.Kick("test", origin); + + Assert.True(result.Failed); + Assert.AreEqual(GameEvent.EventFailReason.Permission, result.FailReason); + } + #endregion + } +}