Opstart zonder mailconfiguratie getest voor alle hosts, Website__LogLevel zonder punt in de naam
Oorzaak 502 op ASF test: Email__Smtp__Host stond al in de omgeving maar App__PublicBaseUrl nog niet; de startvalidatie weigert zo'n halve mailconfiguratie. Een host zonder enige mailinstelling start gewoon: nu voor master, slave, SlpSoftware en ASF getest. Website__LogLevel vervangt de Logging__LogLevel__SlpModularCms.Website-variabele, waarvan systemd de naam met punt negeert. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -28,7 +28,9 @@ public class DeployedConfigurationTests
|
||||
public static TheoryData<string> HostConfigurations => new()
|
||||
{
|
||||
Path.Combine("host-config", "master.appsettings.json"),
|
||||
Path.Combine("host-config", "slave.appsettings.json")
|
||||
Path.Combine("host-config", "slave.appsettings.json"),
|
||||
Path.Combine("host-config", "slpsoftware.appsettings.json"),
|
||||
Path.Combine("host-config", "andreaslop.appsettings.json")
|
||||
};
|
||||
|
||||
private static IConfigurationRoot Load(string relativePath)
|
||||
@@ -130,4 +132,49 @@ public class DeployedConfigurationTests
|
||||
options.PathPolicies
|
||||
.Should().Contain(rule => rule.PathPrefix == "/admin" && rule.Policy == CspPolicyCatalog.Strict);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A deploy without any mail configuration must never fail to start: the mail validation only runs
|
||||
/// when an SMTP host is set (and so needs <c>App:PublicBaseUrl</c> only then).
|
||||
/// </summary>
|
||||
[Theory]
|
||||
[MemberData(nameof(HostConfigurations))]
|
||||
public void HostConfiguration_StartsWithoutAnyMailSettings(string relativePath)
|
||||
{
|
||||
var configuration = Load(relativePath);
|
||||
var services = new ServiceCollection();
|
||||
services.AddLogging();
|
||||
SlpModularCms.Core.Email.EmailServiceCollectionExtensions.AddCmsEmail(services, configuration);
|
||||
using var sp = services.BuildServiceProvider();
|
||||
|
||||
var act = () => sp.GetRequiredService<IStartupValidator>().Validate();
|
||||
|
||||
act.Should().NotThrow();
|
||||
configuration.IsEmailEnabledForTest().Should().BeFalse();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(HostConfigurations))]
|
||||
public void HostConfiguration_NeedsPublicBaseUrl_OnlyOnceAnSmtpHostIsSet(string relativePath)
|
||||
{
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.AddJsonFile(relativePath, optional: false)
|
||||
.AddInMemoryCollection(new Dictionary<string, string?> { ["Email:Smtp:Host"] = "mail.example.nl" })
|
||||
.Build();
|
||||
var services = new ServiceCollection();
|
||||
services.AddLogging();
|
||||
SlpModularCms.Core.Email.EmailServiceCollectionExtensions.AddCmsEmail(services, configuration);
|
||||
using var sp = services.BuildServiceProvider();
|
||||
|
||||
var act = () => sp.GetRequiredService<IStartupValidator>().Validate();
|
||||
|
||||
// With a host but no App__PublicBaseUrl the host refuses to start, and says which setting is missing.
|
||||
act.Should().Throw<OptionsValidationException>().WithMessage("*App:PublicBaseUrl*");
|
||||
}
|
||||
}
|
||||
|
||||
internal static class ConfigurationTestExtensions
|
||||
{
|
||||
public static bool IsEmailEnabledForTest(this IConfiguration configuration) =>
|
||||
SlpModularCms.Core.Email.EmailServiceCollectionExtensions.IsEmailEnabled(configuration);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user