mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-28 07:58:40 +00:00
Implement checking for the Patchwork user agent (#1090)
* 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
This commit is contained in:
parent
df7ebf977a
commit
aeba706391
7 changed files with 85 additions and 4 deletions
|
@ -0,0 +1,44 @@
|
|||
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}.");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue