From 67d0d3d7b149eb0fecd1db0f3e1e098c9c95ae0f Mon Sep 17 00:00:00 2001 From: sudokoko Date: Fri, 5 Apr 2024 09:54:03 -0400 Subject: [PATCH 1/5] Prevent duplicate profile pins --- .../Controllers/UserController.cs | 2 +- .../Unit/Controllers/UserControllerTests.cs | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/UserController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/UserController.cs index cbed989be..7019cdd76 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/UserController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/UserController.cs @@ -180,7 +180,7 @@ public async Task UpdateMyPins() // Sometimes the update gets called periodically as pin progress updates via playing, // may not affect equipped profile pins however, so check before setting it. string currentPins = user.Pins; - string newPins = string.Join(",", pinJson.ProfilePins); + string newPins = string.Join(",", pinJson.ProfilePins.Distinct()); if (string.Equals(currentPins, newPins)) return this.Ok("[{\"StatusCode\":200}]"); diff --git a/ProjectLighthouse.Tests.GameApiTests/Unit/Controllers/UserControllerTests.cs b/ProjectLighthouse.Tests.GameApiTests/Unit/Controllers/UserControllerTests.cs index e7228b2cf..3347db1e6 100644 --- a/ProjectLighthouse.Tests.GameApiTests/Unit/Controllers/UserControllerTests.cs +++ b/ProjectLighthouse.Tests.GameApiTests/Unit/Controllers/UserControllerTests.cs @@ -177,4 +177,29 @@ public async Task UpdateMyPins_ShouldNotSave_WhenPinsAreEqual() Assert.Equal(expectedPins, dbMock.Users.First().Pins); Assert.Equal(expectedResponse, pinsResponse); } + + [Fact] + public async Task UpdateMyPins_ShouldRemove_DuplicatePins() + { + UserEntity entity = MockHelper.GetUnitTestUser(); + entity.Pins = "1234"; + List users = new() + { + entity, + }; + await using DatabaseContext dbMock = await MockHelper.GetTestDatabase(users); + + UserController userController = new(dbMock); + userController.SetupTestController("{\"profile_pins\": [1234, 1234]}"); + + const string expectedPins = "1234"; + const string expectedResponse = "[{\"StatusCode\":200}]"; + + IActionResult result = await userController.UpdateMyPins(); + + string pinsResponse = result.CastTo(); + + Assert.Equal(expectedPins, dbMock.Users.First().Pins); + Assert.Equal(expectedResponse, pinsResponse); + } } \ No newline at end of file From 9348d581584206924b9c24915f4fe0a0fe643192 Mon Sep 17 00:00:00 2001 From: Slendy Date: Mon, 15 Apr 2024 14:11:47 -0500 Subject: [PATCH 2/5] Fix infinite redirect for users with empty usernames --- ProjectLighthouse.Servers.Website/Pages/UserPage.cshtml.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ProjectLighthouse.Servers.Website/Pages/UserPage.cshtml.cs b/ProjectLighthouse.Servers.Website/Pages/UserPage.cshtml.cs index 64bfb5014..05cb5671b 100644 --- a/ProjectLighthouse.Servers.Website/Pages/UserPage.cshtml.cs +++ b/ProjectLighthouse.Servers.Website/Pages/UserPage.cshtml.cs @@ -45,7 +45,8 @@ public async Task OnGet([FromRoute] int userId, string? slug) if (this.ProfileUser == null) return this.NotFound(); string userSlug = this.ProfileUser.GenerateSlug(); - if (slug == null || userSlug != slug) + // Only redirect if there is a valid slug for this user and the current slug doesn't match + if (!string.IsNullOrWhiteSpace(userSlug) && (slug == null || userSlug != slug)) { return this.Redirect($"~/user/{userId}/{userSlug}"); } From 0ce748de8f6efb9f88cf8f846a0dad36f20db300 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 Apr 2024 23:30:25 -0500 Subject: [PATCH 3/5] Bump SixLabors.ImageSharp from 3.1.3 to 3.1.4 in /ProjectLighthouse (#1012) Bumps [SixLabors.ImageSharp](https://github.com/SixLabors/ImageSharp) from 3.1.3 to 3.1.4. - [Release notes](https://github.com/SixLabors/ImageSharp/releases) - [Commits](https://github.com/SixLabors/ImageSharp/compare/v3.1.3...v3.1.4) --- updated-dependencies: - dependency-name: SixLabors.ImageSharp dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- ProjectLighthouse/ProjectLighthouse.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ProjectLighthouse/ProjectLighthouse.csproj b/ProjectLighthouse/ProjectLighthouse.csproj index 44c923488..bc92bc904 100644 --- a/ProjectLighthouse/ProjectLighthouse.csproj +++ b/ProjectLighthouse/ProjectLighthouse.csproj @@ -15,7 +15,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + From ed5bb5d76954d0fe88625b5f5b8e8ed73602191a Mon Sep 17 00:00:00 2001 From: Josh Date: Sun, 28 Apr 2024 20:44:41 -0500 Subject: [PATCH 4/5] Prevent LBP3 reviews from showing up in LBP2 (#1015) --- .../Controllers/Slots/ReviewController.cs | 14 +++ .../Unit/Controllers/ReviewControllerTests.cs | 99 +++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 ProjectLighthouse.Tests.GameApiTests/Unit/Controllers/ReviewControllerTests.cs diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/ReviewController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/ReviewController.cs index 7feae4bf4..0dd54c078 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/Slots/ReviewController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/Slots/ReviewController.cs @@ -157,6 +157,13 @@ public async Task ReviewsFor(int slotId) List reviews = (await this.database.Reviews .Where(r => r.SlotId == slotId) + .Select(r => new + { + Review = r, + SlotVersion = r.Slot!.GameVersion, + }) + .Where(a => a.SlotVersion <= token.GameVersion) + .Select(a => a.Review) .OrderByDescending(r => r.ThumbsUp - r.ThumbsDown) .ThenByDescending(r => r.Timestamp) .ApplyPagination(pageData) @@ -178,6 +185,13 @@ public async Task ReviewsBy(string username) List reviews = (await this.database.Reviews .Where(r => r.ReviewerId == targetUserId) + .Select(r => new + { + Review = r, + SlotVersion = r.Slot!.GameVersion, + }) + .Where(a => a.SlotVersion <= token.GameVersion) + .Select(a => a.Review) .OrderByDescending(r => r.Timestamp) .ApplyPagination(pageData) .ToListAsync()).ToSerializableList(r => GameReview.CreateFromEntity(r, token)); diff --git a/ProjectLighthouse.Tests.GameApiTests/Unit/Controllers/ReviewControllerTests.cs b/ProjectLighthouse.Tests.GameApiTests/Unit/Controllers/ReviewControllerTests.cs new file mode 100644 index 000000000..303b4f859 --- /dev/null +++ b/ProjectLighthouse.Tests.GameApiTests/Unit/Controllers/ReviewControllerTests.cs @@ -0,0 +1,99 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using LBPUnion.ProjectLighthouse.Database; +using LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers.Slots; +using LBPUnion.ProjectLighthouse.Tests.Helpers; +using LBPUnion.ProjectLighthouse.Types.Entities.Level; +using LBPUnion.ProjectLighthouse.Types.Entities.Token; +using LBPUnion.ProjectLighthouse.Types.Serialization; +using LBPUnion.ProjectLighthouse.Types.Users; +using Microsoft.AspNetCore.Mvc; +using Xunit; + +namespace ProjectLighthouse.Tests.GameApiTests.Unit.Controllers; + +public class ReviewControllerTests +{ + private static async Task InsertTestData(DatabaseContext database) + { + database.Slots.Add(new SlotEntity + { + SlotId = 1, + CreatorId = 1, + GameVersion = GameVersion.LittleBigPlanet3, + }); + + database.Slots.Add(new SlotEntity + { + SlotId = 2, + CreatorId = 1, + GameVersion = GameVersion.LittleBigPlanet2, + }); + + database.Reviews.Add(new ReviewEntity + { + ReviewId = 1, + ReviewerId = 1, + SlotId = 1, + }); + + database.Reviews.Add(new ReviewEntity + { + ReviewId = 2, + ReviewerId = 1, + SlotId = 2, + }); + await database.SaveChangesAsync(); + } + + [Theory] + [InlineData(GameVersion.LittleBigPlanet2, 1)] + [InlineData(GameVersion.LittleBigPlanet3, 2)] + public async Task ReviewsBy_ShouldNotList_HigherGameVersions(GameVersion version, int expected) + { + GameTokenEntity token = MockHelper.GetUnitTestToken(); + token.GameVersion = version; + DatabaseContext database = await MockHelper.GetTestDatabase(new List + { + token, + }); + + await InsertTestData(database); + + ReviewController controller = new(database); + controller.SetupTestController(token); + + IActionResult response = await controller.ReviewsBy("unittest"); + ReviewResponse review = response.CastTo(); + + Assert.Equal(expected, review.Reviews.Count); + Assert.True(review.Reviews.All(r => database.Slots.FirstOrDefault(s => s.SlotId == r.Slot.SlotId)?.GameVersion <= version)); + } + + [Theory] + [InlineData(GameVersion.LittleBigPlanet2, 2, 1)] + [InlineData(GameVersion.LittleBigPlanet2, 1, 0)] + [InlineData(GameVersion.LittleBigPlanet3, 2, 1)] + [InlineData(GameVersion.LittleBigPlanet3, 1, 1)] + public async Task ReviewsFor_ShouldNotList_HigherGameVersions(GameVersion version, int slotId, int expected) + { + GameTokenEntity token = MockHelper.GetUnitTestToken(); + token.GameVersion = version; + DatabaseContext database = await MockHelper.GetTestDatabase(new List + { + token, + }); + + await InsertTestData(database); + + ReviewController controller = new(database); + controller.SetupTestController(token); + + IActionResult response = await controller.ReviewsFor(slotId); + ReviewResponse review = response.CastTo(); + + Assert.Equal(expected, review.Reviews.Count); + Assert.True(review.Reviews.All(r => database.Slots.FirstOrDefault(s => s.SlotId == r.Slot.SlotId)?.GameVersion <= version)); + } +} \ No newline at end of file From 9e84e468442f4522cd173b0f8b261384fb37a442 Mon Sep 17 00:00:00 2001 From: Slendy Date: Sat, 11 May 2024 17:58:48 -0500 Subject: [PATCH 5/5] Add custom ToString method for NPTicket section header --- ProjectLighthouse/Tickets/TicketReader.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ProjectLighthouse/Tickets/TicketReader.cs b/ProjectLighthouse/Tickets/TicketReader.cs index ee6b1a708..697a72a1c 100644 --- a/ProjectLighthouse/Tickets/TicketReader.cs +++ b/ProjectLighthouse/Tickets/TicketReader.cs @@ -33,6 +33,9 @@ public struct SectionHeader public SectionType Type; public ushort Length; public int Position; + + public override string ToString() => + $"SectionHeader(Type='{this.Type}', Length='{this.Length}', Position='{this.Position}')"; } public class TicketReader : BinaryReader