Skip to content

Commit bde00d7

Browse files
committed
Test planet/profile updating
1 parent f1b1de4 commit bde00d7

2 files changed

Lines changed: 371 additions & 18 deletions

File tree

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
using System.Security.Cryptography;
2+
using Refresh.Database.Models.Assets;
3+
using Refresh.Database.Models.Authentication;
4+
using Refresh.Database.Models.Users;
5+
using Refresh.Interfaces.Game.Types.UserData;
6+
using RefreshTests.GameServer.Extensions;
7+
8+
namespace RefreshTests.GameServer.Tests.Planets;
9+
10+
public class PlanetUploadTests : GameServerTest
11+
{
12+
[Test]
13+
public void RejectPlanetsIfGuid()
14+
{
15+
using TestContext context = this.GetServer();
16+
GameUser user = context.CreateUser();
17+
18+
using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, TokenGame.LittleBigPlanet3, TokenPlatform.PS3, user);
19+
20+
SerializedUpdateDataProfile request = new()
21+
{
22+
PlanetsHash = "g34567",
23+
};
24+
25+
HttpResponseMessage message = client.PostAsync($"/lbp/updateUser", new StringContent(request.AsXML())).Result;
26+
Assert.That(message.StatusCode, Is.EqualTo(BadRequest));
27+
}
28+
29+
[Test]
30+
public void AllowBlankPlanets()
31+
{
32+
using TestContext context = this.GetServer();
33+
GameUser user = context.CreateUser();
34+
35+
using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, TokenGame.LittleBigPlanet3, TokenPlatform.PS3, user);
36+
37+
SerializedUpdateDataProfile request = new()
38+
{
39+
PlanetsHash = "0",
40+
};
41+
42+
HttpResponseMessage message = client.PostAsync($"/lbp/updateUser", new StringContent(request.AsXML())).Result;
43+
Assert.That(message.StatusCode, Is.EqualTo(OK));
44+
}
45+
46+
[Test]
47+
public void AllowHashedPlanets()
48+
{
49+
using TestContext context = this.GetServer();
50+
GameUser user = context.CreateUser();
51+
52+
ReadOnlySpan<byte> data = "LVLb"u8;
53+
string hash = BitConverter.ToString(SHA1.HashData(data)).Replace("-", "").ToLower();
54+
context.GetDataStore().WriteToStore(hash, data);
55+
56+
using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, TokenGame.LittleBigPlanet3, TokenPlatform.PS3, user);
57+
58+
SerializedUpdateDataProfile request = new()
59+
{
60+
PlanetsHash = hash,
61+
};
62+
63+
HttpResponseMessage message = client.PostAsync($"/lbp/updateUser", new StringContent(request.AsXML())).Result;
64+
Assert.That(message.StatusCode, Is.EqualTo(OK));
65+
}
66+
67+
[Test]
68+
public void AllowHashedPlanetsWithNewline()
69+
{
70+
using TestContext context = this.GetServer();
71+
GameUser user = context.CreateUser();
72+
73+
ReadOnlySpan<byte> data = "LVLb"u8;
74+
string hash = BitConverter.ToString(SHA1.HashData(data)).Replace("-", "").ToLower();
75+
context.GetDataStore().WriteToStore(hash, data);
76+
77+
using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, TokenGame.LittleBigPlanet3, TokenPlatform.PS3, user);
78+
79+
SerializedUpdateDataProfile request = new()
80+
{
81+
PlanetsHash = hash + "\n",
82+
};
83+
84+
HttpResponseMessage message = client.PostAsync($"/lbp/updateUser", new StringContent(request.AsXML())).Result;
85+
Assert.That(message.StatusCode, Is.EqualTo(OK));
86+
}
87+
88+
[Test]
89+
public void RejectPlanetsIfWrongResourceType()
90+
{
91+
using TestContext context = this.GetServer();
92+
GameUser user = context.CreateUser();
93+
94+
ReadOnlySpan<byte> data = "PLNb"u8;
95+
string hash = BitConverter.ToString(SHA1.HashData(data)).Replace("-", "").ToLower();
96+
context.GetDataStore().WriteToStore(hash, data);
97+
98+
using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, TokenGame.LittleBigPlanet3, TokenPlatform.PS3, user);
99+
100+
SerializedUpdateDataProfile request = new()
101+
{
102+
PlanetsHash = hash,
103+
};
104+
105+
HttpResponseMessage message = client.PostAsync($"/lbp/updateUser", new StringContent(request.AsXML())).Result;
106+
Assert.That(message.StatusCode, Is.EqualTo(BadRequest));
107+
}
108+
109+
[Test]
110+
public void RejectPlanetsIfNotUploaded()
111+
{
112+
using TestContext context = this.GetServer();
113+
GameUser user = context.CreateUser();
114+
115+
ReadOnlySpan<byte> data = "LVLb"u8;
116+
string hash = BitConverter.ToString(SHA1.HashData(data)).Replace("-", "").ToLower();
117+
// Don't upload the asset
118+
119+
using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, TokenGame.LittleBigPlanet3, TokenPlatform.PS3, user);
120+
121+
SerializedUpdateDataProfile request = new()
122+
{
123+
PlanetsHash = hash,
124+
};
125+
126+
HttpResponseMessage message = client.PostAsync($"/lbp/updateUser", new StringContent(request.AsXML())).Result;
127+
Assert.That(message.StatusCode, Is.EqualTo(NotFound));
128+
}
129+
130+
[Test]
131+
public void RejectPlanetsIfDisallowed()
132+
{
133+
using TestContext context = this.GetServer();
134+
GameUser user = context.CreateUser();
135+
136+
ReadOnlySpan<byte> data = "LVLb"u8;
137+
string hash = BitConverter.ToString(SHA1.HashData(data)).Replace("-", "").ToLower();
138+
context.GetDataStore().WriteToStore(hash, data);
139+
context.Database.DisallowAsset(hash, GameAssetType.Level, "garbage music");
140+
141+
using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, TokenGame.LittleBigPlanet3, TokenPlatform.PS3, user);
142+
143+
SerializedUpdateDataProfile request = new()
144+
{
145+
PlanetsHash = hash,
146+
};
147+
148+
HttpResponseMessage message = client.PostAsync($"/lbp/updateUser", new StringContent(request.AsXML())).Result;
149+
Assert.That(message.StatusCode, Is.EqualTo(Unauthorized));
150+
}
151+
152+
[Test]
153+
public void RejectPlanetsIfInvalidHash()
154+
{
155+
using TestContext context = this.GetServer();
156+
GameUser user = context.CreateUser();
157+
158+
using HttpClient client = context.GetAuthenticatedClient(TokenType.Game, TokenGame.LittleBigPlanet3, TokenPlatform.PS3, user);
159+
160+
SerializedUpdateDataProfile request = new()
161+
{
162+
PlanetsHash = "adserdtfgzhgj",
163+
};
164+
165+
HttpResponseMessage message = client.PostAsync($"/lbp/updateUser", new StringContent(request.AsXML())).Result;
166+
Assert.That(message.StatusCode, Is.EqualTo(BadRequest));
167+
}
168+
}

0 commit comments

Comments
 (0)