From aecc1066575baccfbdfac5ff78344d5b7710178d Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Tue, 2 Jun 2026 01:17:53 -0400 Subject: [PATCH] fix(auth.ldap): skip LdapOptionsValidator when Enabled=false; bump 0.1.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A disabled LDAP provider's connection fields are inert — don't require Server/SearchBase/ServiceAccountDn at startup when Enabled=false. Surfaced by the MxGateway 1.2 review (dashboard LDAP can be disabled). +1 test. --- ZB.MOM.WW.Auth/Directory.Build.props | 2 +- .../ZB.MOM.WW.Auth.Ldap/LdapOptionsValidator.cs | 12 +++++++++++- .../LdapOptionsValidatorTests.cs | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/ZB.MOM.WW.Auth/Directory.Build.props b/ZB.MOM.WW.Auth/Directory.Build.props index c4755a6..5e21819 100644 --- a/ZB.MOM.WW.Auth/Directory.Build.props +++ b/ZB.MOM.WW.Auth/Directory.Build.props @@ -5,7 +5,7 @@ enable enable latest - 0.1.0 + 0.1.1 true diff --git a/ZB.MOM.WW.Auth/src/ZB.MOM.WW.Auth.Ldap/LdapOptionsValidator.cs b/ZB.MOM.WW.Auth/src/ZB.MOM.WW.Auth.Ldap/LdapOptionsValidator.cs index 68e0b2b..71102b0 100644 --- a/ZB.MOM.WW.Auth/src/ZB.MOM.WW.Auth.Ldap/LdapOptionsValidator.cs +++ b/ZB.MOM.WW.Auth/src/ZB.MOM.WW.Auth.Ldap/LdapOptionsValidator.cs @@ -9,7 +9,9 @@ namespace ZB.MOM.WW.Auth.Ldap; /// low-level error on the first real login attempt. /// /// -/// Four conditions are enforced: +/// Validation is skipped entirely when is false +/// (a disabled provider's connection fields are inert). When enabled, four conditions +/// are enforced: /// /// plaintext transport () is rejected unless /// is explicitly set (dev/test only); @@ -27,6 +29,14 @@ public sealed class LdapOptionsValidator : IValidateOptions { ArgumentNullException.ThrowIfNull(options); + // When LDAP is disabled, its connection fields are inert — do not require them. + // A consumer that turns LDAP off should not have to supply a server/search-base/ + // service-account just to satisfy startup validation. + if (!options.Enabled) + { + return ValidateOptionsResult.Success; + } + if (options.Transport == LdapTransport.None && !options.AllowInsecure) { return ValidateOptionsResult.Fail( diff --git a/ZB.MOM.WW.Auth/tests/ZB.MOM.WW.Auth.Ldap.Tests/LdapOptionsValidatorTests.cs b/ZB.MOM.WW.Auth/tests/ZB.MOM.WW.Auth.Ldap.Tests/LdapOptionsValidatorTests.cs index 9357f08..6535bff 100644 --- a/ZB.MOM.WW.Auth/tests/ZB.MOM.WW.Auth.Ldap.Tests/LdapOptionsValidatorTests.cs +++ b/ZB.MOM.WW.Auth/tests/ZB.MOM.WW.Auth.Ldap.Tests/LdapOptionsValidatorTests.cs @@ -72,4 +72,20 @@ public class LdapOptionsValidatorTests Assert.False(new LdapOptionsValidator() .Validate(null, Opts()) .Failed); + + [Fact] + public void Validator_Skips_AllChecks_WhenDisabled() => + // When LDAP is disabled its connection fields are inert; an otherwise-invalid + // config (plaintext + blank Server/SearchBase/ServiceAccountDn) must still pass. + Assert.False(new LdapOptionsValidator() + .Validate(null, new LdapOptions + { + Enabled = false, + Transport = LdapTransport.None, + AllowInsecure = false, + Server = "", + SearchBase = "", + ServiceAccountDn = "", + }) + .Failed); }