mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-20 00:02:28 +00:00
The Great Formatting of 2022
This commit is contained in:
parent
59cc7f02fb
commit
35f50f5f8c
162 changed files with 6609 additions and 6809 deletions
|
@ -6,62 +6,61 @@ using LBPUnion.ProjectLighthouse.Types;
|
|||
using LBPUnion.ProjectLighthouse.Types.Settings;
|
||||
using Xunit;
|
||||
|
||||
namespace ProjectLighthouse.Tests.GameApiTests
|
||||
namespace ProjectLighthouse.Tests.GameApiTests;
|
||||
|
||||
public class AuthenticationTests : LighthouseServerTest
|
||||
{
|
||||
public class AuthenticationTests : LighthouseServerTest
|
||||
[Fact]
|
||||
public async Task ShouldReturnErrorOnNoPostData()
|
||||
{
|
||||
[Fact]
|
||||
public async Task ShouldReturnErrorOnNoPostData()
|
||||
{
|
||||
HttpResponseMessage response = await this.Client.PostAsync("/LITTLEBIGPLANETPS3_XML/login", null!);
|
||||
Assert.False(response.IsSuccessStatusCode);
|
||||
#if NET6_0_OR_GREATER
|
||||
Assert.True(response.StatusCode == HttpStatusCode.BadRequest);
|
||||
#else
|
||||
HttpResponseMessage response = await this.Client.PostAsync("/LITTLEBIGPLANETPS3_XML/login", null!);
|
||||
Assert.False(response.IsSuccessStatusCode);
|
||||
#if NET6_0_OR_GREATER
|
||||
Assert.True(response.StatusCode == HttpStatusCode.BadRequest);
|
||||
#else
|
||||
Assert.True(response.StatusCode == HttpStatusCode.NotAcceptable);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
[DatabaseFact]
|
||||
public async Task ShouldReturnWithValidData()
|
||||
{
|
||||
HttpResponseMessage response = await this.AuthenticateResponse();
|
||||
Assert.True(response.IsSuccessStatusCode);
|
||||
string responseContent = await response.Content.ReadAsStringAsync();
|
||||
Assert.Contains("MM_AUTH=", responseContent);
|
||||
Assert.Contains(ServerStatics.ServerName, responseContent);
|
||||
}
|
||||
[DatabaseFact]
|
||||
public async Task ShouldReturnWithValidData()
|
||||
{
|
||||
HttpResponseMessage response = await this.AuthenticateResponse();
|
||||
Assert.True(response.IsSuccessStatusCode);
|
||||
string responseContent = await response.Content.ReadAsStringAsync();
|
||||
Assert.Contains("MM_AUTH=", responseContent);
|
||||
Assert.Contains(ServerStatics.ServerName, responseContent);
|
||||
}
|
||||
|
||||
[DatabaseFact]
|
||||
public async Task CanSerializeBack()
|
||||
{
|
||||
LoginResult loginResult = await this.Authenticate();
|
||||
[DatabaseFact]
|
||||
public async Task CanSerializeBack()
|
||||
{
|
||||
LoginResult loginResult = await this.Authenticate();
|
||||
|
||||
Assert.NotNull(loginResult);
|
||||
Assert.NotNull(loginResult.AuthTicket);
|
||||
Assert.NotNull(loginResult.LbpEnvVer);
|
||||
Assert.NotNull(loginResult);
|
||||
Assert.NotNull(loginResult.AuthTicket);
|
||||
Assert.NotNull(loginResult.LbpEnvVer);
|
||||
|
||||
Assert.Contains("MM_AUTH=", loginResult.AuthTicket);
|
||||
Assert.Equal(ServerStatics.ServerName, loginResult.LbpEnvVer);
|
||||
}
|
||||
Assert.Contains("MM_AUTH=", loginResult.AuthTicket);
|
||||
Assert.Equal(ServerStatics.ServerName, loginResult.LbpEnvVer);
|
||||
}
|
||||
|
||||
[DatabaseFact]
|
||||
public async Task CanUseToken()
|
||||
{
|
||||
LoginResult loginResult = await this.Authenticate();
|
||||
[DatabaseFact]
|
||||
public async Task CanUseToken()
|
||||
{
|
||||
LoginResult loginResult = await this.Authenticate();
|
||||
|
||||
HttpResponseMessage response = await this.AuthenticatedRequest("/LITTLEBIGPLANETPS3_XML/enterLevel/1", loginResult.AuthTicket);
|
||||
string responseContent = await response.Content.ReadAsStringAsync();
|
||||
HttpResponseMessage response = await this.AuthenticatedRequest("/LITTLEBIGPLANETPS3_XML/enterLevel/1", loginResult.AuthTicket);
|
||||
string responseContent = await response.Content.ReadAsStringAsync();
|
||||
|
||||
Assert.False(response.StatusCode == HttpStatusCode.Forbidden);
|
||||
}
|
||||
Assert.False(response.StatusCode == HttpStatusCode.Forbidden);
|
||||
}
|
||||
|
||||
[DatabaseFact]
|
||||
public async Task ShouldReturnForbiddenWhenNotAuthenticated()
|
||||
{
|
||||
HttpResponseMessage response = await this.Client.GetAsync("/LITTLEBIGPLANETPS3_XML/announce");
|
||||
Assert.False(response.IsSuccessStatusCode);
|
||||
Assert.True(response.StatusCode == HttpStatusCode.Forbidden);
|
||||
}
|
||||
[DatabaseFact]
|
||||
public async Task ShouldReturnForbiddenWhenNotAuthenticated()
|
||||
{
|
||||
HttpResponseMessage response = await this.Client.GetAsync("/LITTLEBIGPLANETPS3_XML/announce");
|
||||
Assert.False(response.IsSuccessStatusCode);
|
||||
Assert.True(response.StatusCode == HttpStatusCode.Forbidden);
|
||||
}
|
||||
}
|
|
@ -6,23 +6,22 @@ using LBPUnion.ProjectLighthouse.Tests;
|
|||
using LBPUnion.ProjectLighthouse.Types;
|
||||
using Xunit;
|
||||
|
||||
namespace ProjectLighthouse.Tests.GameApiTests
|
||||
namespace ProjectLighthouse.Tests.GameApiTests;
|
||||
|
||||
public class DatabaseTests : LighthouseServerTest
|
||||
{
|
||||
public class DatabaseTests : LighthouseServerTest
|
||||
[DatabaseFact]
|
||||
public async Task CanCreateUserTwice()
|
||||
{
|
||||
[DatabaseFact]
|
||||
public async Task CanCreateUserTwice()
|
||||
{
|
||||
await using Database database = new();
|
||||
int rand = new Random().Next();
|
||||
await using Database database = new();
|
||||
int rand = new Random().Next();
|
||||
|
||||
User userA = await database.CreateUser("createUserTwiceTest" + rand, HashHelper.GenerateAuthToken());
|
||||
User userB = await database.CreateUser("createUserTwiceTest" + rand, HashHelper.GenerateAuthToken());
|
||||
User userA = await database.CreateUser("createUserTwiceTest" + rand, HashHelper.GenerateAuthToken());
|
||||
User userB = await database.CreateUser("createUserTwiceTest" + rand, HashHelper.GenerateAuthToken());
|
||||
|
||||
Assert.NotNull(userA);
|
||||
Assert.NotNull(userB);
|
||||
Assert.NotNull(userA);
|
||||
Assert.NotNull(userB);
|
||||
|
||||
await database.RemoveUser(userA); // Only remove userA since userA and userB are the same user
|
||||
}
|
||||
await database.RemoveUser(userA); // Only remove userA since userA and userB are the same user
|
||||
}
|
||||
}
|
|
@ -8,55 +8,54 @@ using LBPUnion.ProjectLighthouse.Tests;
|
|||
using LBPUnion.ProjectLighthouse.Types;
|
||||
using Xunit;
|
||||
|
||||
namespace ProjectLighthouse.Tests.GameApiTests
|
||||
namespace ProjectLighthouse.Tests.GameApiTests;
|
||||
|
||||
public class MatchTests : LighthouseServerTest
|
||||
{
|
||||
public class MatchTests : LighthouseServerTest
|
||||
private static readonly SemaphoreSlim semaphore = new(1, 1);
|
||||
|
||||
[DatabaseFact]
|
||||
public async Task ShouldRejectEmptyData()
|
||||
{
|
||||
private static readonly SemaphoreSlim semaphore = new(1, 1);
|
||||
LoginResult loginResult = await this.Authenticate();
|
||||
await semaphore.WaitAsync();
|
||||
|
||||
[DatabaseFact]
|
||||
public async Task ShouldRejectEmptyData()
|
||||
{
|
||||
LoginResult loginResult = await this.Authenticate();
|
||||
await semaphore.WaitAsync();
|
||||
HttpResponseMessage result = await this.AuthenticatedUploadDataRequest("LITTLEBIGPLANETPS3_XML/match", Array.Empty<byte>(), loginResult.AuthTicket);
|
||||
|
||||
HttpResponseMessage result = await this.AuthenticatedUploadDataRequest("LITTLEBIGPLANETPS3_XML/match", Array.Empty<byte>(), loginResult.AuthTicket);
|
||||
semaphore.Release();
|
||||
Assert.False(result.IsSuccessStatusCode);
|
||||
}
|
||||
|
||||
semaphore.Release();
|
||||
Assert.False(result.IsSuccessStatusCode);
|
||||
}
|
||||
[DatabaseFact]
|
||||
public async Task ShouldReturnOk()
|
||||
{
|
||||
LoginResult loginResult = await this.Authenticate();
|
||||
await semaphore.WaitAsync();
|
||||
|
||||
[DatabaseFact]
|
||||
public async Task ShouldReturnOk()
|
||||
{
|
||||
LoginResult loginResult = await this.Authenticate();
|
||||
await semaphore.WaitAsync();
|
||||
HttpResponseMessage result = await this.AuthenticatedUploadDataRequest
|
||||
("LITTLEBIGPLANETPS3_XML/match", Encoding.ASCII.GetBytes("[UpdateMyPlayerData,[\"Player\":\"1984\"]]"), loginResult.AuthTicket);
|
||||
|
||||
HttpResponseMessage result = await this.AuthenticatedUploadDataRequest
|
||||
("LITTLEBIGPLANETPS3_XML/match", Encoding.ASCII.GetBytes("[UpdateMyPlayerData,[\"Player\":\"1984\"]]"), loginResult.AuthTicket);
|
||||
semaphore.Release();
|
||||
Assert.True(result.IsSuccessStatusCode);
|
||||
}
|
||||
|
||||
semaphore.Release();
|
||||
Assert.True(result.IsSuccessStatusCode);
|
||||
}
|
||||
[DatabaseFact]
|
||||
public async Task ShouldIncrementPlayerCount()
|
||||
{
|
||||
LoginResult loginResult = await this.Authenticate(new Random().Next());
|
||||
|
||||
[DatabaseFact]
|
||||
public async Task ShouldIncrementPlayerCount()
|
||||
{
|
||||
LoginResult loginResult = await this.Authenticate(new Random().Next());
|
||||
await semaphore.WaitAsync();
|
||||
|
||||
await semaphore.WaitAsync();
|
||||
int oldPlayerCount = await StatisticsHelper.RecentMatches();
|
||||
|
||||
int oldPlayerCount = await StatisticsHelper.RecentMatches();
|
||||
HttpResponseMessage result = await this.AuthenticatedUploadDataRequest
|
||||
("LITTLEBIGPLANETPS3_XML/match", Encoding.ASCII.GetBytes("[UpdateMyPlayerData,[\"Player\":\"1984\"]]"), loginResult.AuthTicket);
|
||||
|
||||
HttpResponseMessage result = await this.AuthenticatedUploadDataRequest
|
||||
("LITTLEBIGPLANETPS3_XML/match", Encoding.ASCII.GetBytes("[UpdateMyPlayerData,[\"Player\":\"1984\"]]"), loginResult.AuthTicket);
|
||||
Assert.True(result.IsSuccessStatusCode);
|
||||
|
||||
Assert.True(result.IsSuccessStatusCode);
|
||||
int playerCount = await StatisticsHelper.RecentMatches();
|
||||
|
||||
int playerCount = await StatisticsHelper.RecentMatches();
|
||||
|
||||
semaphore.Release();
|
||||
Assert.Equal(oldPlayerCount + 1, playerCount);
|
||||
}
|
||||
semaphore.Release();
|
||||
Assert.Equal(oldPlayerCount + 1, playerCount);
|
||||
}
|
||||
}
|
|
@ -9,85 +9,84 @@ using LBPUnion.ProjectLighthouse.Types.Levels;
|
|||
using LBPUnion.ProjectLighthouse.Types.Profiles;
|
||||
using Xunit;
|
||||
|
||||
namespace ProjectLighthouse.Tests.GameApiTests
|
||||
namespace ProjectLighthouse.Tests.GameApiTests;
|
||||
|
||||
public class SlotTests : LighthouseServerTest
|
||||
{
|
||||
public class SlotTests : LighthouseServerTest
|
||||
[DatabaseFact]
|
||||
public async Task ShouldOnlyShowUsersLevels()
|
||||
{
|
||||
[DatabaseFact]
|
||||
public async Task ShouldOnlyShowUsersLevels()
|
||||
await using Database database = new();
|
||||
|
||||
Random r = new();
|
||||
|
||||
User userA = await database.CreateUser($"unitTestUser{r.Next()}", HashHelper.GenerateAuthToken());
|
||||
User userB = await database.CreateUser($"unitTestUser{r.Next()}", HashHelper.GenerateAuthToken());
|
||||
|
||||
Location l = new()
|
||||
{
|
||||
await using Database database = new();
|
||||
X = 0,
|
||||
Y = 0,
|
||||
};
|
||||
database.Locations.Add(l);
|
||||
await database.SaveChangesAsync();
|
||||
|
||||
Random r = new();
|
||||
Slot slotA = new()
|
||||
{
|
||||
Creator = userA,
|
||||
CreatorId = userA.UserId,
|
||||
Name = "slotA",
|
||||
Location = l,
|
||||
LocationId = l.Id,
|
||||
ResourceCollection = "",
|
||||
};
|
||||
|
||||
User userA = await database.CreateUser($"unitTestUser{r.Next()}", HashHelper.GenerateAuthToken());
|
||||
User userB = await database.CreateUser($"unitTestUser{r.Next()}", HashHelper.GenerateAuthToken());
|
||||
Slot slotB = new()
|
||||
{
|
||||
Creator = userB,
|
||||
CreatorId = userB.UserId,
|
||||
Name = "slotB",
|
||||
Location = l,
|
||||
LocationId = l.Id,
|
||||
ResourceCollection = "",
|
||||
};
|
||||
|
||||
Location l = new()
|
||||
{
|
||||
X = 0,
|
||||
Y = 0,
|
||||
};
|
||||
database.Locations.Add(l);
|
||||
await database.SaveChangesAsync();
|
||||
database.Slots.Add(slotA);
|
||||
database.Slots.Add(slotB);
|
||||
|
||||
Slot slotA = new()
|
||||
{
|
||||
Creator = userA,
|
||||
CreatorId = userA.UserId,
|
||||
Name = "slotA",
|
||||
Location = l,
|
||||
LocationId = l.Id,
|
||||
ResourceCollection = "",
|
||||
};
|
||||
|
||||
Slot slotB = new()
|
||||
{
|
||||
Creator = userB,
|
||||
CreatorId = userB.UserId,
|
||||
Name = "slotB",
|
||||
Location = l,
|
||||
LocationId = l.Id,
|
||||
ResourceCollection = "",
|
||||
};
|
||||
|
||||
database.Slots.Add(slotA);
|
||||
database.Slots.Add(slotB);
|
||||
|
||||
await database.SaveChangesAsync();
|
||||
await database.SaveChangesAsync();
|
||||
|
||||
// XmlSerializer serializer = new(typeof(Slot));
|
||||
// Slot slot = (Slot)serializer.Deserialize(new StringReader(bodyString));
|
||||
|
||||
LoginResult loginResult = await this.Authenticate();
|
||||
LoginResult loginResult = await this.Authenticate();
|
||||
|
||||
HttpResponseMessage respMessageA = await this.AuthenticatedRequest
|
||||
($"LITTLEBIGPLANETPS3_XML/slots/by?u={userA.Username}&pageStart=1&pageSize=1", loginResult.AuthTicket);
|
||||
HttpResponseMessage respMessageB = await this.AuthenticatedRequest
|
||||
($"LITTLEBIGPLANETPS3_XML/slots/by?u={userB.Username}&pageStart=1&pageSize=1", loginResult.AuthTicket);
|
||||
HttpResponseMessage respMessageA = await this.AuthenticatedRequest
|
||||
($"LITTLEBIGPLANETPS3_XML/slots/by?u={userA.Username}&pageStart=1&pageSize=1", loginResult.AuthTicket);
|
||||
HttpResponseMessage respMessageB = await this.AuthenticatedRequest
|
||||
($"LITTLEBIGPLANETPS3_XML/slots/by?u={userB.Username}&pageStart=1&pageSize=1", loginResult.AuthTicket);
|
||||
|
||||
Assert.True(respMessageA.IsSuccessStatusCode);
|
||||
Assert.True(respMessageB.IsSuccessStatusCode);
|
||||
Assert.True(respMessageA.IsSuccessStatusCode);
|
||||
Assert.True(respMessageB.IsSuccessStatusCode);
|
||||
|
||||
string respA = await respMessageA.Content.ReadAsStringAsync();
|
||||
string respB = await respMessageB.Content.ReadAsStringAsync();
|
||||
string respA = await respMessageA.Content.ReadAsStringAsync();
|
||||
string respB = await respMessageB.Content.ReadAsStringAsync();
|
||||
|
||||
Assert.False(string.IsNullOrEmpty(respA));
|
||||
Assert.False(string.IsNullOrEmpty(respB));
|
||||
Assert.False(string.IsNullOrEmpty(respA));
|
||||
Assert.False(string.IsNullOrEmpty(respB));
|
||||
|
||||
Assert.NotEqual(respA, respB);
|
||||
Assert.DoesNotContain(respA, "slotB");
|
||||
Assert.DoesNotContain(respB, "slotA");
|
||||
Assert.NotEqual(respA, respB);
|
||||
Assert.DoesNotContain(respA, "slotB");
|
||||
Assert.DoesNotContain(respB, "slotA");
|
||||
|
||||
// Cleanup
|
||||
// Cleanup
|
||||
|
||||
database.Slots.Remove(slotA);
|
||||
database.Slots.Remove(slotB);
|
||||
database.Slots.Remove(slotA);
|
||||
database.Slots.Remove(slotB);
|
||||
|
||||
await database.RemoveUser(userA);
|
||||
await database.RemoveUser(userB);
|
||||
await database.RemoveUser(userA);
|
||||
await database.RemoveUser(userB);
|
||||
|
||||
await database.SaveChangesAsync();
|
||||
}
|
||||
await database.SaveChangesAsync();
|
||||
}
|
||||
}
|
|
@ -6,54 +6,53 @@ using System.Threading.Tasks;
|
|||
using LBPUnion.ProjectLighthouse.Tests;
|
||||
using Xunit;
|
||||
|
||||
namespace ProjectLighthouse.Tests.GameApiTests
|
||||
namespace ProjectLighthouse.Tests.GameApiTests;
|
||||
|
||||
public class UploadTests : LighthouseServerTest
|
||||
{
|
||||
public class UploadTests : LighthouseServerTest
|
||||
public UploadTests()
|
||||
{
|
||||
public UploadTests()
|
||||
{
|
||||
string assetsDirectory = Path.Combine(Environment.CurrentDirectory, "r");
|
||||
if (Directory.Exists(assetsDirectory)) Directory.Delete(assetsDirectory, true);
|
||||
}
|
||||
string assetsDirectory = Path.Combine(Environment.CurrentDirectory, "r");
|
||||
if (Directory.Exists(assetsDirectory)) Directory.Delete(assetsDirectory, true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ShouldNotAcceptScript()
|
||||
{
|
||||
HttpResponseMessage response = await this.UploadFileEndpointRequest("ExampleFiles/TestScript.ff");
|
||||
Assert.False(response.StatusCode == HttpStatusCode.Forbidden);
|
||||
Assert.False(response.IsSuccessStatusCode);
|
||||
}
|
||||
[Fact]
|
||||
public async Task ShouldNotAcceptScript()
|
||||
{
|
||||
HttpResponseMessage response = await this.UploadFileEndpointRequest("ExampleFiles/TestScript.ff");
|
||||
Assert.False(response.StatusCode == HttpStatusCode.Forbidden);
|
||||
Assert.False(response.IsSuccessStatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ShouldNotAcceptFarc()
|
||||
{
|
||||
HttpResponseMessage response = await this.UploadFileEndpointRequest("ExampleFiles/TestFarc.farc");
|
||||
Assert.False(response.StatusCode == HttpStatusCode.Forbidden);
|
||||
Assert.False(response.IsSuccessStatusCode);
|
||||
}
|
||||
[Fact]
|
||||
public async Task ShouldNotAcceptFarc()
|
||||
{
|
||||
HttpResponseMessage response = await this.UploadFileEndpointRequest("ExampleFiles/TestFarc.farc");
|
||||
Assert.False(response.StatusCode == HttpStatusCode.Forbidden);
|
||||
Assert.False(response.IsSuccessStatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ShouldNotAcceptGarbage()
|
||||
{
|
||||
HttpResponseMessage response = await this.UploadFileEndpointRequest("ExampleFiles/TestGarbage.bin");
|
||||
Assert.False(response.StatusCode == HttpStatusCode.Forbidden);
|
||||
Assert.False(response.IsSuccessStatusCode);
|
||||
}
|
||||
[Fact]
|
||||
public async Task ShouldNotAcceptGarbage()
|
||||
{
|
||||
HttpResponseMessage response = await this.UploadFileEndpointRequest("ExampleFiles/TestGarbage.bin");
|
||||
Assert.False(response.StatusCode == HttpStatusCode.Forbidden);
|
||||
Assert.False(response.IsSuccessStatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ShouldAcceptTexture()
|
||||
{
|
||||
HttpResponseMessage response = await this.UploadFileEndpointRequest("ExampleFiles/TestTexture.tex");
|
||||
Assert.False(response.StatusCode == HttpStatusCode.Forbidden);
|
||||
Assert.True(response.IsSuccessStatusCode);
|
||||
}
|
||||
[Fact]
|
||||
public async Task ShouldAcceptTexture()
|
||||
{
|
||||
HttpResponseMessage response = await this.UploadFileEndpointRequest("ExampleFiles/TestTexture.tex");
|
||||
Assert.False(response.StatusCode == HttpStatusCode.Forbidden);
|
||||
Assert.True(response.IsSuccessStatusCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ShouldAcceptLevel()
|
||||
{
|
||||
HttpResponseMessage response = await this.UploadFileEndpointRequest("ExampleFiles/TestLevel.lvl");
|
||||
Assert.False(response.StatusCode == HttpStatusCode.Forbidden);
|
||||
Assert.True(response.IsSuccessStatusCode);
|
||||
}
|
||||
[Fact]
|
||||
public async Task ShouldAcceptLevel()
|
||||
{
|
||||
HttpResponseMessage response = await this.UploadFileEndpointRequest("ExampleFiles/TestLevel.lvl");
|
||||
Assert.False(response.StatusCode == HttpStatusCode.Forbidden);
|
||||
Assert.True(response.IsSuccessStatusCode);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue