summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ldap/person_spec.rb
diff options
context:
space:
mode:
authorDrew Blessing <drew@gitlab.com>2017-01-03 10:05:47 -0600
committerDrew Blessing <drew@gitlab.com>2017-01-03 13:26:47 -0600
commitbabb7d5260087abfe09d7c4d6994433def7d8b99 (patch)
tree7d52381908b12330c035d20b7028e1a06b244e6e /spec/lib/gitlab/ldap/person_spec.rb
parent37ef8d72d447b24f15fc2db1dcf6cec360a2f8be (diff)
downloadgitlab-ce-babb7d5260087abfe09d7c4d6994433def7d8b99.tar.gz
Gitlab::LDAP::Person uses LDAP attributes configuration
We allow users to configure LDAP attribute preferences. For example, email can be configured to use `mail`, `email` and `userPrincipalName`, falling through to the next until a value is found. Prior to this change, Gitlab::LDAP::Person did not honor this configuration. Now, the class will honor `name` and `mail` configuration. It does not handle `username`, or fallback to `first_name` + `last_name` in the absence of `name`.
Diffstat (limited to 'spec/lib/gitlab/ldap/person_spec.rb')
-rw-r--r--spec/lib/gitlab/ldap/person_spec.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/spec/lib/gitlab/ldap/person_spec.rb b/spec/lib/gitlab/ldap/person_spec.rb
new file mode 100644
index 00000000000..60afe046788
--- /dev/null
+++ b/spec/lib/gitlab/ldap/person_spec.rb
@@ -0,0 +1,44 @@
+require 'spec_helper'
+
+describe Gitlab::LDAP::Person do
+ include LdapHelpers
+
+ let(:entry) { ldap_user_entry('john.doe') }
+
+ before do
+ stub_ldap_config(
+ attributes: {
+ name: 'cn',
+ email: %w(mail email userPrincipalName)
+ }
+ )
+ end
+
+ describe '#name' do
+ it 'uses the configured name attribute and handles values as an array' do
+ name = 'John Doe'
+ entry['cn'] = [name]
+ person = Gitlab::LDAP::Person.new(entry, 'ldapmain')
+
+ expect(person.name).to eq(name)
+ end
+ end
+
+ describe '#email' do
+ it 'returns the value of mail, if present' do
+ mail = 'john@example.com'
+ entry['mail'] = mail
+ person = Gitlab::LDAP::Person.new(entry, 'ldapmain')
+
+ expect(person.email).to eq(mail)
+ end
+
+ it 'returns the value of userPrincipalName, if mail and email are not present' do
+ user_principal_name = 'john.doe@example.com'
+ entry['userPrincipalName'] = user_principal_name
+ person = Gitlab::LDAP::Person.new(entry, 'ldapmain')
+
+ expect(person.email).to eq(user_principal_name)
+ end
+ end
+end