Adds book editing tests and parameterizes the shared test fixtures

This commit is contained in:
BinaryAlley committed 2026-09-06 09:37:55 -07:00
1 parent 1bfa07ba5d
commit 145185d715
354 files changed
+7118 -1743

No files matched your search

@@ -11,7 +11,7 @@ using System.Threading.Tasks;
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Themes.Management.DeleteTheme;
/// <summary>
/// Contains security tests for the <c>DELETE /api/v1/themes/{themeId}</c> route.
/// Contains security tests for the <see cref="DeleteThemeEndpoint"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class DeleteThemeEndpointTests : IClassFixture<LuminaApiFactory>, IDisposable
@@ -31,7 +31,7 @@ public class DeleteThemeEndpointTests : IClassFixture<LuminaApiFactory>, IDispos
{
_apiFactory = apiFactory;
_client = apiFactory.CreateClient();
// a unique X-Forwarded-For isolates rate limiting state per test
// A unique X-Forwarded-For isolates rate limiting state per test.
_client.DefaultRequestHeaders.Add("X-Forwarded-For", LuminaApiFactory.GetUniqueTestIp());
}
@@ -13,7 +13,7 @@ using System.Text.Json;
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Themes.Management.InstallTheme;
/// <summary>
/// Contains security tests for the <c>POST /api/v1/themes</c> route.
/// Contains security tests for the <see cref="InstallThemeEndpoint"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class InstallThemeEndpointTests : IClassFixture<LuminaApiFactory>, IDisposable
@@ -48,7 +48,7 @@ public class InstallThemeEndpointTests : IClassFixture<LuminaApiFactory>, IDispo
{
_apiFactory = apiFactory;
_client = apiFactory.CreateClient();
// a unique X-Forwarded-For isolates rate limiting state per test
// A unique X-Forwarded-For isolates rate limiting state per test.
_client.DefaultRequestHeaders.Add("X-Forwarded-For", LuminaApiFactory.GetUniqueTestIp());
}
@@ -4,22 +4,17 @@ using Lumina.Application.Fixtures.Common.DataAccess.Entities.Themes;
using Lumina.DataAccess.Core.UoW;
using Lumina.Presentation.Api.SecurityTests.Common.Setup;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Net.Http;
using System.Net.Http.Json;
using System.Text.Json;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Themes.Management.RestoreTheme;
/// <summary>
/// Contains security tests for the <c>POST /api/v1/themes/{themeId}/restore</c> route.
/// Contains security tests for the <see cref="RestoreThemeEndpoint"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class RestoreThemeEndpointTests : IClassFixture<LuminaApiFactory>, IDisposable
@@ -41,7 +36,7 @@ public class RestoreThemeEndpointTests : IClassFixture<LuminaApiFactory>, IDispo
{
_apiFactory = apiFactory;
_client = apiFactory.CreateClient();
// a unique X-Forwarded-For isolates rate limiting state per test
// A unique X-Forwarded-For isolates rate limiting state per test.
_client.DefaultRequestHeaders.Add("X-Forwarded-For", LuminaApiFactory.GetUniqueTestIp());
_themeId = $"testtheme{Guid.NewGuid():N}";
}
@@ -4,16 +4,14 @@ using Lumina.Presentation.Api.SecurityTests.Common.Setup;
using Microsoft.AspNetCore.Http;
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Net.Http;
using System.Net.Http.Json;
using System.Text.Json;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Themes.Management.SetCurrentTheme;
/// <summary>
/// Contains security tests for the <c>PUT /api/v1/themes/current</c> route.
/// Contains security tests for the <see cref="SetCurrentThemeEndpoint"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class SetCurrentThemeEndpointTests : IClassFixture<LuminaApiFactory>, IDisposable
@@ -33,7 +31,7 @@ public class SetCurrentThemeEndpointTests : IClassFixture<LuminaApiFactory>, IDi
{
_apiFactory = apiFactory;
_client = apiFactory.CreateClient();
// a unique X-Forwarded-For isolates rate limiting state per test
// A unique X-Forwarded-For isolates rate limiting state per test.
_client.DefaultRequestHeaders.Add("X-Forwarded-For", LuminaApiFactory.GetUniqueTestIp());
}
@@ -3,15 +3,13 @@ using Lumina.Presentation.Api.SecurityTests.Common.Setup;
using Microsoft.AspNetCore.Http;
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Themes.Queries.GetCurrentTheme;
/// <summary>
/// Contains security tests for the <c>/api/v1/themes/current</c> route.
/// Contains security tests for the <see cref="GetCurrentThemeEndpoint"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetCurrentThemeEndpointTests : IClassFixture<LuminaApiFactory>, IDisposable
@@ -29,7 +27,7 @@ public class GetCurrentThemeEndpointTests : IClassFixture<LuminaApiFactory>, IDi
public GetCurrentThemeEndpointTests(LuminaApiFactory apiFactory)
{
_client = apiFactory.CreateClient();
// a unique X-Forwarded-For isolates rate limiting state per test
// A unique X-Forwarded-For isolates rate limiting state per test.
_client.DefaultRequestHeaders.Add("X-Forwarded-For", LuminaApiFactory.GetUniqueTestIp());
}
@@ -42,7 +40,7 @@ public class GetCurrentThemeEndpointTests : IClassFixture<LuminaApiFactory>, IDi
string content = await response.Content.ReadAsStringAsync();
// Assert
// the route is AllowAnonymous, so anonymous callers must never be challenged for credentials
// The route is AllowAnonymous, so anonymous callers must never be challenged for credentials.
Assert.NotEqual(HttpStatusCode.Unauthorized, response.StatusCode);
Assert.NotEqual(HttpStatusCode.InternalServerError, response.StatusCode);
@@ -54,7 +52,7 @@ public class GetCurrentThemeEndpointTests : IClassFixture<LuminaApiFactory>, IDi
Assert.DoesNotContain("salt", content, StringComparison.OrdinalIgnoreCase);
Assert.DoesNotContain(AppContext.BaseDirectory, content, StringComparison.OrdinalIgnoreCase);
// when no active theme exists yet, the failure must be a clean, generic 404 that discloses nothing internal
// When no active theme exists yet, the failure must be a clean, generic 404 that discloses nothing internal.
if (response.StatusCode == HttpStatusCode.NotFound)
{
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
@@ -11,7 +11,7 @@ using System.Threading.Tasks;
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Themes.Queries.GetThemeArchive;
/// <summary>
/// Contains security tests for the <c>/api/v1/themes/{themeId}/archive</c> route.
/// Contains security tests for the <see cref="GetThemeArchiveEndpoint"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetThemeArchiveEndpointTests : IClassFixture<LuminaApiFactory>, IDisposable
@@ -31,7 +31,7 @@ public class GetThemeArchiveEndpointTests : IClassFixture<LuminaApiFactory>, IDi
{
_apiFactory = apiFactory;
_client = apiFactory.CreateClient();
// a unique X-Forwarded-For isolates rate limiting state per test
// A unique X-Forwarded-For isolates rate limiting state per test.
_client.DefaultRequestHeaders.Add("X-Forwarded-For", LuminaApiFactory.GetUniqueTestIp());
}
@@ -81,8 +81,8 @@ public class GetThemeArchiveEndpointTests : IClassFixture<LuminaApiFactory>, IDi
Assert.DoesNotContain("stack trace", content, StringComparison.OrdinalIgnoreCase);
Assert.DoesNotContain(AppContext.BaseDirectory, content, StringComparison.OrdinalIgnoreCase);
// note: some payloads are normalized away by the server before routing, producing an empty-body 404;
// when the value reaches the handler, the failure must still be the generic theme-not-found problem
// Note: some payloads are normalized away by the server before routing, producing an empty-body 404;
// when the value reaches the handler, the failure must still be the generic theme-not-found problem.
if (!string.IsNullOrWhiteSpace(content))
{
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
@@ -17,7 +17,7 @@ using System.Threading.Tasks;
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Themes.Queries.GetThemeAsset;
/// <summary>
/// Contains security tests for the <c>/api/v1/themes/{themeId}/assets/{*assetPath}</c> route.
/// Contains security tests for the <see cref="GetThemeAssetEndpoint"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetThemeAssetEndpointTests : IClassFixture<LuminaApiFactory>, IDisposable
@@ -42,7 +42,7 @@ public class GetThemeAssetEndpointTests : IClassFixture<LuminaApiFactory>, IDisp
{
_apiFactory = apiFactory;
_client = apiFactory.CreateClient();
// a unique X-Forwarded-For isolates rate limiting state per test
// A unique X-Forwarded-For isolates rate limiting state per test.
_client.DefaultRequestHeaders.Add("X-Forwarded-For", LuminaApiFactory.GetUniqueTestIp());
_themeId = $"testtheme{Guid.NewGuid():N}";
}
@@ -93,8 +93,8 @@ public class GetThemeAssetEndpointTests : IClassFixture<LuminaApiFactory>, IDisp
string content = await response.Content.ReadAsStringAsync();
// Assert
// the encoded traversal is rejected either by the server before it reaches the handler (403) or by the theme service validation (422);
// in both cases it must be a clean client error that never serves or leaks the decoy
// The encoded traversal is rejected either by the server before it reaches the handler (403) or by the theme service validation (422);
// in both cases it must be a clean client error that never serves or leaks the decoy.
Assert.True(response.StatusCode >= HttpStatusCode.BadRequest && response.StatusCode < HttpStatusCode.InternalServerError, $"Unexpected status code {response.StatusCode}.");
Assert.DoesNotContain("Exception", content, StringComparison.OrdinalIgnoreCase);
Assert.DoesNotContain("SQL", content, StringComparison.OrdinalIgnoreCase);
@@ -112,7 +112,7 @@ public class GetThemeAssetEndpointTests : IClassFixture<LuminaApiFactory>, IDisp
EnsureDecoyFileOnDisk();
// Act
// note: Kestrel normalizes literal dot-segments out of the raw path, so the request is re-routed or rejected before the handler
// Note: Kestrel normalizes literal dot-segments out of the raw path, so the request is re-routed or rejected before the handler.
HttpResponseMessage response = await _client.GetAsync($"/api/v1/themes/{_themeId}/assets/../evil.txt");
string content = await response.Content.ReadAsStringAsync();
@@ -146,8 +146,8 @@ public class GetThemeAssetEndpointTests : IClassFixture<LuminaApiFactory>, IDisp
Assert.DoesNotContain("stack trace", content, StringComparison.OrdinalIgnoreCase);
Assert.DoesNotContain(AppContext.BaseDirectory, content, StringComparison.OrdinalIgnoreCase);
// note: some payloads are normalized away by the server before routing, producing an empty-body 404;
// when the value reaches the handler, the failure must still be the generic theme-not-found problem
// Note: some payloads are normalized away by the server before routing, producing an empty-body 404;
// when the value reaches the handler, the failure must still be the generic theme-not-found problem.
if (!string.IsNullOrWhiteSpace(content))
{
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
@@ -2,14 +2,12 @@
using Lumina.Presentation.Api.SecurityTests.Common.Setup;
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Themes.Queries.GetThemeSettings;
/// <summary>
/// Contains security tests for the <c>/api/v1/themes/settings</c> route.
/// Contains security tests for the <see cref="GetThemeSettingsEndpoint"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetThemeSettingsEndpointTests : IClassFixture<LuminaApiFactory>, IDisposable
@@ -23,7 +21,7 @@ public class GetThemeSettingsEndpointTests : IClassFixture<LuminaApiFactory>, ID
public GetThemeSettingsEndpointTests(LuminaApiFactory apiFactory)
{
_client = apiFactory.CreateClient();
// a unique X-Forwarded-For isolates rate limiting state per test
// A unique X-Forwarded-For isolates rate limiting state per test.
_client.DefaultRequestHeaders.Add("X-Forwarded-For", LuminaApiFactory.GetUniqueTestIp());
}
@@ -35,7 +33,7 @@ public class GetThemeSettingsEndpointTests : IClassFixture<LuminaApiFactory>, ID
HttpResponseMessage response = await _client.GetAsync("/api/v1/themes/settings");
// Assert
// the route is AllowAnonymous, so anonymous callers must never be challenged for credentials
// The route is AllowAnonymous, so anonymous callers must never be challenged for credentials.
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
@@ -4,20 +4,16 @@ using Lumina.Application.Fixtures.Common.DataAccess.Entities.Themes;
using Lumina.DataAccess.Core.UoW;
using Lumina.Presentation.Api.SecurityTests.Common.Setup;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
#endregion
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Themes.Queries.GetThemeTemplate;
/// <summary>
/// Contains security tests for the <c>/api/v1/themes/{themeId}/templates/{*pageKey}</c> route.
/// Contains security tests for the <see cref="GetThemeTemplateEndpoint"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetThemeTemplateEndpointTests : IClassFixture<LuminaApiFactory>, IDisposable
@@ -42,7 +38,7 @@ public class GetThemeTemplateEndpointTests : IClassFixture<LuminaApiFactory>, ID
{
_apiFactory = apiFactory;
_client = apiFactory.CreateClient();
// a unique X-Forwarded-For isolates rate limiting state per test
// A unique X-Forwarded-For isolates rate limiting state per test.
_client.DefaultRequestHeaders.Add("X-Forwarded-For", LuminaApiFactory.GetUniqueTestIp());
_themeId = $"testtheme{Guid.NewGuid():N}";
}
@@ -99,7 +95,7 @@ public class GetThemeTemplateEndpointTests : IClassFixture<LuminaApiFactory>, ID
Assert.DoesNotContain(DECOY_CONTENT, content, StringComparison.OrdinalIgnoreCase);
Assert.DoesNotContain(AppContext.BaseDirectory, content, StringComparison.OrdinalIgnoreCase);
// a successful render must only ever come from a template inside the theme pack
// A successful render must only ever come from a template inside the theme pack.
if (response.StatusCode == HttpStatusCode.OK)
Assert.Contains("default-template", content, StringComparison.OrdinalIgnoreCase);
}
@@ -113,7 +109,7 @@ public class GetThemeTemplateEndpointTests : IClassFixture<LuminaApiFactory>, ID
EnsureDecoyFileOnDisk();
// Act
// note: Kestrel normalizes literal dot-segments out of the raw path, so the request is re-routed or rejected before the handler
// Note: Kestrel normalizes literal dot-segments out of the raw path, so the request is re-routed or rejected before the handler.
HttpResponseMessage response = await _client.GetAsync($"/api/v1/themes/{_themeId}/templates/../evil.html");
string content = await response.Content.ReadAsStringAsync();
@@ -147,8 +143,8 @@ public class GetThemeTemplateEndpointTests : IClassFixture<LuminaApiFactory>, ID
Assert.DoesNotContain("stack trace", content, StringComparison.OrdinalIgnoreCase);
Assert.DoesNotContain(AppContext.BaseDirectory, content, StringComparison.OrdinalIgnoreCase);
// note: some payloads are normalized away by the server before routing, producing an empty-body 404;
// when the value reaches the handler, the failure must still be the generic theme-not-found problem
// Note: some payloads are normalized away by the server before routing, producing an empty-body 404;
// when the value reaches the handler, the failure must still be the generic theme-not-found problem.
if (!string.IsNullOrWhiteSpace(content))
{
Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
@@ -11,7 +11,7 @@ using System.Threading.Tasks;
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Themes.Queries.GetThemes;
/// <summary>
/// Contains security tests for the <c>/api/v1/themes</c> route.
/// Contains security tests for the <see cref="GetThemesEndpoint"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetThemesEndpointTests : IClassFixture<LuminaApiFactory>, IDisposable
@@ -31,7 +31,7 @@ public class GetThemesEndpointTests : IClassFixture<LuminaApiFactory>, IDisposab
{
_apiFactory = apiFactory;
_client = apiFactory.CreateClient();
// a unique X-Forwarded-For isolates rate limiting state per test
// A unique X-Forwarded-For isolates rate limiting state per test.
_client.DefaultRequestHeaders.Add("X-Forwarded-For", LuminaApiFactory.GetUniqueTestIp());
}