prevent ability to kick users of same rank
This commit is contained in:
parent
bb4e51d9c8
commit
a013a1faf0
@ -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;
|
||||||
}
|
}
|
||||||
|
70
Tests/ApplicationTests/ClientTests.cs
Normal file
70
Tests/ApplicationTests/ClientTests.cs
Normal 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
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user