Skip to content

Commit 9fac398

Browse files
committed
Test PSP levels not getting flagged as modded
1 parent 75fef66 commit 9fac398

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

RefreshTests.GameServer/TestContext.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,17 @@ public GameLevel CreateLevel(GameUser author, string title, string description,
147147
return level;
148148
}
149149

150+
public GameLevel CreateLevelWithRootResource(GameUser author, string rootResource, TokenGame gameVersion = TokenGame.LittleBigPlanet1)
151+
{
152+
GameLevelRequest levelRequest = new()
153+
{
154+
RootResource = rootResource,
155+
};
156+
157+
GameLevel level = this.Database.AddLevel(levelRequest, gameVersion, author);
158+
return level;
159+
}
160+
150161
public GamePhoto CreatePhotoWithSubject(GameUser author, string imageHash, GameLevel? level = null, List<SerializedPhotoSubject>? subjects = null)
151162
{
152163
// TODO: Return newly created GamePhoto

RefreshTests.GameServer/Tests/Levels/UploadTests.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
using Refresh.Database.Models.Levels;
33
using Refresh.Interfaces.Game.Endpoints.DataTypes.Request;
44
using Refresh.Database.Models.Authentication;
5+
using System.Security.Cryptography;
6+
using Refresh.Core.Extensions;
7+
using Refresh.Database.Models.Assets;
58

69
namespace RefreshTests.GameServer.Tests.Levels;
710

@@ -152,4 +155,38 @@ public void LevelUpdateDoesNotChangeUpdateDateWhenRootUnchanged()
152155
Assert.That(level.UpdateDate.ToUnixTimeMilliseconds(), Is.EqualTo(1));
153156
});
154157
}
158+
159+
[Test]
160+
public void PspLevelWithUnknownRootTypeDoesNotGetMarkedAsModded()
161+
{
162+
using TestContext context = this.GetServer();
163+
GameUser user = context.CreateUser();
164+
165+
using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, TokenGame.LittleBigPlanetPSP, TokenPlatform.PSP, user);
166+
client.DefaultRequestHeaders.UserAgent.TryParseAdd("LBPPSP CLIENT");
167+
168+
// upload asset from PSP
169+
ReadOnlySpan<byte> data = "MMMMMMMMMMMMMMMMMMMMM"u8;
170+
string hash = BitConverter.ToString(SHA1.HashData(data)).Replace("-", "").ToLower();
171+
172+
HttpResponseMessage response = client.PostAsync("/lbp/upload/" + hash, new ByteArrayContent(data.ToArray())).Result;
173+
Assert.That(response.StatusCode, Is.EqualTo(OK));
174+
175+
GameAsset? rootAsset = context.Database.GetAssetFromHash(hash);
176+
Assert.That(rootAsset, Is.Not.Null);
177+
Assert.That(rootAsset!.IsPSP, Is.True);
178+
Assert.That(rootAsset!.AssetType, Is.EqualTo(GameAssetType.Unknown));
179+
Assert.That(rootAsset!.AssetFormat, Is.EqualTo(GameAssetFormat.Unknown));
180+
181+
GameLevel level = context.CreateLevelWithRootResource(user, hash, TokenGame.LittleBigPlanetPSP);
182+
context.Database.UpdateLevelModdedStatus(level);
183+
184+
context.Database.Refresh();
185+
186+
GameLevel? updatedLevel = context.Database.GetLevelById(level.LevelId);
187+
Assert.That(updatedLevel, Is.Not.Null);
188+
Assert.That(updatedLevel!.LevelId, Is.EqualTo(level.LevelId));
189+
Assert.That(updatedLevel!.RootResource, Is.EqualTo(hash));
190+
Assert.That(updatedLevel!.IsModded, Is.False);
191+
}
155192
}

0 commit comments

Comments
 (0)