- themes/asf/logo-mail.png (+ make-mail-logo.py), geleverd als /admin/brand-logo-mail.png; ASF Email:LogoUrl wijst ernaar - Renderer: plaat weggehaald, licht logo 56px, dark-swap naar LogoDarkUrl blijft - UsersPage: toast na geslaagde rolwijziging (nl+en, ook Owner-bevestiging) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
91 lines
3.6 KiB
C#
91 lines
3.6 KiB
C#
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");
|
|
}
|
|
|
|
[Fact]
|
|
public void Mail_IsOffByDefault_AndNoCredentialIsCommitted()
|
|
{
|
|
var config = Load();
|
|
|
|
config["Email:Smtp:Host"].Should().BeNullOrEmpty("mail is switched on per environment");
|
|
config["Email:Smtp:Username"].Should().BeNullOrEmpty();
|
|
config["Email:Smtp:Password"].Should().BeNullOrEmpty();
|
|
config["Email:FromAddress"].Should().NotBeNullOrEmpty();
|
|
config["Email:LogoUrl"].Should().Be("/admin/brand-logo-mail.png");
|
|
config["Email:LogoDarkUrl"].Should().Be("/admin/brand-logo-on-dark.png");
|
|
}
|
|
}
|