Fix tests

This commit is contained in:
jvyden 2021-10-26 17:27:59 -04:00
parent e4f764784e
commit 24b712cd15
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
4 changed files with 31 additions and 7 deletions

View file

@ -23,10 +23,12 @@ namespace LBPUnion.ProjectLighthouse.Tests {
public async Task<HttpResponseMessage> AuthenticateResponse(int number = 0) { public async Task<HttpResponseMessage> AuthenticateResponse(int number = 0) {
const char nullChar = (char)0x00; const char nullChar = (char)0x00;
const char sepChar = (char)0x20;
const string username = "unitTestUser"; const string username = "unitTestUser";
string stringContent = $"{nullChar}{sepChar}{username}{number}{nullChar}"; string nullString = "";
for(int i = 0; i < 80; i++) nullString += nullChar;
string stringContent = $"{nullString}{username}{number}{nullChar}";
HttpResponseMessage response = await this.Client.PostAsync("/LITTLEBIGPLANETPS3_XML/login", new StringContent(stringContent)); HttpResponseMessage response = await this.Client.PostAsync("/LITTLEBIGPLANETPS3_XML/login", new StringContent(stringContent));
return response; return response;

View file

@ -47,7 +47,7 @@ namespace LBPUnion.ProjectLighthouse.Tests {
string responseContent = await response.Content.ReadAsStringAsync(); string responseContent = await response.Content.ReadAsStringAsync();
Assert.True(response.IsSuccessStatusCode); Assert.True(response.IsSuccessStatusCode);
Assert.Contains("You are logged in", responseContent); Assert.Contains("You are now logged in", responseContent);
} }
[DatabaseFact] [DatabaseFact]

View file

@ -1,5 +1,6 @@
using System; using System;
using System.Net.Http; using System.Net.Http;
using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using LBPUnion.ProjectLighthouse.Types; using LBPUnion.ProjectLighthouse.Types;
@ -10,11 +11,27 @@ namespace LBPUnion.ProjectLighthouse.Tests {
private static readonly SemaphoreSlim semaphore = new(1, 1); private static readonly SemaphoreSlim semaphore = new(1, 1);
[DatabaseFact] [DatabaseFact]
public async Task ShouldReturnOk() { public async Task ShouldRejectEmptyData() {
LoginResult loginResult = await this.Authenticate(); LoginResult loginResult = await this.Authenticate();
await semaphore.WaitAsync(); await semaphore.WaitAsync();
HttpResponseMessage result = await this.AuthenticatedUploadDataRequest("LITTLEBIGPLANETPS3_XML/match", Array.Empty<byte>(), loginResult.AuthTicket); HttpResponseMessage result = await this.AuthenticatedUploadDataRequest("LITTLEBIGPLANETPS3_XML/match", Array.Empty<byte>(), loginResult.AuthTicket);
Assert.False(result.IsSuccessStatusCode);
semaphore.Release();
}
[DatabaseFact]
public async Task ShouldReturnOk() {
LoginResult loginResult = await this.Authenticate();
await semaphore.WaitAsync();
HttpResponseMessage result = await this.AuthenticatedUploadDataRequest(
"LITTLEBIGPLANETPS3_XML/match",
Encoding.ASCII.GetBytes("[UpdateMyPlayerData,[\"Player\":\"1984\"]]"),
loginResult.AuthTicket
);
Assert.True(result.IsSuccessStatusCode); Assert.True(result.IsSuccessStatusCode);
semaphore.Release(); semaphore.Release();
@ -29,7 +46,12 @@ namespace LBPUnion.ProjectLighthouse.Tests {
int oldPlayerCount = await this.GetPlayerCount(); int oldPlayerCount = await this.GetPlayerCount();
HttpResponseMessage result = await this.AuthenticatedUploadDataRequest("LITTLEBIGPLANETPS3_XML/match", Array.Empty<byte>(), loginResult.AuthTicket); HttpResponseMessage result = await this.AuthenticatedUploadDataRequest(
"LITTLEBIGPLANETPS3_XML/match",
Encoding.ASCII.GetBytes("[UpdateMyPlayerData,[\"Player\":\"1984\"]]"),
loginResult.AuthTicket
);
Assert.True(result.IsSuccessStatusCode); Assert.True(result.IsSuccessStatusCode);
int playerCount = await this.GetPlayerCount(); int playerCount = await this.GetPlayerCount();

View file

@ -32,12 +32,12 @@ namespace LBPUnion.ProjectLighthouse.Controllers {
#region Parse match data #region Parse match data
// Example POST /match: [UpdateMyPlayerData,["Player":"FireGamer9872"]] // Example POST /match: [UpdateMyPlayerData,["Player":"FireGamer9872"]]
string bodyString = await new StreamReader(this.Request.Body).ReadToEndAsync(); string? bodyString = await new StreamReader(this.Request.Body).ReadToEndAsync();
if(bodyString.Contains("FindBestRoom")) { if(bodyString.Contains("FindBestRoom")) {
return this.Ok("[{\"StatusCode\":200},{\"Players\":[{\"PlayerId\":\"literally1984\",\"matching_res\":0},{\"PlayerId\":\"jvyden\",\"matching_res\":1}],\"Slots\":[[5,0]],\"RoomState\":\"E_ROOM_IN_POD\",\"HostMood\":\"E_MOOD_EVERYONE\",\"LevelCompletionEstimate\":0,\"PassedNoJoinPoint\":0,\"MoveConnected\":false,\"Location\":[\"127.0.0.1\"],\"BuildVersion\":289,\"Language\":1,\"FirstSeenTimestamp\":1427331263756,\"LastSeenTimestamp\":1635112546000,\"GameId\":1,\"NatType\":2,\"Friends\":[],\"Blocked\":[],\"RecentlyLeft\":[],\"FailedJoin\":[]}]"); return this.Ok("[{\"StatusCode\":200},{\"Players\":[{\"PlayerId\":\"literally1984\",\"matching_res\":0},{\"PlayerId\":\"jvyden\",\"matching_res\":1}],\"Slots\":[[5,0]],\"RoomState\":\"E_ROOM_IN_POD\",\"HostMood\":\"E_MOOD_EVERYONE\",\"LevelCompletionEstimate\":0,\"PassedNoJoinPoint\":0,\"MoveConnected\":false,\"Location\":[\"127.0.0.1\"],\"BuildVersion\":289,\"Language\":1,\"FirstSeenTimestamp\":1427331263756,\"LastSeenTimestamp\":1635112546000,\"GameId\":1,\"NatType\":2,\"Friends\":[],\"Blocked\":[],\"RecentlyLeft\":[],\"FailedJoin\":[]}]");
} }
if(bodyString[0] != '[') return this.BadRequest(); if(string.IsNullOrEmpty(bodyString) || bodyString[0] != '[') return this.BadRequest();
IMatchData? matchData; IMatchData? matchData;
try { try {