From f6c80f765eed1f9854e5469c16f3476a50b0b5d0 Mon Sep 17 00:00:00 2001 From: maliming <6908465+maliming@users.noreply.github.com> Date: Sat, 8 Aug 2020 14:15:51 +0800 Subject: [PATCH] Fix OverrideOptionsAsync method logic error. --- .../Volo/Abp/Ldap/AbpAbpLdapOptionsFactory.cs | 10 +++++----- .../src/Volo.Abp.Ldap/Volo/Abp/Ldap/LdapManager.cs | 2 +- .../Volo/Abp/Ldap/AbpLdapTestModule.cs | 7 +++++-- .../Volo/Abp/Ldap/LdapManager_Tests.cs | 14 +++++++++++++- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/AbpAbpLdapOptionsFactory.cs b/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/AbpAbpLdapOptionsFactory.cs index c3d3549a12..0f7117a42a 100644 --- a/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/AbpAbpLdapOptionsFactory.cs +++ b/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/AbpAbpLdapOptionsFactory.cs @@ -32,15 +32,15 @@ namespace Volo.Abp.Ldap protected virtual async Task OverrideOptionsAsync(AbpLdapOptions options) { - options.ServerHost = await GetStringValueOrDefault(LdapSettingNames.ServerHost) ?? options.ServerHost; + options.ServerHost = await GetSettingOrDefaultValue(LdapSettingNames.ServerHost, options.ServerHost); options.ServerPort = await SettingProvider.GetAsync(LdapSettingNames.ServerPort, options.ServerPort); - options.UserName = await GetStringValueOrDefault(LdapSettingNames.UserName) ?? options.UserName; - options.Password = await GetStringValueOrDefault(LdapSettingNames.Password) ?? options.Password; + options.UserName = await GetSettingOrDefaultValue(LdapSettingNames.UserName, options.UserName); + options.Password = await GetSettingOrDefaultValue(LdapSettingNames.Password, options.Password); } - protected virtual async Task GetStringValueOrDefault(string name, string defaultValue = default) + protected virtual async Task GetSettingOrDefaultValue(string name, string defaultValue) { - var value = await SettingProvider.GetOrNullAsync(LdapSettingNames.ServerHost); + var value = await SettingProvider.GetOrNullAsync(name); return value.IsNullOrWhiteSpace() ? defaultValue : value; } } diff --git a/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/LdapManager.cs b/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/LdapManager.cs index eeb7ce88b2..61b8f608d1 100644 --- a/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/LdapManager.cs +++ b/framework/src/Volo.Abp.Ldap/Volo/Abp/Ldap/LdapManager.cs @@ -29,7 +29,7 @@ namespace Volo.Abp.Ldap try { var conn = CreateLdapConnection(); - AuthenticateLdapConnection(conn, username,password); + AuthenticateLdapConnection(conn, username, password); return true; } catch (Exception ex) diff --git a/framework/test/Volo.Abp.Ldap.Tests/Volo/Abp/Ldap/AbpLdapTestModule.cs b/framework/test/Volo.Abp.Ldap.Tests/Volo/Abp/Ldap/AbpLdapTestModule.cs index 7d6ba4d759..a9ab4a28ed 100644 --- a/framework/test/Volo.Abp.Ldap.Tests/Volo/Abp/Ldap/AbpLdapTestModule.cs +++ b/framework/test/Volo.Abp.Ldap.Tests/Volo/Abp/Ldap/AbpLdapTestModule.cs @@ -12,9 +12,12 @@ namespace Volo.Abp.Ldap { public override void ConfigureServices(ServiceConfigurationContext context) { - Configure(settings => + Configure(options => { - + options.ServerHost = "192.168.0.3"; + options.ServerPort = 389; + options.UserName = "cn=admin,dc=abp,dc=io"; + options.Password = "123qwe"; }); } } diff --git a/framework/test/Volo.Abp.Ldap.Tests/Volo/Abp/Ldap/LdapManager_Tests.cs b/framework/test/Volo.Abp.Ldap.Tests/Volo/Abp/Ldap/LdapManager_Tests.cs index c793347f95..4cfc8718c8 100644 --- a/framework/test/Volo.Abp.Ldap.Tests/Volo/Abp/Ldap/LdapManager_Tests.cs +++ b/framework/test/Volo.Abp.Ldap.Tests/Volo/Abp/Ldap/LdapManager_Tests.cs @@ -1,4 +1,7 @@ -using Volo.Abp.Testing; +using System; +using Shouldly; +using Volo.Abp.Testing; +using Xunit; namespace Volo.Abp.Ldap { @@ -15,5 +18,14 @@ namespace Volo.Abp.Ldap { options.UseAutofac(); } + + [Fact(Skip = "Required Ldap environment")] + public void Authenticate() + { + _ldapManager.Authenticate().ShouldBe(true); + _ldapManager.Authenticate("cn=abp,dc=abp,dc=io", "123qwe").ShouldBe(true); + _ldapManager.Authenticate("NoExists", "123qwe").ShouldBe(false); + } + } }