From cd19afc5777804a22793e20b2b49ee615b138336 Mon Sep 17 00:00:00 2001 From: jvyden Date: Tue, 2 Nov 2021 19:06:45 -0400 Subject: [PATCH] Fix test failures --- .../Tests/AuthenticationTests.cs | 2 +- ProjectLighthouse/Controllers/MatchController.cs | 2 +- ProjectLighthouse/Helpers/FileHelper.cs | 14 +++++++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ProjectLighthouse.Tests/Tests/AuthenticationTests.cs b/ProjectLighthouse.Tests/Tests/AuthenticationTests.cs index 87bdf599..893648e0 100644 --- a/ProjectLighthouse.Tests/Tests/AuthenticationTests.cs +++ b/ProjectLighthouse.Tests/Tests/AuthenticationTests.cs @@ -49,7 +49,7 @@ namespace LBPUnion.ProjectLighthouse.Tests { LoginResult loginResult = await this.Authenticate(); - HttpResponseMessage response = await this.AuthenticatedRequest("/LITTLEBIGPLANETPS3_XML/eula", loginResult.AuthTicket); + HttpResponseMessage response = await this.AuthenticatedRequest("/LITTLEBIGPLANETPS3_XML/announce", loginResult.AuthTicket); string responseContent = await response.Content.ReadAsStringAsync(); Assert.True(response.IsSuccessStatusCode); diff --git a/ProjectLighthouse/Controllers/MatchController.cs b/ProjectLighthouse/Controllers/MatchController.cs index 81fe97e0..ddf4de8f 100644 --- a/ProjectLighthouse/Controllers/MatchController.cs +++ b/ProjectLighthouse/Controllers/MatchController.cs @@ -45,7 +45,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers "[{\"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 (bodyString.Length == 0 || bodyString[0] != '[') return this.BadRequest(); IMatchData? matchData; try diff --git a/ProjectLighthouse/Helpers/FileHelper.cs b/ProjectLighthouse/Helpers/FileHelper.cs index 2b05f6f1..e81fe118 100644 --- a/ProjectLighthouse/Helpers/FileHelper.cs +++ b/ProjectLighthouse/Helpers/FileHelper.cs @@ -37,9 +37,17 @@ namespace LBPUnion.ProjectLighthouse.Helpers public static LbpFileType DetermineFileType(byte[] data) { + if (data.Length == 0) return LbpFileType.Unknown; // Can't be anything if theres no data. + using MemoryStream ms = new(data); using BinaryReader reader = new(ms); + // Determine if file is a FARC (File Archive). + // Needs to be done before anything else that determines the type by the header + // because this determines the type by the footer. + string footer = Encoding.ASCII.GetString(BinaryHelper.ReadLastBytes(reader, 4)); + if (footer == "FARC") return LbpFileType.FileArchive; + byte[] header = reader.ReadBytes(3); return Encoding.ASCII.GetString(header) switch @@ -57,11 +65,7 @@ namespace LBPUnion.ProjectLighthouse.Helpers private static LbpFileType determineFileTypePartTwoWeirdName(BinaryReader reader) { reader.BaseStream.Position = 0; - - // Determine if file is FARC - string footer = Encoding.ASCII.GetString(BinaryHelper.ReadLastBytes(reader, 4)); - if (footer == "FARC") return LbpFileType.FileArchive; - + // Determine if file is JPEG byte[] header = reader.ReadBytes(9);