using Microsoft.Extensions.Configuration; using Shouldly; using Xunit; using ZB.MOM.WW.OtOpcUa.Security.Ldap; namespace ZB.MOM.WW.OtOpcUa.Host.IntegrationTests; /// /// Regression guard for the LDAP config-section fix. The real config (admin/driver/Development /// overlays) lives under Security:Ldap, and must point /// there so the configured DevStubMode actually binds. Previously the binders used the /// nonexistent "Ldap"/"Authentication:Ldap" sections, so the dev stub never activated. /// public sealed class LdapOptionsBindingTests { /// resolves to the real overlay section. [Fact] public void SectionName_is_Security_Ldap() { LdapOptions.SectionName.ShouldBe("Security:Ldap"); } /// /// Binding from reads the configured DevStubMode /// from the real Security:Ldap section — proving the dev stub now takes effect. /// [Fact] public void Binding_from_SectionName_reads_Security_Ldap_DevStubMode() { var configuration = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary { ["Security:Ldap:DevStubMode"] = "true", }) .Build(); var options = configuration.GetSection(LdapOptions.SectionName).Get(); options.ShouldNotBeNull(); options.DevStubMode.ShouldBeTrue(); } /// /// Negative control: binding from the old (nonexistent) "Ldap" section against the same /// Security:Ldap config does NOT pick up DevStubMode — it falls back to the C# /// default (false). This is the pre-fix behaviour the change corrects. /// [Fact] public void Binding_from_old_Ldap_section_does_not_read_DevStubMode() { var configuration = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary { ["Security:Ldap:DevStubMode"] = "true", }) .Build(); var options = configuration.GetSection("Ldap").Get() ?? new LdapOptions(); options.DevStubMode.ShouldBeFalse(); } }