Voeg Api.AndreaSlopFotografie toe met setup-token, proxy-bewuste limiters en ASF-admin-thema
- Core: opt-in ForwardedHeaders:KnownProxies en rate limiters per clientadres (zonder configuratie ongewijzigd gedrag) - Identity: optioneel setup-token (X-Setup-Token), beide setup-endpoints onder de login-limiter, beveiligingsgebeurtenis setup_token_rejected (5007) - Nieuw client-project SlpModularCms.Api.AndreaSlopFotografie (Identity + Availability) met bijbehorende tests - Frontend: thema asf (VITE_THEME), VITE_DEFAULT_LANGUAGE, tokenveld op de setup-pagina - CI: jobs publish/deploy-asf-test achter ASF_TEST_DEPLOY_ENABLED - Fix U1: 301-Location wordt nu percent-encoded (gevonden door de property-test) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
using FluentAssertions;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace SlpModularCms.Api.AndreaSlopFotografie.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Guards the committed defaults of the Andrea Slop Fotografie host. These need no database, so they
|
||||
/// run everywhere (unlike <see cref="HostPipelineTests"/>).
|
||||
/// </summary>
|
||||
public class HostConfigurationTests
|
||||
{
|
||||
private static IConfigurationRoot Load()
|
||||
{
|
||||
var dir = new DirectoryInfo(AppContext.BaseDirectory);
|
||||
while (dir is not null &&
|
||||
!File.Exists(Path.Combine(dir.FullName, "SlpModularCms.Api.AndreaSlopFotografie", "appsettings.json")))
|
||||
{
|
||||
dir = dir.Parent;
|
||||
}
|
||||
|
||||
dir.Should().NotBeNull("the host project must be found next to this test project");
|
||||
var path = Path.Combine(dir!.FullName, "SlpModularCms.Api.AndreaSlopFotografie", "appsettings.json");
|
||||
return new ConfigurationBuilder().AddJsonFile(path, optional: false).Build();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WebsiteIsNoIndex_ByDefault()
|
||||
{
|
||||
Load().GetValue<bool>("Website:NoIndex").Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DefaultPolicyIsStrictSite_AndAdminApiHealthStayStrict()
|
||||
{
|
||||
var config = Load();
|
||||
|
||||
config["SecurityHeaders:DefaultPolicy"].Should().Be("StrictSite");
|
||||
var rules = config.GetSection("SecurityHeaders:PathPolicies").GetChildren()
|
||||
.ToDictionary(c => c["PathPrefix"]!, c => c["Policy"]!);
|
||||
rules.Should().Contain(new KeyValuePair<string, string>("/admin", "Strict"))
|
||||
.And.Contain(new KeyValuePair<string, string>("/api/v1", "Strict"))
|
||||
.And.Contain(new KeyValuePair<string, string>("/health", "Strict"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SiteOrigins_AreHttpsOnly_AndNotAddedToTheAdminLists()
|
||||
{
|
||||
var config = Load();
|
||||
var site = config.GetSection("SecurityHeaders:AllowedSiteScriptOrigins").Get<string[]>()!
|
||||
.Concat(config.GetSection("SecurityHeaders:AllowedSiteConnectOrigins").Get<string[]>()!);
|
||||
|
||||
site.Should().NotBeEmpty().And.OnlyContain(o => o.StartsWith("https://"));
|
||||
config.GetSection("SecurityHeaders:AllowedScriptOrigins").Get<string[]>().Should().BeEmpty();
|
||||
config.GetSection("SecurityHeaders:AllowedConnectOrigins").Get<string[]>().Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NoSecretsAreCommitted()
|
||||
{
|
||||
var config = Load();
|
||||
|
||||
config["JwtSettings:Secret"].Should().StartWith("<");
|
||||
config["ConnectionStrings:DefaultConnection"].Should().Contain("<db-password>");
|
||||
config["Identity:Setup:Token"].Should().BeNullOrEmpty();
|
||||
config["Observability:SentryDsn"].Should().BeNullOrEmpty();
|
||||
config.GetSection("ForwardedHeaders:KnownProxies").Get<string[]>().Should().BeNullOrEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Host_DoesNotReferenceMasterOrOfferingsModules()
|
||||
{
|
||||
var referenced = typeof(Program).Assembly.GetReferencedAssemblies().Select(a => a.Name);
|
||||
|
||||
referenced.Should().NotContain("SlpModularCms.Modules.Offerings")
|
||||
.And.NotContain("SlpModularCms.Modules.Master");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
using System.Net;
|
||||
using System.Text.Json;
|
||||
using FluentAssertions;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
|
||||
namespace SlpModularCms.Api.AndreaSlopFotografie.Tests;
|
||||
|
||||
/// <summary>Starts the real host in-memory (Development environment).</summary>
|
||||
public class AsfWebApplicationFactory : WebApplicationFactory<Program>
|
||||
{
|
||||
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
||||
{
|
||||
builder.UseEnvironment("Development");
|
||||
}
|
||||
}
|
||||
|
||||
/// <remarks>
|
||||
/// Requires a reachable local MariaDB matching <c>appsettings.Development.json</c> of the host,
|
||||
/// because <c>CmsHost.ConfigurePipeline</c> migrates the database before any endpoint answers
|
||||
/// (same precondition as <c>SlpModularCms.Api.Tests</c>).
|
||||
/// </remarks>
|
||||
public class HostPipelineTests : IClassFixture<AsfWebApplicationFactory>
|
||||
{
|
||||
private readonly AsfWebApplicationFactory _factory;
|
||||
|
||||
public HostPipelineTests(AsfWebApplicationFactory factory) => _factory = factory;
|
||||
|
||||
[Fact]
|
||||
public async Task Capabilities_ListIdentityAndAvailability_ButNotOfferingsOrMaster()
|
||||
{
|
||||
var response = await _factory.CreateClient().GetAsync("/api/v1/System/capabilities");
|
||||
|
||||
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
using var doc = JsonDocument.Parse(await response.Content.ReadAsStringAsync());
|
||||
var modules = doc.RootElement.GetProperty("modules").EnumerateArray().Select(e => e.GetString()).ToList();
|
||||
modules.Should().Contain("Identity").And.Contain("Availability");
|
||||
modules.Should().NotContain("Offerings").And.NotContain("Master");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Health_IsReachable()
|
||||
{
|
||||
(await _factory.CreateClient().GetAsync("/health")).IsSuccessStatusCode.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SetupStatus_ReportsNoTokenRequired_WhenNoneConfigured()
|
||||
{
|
||||
var response = await _factory.CreateClient().GetAsync("/api/v1/Setup/status");
|
||||
|
||||
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
(await response.Content.ReadAsStringAsync()).Should().Contain("\"tokenRequired\":false");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task UnknownWebsitePath_Returns404_WithTheSiteSecurityHeaders_AndNoIndex()
|
||||
{
|
||||
var response = await _factory.CreateClient().GetAsync("/some-page-that-does-not-exist");
|
||||
|
||||
response.StatusCode.Should().Be(HttpStatusCode.NotFound);
|
||||
response.Headers.GetValues("Content-Security-Policy").Single()
|
||||
.Should().Contain("https://analytics.slpsoftware.nl");
|
||||
response.Headers.GetValues("X-Robots-Tag").Single().Should().Be("noindex, nofollow");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RobotsTxt_DisallowsEverything_OnTheDefaultNoIndexConfiguration()
|
||||
{
|
||||
var body = await _factory.CreateClient().GetStringAsync("/robots.txt");
|
||||
|
||||
body.Should().Contain("Disallow: /");
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
<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>
|
||||
<ProjectReference Include="..\SlpModularCms.Api.AndreaSlopFotografie\SlpModularCms.Api.AndreaSlopFotografie.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user