mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-23 13:41:31 +00:00
* Implement checking for the Patchwork user agent, move logout into standalone method * Quick fixes (awesome name) * 403 user at login instead of logging out at /announce * Move configuration and revert logout changes * Rework parsing to check against GameVersion enum and game token GameVersion * Fix logic error oopsie * Fix Zaprit suggestions * Simplify patchwork game version test * Test patchwork user agent with regex instead * Fix Qodana warnings * Fix remaining Qodana warnings
44 lines
No EOL
1.4 KiB
C#
44 lines
No EOL
1.4 KiB
C#
using LBPUnion.ProjectLighthouse.Servers.GameServer.Helpers;
|
|
using Xunit;
|
|
|
|
namespace ProjectLighthouse.Tests.GameApiTests.Unit;
|
|
|
|
[Trait("Category", "Unit")]
|
|
public class PatchworkUserAgentTests
|
|
{
|
|
[Fact]
|
|
public void CanValidatePatchworkUserAgents()
|
|
{
|
|
string[] validUserAgents = {
|
|
"PatchworkLBP1 1.0",
|
|
"PatchworkLBP2 2.0",
|
|
"PatchworkLBP3 3.0",
|
|
"PatchworkLBPV 4.0",
|
|
"PatchworkLBP1 1.5",
|
|
};
|
|
|
|
string[] invalidUserAgents = {
|
|
// Matching
|
|
"patchworklbp1 1.0", // Case sensitive
|
|
"ptchwrklbp1 1.0", // Misspelled
|
|
"PatchworkLBP1 1", // Missing major/minor
|
|
"PatchworkLBP1 1.000001", // Major/minor too long
|
|
|
|
// Data
|
|
"PatchworkLBP1 0.5", // Version number too low
|
|
"PatchworkLBP1 A.0" // Int cannot be parsed
|
|
};
|
|
|
|
bool result;
|
|
foreach (string userAgent in validUserAgents)
|
|
{
|
|
result = PatchworkHelper.IsValidPatchworkUserAgent(userAgent);
|
|
Assert.True(result, $"Valid user agent: \"{userAgent}\" was evaluated as {result}.");
|
|
}
|
|
foreach (string userAgent in invalidUserAgents)
|
|
{
|
|
result = PatchworkHelper.IsValidPatchworkUserAgent(userAgent);
|
|
Assert.False(result, $"Invalid user agent: \"{userAgent}\" was evaluated as {result}.");
|
|
}
|
|
}
|
|
} |