prevent ability to kick users of same rank

This commit is contained in:
RaidMax 2020-06-17 15:20:07 -05:00
parent bb4e51d9c8
commit a013a1faf0
2 changed files with 72 additions and 2 deletions

View File

@ -317,7 +317,7 @@ namespace SharedLibraryCore.Database.Models
/// </summary> /// </summary>
/// <param name="kickReason">reason to kick for</param> /// <param name="kickReason">reason to kick for</param>
/// <param name="sender">client performing the kick</param> /// <param name="sender">client performing the kick</param>
public GameEvent Kick(String kickReason, EFClient sender) public GameEvent Kick(string kickReason, EFClient sender)
{ {
var e = new GameEvent() var e = new GameEvent()
{ {
@ -330,7 +330,7 @@ namespace SharedLibraryCore.Database.Models
}; };
// enforce level restrictions // enforce level restrictions
if (Level > sender.Level) if (sender.Level <= Level)
{ {
e.FailReason = GameEvent.EventFailReason.Permission; e.FailReason = GameEvent.EventFailReason.Permission;
} }

View File

@ -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<IW4MServer>();
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<IW4MServer>();
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<IW4MServer>();
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
}
}