diff --git a/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Directories/GetDirectoriesEndpointTests.cs b/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Directories/GetDirectoriesEndpointTests.cs new file mode 100644 index 00000000..77ab4939 --- /dev/null +++ b/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Directories/GetDirectoriesEndpointTests.cs @@ -0,0 +1,52 @@ +#region ========================================================================= USING ===================================================================================== +using FluentAssertions; +using Lumina.Presentation.Api.SecurityTests.Common.Setup; +using Microsoft.AspNetCore.Http; +using System.Diagnostics.CodeAnalysis; +using System.Net; +using System.Text.Json; +#endregion + +namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.FileSystemManagement.Directories; + +/// +/// Contains security tests for the /directories/get-directories route. +/// +[ExcludeFromCodeCoverage] +public class GetDirectoriesEndpointTests : IClassFixture +{ + private readonly HttpClient _client; + private readonly JsonSerializerOptions _jsonOptions = new() + { + PropertyNameCaseInsensitive = true + }; + + /// + /// Initializes a new instance of the class. + /// + /// Injected in-memory API factory. + public GetDirectoriesEndpointTests(LuminaApiFactory apiFactory) + { + _client = apiFactory.CreateClient(); + } + + [Fact] + public async Task GetDirectories_WhenUnauthorized_ShouldReturnUnauthorizedResult() + { + // Act + HttpResponseMessage response = await _client.GetAsync("/api/v1/directories/get-directories"); + + // Assert + response.StatusCode.Should().Be(HttpStatusCode.Unauthorized); + + string content = await response.Content.ReadAsStringAsync(); + + Dictionary? problemDetails = JsonSerializer.Deserialize>(content, _jsonOptions); + problemDetails.Should().NotBeNull(); + problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized); + problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1"); + problemDetails["title"].GetString().Should().Be("Unauthorized"); + problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/directories/get-directories"); + problemDetails["detail"].GetString().Should().Be("Authentication failed"); + } +} diff --git a/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Directories/GetDirectoryTreeEndpointTests.cs b/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Directories/GetDirectoryTreeEndpointTests.cs new file mode 100644 index 00000000..c68c9431 --- /dev/null +++ b/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Directories/GetDirectoryTreeEndpointTests.cs @@ -0,0 +1,52 @@ +#region ========================================================================= USING ===================================================================================== +using FluentAssertions; +using Lumina.Presentation.Api.SecurityTests.Common.Setup; +using Microsoft.AspNetCore.Http; +using System.Diagnostics.CodeAnalysis; +using System.Net; +using System.Text.Json; +#endregion + +namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.FileSystemManagement.Directories; + +/// +/// Contains security tests for the /directories/get-directory-tree route. +/// +[ExcludeFromCodeCoverage] +public class GetDirectoryTreeEndpointTests : IClassFixture +{ + private readonly HttpClient _client; + private readonly JsonSerializerOptions _jsonOptions = new() + { + PropertyNameCaseInsensitive = true + }; + + /// + /// Initializes a new instance of the class. + /// + /// Injected in-memory API factory. + public GetDirectoryTreeEndpointTests(LuminaApiFactory apiFactory) + { + _client = apiFactory.CreateClient(); + } + + [Fact] + public async Task GetDirectoryTree_WhenUnauthorized_ShouldReturnUnauthorizedResult() + { + // Act + HttpResponseMessage response = await _client.GetAsync("/api/v1/directories/get-directory-tree"); + + // Assert + response.StatusCode.Should().Be(HttpStatusCode.Unauthorized); + + string content = await response.Content.ReadAsStringAsync(); + + Dictionary? problemDetails = JsonSerializer.Deserialize>(content, _jsonOptions); + problemDetails.Should().NotBeNull(); + problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized); + problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1"); + problemDetails["title"].GetString().Should().Be("Unauthorized"); + problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/directories/get-directory-tree"); + problemDetails["detail"].GetString().Should().Be("Authentication failed"); + } +} diff --git a/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Directories/GetTreeDirectoriesEndpointTests.cs b/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Directories/GetTreeDirectoriesEndpointTests.cs new file mode 100644 index 00000000..95522397 --- /dev/null +++ b/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Directories/GetTreeDirectoriesEndpointTests.cs @@ -0,0 +1,52 @@ +#region ========================================================================= USING ===================================================================================== +using FluentAssertions; +using Lumina.Presentation.Api.SecurityTests.Common.Setup; +using Microsoft.AspNetCore.Http; +using System.Diagnostics.CodeAnalysis; +using System.Net; +using System.Text.Json; +#endregion + +namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.FileSystemManagement.Directories; + +/// +/// Contains security tests for the /directories/get-tree-directories route. +/// +[ExcludeFromCodeCoverage] +public class GetTreeDirectoriesEndpointTests : IClassFixture +{ + private readonly HttpClient _client; + private readonly JsonSerializerOptions _jsonOptions = new() + { + PropertyNameCaseInsensitive = true + }; + + /// + /// Initializes a new instance of the class. + /// + /// Injected in-memory API factory. + public GetTreeDirectoriesEndpointTests(LuminaApiFactory apiFactory) + { + _client = apiFactory.CreateClient(); + } + + [Fact] + public async Task GetTreeDirectories_WhenUnauthorized_ShouldReturnUnauthorizedResult() + { + // Act + HttpResponseMessage response = await _client.GetAsync("/api/v1/directories/get-tree-directories"); + + // Assert + response.StatusCode.Should().Be(HttpStatusCode.Unauthorized); + + string content = await response.Content.ReadAsStringAsync(); + + Dictionary? problemDetails = JsonSerializer.Deserialize>(content, _jsonOptions); + problemDetails.Should().NotBeNull(); + problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized); + problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1"); + problemDetails["title"].GetString().Should().Be("Unauthorized"); + problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/directories/get-tree-directories"); + problemDetails["detail"].GetString().Should().Be("Authentication failed"); + } +} diff --git a/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Drives/GetDrivesEndpointTests.cs b/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Drives/GetDrivesEndpointTests.cs new file mode 100644 index 00000000..a24884f8 --- /dev/null +++ b/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Drives/GetDrivesEndpointTests.cs @@ -0,0 +1,52 @@ +#region ========================================================================= USING ===================================================================================== +using FluentAssertions; +using Lumina.Presentation.Api.SecurityTests.Common.Setup; +using Microsoft.AspNetCore.Http; +using System.Diagnostics.CodeAnalysis; +using System.Net; +using System.Text.Json; +#endregion + +namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.FileSystemManagement.Drives; + +/// +/// Contains security tests for the /drives/get-drives route. +/// +[ExcludeFromCodeCoverage] +public class GetDrivesEndpointTests : IClassFixture +{ + private readonly HttpClient _client; + private readonly JsonSerializerOptions _jsonOptions = new() + { + PropertyNameCaseInsensitive = true + }; + + /// + /// Initializes a new instance of the class. + /// + /// Injected in-memory API factory. + public GetDrivesEndpointTests(LuminaApiFactory apiFactory) + { + _client = apiFactory.CreateClient(); + } + + [Fact] + public async Task GetDrives_WhenUnauthorized_ShouldReturnUnauthorizedResult() + { + // Act + HttpResponseMessage response = await _client.GetAsync("/api/v1/drives/get-drives"); + + // Assert + response.StatusCode.Should().Be(HttpStatusCode.Unauthorized); + + string content = await response.Content.ReadAsStringAsync(); + + Dictionary? problemDetails = JsonSerializer.Deserialize>(content, _jsonOptions); + problemDetails.Should().NotBeNull(); + problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized); + problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1"); + problemDetails["title"].GetString().Should().Be("Unauthorized"); + problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/drives/get-drives"); + problemDetails["detail"].GetString().Should().Be("Authentication failed"); + } +} diff --git a/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/FileSystem/GetTypeEndpointTests.cs b/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/FileSystem/GetTypeEndpointTests.cs new file mode 100644 index 00000000..b8671a4e --- /dev/null +++ b/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/FileSystem/GetTypeEndpointTests.cs @@ -0,0 +1,52 @@ +#region ========================================================================= USING ===================================================================================== +using FluentAssertions; +using Lumina.Presentation.Api.SecurityTests.Common.Setup; +using Microsoft.AspNetCore.Http; +using System.Diagnostics.CodeAnalysis; +using System.Net; +using System.Text.Json; +#endregion + +namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.FileSystemManagement.FileSystem; + +/// +/// Contains security tests for the /file-system/get-type route. +/// +[ExcludeFromCodeCoverage] +public class GetTypeEndpointTests : IClassFixture +{ + private readonly HttpClient _client; + private readonly JsonSerializerOptions _jsonOptions = new() + { + PropertyNameCaseInsensitive = true + }; + + /// + /// Initializes a new instance of the class. + /// + /// Injected in-memory API factory. + public GetTypeEndpointTests(LuminaApiFactory apiFactory) + { + _client = apiFactory.CreateClient(); + } + + [Fact] + public async Task GetType_WhenUnauthorized_ShouldReturnUnauthorizedResult() + { + // Act + HttpResponseMessage response = await _client.GetAsync("/api/v1/file-system/get-type"); + + // Assert + response.StatusCode.Should().Be(HttpStatusCode.Unauthorized); + + string content = await response.Content.ReadAsStringAsync(); + + Dictionary? problemDetails = JsonSerializer.Deserialize>(content, _jsonOptions); + problemDetails.Should().NotBeNull(); + problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized); + problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1"); + problemDetails["title"].GetString().Should().Be("Unauthorized"); + problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/file-system/get-type"); + problemDetails["detail"].GetString().Should().Be("Authentication failed"); + } +} diff --git a/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Files/GetFilesEndpointTests.cs b/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Files/GetFilesEndpointTests.cs new file mode 100644 index 00000000..469e281e --- /dev/null +++ b/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Files/GetFilesEndpointTests.cs @@ -0,0 +1,52 @@ +#region ========================================================================= USING ===================================================================================== +using FluentAssertions; +using Lumina.Presentation.Api.SecurityTests.Common.Setup; +using Microsoft.AspNetCore.Http; +using System.Diagnostics.CodeAnalysis; +using System.Net; +using System.Text.Json; +#endregion + +namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.FileSystemManagement.Files; + +/// +/// Contains security tests for the /files/get-files route. +/// +[ExcludeFromCodeCoverage] +public class GetFilesEndpointTests : IClassFixture +{ + private readonly HttpClient _client; + private readonly JsonSerializerOptions _jsonOptions = new() + { + PropertyNameCaseInsensitive = true + }; + + /// + /// Initializes a new instance of the class. + /// + /// Injected in-memory API factory. + public GetFilesEndpointTests(LuminaApiFactory apiFactory) + { + _client = apiFactory.CreateClient(); + } + + [Fact] + public async Task GetFiles_WhenUnauthorized_ShouldReturnUnauthorizedResult() + { + // Act + HttpResponseMessage response = await _client.GetAsync("/api/v1/files/get-files"); + + // Assert + response.StatusCode.Should().Be(HttpStatusCode.Unauthorized); + + string content = await response.Content.ReadAsStringAsync(); + + Dictionary? problemDetails = JsonSerializer.Deserialize>(content, _jsonOptions); + problemDetails.Should().NotBeNull(); + problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized); + problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1"); + problemDetails["title"].GetString().Should().Be("Unauthorized"); + problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/files/get-files"); + problemDetails["detail"].GetString().Should().Be("Authentication failed"); + } +} diff --git a/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Files/GetTreeFilesEndpointTests.cs b/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Files/GetTreeFilesEndpointTests.cs new file mode 100644 index 00000000..f5180c0e --- /dev/null +++ b/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Files/GetTreeFilesEndpointTests.cs @@ -0,0 +1,52 @@ +#region ========================================================================= USING ===================================================================================== +using FluentAssertions; +using Lumina.Presentation.Api.SecurityTests.Common.Setup; +using Microsoft.AspNetCore.Http; +using System.Diagnostics.CodeAnalysis; +using System.Net; +using System.Text.Json; +#endregion + +namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.FileSystemManagement.Files; + +/// +/// Contains security tests for the /files/get-tree-files route. +/// +[ExcludeFromCodeCoverage] +public class GetTreeFilesEndpointTests : IClassFixture +{ + private readonly HttpClient _client; + private readonly JsonSerializerOptions _jsonOptions = new() + { + PropertyNameCaseInsensitive = true + }; + + /// + /// Initializes a new instance of the class. + /// + /// Injected in-memory API factory. + public GetTreeFilesEndpointTests(LuminaApiFactory apiFactory) + { + _client = apiFactory.CreateClient(); + } + + [Fact] + public async Task GetTreeFiles_WhenUnauthorized_ShouldReturnUnauthorizedResult() + { + // Act + HttpResponseMessage response = await _client.GetAsync("/api/v1/files/get-tree-files"); + + // Assert + response.StatusCode.Should().Be(HttpStatusCode.Unauthorized); + + string content = await response.Content.ReadAsStringAsync(); + + Dictionary? problemDetails = JsonSerializer.Deserialize>(content, _jsonOptions); + problemDetails.Should().NotBeNull(); + problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized); + problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1"); + problemDetails["title"].GetString().Should().Be("Unauthorized"); + problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/files/get-tree-files"); + problemDetails["detail"].GetString().Should().Be("Authentication failed"); + } +} diff --git a/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Path/CheckPathExistsEndpointTests.cs b/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Path/CheckPathExistsEndpointTests.cs new file mode 100644 index 00000000..19fe6fc4 --- /dev/null +++ b/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Path/CheckPathExistsEndpointTests.cs @@ -0,0 +1,52 @@ +#region ========================================================================= USING ===================================================================================== +using FluentAssertions; +using Lumina.Presentation.Api.SecurityTests.Common.Setup; +using Microsoft.AspNetCore.Http; +using System.Diagnostics.CodeAnalysis; +using System.Net; +using System.Text.Json; +#endregion + +namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.FileSystemManagement.Path; + +/// +/// Contains security tests for the /path/check-path-exists route. +/// +[ExcludeFromCodeCoverage] +public class CheckPathExistsEndpointTests : IClassFixture +{ + private readonly HttpClient _client; + private readonly JsonSerializerOptions _jsonOptions = new() + { + PropertyNameCaseInsensitive = true + }; + + /// + /// Initializes a new instance of the class. + /// + /// Injected in-memory API factory. + public CheckPathExistsEndpointTests(LuminaApiFactory apiFactory) + { + _client = apiFactory.CreateClient(); + } + + [Fact] + public async Task CheckPathExists_WhenUnauthorized_ShouldReturnUnauthorizedResult() + { + // Act + HttpResponseMessage response = await _client.GetAsync("/api/v1/path/check-path-exists"); + + // Assert + response.StatusCode.Should().Be(HttpStatusCode.Unauthorized); + + string content = await response.Content.ReadAsStringAsync(); + + Dictionary? problemDetails = JsonSerializer.Deserialize>(content, _jsonOptions); + problemDetails.Should().NotBeNull(); + problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized); + problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1"); + problemDetails["title"].GetString().Should().Be("Unauthorized"); + problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/path/check-path-exists"); + problemDetails["detail"].GetString().Should().Be("Authentication failed"); + } +} diff --git a/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Path/CombinePathEndpointTests.cs b/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Path/CombinePathEndpointTests.cs new file mode 100644 index 00000000..aaf688b0 --- /dev/null +++ b/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Path/CombinePathEndpointTests.cs @@ -0,0 +1,52 @@ +#region ========================================================================= USING ===================================================================================== +using FluentAssertions; +using Lumina.Presentation.Api.SecurityTests.Common.Setup; +using Microsoft.AspNetCore.Http; +using System.Diagnostics.CodeAnalysis; +using System.Net; +using System.Text.Json; +#endregion + +namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.FileSystemManagement.Path; + +/// +/// Contains security tests for the /path/combine route. +/// +[ExcludeFromCodeCoverage] +public class CombinePathEndpointTests : IClassFixture +{ + private readonly HttpClient _client; + private readonly JsonSerializerOptions _jsonOptions = new() + { + PropertyNameCaseInsensitive = true + }; + + /// + /// Initializes a new instance of the class. + /// + /// Injected in-memory API factory. + public CombinePathEndpointTests(LuminaApiFactory apiFactory) + { + _client = apiFactory.CreateClient(); + } + + [Fact] + public async Task CombinePath_WhenUnauthorized_ShouldReturnUnauthorizedResult() + { + // Act + HttpResponseMessage response = await _client.GetAsync("/api/v1/path/combine"); + + // Assert + response.StatusCode.Should().Be(HttpStatusCode.Unauthorized); + + string content = await response.Content.ReadAsStringAsync(); + + Dictionary? problemDetails = JsonSerializer.Deserialize>(content, _jsonOptions); + problemDetails.Should().NotBeNull(); + problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized); + problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1"); + problemDetails["title"].GetString().Should().Be("Unauthorized"); + problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/path/combine"); + problemDetails["detail"].GetString().Should().Be("Authentication failed"); + } +} diff --git a/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Path/GetPathParentEndpointTests.cs b/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Path/GetPathParentEndpointTests.cs new file mode 100644 index 00000000..f345a64a --- /dev/null +++ b/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Path/GetPathParentEndpointTests.cs @@ -0,0 +1,52 @@ +#region ========================================================================= USING ===================================================================================== +using FluentAssertions; +using Lumina.Presentation.Api.SecurityTests.Common.Setup; +using Microsoft.AspNetCore.Http; +using System.Diagnostics.CodeAnalysis; +using System.Net; +using System.Text.Json; +#endregion + +namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.FileSystemManagement.Path; + +/// +/// Contains security tests for the /path/get-path-parent route. +/// +[ExcludeFromCodeCoverage] +public class GetPathParentEndpointTests : IClassFixture +{ + private readonly HttpClient _client; + private readonly JsonSerializerOptions _jsonOptions = new() + { + PropertyNameCaseInsensitive = true + }; + + /// + /// Initializes a new instance of the class. + /// + /// Injected in-memory API factory. + public GetPathParentEndpointTests(LuminaApiFactory apiFactory) + { + _client = apiFactory.CreateClient(); + } + + [Fact] + public async Task GetPathParent_WhenUnauthorized_ShouldReturnUnauthorizedResult() + { + // Act + HttpResponseMessage response = await _client.GetAsync("/api/v1/path/get-path-parent"); + + // Assert + response.StatusCode.Should().Be(HttpStatusCode.Unauthorized); + + string content = await response.Content.ReadAsStringAsync(); + + Dictionary? problemDetails = JsonSerializer.Deserialize>(content, _jsonOptions); + problemDetails.Should().NotBeNull(); + problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized); + problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1"); + problemDetails["title"].GetString().Should().Be("Unauthorized"); + problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/path/get-path-parent"); + problemDetails["detail"].GetString().Should().Be("Authentication failed"); + } +} diff --git a/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Path/GetPathRootEndpointTests.cs b/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Path/GetPathRootEndpointTests.cs new file mode 100644 index 00000000..ecaf1d29 --- /dev/null +++ b/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Path/GetPathRootEndpointTests.cs @@ -0,0 +1,52 @@ +#region ========================================================================= USING ===================================================================================== +using FluentAssertions; +using Lumina.Presentation.Api.SecurityTests.Common.Setup; +using Microsoft.AspNetCore.Http; +using System.Diagnostics.CodeAnalysis; +using System.Net; +using System.Text.Json; +#endregion + +namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.FileSystemManagement.Path; + +/// +/// Contains security tests for the /path/get-path-root route. +/// +[ExcludeFromCodeCoverage] +public class GetPathRootEndpointTests : IClassFixture +{ + private readonly HttpClient _client; + private readonly JsonSerializerOptions _jsonOptions = new() + { + PropertyNameCaseInsensitive = true + }; + + /// + /// Initializes a new instance of the class. + /// + /// Injected in-memory API factory. + public GetPathRootEndpointTests(LuminaApiFactory apiFactory) + { + _client = apiFactory.CreateClient(); + } + + [Fact] + public async Task GetPathRoot_WhenUnauthorized_ShouldReturnUnauthorizedResult() + { + // Act + HttpResponseMessage response = await _client.GetAsync("/api/v1/path/get-path-root"); + + // Assert + response.StatusCode.Should().Be(HttpStatusCode.Unauthorized); + + string content = await response.Content.ReadAsStringAsync(); + + Dictionary? problemDetails = JsonSerializer.Deserialize>(content, _jsonOptions); + problemDetails.Should().NotBeNull(); + problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized); + problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1"); + problemDetails["title"].GetString().Should().Be("Unauthorized"); + problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/path/get-path-root"); + problemDetails["detail"].GetString().Should().Be("Authentication failed"); + } +} diff --git a/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Path/GetPathSeparatorEndpointTests.cs b/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Path/GetPathSeparatorEndpointTests.cs new file mode 100644 index 00000000..a0dee181 --- /dev/null +++ b/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Path/GetPathSeparatorEndpointTests.cs @@ -0,0 +1,52 @@ +#region ========================================================================= USING ===================================================================================== +using FluentAssertions; +using Lumina.Presentation.Api.SecurityTests.Common.Setup; +using Microsoft.AspNetCore.Http; +using System.Diagnostics.CodeAnalysis; +using System.Net; +using System.Text.Json; +#endregion + +namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.FileSystemManagement.Path; + +/// +/// Contains security tests for the /path/get-path-separator route. +/// +[ExcludeFromCodeCoverage] +public class GetPathSeparatorEndpointTests : IClassFixture +{ + private readonly HttpClient _client; + private readonly JsonSerializerOptions _jsonOptions = new() + { + PropertyNameCaseInsensitive = true + }; + + /// + /// Initializes a new instance of the class. + /// + /// Injected in-memory API factory. + public GetPathSeparatorEndpointTests(LuminaApiFactory apiFactory) + { + _client = apiFactory.CreateClient(); + } + + [Fact] + public async Task GetPathSeparator_WhenUnauthorized_ShouldReturnUnauthorizedResult() + { + // Act + HttpResponseMessage response = await _client.GetAsync("/api/v1/path/get-path-separator"); + + // Assert + response.StatusCode.Should().Be(HttpStatusCode.Unauthorized); + + string content = await response.Content.ReadAsStringAsync(); + + Dictionary? problemDetails = JsonSerializer.Deserialize>(content, _jsonOptions); + problemDetails.Should().NotBeNull(); + problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized); + problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1"); + problemDetails["title"].GetString().Should().Be("Unauthorized"); + problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/path/get-path-separator"); + problemDetails["detail"].GetString().Should().Be("Authentication failed"); + } +} diff --git a/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Path/SplitPathEndpointTests.cs b/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Path/SplitPathEndpointTests.cs new file mode 100644 index 00000000..aaeff265 --- /dev/null +++ b/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Path/SplitPathEndpointTests.cs @@ -0,0 +1,52 @@ +#region ========================================================================= USING ===================================================================================== +using FluentAssertions; +using Lumina.Presentation.Api.SecurityTests.Common.Setup; +using Microsoft.AspNetCore.Http; +using System.Diagnostics.CodeAnalysis; +using System.Net; +using System.Text.Json; +#endregion + +namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.FileSystemManagement.Path; + +/// +/// Contains security tests for the /path/split route. +/// +[ExcludeFromCodeCoverage] +public class SplitPathEndpointTests : IClassFixture +{ + private readonly HttpClient _client; + private readonly JsonSerializerOptions _jsonOptions = new() + { + PropertyNameCaseInsensitive = true + }; + + /// + /// Initializes a new instance of the class. + /// + /// Injected in-memory API factory. + public SplitPathEndpointTests(LuminaApiFactory apiFactory) + { + _client = apiFactory.CreateClient(); + } + + [Fact] + public async Task SplitPath_WhenUnauthorized_ShouldReturnUnauthorizedResult() + { + // Act + HttpResponseMessage response = await _client.GetAsync("/api/v1/path/split"); + + // Assert + response.StatusCode.Should().Be(HttpStatusCode.Unauthorized); + + string content = await response.Content.ReadAsStringAsync(); + + Dictionary? problemDetails = JsonSerializer.Deserialize>(content, _jsonOptions); + problemDetails.Should().NotBeNull(); + problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized); + problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1"); + problemDetails["title"].GetString().Should().Be("Unauthorized"); + problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/path/split"); + problemDetails["detail"].GetString().Should().Be("Authentication failed"); + } +} diff --git a/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Path/ValidatePathEndpointTests.cs b/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Path/ValidatePathEndpointTests.cs new file mode 100644 index 00000000..89f16ee8 --- /dev/null +++ b/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Path/ValidatePathEndpointTests.cs @@ -0,0 +1,52 @@ +#region ========================================================================= USING ===================================================================================== +using FluentAssertions; +using Lumina.Presentation.Api.SecurityTests.Common.Setup; +using Microsoft.AspNetCore.Http; +using System.Diagnostics.CodeAnalysis; +using System.Net; +using System.Text.Json; +#endregion + +namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.FileSystemManagement.Path; + +/// +/// Contains security tests for the /path/validate route. +/// +[ExcludeFromCodeCoverage] +public class ValidatePathEndpointTests : IClassFixture +{ + private readonly HttpClient _client; + private readonly JsonSerializerOptions _jsonOptions = new() + { + PropertyNameCaseInsensitive = true + }; + + /// + /// Initializes a new instance of the class. + /// + /// Injected in-memory API factory. + public ValidatePathEndpointTests(LuminaApiFactory apiFactory) + { + _client = apiFactory.CreateClient(); + } + + [Fact] + public async Task ValidatePath_WhenUnauthorized_ShouldReturnUnauthorizedResult() + { + // Act + HttpResponseMessage response = await _client.GetAsync("/api/v1/path/validate"); + + // Assert + response.StatusCode.Should().Be(HttpStatusCode.Unauthorized); + + string content = await response.Content.ReadAsStringAsync(); + + Dictionary? problemDetails = JsonSerializer.Deserialize>(content, _jsonOptions); + problemDetails.Should().NotBeNull(); + problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized); + problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1"); + problemDetails["title"].GetString().Should().Be("Unauthorized"); + problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/path/validate"); + problemDetails["detail"].GetString().Should().Be("Authentication failed"); + } +} diff --git a/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Thumbnails/GetThumbnailEndpointTests.cs b/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Thumbnails/GetThumbnailEndpointTests.cs new file mode 100644 index 00000000..1e85f3fb --- /dev/null +++ b/tests/SecurityTests/Lumina.Presentation.Api.SecurityTests/Core/Endpoints/FileSystemManagement/Thumbnails/GetThumbnailEndpointTests.cs @@ -0,0 +1,52 @@ +#region ========================================================================= USING ===================================================================================== +using FluentAssertions; +using Lumina.Presentation.Api.SecurityTests.Common.Setup; +using Microsoft.AspNetCore.Http; +using System.Diagnostics.CodeAnalysis; +using System.Net; +using System.Text.Json; +#endregion + +namespace Lumina.Presentation.Api.SecurityTests.Core.Endpoints.FileSystemManagement.Thumbnails; + +/// +/// Contains security tests for the /thumbnails/get-thumbnail route. +/// +[ExcludeFromCodeCoverage] +public class GetThumbnailEndpointTests : IClassFixture +{ + private readonly HttpClient _client; + private readonly JsonSerializerOptions _jsonOptions = new() + { + PropertyNameCaseInsensitive = true + }; + + /// + /// Initializes a new instance of the class. + /// + /// Injected in-memory API factory. + public GetThumbnailEndpointTests(LuminaApiFactory apiFactory) + { + _client = apiFactory.CreateClient(); + } + + [Fact] + public async Task GetThumbnail_WhenUnauthorized_ShouldReturnUnauthorizedResult() + { + // Act + HttpResponseMessage response = await _client.GetAsync("/api/v1/thumbnails/get-thumbnail"); + + // Assert + response.StatusCode.Should().Be(HttpStatusCode.Unauthorized); + + string content = await response.Content.ReadAsStringAsync(); + + Dictionary? problemDetails = JsonSerializer.Deserialize>(content, _jsonOptions); + problemDetails.Should().NotBeNull(); + problemDetails!["status"].GetInt32().Should().Be(StatusCodes.Status401Unauthorized); + problemDetails["type"].GetString().Should().Be("https://tools.ietf.org/html/rfc7235#section-3.1"); + problemDetails["title"].GetString().Should().Be("Unauthorized"); + problemDetails["instance"].GetProperty("value").GetString().Should().Be("/api/v1/thumbnails/get-thumbnail"); + problemDetails["detail"].GetString().Should().Be("Authentication failed"); + } +}