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