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); }