ProjectLighthouse/ProjectLighthouse.Tests.GameApiTests/Tests/MatchTests.cs
Josh 19ea44e0e2
Rework login and registration systems (#600)
* Initial work for verifying login ticket signatures

* Add candidate psn public key

* Add candidate psn public key and fix nuget packages

* Finalize npticket changes

* Add support for ticket version 3.0

* Rework login system to link platform accounts instead of using ip addresses

* Make linked accounts green instead of blue

* Fix api building

* Fix unit tests

* Actually fix unit tests

* Set unit test user's linked platform

* Why was this the wrong default value?

* Fix username change code

* Make TicketHash hash the entire ticket instead of just the serial

* Send password setup email when user sets their email for the first time

* Changes from self review
2022-12-26 01:03:14 -08:00

65 lines
No EOL
2.1 KiB
C#

using System;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using LBPUnion.ProjectLighthouse;
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.PlayerData;
using LBPUnion.ProjectLighthouse.Servers.GameServer.Startup;
using LBPUnion.ProjectLighthouse.Tests;
using Xunit;
namespace ProjectLighthouse.Tests.GameApiTests.Tests;
public class MatchTests : LighthouseServerTest<GameServerTestStartup>
{
private static readonly SemaphoreSlim semaphore = new(1, 1);
[DatabaseFact]
public async Task ShouldRejectEmptyData()
{
LoginResult loginResult = await this.Authenticate();
await semaphore.WaitAsync();
HttpResponseMessage result = await this.AuthenticatedUploadDataRequest("LITTLEBIGPLANETPS3_XML/match", Array.Empty<byte>(), loginResult.AuthTicket);
semaphore.Release();
Assert.False(result.IsSuccessStatusCode);
}
[DatabaseFact]
public async Task ShouldReturnOk()
{
LoginResult loginResult = await this.Authenticate();
await semaphore.WaitAsync();
HttpResponseMessage result = await this.AuthenticatedUploadDataRequest
("LITTLEBIGPLANETPS3_XML/match", "[UpdateMyPlayerData,[\"Player\":\"1984\"]]"u8.ToArray(), loginResult.AuthTicket);
semaphore.Release();
Assert.True(result.IsSuccessStatusCode);
}
[DatabaseFact]
public async Task ShouldIncrementPlayerCount()
{
LoginResult loginResult = await this.Authenticate(new Random().Next());
await semaphore.WaitAsync();
await using Database database = new();
int oldPlayerCount = await StatisticsHelper.RecentMatches(database);
HttpResponseMessage result = await this.AuthenticatedUploadDataRequest
("LITTLEBIGPLANETPS3_XML/match", "[UpdateMyPlayerData,[\"Player\":\"1984\"]]"u8.ToArray(), loginResult.AuthTicket);
Assert.True(result.IsSuccessStatusCode);
int playerCount = await StatisticsHelper.RecentMatches(database);
semaphore.Release();
Assert.Equal(oldPlayerCount + 1, playerCount);
}
}