mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-09 11:52:27 +00:00
Fix authentication (mostly) and file upload tests failing
This commit is contained in:
parent
8289e6c04e
commit
0d682dceeb
5 changed files with 25 additions and 13 deletions
|
@ -4,9 +4,11 @@ using Xunit;
|
|||
|
||||
namespace LBPUnion.ProjectLighthouse.Tests
|
||||
{
|
||||
public sealed class DatabaseFact : FactAttribute
|
||||
public sealed class DatabaseFactAttribute : FactAttribute
|
||||
{
|
||||
public DatabaseFact()
|
||||
private static readonly object migrateLock = new();
|
||||
|
||||
public DatabaseFactAttribute()
|
||||
{
|
||||
ServerSettings.Instance = new ServerSettings();
|
||||
ServerSettings.Instance.DbConnectionString = "server=127.0.0.1;uid=root;pwd=lighthouse;database=lighthouse";
|
||||
|
@ -15,10 +17,13 @@ namespace LBPUnion.ProjectLighthouse.Tests
|
|||
this.Skip = "Database not available";
|
||||
}
|
||||
else
|
||||
{
|
||||
lock(migrateLock)
|
||||
{
|
||||
using Database database = new();
|
||||
database.Database.Migrate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Serialization;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
|
@ -25,9 +25,13 @@ namespace LBPUnion.ProjectLighthouse.Tests
|
|||
|
||||
this.Client = this.Server.CreateClient();
|
||||
}
|
||||
|
||||
public async Task<HttpResponseMessage> AuthenticateResponse(int number = 0, bool createUser = true)
|
||||
public async Task<HttpResponseMessage> AuthenticateResponse(int number = -1, bool createUser = true)
|
||||
{
|
||||
if (number == -1)
|
||||
{
|
||||
number = new Random().Next();
|
||||
}
|
||||
|
||||
const string username = "unitTestUser";
|
||||
if (createUser)
|
||||
{
|
||||
|
@ -65,8 +69,8 @@ namespace LBPUnion.ProjectLighthouse.Tests
|
|||
|
||||
public async Task<HttpResponseMessage> UploadFileEndpointRequest(string filePath)
|
||||
{
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(await File.ReadAllTextAsync(filePath));
|
||||
string hash = HashHelper.Sha1Hash(bytes);
|
||||
byte[] bytes = await File.ReadAllBytesAsync(filePath);
|
||||
string hash = HashHelper.Sha1Hash(bytes).ToLower();
|
||||
|
||||
return await this.Client.PostAsync($"/LITTLEBIGPLANETPS3_XML/upload/{hash}", new ByteArrayContent(bytes));
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
@ -18,6 +19,7 @@ namespace LBPUnion.ProjectLighthouse.Tests
|
|||
public async Task ShouldNotAcceptScript()
|
||||
{
|
||||
HttpResponseMessage response = await this.UploadFileEndpointRequest("ExampleFiles/TestScript.ff");
|
||||
Assert.False(response.StatusCode == HttpStatusCode.Forbidden);
|
||||
Assert.False(response.IsSuccessStatusCode);
|
||||
}
|
||||
|
||||
|
@ -25,6 +27,7 @@ namespace LBPUnion.ProjectLighthouse.Tests
|
|||
public async Task ShouldNotAcceptFarc()
|
||||
{
|
||||
HttpResponseMessage response = await this.UploadFileEndpointRequest("ExampleFiles/TestFarc.farc");
|
||||
Assert.False(response.StatusCode == HttpStatusCode.Forbidden);
|
||||
Assert.False(response.IsSuccessStatusCode);
|
||||
}
|
||||
|
||||
|
@ -32,6 +35,7 @@ namespace LBPUnion.ProjectLighthouse.Tests
|
|||
public async Task ShouldNotAcceptGarbage()
|
||||
{
|
||||
HttpResponseMessage response = await this.UploadFileEndpointRequest("ExampleFiles/TestGarbage.bin");
|
||||
Assert.False(response.StatusCode == HttpStatusCode.Forbidden);
|
||||
Assert.False(response.IsSuccessStatusCode);
|
||||
}
|
||||
|
||||
|
@ -39,6 +43,7 @@ namespace LBPUnion.ProjectLighthouse.Tests
|
|||
public async Task ShouldAcceptTexture()
|
||||
{
|
||||
HttpResponseMessage response = await this.UploadFileEndpointRequest("ExampleFiles/TestTexture.tex");
|
||||
Assert.False(response.StatusCode == HttpStatusCode.Forbidden);
|
||||
Assert.True(response.IsSuccessStatusCode);
|
||||
}
|
||||
|
||||
|
@ -46,6 +51,7 @@ namespace LBPUnion.ProjectLighthouse.Tests
|
|||
public async Task ShouldAcceptLevel()
|
||||
{
|
||||
HttpResponseMessage response = await this.UploadFileEndpointRequest("ExampleFiles/TestLevel.lvl");
|
||||
Assert.False(response.StatusCode == HttpStatusCode.Forbidden);
|
||||
Assert.True(response.IsSuccessStatusCode);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,6 +73,7 @@ namespace LBPUnion.ProjectLighthouse
|
|||
GameToken gameToken = new()
|
||||
{
|
||||
UserToken = HashHelper.GenerateAuthToken(),
|
||||
User = user,
|
||||
UserId = user.UserId,
|
||||
UserLocation = userLocation,
|
||||
GameVersion = GameVersionHelper.FromTitleId(titleId),
|
||||
|
|
|
@ -33,10 +33,6 @@
|
|||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<_ContentIncludedByDefault Remove="Pages\Admin\Index.cshtml"/>
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
|
||||
<Exec Command="git describe --long --always --dirty --exclude=\* --abbrev=8 > "$(ProjectDir)/gitVersion.txt""/>
|
||||
<Exec Command="git branch --show-current > "$(ProjectDir)/gitBranch.txt""/>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue