Fase B2: ASF-testproject opgeheven; tests verhuisd naar de master-Api (geen testverlies, 18 -> 18)
Tellijst Api.AndreaSlopFotografie.Tests (18): - HostConfigurationTests (7) -> Api.Tests/SiteContractTests: NoIndex (beide sites), StrictSite+padbeleid, https-only site-origins, geen geheimen (beide), Contact uit + SiteId (beide), 'ASF zonder Master' (nu exacte modulelijst per csproj), mail uit (beide) + logo-urls. - HostPipelineTests (7) -> Api.Tests: AsfVariantPipelineTests (health, setup/status, 404+CSP+noindex, robots; master-host met de gedragsinstellingen van ASF) en OfferingsOnTheMasterHostTests (capabilities, banner 204, migraties == model). - ContactHostTests (4) -> Contact.Tests/Pipeline/SiteVariantContactTests (defaults dicht, poort + SiteId andreaslop, proxy bekend/onbekend). Nieuw: sitecontract per site (modules, Website:Mode, Program.cs dun), WebsiteModeSelection (modus eenmalig bepaald), Api.Tests serieel (MySql.Data). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,155 @@
|
||||
using FluentAssertions;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace SlpModularCms.Api.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// What every site (client project) must look like, checked from its files alone: the modules it references and
|
||||
/// the defaults it commits. The sites carry no logic of their own (all behaviour lives in Core and the modules and
|
||||
/// is tested against the master <c>SlpModularCms.Api</c> host), so a site can only go wrong in its composition:
|
||||
/// a module reference that is missing or too much, or an unsafe default. These tests need no database.
|
||||
/// </summary>
|
||||
public class SiteContractTests
|
||||
{
|
||||
public static IEnumerable<object[]> Sites() =>
|
||||
[
|
||||
[SiteFiles.SlpSoftware],
|
||||
[SiteFiles.AndreaSlopFotografie],
|
||||
];
|
||||
|
||||
[Fact]
|
||||
public void TheMasterCms_ReferencesEveryModule()
|
||||
{
|
||||
SiteFiles.Modules("SlpModularCms.Api").Should().BeEquivalentTo(
|
||||
["Availability", "Contact", "Identity", "Master", "Offerings"],
|
||||
"the master Api is the all-modules composition the CI builds and tests");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SlpSoftware_IsTheFullComposition()
|
||||
{
|
||||
SiteFiles.Modules(SiteFiles.SlpSoftware).Should().BeEquivalentTo(
|
||||
["Availability", "Contact", "Identity", "Master", "Offerings"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AndreaSlopFotografie_HasEverythingExceptTheMasterModule()
|
||||
{
|
||||
// Not a master/slave setup: no Master module, so /System/capabilities does not list it.
|
||||
SiteFiles.Modules(SiteFiles.AndreaSlopFotografie).Should().BeEquivalentTo(
|
||||
["Availability", "Contact", "Identity", "Offerings"]);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Sites))]
|
||||
public void NoSiteReferencesAModuleTheMasterDoesNot(string site)
|
||||
{
|
||||
SiteFiles.Modules(site).Should().BeSubsetOf(SiteFiles.Modules("SlpModularCms.Api"),
|
||||
"a module that the CI does not build and test must not ship in a site");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(SiteFiles.SlpSoftware, "SpaFallback")]
|
||||
[InlineData(SiteFiles.AndreaSlopFotografie, "PrerenderedPages")]
|
||||
public void EachSite_ServesItsWebsiteTheRightWay(string site, string mode)
|
||||
{
|
||||
// Missing means SpaFallback (the host's default); Andrea's prerendered site must say so explicitly,
|
||||
// otherwise it would start as an SPA and answer 200 for every unknown path.
|
||||
var configured = SiteFiles.Committed(site)["Website:Mode"];
|
||||
(configured ?? "SpaFallback").Should().Be(mode);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Sites))]
|
||||
public void WebsiteIsNoIndex_ByDefault(string site)
|
||||
{
|
||||
SiteFiles.Committed(site).GetValue<bool>("Website:NoIndex").Should().BeTrue(
|
||||
"indexing is switched on per environment, never by the committed defaults");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Sites))]
|
||||
public void NoSecretsAreCommitted(string site)
|
||||
{
|
||||
var config = SiteFiles.Committed(site);
|
||||
|
||||
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(
|
||||
"the proxy address is environment configuration");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(SiteFiles.SlpSoftware, "slpsoftware")]
|
||||
[InlineData(SiteFiles.AndreaSlopFotografie, "andreaslop")]
|
||||
public void Contact_IsOffByDefault_ForTheRightSite_WithNoRecipientOrCaptchaSecretCommitted(string site, string siteId)
|
||||
{
|
||||
var config = SiteFiles.Committed(site);
|
||||
|
||||
config.GetValue<bool>("Contact:Enabled").Should().BeFalse();
|
||||
config["Contact:SiteId"].Should().Be(siteId);
|
||||
config.GetValue<bool>("Contact:Captcha:Enabled").Should().BeFalse();
|
||||
config["Contact:RecipientEmail"].Should().BeNullOrEmpty("the address comes from the environment only");
|
||||
config["Contact:Captcha:Secret"].Should().BeNullOrEmpty();
|
||||
config["Contact:Captcha:SiteKey"].Should().BeNullOrEmpty();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Sites))]
|
||||
public void Mail_IsOffByDefault_AndNoCredentialIsCommitted(string site)
|
||||
{
|
||||
var config = SiteFiles.Committed(site);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AndreaSlopFotografie_DefaultPolicyIsStrictSite_AndAdminApiHealthStayStrict()
|
||||
{
|
||||
var config = SiteFiles.Committed(SiteFiles.AndreaSlopFotografie);
|
||||
|
||||
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 AndreaSlopFotografie_SiteOrigins_AreHttpsOnly_AndNotAddedToTheAdminLists()
|
||||
{
|
||||
var config = SiteFiles.Committed(SiteFiles.AndreaSlopFotografie);
|
||||
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 AndreaSlopFotografie_MailBrandingPointsAtTheAdminAssets()
|
||||
{
|
||||
var config = SiteFiles.Committed(SiteFiles.AndreaSlopFotografie);
|
||||
|
||||
config["Email:LogoUrl"].Should().Be("/admin/brand-logo-mail.png");
|
||||
config["Email:LogoDarkUrl"].Should().Be("/admin/brand-logo-on-dark.png");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Sites))]
|
||||
public void EachSiteProgram_IsAThinComposition(string site)
|
||||
{
|
||||
// The site's Program.cs may only compose: no mode, module or option decisions in code.
|
||||
var program = File.ReadAllText(Path.Combine(SiteFiles.SourceRoot(), site, "Program.cs"));
|
||||
|
||||
program.Should().Contain("CmsHost.ConfigureServices").And.Contain("CmsHost.ConfigurePipeline");
|
||||
program.Should().NotContain("WebsiteMode.", "the mode is chosen with Website:Mode in appsettings.json");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user