2020-04-13 17:16:31 -04:00
|
|
|
|
using IW4MAdmin;
|
2020-04-14 16:46:14 -04:00
|
|
|
|
using IW4MAdmin.Application.Misc;
|
2020-04-21 18:34:00 -04:00
|
|
|
|
using SharedLibraryCore.Interfaces;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2020-04-13 17:16:31 -04:00
|
|
|
|
using NUnit.Framework;
|
2020-04-21 18:34:00 -04:00
|
|
|
|
using FakeItEasy;
|
|
|
|
|
using System;
|
|
|
|
|
using ApplicationTests.Fixtures;
|
|
|
|
|
using SharedLibraryCore.Services;
|
|
|
|
|
using SharedLibraryCore.Database.Models;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using ApplicationTests.Mocks;
|
|
|
|
|
using System.Linq;
|
2020-04-22 19:46:41 -04:00
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
using SharedLibraryCore.Exceptions;
|
|
|
|
|
using SharedLibraryCore.Configuration;
|
2020-04-13 17:16:31 -04:00
|
|
|
|
|
|
|
|
|
namespace ApplicationTests
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class IW4MServerTests
|
|
|
|
|
{
|
2020-04-21 18:34:00 -04:00
|
|
|
|
private IServiceProvider serviceProvider;
|
|
|
|
|
private ILogger fakeLogger;
|
|
|
|
|
private IManager fakeManager;
|
|
|
|
|
private IRConConnection fakeRConConnection;
|
|
|
|
|
private IRConParser fakeRConParser;
|
|
|
|
|
private MockEventHandler mockEventHandler;
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
2020-04-22 19:46:41 -04:00
|
|
|
|
serviceProvider = new ServiceCollection().BuildBase().BuildServiceProvider();
|
|
|
|
|
|
|
|
|
|
fakeLogger = serviceProvider.GetRequiredService<ILogger>();
|
|
|
|
|
fakeManager = serviceProvider.GetRequiredService<IManager>();
|
|
|
|
|
fakeRConConnection = serviceProvider.GetRequiredService<IRConConnection>();
|
|
|
|
|
fakeRConParser = serviceProvider.GetRequiredService<IRConParser>();
|
|
|
|
|
|
|
|
|
|
var rconConnectionFactory = serviceProvider.GetRequiredService<IRConConnectionFactory>();
|
|
|
|
|
|
2020-04-21 18:34:00 -04:00
|
|
|
|
A.CallTo(() => rconConnectionFactory.CreateConnection(A<string>.Ignored, A<int>.Ignored, A<string>.Ignored))
|
|
|
|
|
.Returns(fakeRConConnection);
|
2020-04-22 19:46:41 -04:00
|
|
|
|
|
2020-04-21 18:34:00 -04:00
|
|
|
|
A.CallTo(() => fakeRConParser.Configuration)
|
2020-04-22 19:46:41 -04:00
|
|
|
|
.Returns(ConfigurationGenerators.CreateRConParserConfiguration(serviceProvider.GetRequiredService<IParserRegexFactory>()));
|
|
|
|
|
|
2020-04-21 18:34:00 -04:00
|
|
|
|
|
|
|
|
|
mockEventHandler = new MockEventHandler();
|
|
|
|
|
A.CallTo(() => fakeManager.GetEventHandler())
|
|
|
|
|
.Returns(mockEventHandler);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-22 19:46:41 -04:00
|
|
|
|
#region LOG
|
2020-04-13 17:16:31 -04:00
|
|
|
|
[Test]
|
|
|
|
|
public void Test_GenerateLogPath_Basic()
|
|
|
|
|
{
|
|
|
|
|
string expected = "C:\\Game\\main\\log.log";
|
2020-04-14 16:46:14 -04:00
|
|
|
|
var info = new LogPathGeneratorInfo()
|
|
|
|
|
{
|
|
|
|
|
BasePathDirectory = "C:\\Game",
|
|
|
|
|
GameDirectory = "main",
|
|
|
|
|
LogFile = "log.log"
|
|
|
|
|
};
|
|
|
|
|
string generated = IW4MServer.GenerateLogPath(info);
|
2020-04-13 17:16:31 -04:00
|
|
|
|
|
|
|
|
|
Assert.AreEqual(expected, generated);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Test_GenerateLogPath_WithMod()
|
|
|
|
|
{
|
|
|
|
|
string expected = "C:\\Game\\mods\\mod\\log.log";
|
2020-04-14 16:46:14 -04:00
|
|
|
|
var info = new LogPathGeneratorInfo()
|
|
|
|
|
{
|
|
|
|
|
BasePathDirectory = "C:\\Game",
|
|
|
|
|
GameDirectory = "main",
|
|
|
|
|
ModDirectory = "mods\\mod",
|
|
|
|
|
LogFile = "log.log"
|
|
|
|
|
};
|
|
|
|
|
string generated = IW4MServer.GenerateLogPath(info);
|
2020-04-13 17:16:31 -04:00
|
|
|
|
|
|
|
|
|
Assert.AreEqual(expected, generated);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2020-04-14 16:46:14 -04:00
|
|
|
|
public void Test_GenerateLogPath_WithBaseGame()
|
2020-04-13 17:16:31 -04:00
|
|
|
|
{
|
|
|
|
|
string expected = "C:\\GameAlt\\main\\log.log";
|
2020-04-14 16:46:14 -04:00
|
|
|
|
var info = new LogPathGeneratorInfo()
|
|
|
|
|
{
|
|
|
|
|
BaseGameDirectory = "C:\\GameAlt",
|
|
|
|
|
BasePathDirectory = "C:\\Game",
|
|
|
|
|
GameDirectory = "main",
|
|
|
|
|
LogFile = "log.log"
|
|
|
|
|
};
|
|
|
|
|
string generated = IW4MServer.GenerateLogPath(info);
|
2020-04-13 17:16:31 -04:00
|
|
|
|
|
|
|
|
|
Assert.AreEqual(expected, generated);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2020-04-14 16:46:14 -04:00
|
|
|
|
public void Test_GenerateLogPath_WithBaseGameAndMod()
|
2020-04-13 17:16:31 -04:00
|
|
|
|
{
|
|
|
|
|
string expected = "C:\\GameAlt\\mods\\mod\\log.log";
|
2020-04-14 16:46:14 -04:00
|
|
|
|
var info = new LogPathGeneratorInfo()
|
|
|
|
|
{
|
|
|
|
|
BaseGameDirectory = "C:\\GameAlt",
|
|
|
|
|
BasePathDirectory = "C:\\Game",
|
|
|
|
|
GameDirectory = "main",
|
|
|
|
|
ModDirectory = "mods\\mod",
|
|
|
|
|
LogFile = "log.log"
|
|
|
|
|
};
|
|
|
|
|
string generated = IW4MServer.GenerateLogPath(info);
|
2020-04-13 17:16:31 -04:00
|
|
|
|
|
|
|
|
|
Assert.AreEqual(expected, generated);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Test_GenerateLogPath_InvalidBasePath()
|
|
|
|
|
{
|
|
|
|
|
string expected = "C:\\Game\\main\\log.log";
|
2020-04-14 16:46:14 -04:00
|
|
|
|
var info = new LogPathGeneratorInfo()
|
|
|
|
|
{
|
|
|
|
|
BaseGameDirectory = "game",
|
|
|
|
|
BasePathDirectory = "C:\\Game",
|
|
|
|
|
GameDirectory = "main",
|
|
|
|
|
LogFile = "log.log"
|
|
|
|
|
};
|
|
|
|
|
string generated = IW4MServer.GenerateLogPath(info);
|
2020-04-13 17:16:31 -04:00
|
|
|
|
|
|
|
|
|
Assert.AreEqual(expected, generated);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Test_GenerateLogPath_BadSeparators()
|
|
|
|
|
{
|
|
|
|
|
string expected = "C:\\Game\\main\\folder\\log.log";
|
2020-04-14 16:46:14 -04:00
|
|
|
|
var info = new LogPathGeneratorInfo()
|
|
|
|
|
{
|
|
|
|
|
BasePathDirectory = "C:/Game",
|
|
|
|
|
GameDirectory = "main/folder",
|
|
|
|
|
LogFile = "log.log"
|
|
|
|
|
};
|
|
|
|
|
string generated = IW4MServer.GenerateLogPath(info);
|
2020-04-13 17:16:31 -04:00
|
|
|
|
|
|
|
|
|
Assert.AreEqual(expected, generated);
|
|
|
|
|
}
|
2020-04-13 19:15:46 -04:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Test_GenerateLogPath_RelativeBasePath()
|
|
|
|
|
{
|
|
|
|
|
string expected = "C:\\Game\\main\\folder\\log.log";
|
2020-04-14 16:46:14 -04:00
|
|
|
|
var info = new LogPathGeneratorInfo()
|
|
|
|
|
{
|
|
|
|
|
BaseGameDirectory = "main\\folder",
|
|
|
|
|
BasePathDirectory = "C:\\Game",
|
|
|
|
|
GameDirectory = "main\\folder",
|
|
|
|
|
LogFile = "log.log"
|
|
|
|
|
};
|
|
|
|
|
string generated = IW4MServer.GenerateLogPath(info);
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(expected, generated);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Test_GenerateLogPath_FixWineDriveMangling()
|
|
|
|
|
{
|
|
|
|
|
string expected = "/opt/server/game/log.log";
|
|
|
|
|
var info = new LogPathGeneratorInfo()
|
|
|
|
|
{
|
|
|
|
|
BasePathDirectory = "Z:\\opt\\server",
|
|
|
|
|
GameDirectory = "game",
|
|
|
|
|
LogFile = "log.log",
|
|
|
|
|
IsWindows = false
|
|
|
|
|
};
|
|
|
|
|
string generated = IW4MServer.GenerateLogPath(info).Replace('\\', '/');
|
2020-04-13 19:15:46 -04:00
|
|
|
|
|
|
|
|
|
Assert.AreEqual(expected, generated);
|
|
|
|
|
}
|
2020-04-22 19:46:41 -04:00
|
|
|
|
#endregion
|
2020-04-21 18:34:00 -04:00
|
|
|
|
|
|
|
|
|
#region BAN
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_BanCreatesPenalty()
|
|
|
|
|
{
|
|
|
|
|
var fakePenaltyService = A.Fake<PenaltyService>();
|
|
|
|
|
A.CallTo(() => fakeManager.GetPenaltyService())
|
|
|
|
|
.Returns(fakePenaltyService);
|
|
|
|
|
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var target = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
var origin = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
|
|
|
|
|
await server.Ban("test reason", target, origin);
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => fakePenaltyService.Create(A<EFPenalty>.Ignored))
|
|
|
|
|
.MustHaveHappenedOnceExactly();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_BanExecutesKickCommand()
|
|
|
|
|
{
|
|
|
|
|
var fakePenaltyService = A.Fake<PenaltyService>();
|
|
|
|
|
A.CallTo(() => fakeManager.GetPenaltyService())
|
|
|
|
|
.Returns(fakePenaltyService);
|
|
|
|
|
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var target = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
var origin = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
|
|
|
|
|
await server.Ban("test reason", target, origin);
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => fakeRConParser.ExecuteCommandAsync(fakeRConConnection, "kick"))
|
|
|
|
|
.MustHaveHappenedOnceExactly();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_BanQueuesSetLevelEvent()
|
|
|
|
|
{
|
|
|
|
|
var fakePenaltyService = A.Fake<PenaltyService>();
|
|
|
|
|
A.CallTo(() => fakeManager.GetPenaltyService())
|
|
|
|
|
.Returns(fakePenaltyService);
|
|
|
|
|
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var target = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
var origin = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
|
|
|
|
|
await server.Ban("test reason", target, origin);
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(mockEventHandler.Events.Any(_event => _event.Type == SharedLibraryCore.GameEvent.EventType.ChangePermission &&
|
|
|
|
|
_event.Origin == origin &&
|
|
|
|
|
_event.Target == target &&
|
|
|
|
|
(EFClient.Permission)_event.Extra == EFClient.Permission.Banned));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_BanFindsIngameClientToExecuteFor()
|
|
|
|
|
{
|
|
|
|
|
var fakePenaltyService = A.Fake<PenaltyService>();
|
|
|
|
|
A.CallTo(() => fakeManager.GetPenaltyService())
|
|
|
|
|
.Returns(fakePenaltyService);
|
|
|
|
|
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var origin = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
var target = ClientGenerators.CreateBasicClient(server, isIngame: false);
|
|
|
|
|
var ingameTarget = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => fakeManager.GetActiveClients())
|
|
|
|
|
.Returns(new[] { ingameTarget });
|
|
|
|
|
|
|
|
|
|
await server.Ban("test reason", target, origin);
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(mockEventHandler.Events.Any(_event => _event.Target == ingameTarget));
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region TEMPBAN
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_TempBanCreatesPenalty()
|
|
|
|
|
{
|
|
|
|
|
var fakePenaltyService = A.Fake<PenaltyService>();
|
|
|
|
|
A.CallTo(() => fakeManager.GetPenaltyService())
|
|
|
|
|
.Returns(fakePenaltyService);
|
|
|
|
|
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var target = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
var origin = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
|
|
|
|
|
await server.TempBan("test reason", TimeSpan.Zero, target, origin);
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => fakePenaltyService.Create(A<EFPenalty>.Ignored))
|
|
|
|
|
.MustHaveHappenedOnceExactly();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_TempBanExecutesKickCommand()
|
|
|
|
|
{
|
|
|
|
|
var fakePenaltyService = A.Fake<PenaltyService>();
|
|
|
|
|
A.CallTo(() => fakeManager.GetPenaltyService())
|
|
|
|
|
.Returns(fakePenaltyService);
|
|
|
|
|
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var target = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
var origin = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
|
|
|
|
|
await server.TempBan("test reason", TimeSpan.Zero, target, origin);
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => fakeRConParser.ExecuteCommandAsync(fakeRConConnection, "kick"))
|
|
|
|
|
.MustHaveHappenedOnceExactly();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_TempBanFindsIngameClientToExecuteFor()
|
|
|
|
|
{
|
|
|
|
|
var fakePenaltyService = A.Fake<PenaltyService>();
|
|
|
|
|
A.CallTo(() => fakeManager.GetPenaltyService())
|
|
|
|
|
.Returns(fakePenaltyService);
|
|
|
|
|
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var origin = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
var target = ClientGenerators.CreateBasicClient(server, isIngame: false);
|
|
|
|
|
|
|
|
|
|
var ingameTarget = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => fakeManager.GetActiveClients())
|
|
|
|
|
.Returns(new[] { ingameTarget });
|
|
|
|
|
|
|
|
|
|
await server.TempBan("test reason", TimeSpan.Zero, target, origin);
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => fakeRConParser.ExecuteCommandAsync(fakeRConConnection, "kick"))
|
|
|
|
|
.MustHaveHappenedOnceExactly();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region KICK
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_KickCreatesPenalty()
|
|
|
|
|
{
|
|
|
|
|
var fakePenaltyService = A.Fake<PenaltyService>();
|
|
|
|
|
A.CallTo(() => fakeManager.GetPenaltyService())
|
|
|
|
|
.Returns(fakePenaltyService);
|
|
|
|
|
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var target = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
var origin = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
|
|
|
|
|
await server.Kick("test reason", target, origin);
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => fakePenaltyService.Create(A<EFPenalty>.Ignored))
|
|
|
|
|
.MustHaveHappenedOnceExactly();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_KickExecutesKickCommand()
|
|
|
|
|
{
|
|
|
|
|
var fakePenaltyService = A.Fake<PenaltyService>();
|
|
|
|
|
A.CallTo(() => fakeManager.GetPenaltyService())
|
|
|
|
|
.Returns(fakePenaltyService);
|
|
|
|
|
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var target = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
var origin = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
|
|
|
|
|
await server.Kick("test reason", target, origin);
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => fakeRConParser.ExecuteCommandAsync(fakeRConConnection, "kick"))
|
|
|
|
|
.MustHaveHappenedOnceExactly();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_KickQueuesPredisconnectEvent()
|
|
|
|
|
{
|
|
|
|
|
var fakePenaltyService = A.Fake<PenaltyService>();
|
|
|
|
|
A.CallTo(() => fakeManager.GetPenaltyService())
|
|
|
|
|
.Returns(fakePenaltyService);
|
|
|
|
|
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var target = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
var origin = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
|
|
|
|
|
await server.Kick("test reason", target, origin);
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(mockEventHandler.Events.Any(_event => _event.Type == SharedLibraryCore.GameEvent.EventType.PreDisconnect && _event.Origin == target));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_KickFindsIngameClientToExecuteFor()
|
|
|
|
|
{
|
|
|
|
|
var fakePenaltyService = A.Fake<PenaltyService>();
|
|
|
|
|
A.CallTo(() => fakeManager.GetPenaltyService())
|
|
|
|
|
.Returns(fakePenaltyService);
|
|
|
|
|
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var origin = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
var target = ClientGenerators.CreateBasicClient(server, isIngame: false);
|
|
|
|
|
|
|
|
|
|
var ingameTarget = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => fakeManager.GetActiveClients())
|
|
|
|
|
.Returns(new[] { ingameTarget });
|
|
|
|
|
|
|
|
|
|
await server.Kick("test reason", target, origin);
|
|
|
|
|
|
|
|
|
|
// kick creates a pre disconnect event
|
|
|
|
|
Assert.IsTrue(mockEventHandler.Events.Any(_event => _event.Origin == ingameTarget));
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region WARN
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_WarnCreatesPenalty()
|
|
|
|
|
{
|
|
|
|
|
var fakePenaltyService = A.Fake<PenaltyService>();
|
|
|
|
|
A.CallTo(() => fakeManager.GetPenaltyService())
|
|
|
|
|
.Returns(fakePenaltyService);
|
|
|
|
|
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var target = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
var origin = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
|
|
|
|
|
await server.Warn("test reason", target, origin);
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => fakePenaltyService.Create(A<EFPenalty>.Ignored))
|
|
|
|
|
.MustHaveHappenedOnceExactly();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_WarnBroadCastMessageForIngameClient()
|
|
|
|
|
{
|
|
|
|
|
var fakePenaltyService = A.Fake<PenaltyService>();
|
|
|
|
|
A.CallTo(() => fakeManager.GetPenaltyService())
|
|
|
|
|
.Returns(fakePenaltyService);
|
|
|
|
|
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var target = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
var origin = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
|
|
|
|
|
await server.Warn("test reason", target, origin);
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(mockEventHandler.Events.Any(_event => _event.Type == SharedLibraryCore.GameEvent.EventType.Broadcast));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_WarnLimitReachedQueuesKickEvent()
|
|
|
|
|
{
|
|
|
|
|
var fakePenaltyService = A.Fake<PenaltyService>();
|
|
|
|
|
A.CallTo(() => fakeManager.GetPenaltyService())
|
|
|
|
|
.Returns(fakePenaltyService);
|
|
|
|
|
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var target = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
var origin = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
target.Warnings = 5;
|
|
|
|
|
|
|
|
|
|
await server.Warn("test reason", target, origin);
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(mockEventHandler.Events.Any(_event => _event.Type == SharedLibraryCore.GameEvent.EventType.Kick && _event.Target == target));
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region UNBAN
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_UnbanQueuesSetLevelEvent()
|
|
|
|
|
{
|
|
|
|
|
var fakePenaltyService = A.Fake<PenaltyService>();
|
|
|
|
|
A.CallTo(() => fakeManager.GetPenaltyService())
|
|
|
|
|
.Returns(fakePenaltyService);
|
|
|
|
|
A.CallTo(() => fakePenaltyService.RemoveActivePenalties(A<int>.Ignored))
|
|
|
|
|
.Returns(Task.CompletedTask);
|
|
|
|
|
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var origin = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
var target = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
|
|
|
|
|
target.Level = EFClient.Permission.Banned;
|
|
|
|
|
target.AliasLink = new EFAliasLink();
|
|
|
|
|
|
|
|
|
|
await server.Unban("test reason", target, origin);
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(mockEventHandler.Events.Any(_event => _event.Type == SharedLibraryCore.GameEvent.EventType.ChangePermission && _event.Target == target));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_UnbanRemovedActivePenalties()
|
|
|
|
|
{
|
|
|
|
|
var fakePenaltyService = A.Fake<PenaltyService>();
|
|
|
|
|
A.CallTo(() => fakeManager.GetPenaltyService())
|
|
|
|
|
.Returns(fakePenaltyService);
|
|
|
|
|
A.CallTo(() => fakePenaltyService.RemoveActivePenalties(A<int>.Ignored))
|
|
|
|
|
.Returns(Task.CompletedTask);
|
|
|
|
|
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var origin = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
var target = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
|
|
|
|
|
target.Level = EFClient.Permission.Banned;
|
|
|
|
|
target.AliasLink = new EFAliasLink()
|
|
|
|
|
{
|
|
|
|
|
AliasLinkId = 1
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await server.Unban("test reason", target, origin);
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => fakePenaltyService.RemoveActivePenalties(target.AliasLink.AliasLinkId))
|
|
|
|
|
.MustHaveHappened();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_UnbanCreatesPenalty()
|
|
|
|
|
{
|
|
|
|
|
var fakePenaltyService = A.Fake<PenaltyService>();
|
|
|
|
|
A.CallTo(() => fakeManager.GetPenaltyService())
|
|
|
|
|
.Returns(fakePenaltyService);
|
|
|
|
|
A.CallTo(() => fakePenaltyService.RemoveActivePenalties(A<int>.Ignored))
|
|
|
|
|
.Returns(Task.CompletedTask);
|
|
|
|
|
|
|
|
|
|
var server = serviceProvider.GetRequiredService<IW4MServer>();
|
|
|
|
|
var origin = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
var target = ClientGenerators.CreateBasicClient(server);
|
|
|
|
|
|
|
|
|
|
target.Level = EFClient.Permission.Banned;
|
|
|
|
|
target.AliasLink = new EFAliasLink()
|
|
|
|
|
{
|
|
|
|
|
AliasLinkId = 1
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await server.Unban("test reason", target, origin);
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => fakePenaltyService.Create(A<EFPenalty>.Ignored))
|
|
|
|
|
.MustHaveHappened();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
2020-04-22 19:46:41 -04:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_ConnectionLostNotificationDisabled()
|
|
|
|
|
{
|
|
|
|
|
var server = serviceProvider.GetService<IW4MServer>();
|
|
|
|
|
var fakeConfigHandler = A.Fake<IConfigurationHandler<ApplicationConfiguration>>();
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => fakeManager.GetApplicationSettings())
|
|
|
|
|
.Returns(fakeConfigHandler);
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => fakeConfigHandler.Configuration())
|
|
|
|
|
.Returns(new ApplicationConfiguration() { IgnoreServerConnectionLost = true });
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => fakeRConParser.GetStatusAsync(A<IRConConnection>.Ignored))
|
|
|
|
|
.ThrowsAsync(new NetworkException("err"));
|
|
|
|
|
|
|
|
|
|
// simulate failed connection attempts
|
|
|
|
|
for (int i = 0; i < 5; i++)
|
|
|
|
|
{
|
|
|
|
|
await server.ProcessUpdatesAsync(new System.Threading.CancellationToken());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => fakeLogger.WriteError(A<string>.Ignored))
|
|
|
|
|
.MustNotHaveHappened();
|
|
|
|
|
Assert.IsEmpty(mockEventHandler.Events);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Test_ConnectionLostNotificationEnabled()
|
|
|
|
|
{
|
|
|
|
|
var server = serviceProvider.GetService<IW4MServer>();
|
|
|
|
|
var fakeConfigHandler = A.Fake<IConfigurationHandler<ApplicationConfiguration>>();
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => fakeManager.GetApplicationSettings())
|
|
|
|
|
.Returns(fakeConfigHandler);
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => fakeConfigHandler.Configuration())
|
|
|
|
|
.Returns(new ApplicationConfiguration() { IgnoreServerConnectionLost = false });
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => fakeRConParser.GetStatusAsync(A<IRConConnection>.Ignored))
|
|
|
|
|
.ThrowsAsync(new NetworkException("err"));
|
|
|
|
|
|
|
|
|
|
// simulate failed connection attempts
|
|
|
|
|
for (int i = 0; i < 5; i++)
|
|
|
|
|
{
|
|
|
|
|
await server.ProcessUpdatesAsync(new System.Threading.CancellationToken());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// execute the connection lost event
|
|
|
|
|
foreach(var e in mockEventHandler.Events.ToList())
|
|
|
|
|
{
|
|
|
|
|
await server.ExecuteEvent(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
A.CallTo(() => fakeLogger.WriteError(A<string>.Ignored))
|
|
|
|
|
.MustHaveHappenedOnceExactly();
|
|
|
|
|
|
|
|
|
|
Assert.IsNotEmpty(mockEventHandler.Events);
|
|
|
|
|
Assert.AreEqual("err", (mockEventHandler.Events[0].Extra as NetworkException).Message);
|
|
|
|
|
}
|
2020-04-13 17:16:31 -04:00
|
|
|
|
}
|
|
|
|
|
}
|