summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancisco Javier López <fjlopez@gitlab.com>2018-02-05 20:35:58 +0100
committerFrancisco Javier López <fjlopez@gitlab.com>2018-02-05 20:35:58 +0100
commit6f6859fac453dfdc4a806fb85c5bd0326e11c632 (patch)
tree6797e86e9b7ebb35a061e64ca69981b388541e47
parent4f83724d12d3fb4d673aa240ba701fe6b7d4deb8 (diff)
downloadgitlab-ce-6f6859fac453dfdc4a806fb85c5bd0326e11c632.tar.gz
Comments applied
-rw-r--r--doc/administration/auth/ldap.md2
-rw-r--r--lib/gitlab/ldap/person.rb4
-rw-r--r--spec/lib/gitlab/ldap/person_spec.rb21
3 files changed, 25 insertions, 2 deletions
diff --git a/doc/administration/auth/ldap.md b/doc/administration/auth/ldap.md
index 658868de523..cfa48fcf457 100644
--- a/doc/administration/auth/ldap.md
+++ b/doc/administration/auth/ldap.md
@@ -298,7 +298,7 @@ LDAP email address, and then sign into GitLab via their LDAP credentials.
Some LDAP servers, depending on their configurations, can return uppercase usernames. This can lead to several confusing issues like, for example, creating links or namespaces with uppercase names.
-Gitlab can automatically lowercase usernames provided by the LDAP server by enabling
+GitLab can automatically lowercase usernames provided by the LDAP server by enabling
the configuration option `lowercase_usernames`. By default, this configuration option is `false`.
```yaml
diff --git a/lib/gitlab/ldap/person.rb b/lib/gitlab/ldap/person.rb
index e81cec6ba1a..b91757c2a4b 100644
--- a/lib/gitlab/ldap/person.rb
+++ b/lib/gitlab/ldap/person.rb
@@ -82,7 +82,9 @@ module Gitlab
# be returned. We need only one for username.
# Ex. `uid` returns only one value but `mail` may
# return an array of multiple email addresses.
- [username].flatten.first
+ [username].flatten.first.tap do |username|
+ username.downcase! if config.lowercase_usernames
+ end
end
def email
diff --git a/spec/lib/gitlab/ldap/person_spec.rb b/spec/lib/gitlab/ldap/person_spec.rb
index ff29d9aa5be..b54d4000b53 100644
--- a/spec/lib/gitlab/ldap/person_spec.rb
+++ b/spec/lib/gitlab/ldap/person_spec.rb
@@ -139,6 +139,27 @@ describe Gitlab::LDAP::Person do
expect(person.username).to eq(attr_value)
end
end
+
+ context 'if lowercase_usernames setting is' do
+ let(:username_attribute) { 'uid' }
+
+ before do
+ entry[username_attribute] = 'JOHN'
+ @person = described_class.new(entry, 'ldapmain')
+ end
+
+ it 'enabled the username attribute is lower cased' do
+ stub_ldap_config(lowercase_usernames: true)
+
+ expect(@person.username).to eq 'john'
+ end
+
+ it 'disabled the username attribute is not lower cased' do
+ stub_ldap_config(lowercase_usernames: false)
+
+ expect(@person.username).to eq 'JOHN'
+ end
+ end
end
def assert_generic_test(test_description, got, expected)