Adds SlpModularCms.Api.SlpSoftware and extracts shared CmsHost composition
Continuous Integration / config (pull_request) Successful in 11s
Continuous Integration / changes (pull_request) Successful in 21s
Continuous Integration / backend-build (pull_request) Successful in 6m10s
Continuous Integration / vulnerability-scan (pull_request) Successful in 4m59s
Continuous Integration / frontend-prepare (pull_request) Successful in 1m27s
Continuous Integration / backend-test (pull_request) Failing after 7m48s
Continuous Integration / frontend-build (pull_request) Successful in 2m5s
Continuous Integration / frontend-test (pull_request) Successful in 4m24s
Continuous Integration / frontend-lint (pull_request) Successful in 2m0s
Continuous Integration / publish-test (pull_request) Skipped
Continuous Integration / publish-production (pull_request) Skipped
Continuous Integration / deploy-test (pull_request) Skipped
Continuous Integration / deploy-production (pull_request) Skipped

Unit 1 of the slpsoftware-api feature (FR-1/FR-2/FR-3): a new Client project
in the Clients solution folder, intended to eventually become the deployed
API for test.slpsoftware.nl/slpsoftware.nl, hosting the same four modules as
SlpModularCms.Api plus a future Offerings module.

- Extracts SlpModularCms.Api/Program.cs's hosting-pipeline composition into
  SlpModularCms.Core.Hosting.CmsHost (ConfigureServices/ConfigurePipeline),
  shared by both Client projects so they cannot drift apart
- Moves StaticContentExtensions.cs + WebsitePlaceholder.html from Api into
  Core, since CmsHost cannot live in Api but Core cannot depend on Api
- Adds SlpModularCms.Api.SlpSoftware with its own isolated local dev database
  and dev ports (5286/7223, distinct from Api's and Api.Slave's)
- Adds SlpModularCms.Api.Tests with WebApplicationFactory-based pipeline
  regression tests (security headers, health check, SPA fallback, rate
  limiting), scoped to Api per NFR Design
- Adds a frontend dev:slpsoftware pnpm script mirroring dev:slave
- Fixes GlobalExceptionHandler logging routine 401s (e.g. an expired/missing
  refresh token) as unhandled errors -- pre-existing, unrelated to this
  feature's own scope, found while testing the new instance

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FWyStNL2ZsjrS7FLd7xvvN
This commit is contained in:
2026-08-02 01:28:39 +02:00
co-authored by Claude Sonnet 5
parent dcc82cdf62
commit fa389e42ee
51 changed files with 3119 additions and 127 deletions
@@ -0,0 +1,106 @@
using System.Net;
using FluentAssertions;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
namespace SlpModularCms.Api.Tests;
/// <summary>
/// Regression guard for the hosting pipeline extracted into <c>CmsHost</c> (NFR-CS-01).
/// </summary>
/// <remarks>
/// Requires a reachable local MariaDB matching <c>SlpModularCms.Api/appsettings.Development.json</c>
/// (the same one a developer needs to run <c>SlpModularCms.Api</c> locally, per the root README) —
/// <c>CmsHost.ConfigurePipeline</c> runs a startup database migration before any endpoint is
/// reachable, so there is no way to exercise the real pipeline without it.
/// </remarks>
public class ApiWebApplicationFactory : WebApplicationFactory<Program>
{
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
// Development, not the default: the Production connection string in appsettings.json is a
// placeholder host, and the startup migration would fail before any endpoint could be
// tested. This also means Strict-Transport-Security is deliberately absent in these tests
// — see SecurityHeadersMiddleware's constructor comment — which is asserted below, not
// worked around.
builder.UseEnvironment("Development");
}
}
public class PipelineTests : IClassFixture<ApiWebApplicationFactory>
{
private readonly ApiWebApplicationFactory _factory;
public PipelineTests(ApiWebApplicationFactory factory)
{
_factory = factory;
}
[Fact]
public async Task Health_endpoint_is_reachable()
{
var client = _factory.CreateClient();
var response = await client.GetAsync("/health");
response.IsSuccessStatusCode.Should().BeTrue();
}
[Fact]
public async Task Html_response_carries_the_required_security_headers()
{
var client = _factory.CreateClient();
// A non-file, non-admin path with no website deployed falls through to the built-in
// placeholder (StaticContentExtensions.WritePlaceholderAsync) — an HTML response that does
// not depend on any built frontend/admin assets being present in this test run.
var response = await client.GetAsync("/some-page-that-does-not-exist");
response.Content.Headers.ContentType?.MediaType.Should().Be("text/html");
response.Headers.TryGetValues("X-Content-Type-Options", out _).Should().BeTrue();
response.Headers.TryGetValues("Content-Security-Policy", out _).Should().BeTrue();
response.Headers.TryGetValues("X-Frame-Options", out _).Should().BeTrue();
response.Headers.TryGetValues("Referrer-Policy", out _).Should().BeTrue();
// Deliberately NOT asserting presence: SecurityHeadersMiddleware intentionally skips HSTS
// in Development (localhost is shared with every other local project), so its ABSENCE
// here is the correct, tested behavior, not an oversight.
response.Headers.TryGetValues("Strict-Transport-Security", out _).Should().BeFalse();
}
[Fact]
public async Task Admin_spa_fallback_returns_not_found_when_no_admin_build_is_present()
{
var client = _factory.CreateClient();
// No frontend/dist build exists in this test run, so the admin mount's fallback correctly
// 404s rather than serving something else — this proves the /admin fallback route itself
// is registered and reachable (a broken registration, or the wrong ordering relative to
// the website's own fallback, would surface as a different status code or as the website
// placeholder being served under /admin instead).
var response = await client.GetAsync("/admin/some-page-that-does-not-exist");
response.StatusCode.Should().Be(HttpStatusCode.NotFound);
}
[Fact]
public async Task Sentry_tunnel_rate_limiter_engages_after_the_configured_permit_limit()
{
var client = _factory.CreateClient();
// Must track RateLimiting:SentryTunnel:PermitLimit in SlpModularCms.Api/appsettings.json.
const int permitLimit = 60;
HttpResponseMessage? last = null;
for (var i = 0; i < permitLimit + 1; i++)
{
last = await client.PostAsync("/sentry-tunnel", new ByteArrayContent([]));
}
// The request beyond the permit limit, within the same fixed window, must be rejected —
// regardless of whether a Sentry DSN is configured (an unconfigured DSN 404s every
// request instead, which would otherwise mask a rate limiter that silently stopped
// engaging).
last!.StatusCode.Should().Be(HttpStatusCode.TooManyRequests);
}
}
@@ -0,0 +1,38 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.4" />
<PackageReference Include="FluentAssertions" Version="8.10.0" />
<!-- Provides WebApplicationFactory<TEntryPoint>, used to test the real, composed HTTP pipeline
rather than individual option/handler classes in isolation (NFR-CS-01). -->
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="10.0.9" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.4" />
</ItemGroup>
<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>
<ItemGroup>
<!--
Targets SlpModularCms.Api specifically (Infrastructure/NFR Design decision Q1 = C) — the
shared CmsHost composition is exercised through this project; SlpModularCms.Api.SlpSoftware
is not separately pipeline-tested in this unit.
-->
<ProjectReference Include="..\SlpModularCms.Api\SlpModularCms.Api.csproj" />
</ItemGroup>
</Project>