From 717c307f06caeebef33a28c428aafb741abae324 Mon Sep 17 00:00:00 2001 From: Tatsuya Sato Date: Wed, 13 Jan 2016 20:04:24 +0900 Subject: [PATCH 1/3] Raises errors when giving encryption as non-Hash object fix #250 --- lib/net/ldap.rb | 3 +++ test/test_ldap.rb | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/lib/net/ldap.rb b/lib/net/ldap.rb index a9c843e7..e7bb0674 100644 --- a/lib/net/ldap.rb +++ b/lib/net/ldap.rb @@ -540,6 +540,9 @@ def initialize(args = {}) @base = args[:base] || DefaultTreebase @force_no_page = args[:force_no_page] || DefaultForceNoPage @encryption = args[:encryption] # may be nil + if !@encryption.nil? and !@encryption.is_a?(Hash) + raise ArgumentError, "encryption must be given as Hash" + end @connect_timeout = args[:connect_timeout] if pr = @auth[:password] and pr.respond_to?(:call) diff --git a/test/test_ldap.rb b/test/test_ldap.rb index 85325457..53ba3010 100644 --- a/test/test_ldap.rb +++ b/test/test_ldap.rb @@ -91,4 +91,10 @@ def test_encryption assert_equal enc[:method], :start_tls end + + def test_initialize + assert_raise ArgumentError, "encryption must be given as Hash" do + Net::LDAP.new encryption: [ :simple_tls ] + end + end end From fd71e028af501ab3ba58dd2651c9ddb71c430c73 Mon Sep 17 00:00:00 2001 From: Tatsuya Sato Date: Thu, 14 Jan 2016 18:43:02 +0900 Subject: [PATCH 2/3] Simplified the condition on a validation for encryption --- lib/net/ldap.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/net/ldap.rb b/lib/net/ldap.rb index e7bb0674..0447ed0c 100644 --- a/lib/net/ldap.rb +++ b/lib/net/ldap.rb @@ -540,7 +540,7 @@ def initialize(args = {}) @base = args[:base] || DefaultTreebase @force_no_page = args[:force_no_page] || DefaultForceNoPage @encryption = args[:encryption] # may be nil - if !@encryption.nil? and !@encryption.is_a?(Hash) + if @encryption && !@encryption.is_a?(Hash) raise ArgumentError, "encryption must be given as Hash" end @connect_timeout = args[:connect_timeout] From 175974dfdc52d7a563c447a7b26038bda7570a00 Mon Sep 17 00:00:00 2001 From: Tatsuya Sato Date: Thu, 14 Jan 2016 18:46:35 +0900 Subject: [PATCH 3/3] Made a test title more descriptive --- test/test_ldap.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_ldap.rb b/test/test_ldap.rb index 53ba3010..a1fd910a 100644 --- a/test/test_ldap.rb +++ b/test/test_ldap.rb @@ -92,7 +92,7 @@ def test_encryption assert_equal enc[:method], :start_tls end - def test_initialize + def test_initializer_requires_hash_encryption assert_raise ArgumentError, "encryption must be given as Hash" do Net::LDAP.new encryption: [ :simple_tls ] end