Skip to content

Commit

Permalink
PSP uploading fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jvyden committed Apr 15, 2024
1 parent db52d64 commit 63e070a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Refresh.GameServer/Endpoints/Game/ResourceEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ public Response UploadAsset(RequestContext context, string hash, string type, by
return Unauthorized;
}

if (isPSP && gameAsset.SafetyLevel == AssetSafetyLevel.SafeMedia && safetyLevel < AssetSafetyLevel.SafeMedia)
{
context.Logger.LogWarning(BunkumCategory.UserContent, $"{gameAsset.AssetType} {hash} by {user} cannot be uploaded because media is disabled");
return Unauthorized;
}

if (!dataStore.WriteToStore(assetPath, body))
return InternalServerError;

Expand Down
44 changes: 44 additions & 0 deletions RefreshTests.GameServer/Tests/Assets/AssetUploadTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,50 @@ public void NormalUserCantUploadAssetWithSafetyLevel()
Assert.That(response.StatusCode, Is.EqualTo(Unauthorized));
}

[Test]
public void PspCantUploadMediaAssetWhileBlocked()
{
using TestContext context = this.GetServer();
context.Server.Value.Server.AddService<ImportService>();
context.Server.Value.GameServerConfig.MaximumAssetSafetyLevel = AssetSafetyLevel.Safe;

GameUser user = context.CreateUser();

using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, user);
client.DefaultRequestHeaders.UserAgent.TryParseAdd("LBPPSP CLIENT");

ReadOnlySpan<byte> data = "TEX a"u8;

string hash = BitConverter.ToString(SHA1.HashData(data))
.Replace("-", "")
.ToLower();

HttpResponseMessage response = client.PostAsync("/lbp/upload/" + hash, new ByteArrayContent(data.ToArray())).Result;
Assert.That(response.StatusCode, Is.EqualTo(Unauthorized));
}

[Test]
public void PspCanUploadNormalAssetWhileBlocked()
{
using TestContext context = this.GetServer();
context.Server.Value.Server.AddService<ImportService>();
context.Server.Value.GameServerConfig.MaximumAssetSafetyLevel = AssetSafetyLevel.Safe;

GameUser user = context.CreateUser();

using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, user);
client.DefaultRequestHeaders.UserAgent.TryParseAdd("LBPPSP CLIENT");

ReadOnlySpan<byte> data = "LVLb "u8;

string hash = BitConverter.ToString(SHA1.HashData(data))
.Replace("-", "")
.ToLower();

HttpResponseMessage response = client.PostAsync("/lbp/upload/" + hash, new ByteArrayContent(data.ToArray())).Result;
Assert.That(response.StatusCode, Is.EqualTo(OK));
}

[Test]
public void CantUploadAssetWithInvalidHash()
{
Expand Down

0 comments on commit 63e070a

Please sign in to comment.