mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 15:11:10 +00:00
Adds book editing tests and parameterizes the shared test fixtures
This commit is contained in:
1 parent
1bfa07ba5d
commit
145185d715
354 files changed
+7118
-1743
No files matched your search
+1
-1
@@ -9,7 +9,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Admin.Authorization.Permissions;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/auth/permissions</c> route.
|
||||
/// Contains security tests for the <see cref="GetPermissionsEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetPermissionsEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Admin.Authorization.Roles;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/auth/roles</c> route.
|
||||
/// Contains security tests for the <see cref="AddRoleEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class AddRoleEndpointTests : IClassFixture<LuminaApiFactory>, IAsyncDisposable
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Admin.Authorization.Roles;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/auth/roles/{roleId}</c> route.
|
||||
/// Contains security tests for the <see cref="DeleteRoleEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DeleteRoleEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Admin.Authorization.Roles;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/auth/roles/{roleId}/permissions</c> route.
|
||||
/// Contains security tests for the <see cref="GetRolePermissionsEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetRolePermissionsEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Admin.Authorization.Roles;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/auth/roles</c> route.
|
||||
/// Contains security tests for the <see cref="GetRolesEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetRolesEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Admin.Authorization.Roles;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/auth/roles</c> route.
|
||||
/// Contains security tests for the <see cref="UpdateRoleEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UpdateRoleEndpointTests : IClassFixture<LuminaApiFactory>, IAsyncDisposable
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.FileSystemManagement.Directories;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/directories/get-directories</c> route.
|
||||
/// Contains security tests for the <see cref="GetDirectoriesEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetDirectoriesEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.FileSystemManagement.Drives;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/drives/get-drives</c> route.
|
||||
/// Contains security tests for the <see cref="GetDrivesEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetDrivesEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.FileSystemManagement.FileSystem;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/file-system/get-type</c> route.
|
||||
/// Contains security tests for the <see cref="GetTypeEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetTypeEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.FileSystemManagement.Files;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/files/get-files</c> route.
|
||||
/// Contains security tests for the <see cref="GetFilesEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetFilesEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.FileSystemManagement.Files;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/files/get-tree-files</c> route.
|
||||
/// Contains security tests for the <see cref="GetTreeFilesEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetTreeFilesEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.FileSystemManagement.Path;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/path/check-path-exists</c> route.
|
||||
/// Contains security tests for the <see cref="CheckPathExistsEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class CheckPathExistsEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.FileSystemManagement.Path;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/path/combine</c> route.
|
||||
/// Contains security tests for the <see cref="CombinePathEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class CombinePathEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.FileSystemManagement.Path;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/path/get-path-parent</c> route.
|
||||
/// Contains security tests for the <see cref="GetPathParentEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetPathParentEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.FileSystemManagement.Path;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/path/get-path-root</c> route.
|
||||
/// Contains security tests for the <see cref="GetPathRootEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetPathRootEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.FileSystemManagement.Path;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/path/get-path-separator</c> route.
|
||||
/// Contains security tests for the <see cref="GetPathSeparatorEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetPathSeparatorEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.FileSystemManagement.Path;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/path/split</c> route.
|
||||
/// Contains security tests for the <see cref="SplitPathEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class SplitPathEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.FileSystemManagement.Path;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/path/validate</c> route.
|
||||
/// Contains security tests for the <see cref="ValidatePathEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ValidatePathEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.FileSystemManagement.Thumbnails;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/thumbnails/get-thumbnail</c> route.
|
||||
/// Contains security tests for the <see cref="GetThumbnailEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetThumbnailEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Library.Management.AddLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/libraries</c> route.
|
||||
/// Contains security tests for the <see cref="AddLibraryEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class AddLibraryEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Library.Management.CancelLibrariesScan;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/libraries/scans/cancel</c> route.
|
||||
/// Contains security tests for the <see cref="CancelLibrariesScanEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class CancelLibrariesScanEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Library.Management.CancelLibraryScan;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/libraries/{libraryId}/scans/{scanId}/cancel</c> route.
|
||||
/// Contains security tests for the <see cref="CancelLibraryScanEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class CancelLibraryScanEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Library.Management.DeleteLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/libraries/{id}</c> route.
|
||||
/// Contains security tests for the <see cref="DeleteLibraryEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DeleteLibraryEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Library.Management.GetEnabledLibraries;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/libraries/enabled</c> route.
|
||||
/// Contains security tests for the <see cref="GetEnabledLibrariesEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetEnabledLibrariesEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Library.Management.GetLibraries;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/libraries</c> route.
|
||||
/// Contains security tests for the <see cref="GetLibrariesEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetLibrariesEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Library.Management.GetLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/libraries/{id}</c> route.
|
||||
/// Contains security tests for the <see cref="GetLibraryEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetLibraryEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Library.Management.GetLibraryScanProgress;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/libraries/{libraryId}/scans/{scanId}/progress</c> route.
|
||||
/// Contains security tests for the <see cref="GetLibraryScanProgressEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetLibraryScanProgressEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Library.Management.GetRunningLibraryScans;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/libraries/scans/running</c> route.
|
||||
/// Contains security tests for the <see cref="GetRunningLibraryScansEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetRunningLibraryScansEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Library.Management.ScanLibraries;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/libraries/scans</c> route.
|
||||
/// Contains security tests for the <see cref="ScanLibrariesEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ScanLibrariesEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Library.Management.ScanLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/libraries/{id}/scans</c> route.
|
||||
/// Contains security tests for the <see cref="ScanLibraryEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ScanLibraryEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Library.Management.UpdateLibrary;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/libraries/{id}</c> route.
|
||||
/// Contains security tests for the <see cref="UpdateLibraryEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UpdateLibraryEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+2
-2
@@ -20,7 +20,7 @@ using System.Threading.Tasks;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.AddBook;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/books</c> route.
|
||||
/// Contains security tests for the <see cref="AddBookEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class AddBookEndpointTests : IClassFixture<LuminaApiFactory>, IDisposable
|
||||
@@ -51,7 +51,7 @@ public class AddBookEndpointTests : IClassFixture<LuminaApiFactory>, IDisposable
|
||||
(Guid userId, string username) = await _apiFactory.CreateAndAuthenticateUserAsync(client);
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
await _apiFactory.SeedLibraryAsync(libraryId, userId);
|
||||
AddBookRequest request = _addBookRequestFixture.Create() with { LibraryId = libraryId, Path = maliciousPath };
|
||||
AddBookRequest request = _addBookRequestFixture.Create(libraryId: libraryId, path: maliciousPath);
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await client.PostAsJsonAsync("/api/v1/books", request);
|
||||
|
||||
+24
-21
@@ -1,20 +1,23 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.GetBook;
|
||||
using Lumina.Presentation.Api.SecurityTests.Common.Setup;
|
||||
using System;
|
||||
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.Library.WrittenContentLibrary.BookLibrary.Books.GetBook;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/books/{id}</c> route.
|
||||
/// Contains security tests for the <see cref="GetBookEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetBookEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
{
|
||||
private readonly HttpClient _client;
|
||||
private readonly LuminaApiFactory _apiFactory;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetBookEndpointTests"/> class.
|
||||
@@ -22,46 +25,46 @@ public class GetBookEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
/// <param name="apiFactory">Injected in-memory API factory.</param>
|
||||
public GetBookEndpointTests(LuminaApiFactory apiFactory)
|
||||
{
|
||||
_client = apiFactory.CreateClient();
|
||||
_apiFactory = apiFactory;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetBook_WhenCalledWithoutAuthentication_ShouldBeAccessible()
|
||||
public async Task GetBook_WhenCalledWithoutAuthentication_ShouldReturnUnauthorized()
|
||||
{
|
||||
// Arrange
|
||||
Guid bookId = Guid.NewGuid();
|
||||
HttpClient client = _apiFactory.CreateClient();
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await _client.GetAsync($"/api/v1/books/{bookId}");
|
||||
HttpResponseMessage response = await client.GetAsync($"/api/v1/books/{Guid.NewGuid()}");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
|
||||
string content = await response.Content.ReadAsStringAsync();
|
||||
Assert.DoesNotContain("password", content, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.DoesNotContain("hash", content, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.DoesNotContain("salt", content, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.DoesNotContain("Exception", content, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("' OR '1'='1")] // basic SQL injection
|
||||
[InlineData("'; DROP TABLE Books--")] // destructive injection
|
||||
public async Task GetBook_WithSQLInjectionInBookId_ShouldNotLeakOrError(string maliciousBookId)
|
||||
[InlineData("'; DROP TABLE Books; --")] // destructive injection
|
||||
[InlineData("' OR '1'='1")] // boolean-based injection
|
||||
public async Task GetBook_WithSQLInjectionInBookId_ShouldNotCorruptOrLeakData(string maliciousBookId)
|
||||
{
|
||||
// Arrange
|
||||
// the {id} route parameter is string-typed, so the malicious value binds and reaches the anonymous endpoint handler
|
||||
HttpClient client = _apiFactory.CreateClient();
|
||||
(_, string username) = await _apiFactory.CreateAndAuthenticateUserAsync(client);
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await _client.GetAsync($"/api/v1/books/{Uri.EscapeDataString(maliciousBookId)}");
|
||||
string content = await response.Content.ReadAsStringAsync();
|
||||
HttpResponseMessage response = await client.GetAsync($"/api/v1/books/{Uri.EscapeDataString(maliciousBookId)}");
|
||||
|
||||
// Assert
|
||||
// the endpoint processes the value without querying the persistence medium and without leaking it
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
// The unparseable route value becomes an empty book Id, which the query validator reports as a missing book Id.
|
||||
Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode);
|
||||
string content = await response.Content.ReadAsStringAsync();
|
||||
Assert.DoesNotContain("SqliteException", content, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.DoesNotContain("SQL", content, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.DoesNotContain("Exception", content, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.DoesNotContain("password", content, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.DoesNotContain("hash", content, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.DoesNotContain("salt", content, StringComparison.OrdinalIgnoreCase);
|
||||
using JsonDocument problemDetails = JsonDocument.Parse(content);
|
||||
Assert.Equal("General.Validation", problemDetails.RootElement.GetProperty("title").GetString());
|
||||
|
||||
await _apiFactory.RemoveTestUserAsync(username);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -14,7 +14,7 @@ using System.Threading.Tasks;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.GetBooks;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/books</c> route.
|
||||
/// Contains security tests for the <see cref="GetBooksEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetBooksEndpointTests : IClassFixture<LuminaApiFactory>, IDisposable
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ using System.Threading.Tasks;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.GetBooksLite;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/books/lite</c> route.
|
||||
/// Contains security tests for the <see cref="GetBooksLiteEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetBooksLiteEndpointTests : IClassFixture<LuminaApiFactory>, IDisposable
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.Reading.GetReadingAvailability;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/books/{bookId}/reading/availability</c> route.
|
||||
/// Contains security tests for the <see cref="GetReadingAvailabilityEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetReadingAvailabilityEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ using System.Threading.Tasks;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.Reading.GetReadingManifest;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/books/{bookId}/reading/manifest</c> route.
|
||||
/// Contains security tests for the <see cref="GetReadingManifestEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetReadingManifestEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ using System.Threading.Tasks;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.Reading.GetReadingResource;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/books/{bookId}/reading/resources/{resourceKey}</c> route.
|
||||
/// Contains security tests for the <see cref="GetReadingResourceEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetReadingResourceEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ using System.Threading.Tasks;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.Reading.GetReadingSection;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/books/{bookId}/reading/sections/{locationRef}</c> route.
|
||||
/// Contains security tests for the <see cref="GetReadingSectionEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetReadingSectionEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.WrittenContentLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.UpdateBook;
|
||||
using Lumina.Presentation.Api.SecurityTests.Common.Setup;
|
||||
using System;
|
||||
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.Library.WrittenContentLibrary.BookLibrary.Books.UpdateBook;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <see cref="UpdateBookEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UpdateBookEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
{
|
||||
private readonly LuminaApiFactory _apiFactory;
|
||||
private readonly UpdateBookRequestFixture _updateBookRequestFixture = new();
|
||||
private readonly WrittenContentMetadataDtoFixture _writtenContentMetadataDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UpdateBookEndpointTests"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiFactory">Injected in-memory API factory.</param>
|
||||
public UpdateBookEndpointTests(LuminaApiFactory apiFactory)
|
||||
{
|
||||
_apiFactory = apiFactory;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateBook_WhenCalledWithoutAuthentication_ShouldReturnUnauthorized()
|
||||
{
|
||||
// Arrange
|
||||
HttpClient client = _apiFactory.CreateClient();
|
||||
UpdateBookRequest request = _updateBookRequestFixture.Create();
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await client.PutAsJsonAsync($"/api/v1/books/{request.Id}", request);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
|
||||
string content = await response.Content.ReadAsStringAsync();
|
||||
Assert.DoesNotContain("Exception", content, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("'; DROP TABLE Books; --")] // destructive injection
|
||||
[InlineData("' OR '1'='1")] // boolean-based injection
|
||||
public async Task UpdateBook_WithSQLInjectionInBody_ShouldNotCorruptOrLeakData(string maliciousTitle)
|
||||
{
|
||||
// Arrange
|
||||
HttpClient client = _apiFactory.CreateClient();
|
||||
(_, string username) = await _apiFactory.CreateAndAuthenticateUserAsync(client);
|
||||
UpdateBookRequest request = _updateBookRequestFixture.Create(metadata: _writtenContentMetadataDtoFixture.Create(title: maliciousTitle));
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await client.PutAsJsonAsync($"/api/v1/books/{request.Id}", request);
|
||||
|
||||
// Assert
|
||||
// The injected title is validated and handled by the parameterized update flow: the route book does not exist,
|
||||
// so the request fails with a clean not found response and the injected payload is never executed as SQL.
|
||||
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
||||
string content = await response.Content.ReadAsStringAsync();
|
||||
Assert.DoesNotContain("SqliteException", content, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.DoesNotContain("Exception", content, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.DoesNotContain(maliciousTitle, content, StringComparison.Ordinal);
|
||||
|
||||
await _apiFactory.RemoveTestUserAsync(username);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("'; DROP TABLE Books; --")] // destructive injection
|
||||
[InlineData("' OR '1'='1")] // boolean-based injection
|
||||
public async Task UpdateBook_WithSQLInjectionInRouteId_ShouldNeverCorruptOrLeakData(string maliciousBookId)
|
||||
{
|
||||
// Arrange
|
||||
HttpClient client = _apiFactory.CreateClient();
|
||||
(_, string username) = await _apiFactory.CreateAndAuthenticateUserAsync(client);
|
||||
UpdateBookRequest request = _updateBookRequestFixture.Create();
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await client.PutAsJsonAsync($"/api/v1/books/{Uri.EscapeDataString(maliciousBookId)}", request);
|
||||
|
||||
// Assert
|
||||
// The route is authoritative and its raw value is kept as a string, so an unparseable route Id reaches the command
|
||||
// mapping and becomes Guid.Empty, which the command validator reports as a clean validation error. The response must
|
||||
// not leak stack traces, database details, or the injected payload, and the body Id never redirects the update.
|
||||
Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode);
|
||||
string content = await response.Content.ReadAsStringAsync();
|
||||
Assert.DoesNotContain("SqliteException", content, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.DoesNotContain("Exception", content, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.DoesNotContain(maliciousBookId, content, StringComparison.Ordinal);
|
||||
using JsonDocument problemDetails = JsonDocument.Parse(content);
|
||||
Assert.Equal("General.Validation", problemDetails.RootElement.GetProperty("title").GetString());
|
||||
Assert.Contains("BookIdCannotBeEmpty", content, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
await _apiFactory.RemoveTestUserAsync(username);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateBook_WhenRouteBookDoesNotExistEvenIfBodyIdDiffers_ShouldReturnNotFound()
|
||||
{
|
||||
// Arrange
|
||||
HttpClient client = _apiFactory.CreateClient();
|
||||
(_, string username) = await _apiFactory.CreateAndAuthenticateUserAsync(client);
|
||||
Guid routeId = Guid.NewGuid();
|
||||
UpdateBookRequest request = _updateBookRequestFixture.Create();
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await client.PutAsJsonAsync($"/api/v1/books/{routeId}", request);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
||||
string content = await response.Content.ReadAsStringAsync();
|
||||
Assert.DoesNotContain("SqliteException", content, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.DoesNotContain("Exception", content, StringComparison.OrdinalIgnoreCase);
|
||||
using JsonDocument problemDetails = JsonDocument.Parse(content);
|
||||
Assert.Equal("General.NotFound", problemDetails.RootElement.GetProperty("title").GetString());
|
||||
Assert.Equal("BookNotFound", problemDetails.RootElement.GetProperty("detail").GetString());
|
||||
|
||||
await _apiFactory.RemoveTestUserAsync(username);
|
||||
}
|
||||
}
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.UpdateBookCover;
|
||||
using Lumina.Presentation.Api.SecurityTests.Common.Setup;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.UpdateBookCover;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <see cref="UpdateBookCoverEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UpdateBookCoverEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
{
|
||||
private readonly LuminaApiFactory _apiFactory;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UpdateBookCoverEndpointTests"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiFactory">Injected in-memory API factory.</param>
|
||||
public UpdateBookCoverEndpointTests(LuminaApiFactory apiFactory)
|
||||
{
|
||||
_apiFactory = apiFactory;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateBookCover_WhenCalledWithoutAuthentication_ShouldReturnUnauthorized()
|
||||
{
|
||||
// Arrange
|
||||
HttpClient client = _apiFactory.CreateClient();
|
||||
MultipartFormDataContent form = CreateCoverForm("cover.jpg");
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await client.PutAsync($"/api/v1/books/{Guid.NewGuid()}/cover", form);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
|
||||
string content = await response.Content.ReadAsStringAsync();
|
||||
Assert.DoesNotContain("Exception", content, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("'; DROP TABLE Books; --")] // destructive injection
|
||||
[InlineData("' OR '1'='1")] // boolean-based injection
|
||||
public async Task UpdateBookCover_WithSQLInjectionInRouteId_ShouldNotCorruptOrLeakData(string maliciousBookId)
|
||||
{
|
||||
// Arrange
|
||||
HttpClient client = _apiFactory.CreateClient();
|
||||
(_, string username) = await _apiFactory.CreateAndAuthenticateUserAsync(client);
|
||||
MultipartFormDataContent form = CreateCoverForm("cover.jpg");
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await client.PutAsync($"/api/v1/books/{Uri.EscapeDataString(maliciousBookId)}/cover", form);
|
||||
|
||||
// Assert
|
||||
// The unparseable route value becomes an empty book Id, which the command validator reports as a missing book Id.
|
||||
Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode);
|
||||
string content = await response.Content.ReadAsStringAsync();
|
||||
Assert.DoesNotContain("SqliteException", content, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.DoesNotContain("SQL", content, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.DoesNotContain("Exception", content, StringComparison.OrdinalIgnoreCase);
|
||||
using JsonDocument problemDetails = JsonDocument.Parse(content);
|
||||
Assert.Equal("General.Validation", problemDetails.RootElement.GetProperty("title").GetString());
|
||||
|
||||
await _apiFactory.RemoveTestUserAsync(username);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateBookCover_WithMaliciousFileName_ShouldNotCorruptOrLeakData()
|
||||
{
|
||||
// Arrange
|
||||
HttpClient client = _apiFactory.CreateClient();
|
||||
(_, string username) = await _apiFactory.CreateAndAuthenticateUserAsync(client);
|
||||
MultipartFormDataContent form = CreateCoverForm("..\\..\\evil.jpg");
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await client.PutAsync($"/api/v1/books/{Guid.NewGuid()}/cover", form);
|
||||
|
||||
// Assert
|
||||
// The book does not exist, so the handler returns a clean not found response before the uploaded file name is used.
|
||||
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
||||
string content = await response.Content.ReadAsStringAsync();
|
||||
Assert.DoesNotContain("SqliteException", content, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.DoesNotContain("Exception", content, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
await _apiFactory.RemoveTestUserAsync(username);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a multipart form carrying a minimal cover payload with the specified file name.
|
||||
/// </summary>
|
||||
/// <param name="fileName">The name of the uploaded file.</param>
|
||||
/// <returns>A configured <see cref="MultipartFormDataContent"/> instance.</returns>
|
||||
private static MultipartFormDataContent CreateCoverForm(string fileName)
|
||||
{
|
||||
MultipartFormDataContent form = [];
|
||||
ByteArrayContent fileContent = new(Encoding.UTF8.GetBytes("fake cover payload"));
|
||||
fileContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
|
||||
form.Add(fileContent, "cover", fileName);
|
||||
return form;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -7,7 +7,7 @@ using System.Net;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Maintenance.ApplicationSetup;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/initialization</c> route.
|
||||
/// Contains security tests for the <see cref="CheckInitializationEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class CheckInitializationEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ using System.Net.Http.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Maintenance.ApplicationSetup;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/initialization</c> route.
|
||||
/// Contains security tests for the <see cref="SetupApplicationEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class SetupApplicationEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-3
@@ -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.Maintenance;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/check-health</c> route.
|
||||
/// Contains security tests for the <see cref="CheckHealthEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class CheckHealthEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Plugins.GetLibraryArtworkProviders;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/libraries/{libraryId}/artwork-providers</c> route.
|
||||
/// Contains security tests for the <see cref="GetLibraryArtworkProvidersEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetLibraryArtworkProvidersEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ using System.Threading.Tasks;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Plugins.GetLibraryBookReaders;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/libraries/{libraryId}/book-readers</c> route.
|
||||
/// Contains security tests for the <see cref="GetLibraryBookReadersEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetLibraryBookReadersEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Plugins.GetLibraryMetadataProviders;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/libraries/{libraryId}/metadata-providers</c> route.
|
||||
/// Contains security tests for the <see cref="GetLibraryMetadataProvidersEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetLibraryMetadataProvidersEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Plugins.GetPluginSettings;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/plugins/{pluginId}/settings</c> route.
|
||||
/// Contains security tests for the <see cref="GetPluginSettingsEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetPluginSettingsEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ using System.Threading.Tasks;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Plugins.GetPlugins;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/plugins</c> route.
|
||||
/// Contains security tests for the <see cref="GetPluginsEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetPluginsEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+2
-2
@@ -16,7 +16,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Plugins.InstallPlugin;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>POST /api/v1/plugins</c> route.
|
||||
/// Contains security tests for the <see cref="InstallPluginEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class InstallPluginEndpointTests : IClassFixture<LuminaApiFactory>, IDisposable
|
||||
@@ -37,7 +37,7 @@ public class InstallPluginEndpointTests : 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());
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Plugins.ReorderLibraryArtworkProviders;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/libraries/{libraryId}/artwork-providers/reorder</c> route.
|
||||
/// Contains security tests for the <see cref="ReorderLibraryArtworkProvidersEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ReorderLibraryArtworkProvidersEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Plugins.ReorderLibraryMetadataProviders;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/libraries/{libraryId}/metadata-providers/reorder</c> route.
|
||||
/// Contains security tests for the <see cref="ReorderLibraryMetadataProvidersEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ReorderLibraryMetadataProvidersEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Plugins.SetLibraryArtworkProviderEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/libraries/{libraryId}/artwork-providers/{pluginId}/enabled</c> route.
|
||||
/// Contains security tests for the <see cref="SetLibraryArtworkProviderEnabledEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class SetLibraryArtworkProviderEnabledEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Plugins.SetLibraryBookReaderEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/libraries/{libraryId}/book-readers/{pluginId}/enabled</c> route.
|
||||
/// Contains security tests for the <see cref="SetLibraryBookReaderEnabledEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class SetLibraryBookReaderEnabledEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Plugins.SetLibraryMetadataProviderEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/libraries/{libraryId}/metadata-providers/{pluginId}/enabled</c> route.
|
||||
/// Contains security tests for the <see cref="SetLibraryMetadataProviderEnabledEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class SetLibraryMetadataProviderEnabledEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Plugins.UpdatePluginSettings;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/plugins/{pluginId}/settings</c> route.
|
||||
/// Contains security tests for the <see cref="UpdatePluginSettingsEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UpdatePluginSettingsEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ using System.Threading.Tasks;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.Scheduling.AddScheduledJob;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/api/v1/scheduled-jobs</c> route.
|
||||
/// Contains security tests for the <see cref="AddScheduledJobEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class AddScheduledJobEndpointTests : IClassFixture<LuminaApiFactory>, IAsyncDisposable
|
||||
|
||||
+2
-2
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
+2
-7
@@ -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}";
|
||||
}
|
||||
|
||||
+2
-4
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
+4
-6
@@ -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);
|
||||
|
||||
+4
-4
@@ -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);
|
||||
|
||||
+7
-7
@@ -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);
|
||||
|
||||
+3
-5
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
+6
-10
@@ -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);
|
||||
|
||||
+2
-2
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
+6
-6
@@ -20,7 +20,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.UsersManagement.Authentication;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/auth/change-password</c> route.
|
||||
/// Contains security tests for the <see cref="ChangePasswordEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ChangePasswordEndpointTests : IClassFixture<LuminaApiFactory>, IDisposable
|
||||
@@ -121,9 +121,9 @@ public class ChangePasswordEndpointTests : IClassFixture<LuminaApiFactory>, IDis
|
||||
HttpResponseMessage response = await _client.PostAsJsonAsync("/api/v1/auth/change-password", request);
|
||||
|
||||
// Assert
|
||||
// the malicious username is queried by GetByUsernameAsync, so it must never be executed against the database;
|
||||
// The malicious username is queried by GetByUsernameAsync, so it must never be executed against the database;
|
||||
// if a boolean-injection regression returned the only user in the database, the current password would match and
|
||||
// the password would change, so the response must be a failure and the stored password hash must be unchanged
|
||||
// the password would change, so the response must be a failure and the stored password hash must be unchanged.
|
||||
Assert.NotEqual(HttpStatusCode.OK, response.StatusCode);
|
||||
Assert.DoesNotContain("SqliteException", await response.Content.ReadAsStringAsync(), StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
@@ -157,14 +157,14 @@ public class ChangePasswordEndpointTests : IClassFixture<LuminaApiFactory>, IDis
|
||||
using IServiceScope scope = _apiFactory.Services.CreateScope();
|
||||
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
|
||||
|
||||
// create test user
|
||||
// Create test user.
|
||||
UserEntity user = _userEntityFixture.Create(username: _testUsername, password: _hashService.HashString("TestPass123!"));
|
||||
user.TotpSecret = null;
|
||||
|
||||
dbContext.Users.Add(user);
|
||||
await dbContext.SaveChangesAsync();
|
||||
|
||||
// authenticate user
|
||||
// Authenticate user.
|
||||
LoginRequest loginRequest = new(
|
||||
Username: user.Username,
|
||||
Password: "TestPass123!"
|
||||
@@ -174,7 +174,7 @@ public class ChangePasswordEndpointTests : IClassFixture<LuminaApiFactory>, IDis
|
||||
string content = await loginResponse.Content.ReadAsStringAsync();
|
||||
LoginResponse? result = JsonSerializer.Deserialize<LoginResponse>(content, _jsonOptions);
|
||||
|
||||
// set auth header for subsequent requests
|
||||
// Set auth header for subsequent requests.
|
||||
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", result!.Token);
|
||||
|
||||
return user;
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.UsersManagement.Authentication;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/auth/users</c> route.
|
||||
/// Contains security tests for the <see cref="GetUsersEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetUsersEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+8
-8
@@ -23,7 +23,7 @@ using System.Text.Json.Serialization;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.UsersManagement.Authentication;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/auth/login</c> route.
|
||||
/// Contains security tests for the <see cref="LoginEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LoginEndpointTests : IClassFixture<LuminaApiFactory>, IDisposable
|
||||
@@ -50,7 +50,7 @@ public class LoginEndpointTests : IClassFixture<LuminaApiFactory>, IDisposable
|
||||
{
|
||||
_apiFactory = apiFactory;
|
||||
_client = apiFactory.CreateClient();
|
||||
// set a fake IP for this test instance
|
||||
// Set a fake IP for this test instance.
|
||||
_client.DefaultRequestHeaders.Clear();
|
||||
_client.DefaultRequestHeaders.Add("X-Forwarded-For", $"192.168.1.1");
|
||||
_testUsername = $"testuser_{Guid.NewGuid()}";
|
||||
@@ -85,7 +85,7 @@ public class LoginEndpointTests : IClassFixture<LuminaApiFactory>, IDisposable
|
||||
DateTimeOffset tokenExpiration = DateTimeOffset.FromUnixTimeSeconds(long.Parse(expValue));
|
||||
DateTimeOffset expectedExpiration = beforeRequest.AddMinutes(15);
|
||||
|
||||
// verify token duration (should be 15 minutes from request time - expiration value is set in tests setup class)
|
||||
// Verify token duration (should be 15 minutes from request time - expiration value is set in tests setup class).
|
||||
TimeSpan allowedVariance = TimeSpan.FromSeconds(30); // allow for processing time
|
||||
TimeSpan actualDifference = tokenExpiration - beforeRequest;
|
||||
TimeSpan expectedDifference = TimeSpan.FromMinutes(15);
|
||||
@@ -146,7 +146,7 @@ public class LoginEndpointTests : IClassFixture<LuminaApiFactory>, IDisposable
|
||||
public async Task Login_WhenRateLimitExceeded_ShouldReturnTooManyRequests()
|
||||
{
|
||||
// Arrange
|
||||
// set a fake IP for this test instance
|
||||
// Set a fake IP for this test instance.
|
||||
_client.DefaultRequestHeaders.Clear();
|
||||
_client.DefaultRequestHeaders.Add("X-Forwarded-For", $"192.168.1.3");
|
||||
LoginRequest request = _loginRequestFixture.Create(
|
||||
@@ -156,7 +156,7 @@ public class LoginEndpointTests : IClassFixture<LuminaApiFactory>, IDisposable
|
||||
|
||||
// Act
|
||||
List<HttpResponseMessage> responses = [];
|
||||
for (int i = 0; i < 11; i++) // exceed the 10 request limit
|
||||
for (int i = 0; i < 11; i++) // Exceed the 10 request limit.
|
||||
responses.Add(await _client.PostAsJsonAsync("/api/v1/auth/login", request));
|
||||
|
||||
// Assert
|
||||
@@ -200,10 +200,10 @@ public class LoginEndpointTests : IClassFixture<LuminaApiFactory>, IDisposable
|
||||
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
|
||||
Assert.DoesNotContain("SQL", content);
|
||||
Assert.DoesNotContain("Exception", content);
|
||||
Assert.DoesNotContain(legitimateUser.Username, content); // shouldn't expose other usernames
|
||||
Assert.DoesNotContain(legitimateUser.Password, content); // shouldn't expose password hashes
|
||||
Assert.DoesNotContain(legitimateUser.Username, content); // Shouldn't expose other usernames.
|
||||
Assert.DoesNotContain(legitimateUser.Password, content); // Shouldn't expose password hashes.
|
||||
|
||||
// the injected statement must never be executed: the Users table and the seeded user must still be there
|
||||
// The injected statement must never be executed: the Users table and the seeded user must still be there.
|
||||
using IServiceScope scope = _apiFactory.Services.CreateScope();
|
||||
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
|
||||
Assert.NotNull(await dbContext.Users.FirstOrDefaultAsync(user => user.Id == legitimateUser.Id));
|
||||
|
||||
+6
-6
@@ -23,7 +23,7 @@ using System.Threading.Tasks;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.UsersManagement.Authentication;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/auth/recover-password</c> route.
|
||||
/// Contains security tests for the <see cref="RecoverPasswordEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class RecoverPasswordEndpointTests : IClassFixture<LuminaApiFactory>, IDisposable
|
||||
@@ -47,7 +47,7 @@ public class RecoverPasswordEndpointTests : IClassFixture<LuminaApiFactory>, IDi
|
||||
{
|
||||
_apiFactory = apiFactory;
|
||||
_client = apiFactory.CreateClient();
|
||||
// set a fake IP for this test instance
|
||||
// Set a fake IP for this test instance.
|
||||
_client.DefaultRequestHeaders.Clear();
|
||||
_client.DefaultRequestHeaders.Add("X-Forwarded-For", $"192.168.1.4");
|
||||
_testUsername = $"testuser_{Guid.NewGuid()}";
|
||||
@@ -64,7 +64,7 @@ public class RecoverPasswordEndpointTests : IClassFixture<LuminaApiFactory>, IDi
|
||||
|
||||
// Act
|
||||
List<HttpResponseMessage> responses = [];
|
||||
for (int i = 0; i < 11; i++) // exceed the 10 request limit
|
||||
for (int i = 0; i < 11; i++) // Exceed the 10 request limit.
|
||||
responses.Add(await _client.PostAsJsonAsync("/api/v1/auth/recover-password", request));
|
||||
|
||||
// Assert
|
||||
@@ -91,8 +91,8 @@ public class RecoverPasswordEndpointTests : IClassFixture<LuminaApiFactory>, IDi
|
||||
public async Task RecoverPassword_WithSQLInjectionInUsername_ShouldNotCorruptOrDeleteData(string maliciousUsername)
|
||||
{
|
||||
// Arrange
|
||||
// use a dedicated unique IP, so the rate-limit test (which exhausts the 10-permit window on its own IP)
|
||||
// cannot run first and 429 this test; the NotEqual(TooManyRequests) assertion below guards against any collision
|
||||
// Use a dedicated unique IP, so the rate-limit test (which exhausts the 10-permit window on its own IP)
|
||||
// cannot run first and 429 this test; the NotEqual(TooManyRequests) assertion below guards against any collision.
|
||||
HttpClient client = _apiFactory.CreateClient();
|
||||
client.DefaultRequestHeaders.Clear();
|
||||
client.DefaultRequestHeaders.Add("X-Forwarded-For", LuminaApiFactory.GetUniqueTestIp());
|
||||
@@ -106,7 +106,7 @@ public class RecoverPasswordEndpointTests : IClassFixture<LuminaApiFactory>, IDi
|
||||
HttpResponseMessage response = await client.PostAsJsonAsync("/api/v1/auth/recover-password", request);
|
||||
|
||||
// Assert
|
||||
// the malicious username queries for a user, so it must never be executed against the database
|
||||
// The malicious username queries for a user, so it must never be executed against the database.
|
||||
Assert.NotEqual(HttpStatusCode.TooManyRequests, response.StatusCode);
|
||||
Assert.DoesNotContain("SqliteException", await response.Content.ReadAsStringAsync(), StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
|
||||
+3
-3
@@ -18,7 +18,7 @@ using System.Text.Json.Serialization;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.UsersManagement.Authentication;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/auth/register</c> route.
|
||||
/// Contains security tests for the <see cref="RegisterEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class RegisterEndpointTests : IClassFixture<LuminaApiFactory>, IDisposable
|
||||
@@ -114,8 +114,8 @@ public class RegisterEndpointTests : IClassFixture<LuminaApiFactory>, IDisposabl
|
||||
public async Task Register_WithSQLInjectionAttempt_ShouldRemainSecure(string maliciousUsername)
|
||||
{
|
||||
// Arrange
|
||||
// note: the register validator rejects these usernames (invalid username format) with 422 before any DB access,
|
||||
// so the malicious username never reaches a query; the 422 assertion below is the security guarantee
|
||||
// Note: the register validator rejects these usernames (invalid username format) with 422 before any DB access,
|
||||
// so the malicious username never reaches a query; the 422 assertion below is the security guarantee.
|
||||
RegistrationRequest request = _registrationRequestFixture.Create(
|
||||
username: maliciousUsername,
|
||||
password: "TestPass123!",
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.UsersManagement.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/auth/get-authorization</c> route.
|
||||
/// Contains security tests for the <see cref="GetAuthorizationEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetAuthorizationEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.UsersManagement.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/auth/users/{userId}/permissions</c> route.
|
||||
/// Contains security tests for the <see cref="GetUserPermissionsEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetUserPermissionsEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.UsersManagement.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/auth/users/{userId}/role</c> route.
|
||||
/// Contains security tests for the <see cref="GetUserRoleEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetUserRoleEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.UsersManagement.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/auth/users/{userId}/role-and-permissions</c> route.
|
||||
/// Contains security tests for the <see cref="UpdateUserRoleAndPermissionsEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UpdateUserRoleAndPermissionsEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.UsersManagement.Settings.GetUserSettings;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/users/me/settings</c> route.
|
||||
/// Contains security tests for the <see cref="GetUserSettingsEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetUserSettingsEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ using System.Text.Json;
|
||||
namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.UsersManagement.Settings.UpdateUserSettings;
|
||||
|
||||
/// <summary>
|
||||
/// Contains security tests for the <c>/users/me/settings</c> route.
|
||||
/// Contains security tests for the <see cref="UpdateUserSettingsEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UpdateUserSettingsEndpointTests : IClassFixture<LuminaApiFactory>
|
||||
|
||||
Reference in new issue
Block a user