From 7f92a36a36ab8183c843982bf91bdabb45861154 Mon Sep 17 00:00:00 2001
From: Michael Kozono <mkozono@gmail.com>
Date: Tue, 13 Jun 2017 14:01:28 -0700
Subject: [PATCH] Fix plain LDAP (no encryption)

---
 Gemfile                             | 2 +-
 Gemfile.lock                        | 4 ++--
 lib/gitlab/ldap/config.rb           | 9 ++++++---
 spec/lib/gitlab/ldap/config_spec.rb | 2 +-
 4 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/Gemfile b/Gemfile
index 276893d0ff4..7bb912571f4 100644
--- a/Gemfile
+++ b/Gemfile
@@ -61,7 +61,7 @@ gem 'browser', '~> 2.2'
 # LDAP Auth
 # GitLab fork with several improvements to original library. For full list of changes
 # see https://github.com/intridea/omniauth-ldap/compare/master...gitlabhq:master
-gem 'gitlab_omniauth-ldap', '~> 2.0.1', require: 'omniauth-ldap'
+gem 'gitlab_omniauth-ldap', '~> 2.0.2', require: 'omniauth-ldap'
 
 # Git Wiki
 # Required manually in config/initializers/gollum.rb to control load order
diff --git a/Gemfile.lock b/Gemfile.lock
index 2b2df1b6bcc..661f0294646 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -288,7 +288,7 @@ GEM
       mime-types (>= 1.16, < 3)
       posix-spawn (~> 0.3)
     gitlab-markup (1.5.1)
-    gitlab_omniauth-ldap (2.0.1)
+    gitlab_omniauth-ldap (2.0.2)
       net-ldap (~> 0.16)
       omniauth (~> 1.3)
       pyu-ruby-sasl (>= 0.0.3.3, < 0.1)
@@ -978,7 +978,7 @@ DEPENDENCIES
   github-linguist (~> 4.7.0)
   gitlab-flowdock-git-hook (~> 1.0.1)
   gitlab-markup (~> 1.5.1)
-  gitlab_omniauth-ldap (~> 2.0.1)
+  gitlab_omniauth-ldap (~> 2.0.2)
   gollum-lib (~> 4.2)
   gollum-rugged_adapter (~> 0.4.4)
   gon (~> 6.1.0)
diff --git a/lib/gitlab/ldap/config.rb b/lib/gitlab/ldap/config.rb
index 163e49ecc1c..8eda3ea03f9 100644
--- a/lib/gitlab/ldap/config.rb
+++ b/lib/gitlab/ldap/config.rb
@@ -169,9 +169,12 @@ module Gitlab
 
       def encryption_options
         method = translate_method(options['encryption'])
-        options = { method: method }
-        options[:tls_options] = tls_options(method) if method
-        options
+        return nil unless method
+
+        {
+          method: method,
+          tls_options: tls_options(method)
+        }
       end
 
       def translate_method(method_from_config)
diff --git a/spec/lib/gitlab/ldap/config_spec.rb b/spec/lib/gitlab/ldap/config_spec.rb
index e3a9505531d..3a56797d68b 100644
--- a/spec/lib/gitlab/ldap/config_spec.rb
+++ b/spec/lib/gitlab/ldap/config_spec.rb
@@ -32,7 +32,7 @@ describe Gitlab::LDAP::Config, lib: true do
       expect(config.adapter_options).to eq(
         host: 'ldap.example.com',
         port: 386,
-        encryption: { method: nil }
+        encryption: nil
       )
     end
 
-- 
GitLab