ProjectLighthouse/ProjectLighthouse.Tests.GameApiTests/Unit/PatchworkUserAgentTests.cs
FeTetra aeba706391
Some checks failed
Continuous Integration / Build & Test (push) Has been cancelled
Upload Translations to Crowdin / crowdin-sync (push) Has been cancelled
Build Docker Image / Build and Publish (push) Has been cancelled
Qodana / qodana (push) Has been cancelled
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
2025-06-04 12:14:40 +00:00

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}.");
}
}
}