Commit 3d66e672 authored by Drew Blessing's avatar Drew Blessing Committed by Drew Blessing

Include LDAP UID attr in default attrs for LDAP lookups

In cases where the configured LDAP `uid` attribute is non-standard
(not `uid`, `samaccountname`, `userid`) the `username` value in
the LDAP auth hash will not contain a value. By including the
configured `uid` attribute in the `username` default attributes
array we ensure that the value will be present in the auth hash.
parent 8d1fe49b
---
title: Include LDAP UID attribute in default attributes for all LDAP lookups
merge_request: 28148
author:
type: fixed
...@@ -178,7 +178,7 @@ module Gitlab ...@@ -178,7 +178,7 @@ module Gitlab
def default_attributes def default_attributes
{ {
'username' => %w(uid sAMAccountName userid), 'username' => %W(#{uid} uid sAMAccountName userid).uniq,
'email' => %w(mail email userPrincipalName), 'email' => %w(mail email userPrincipalName),
'name' => 'cn', 'name' => 'cn',
'first_name' => 'givenName', 'first_name' => 'givenName',
......
...@@ -502,6 +502,20 @@ AtlErSqafbECNDSwS5BX8yDpu5yRBJ4xegO/rNlmb8ICRYkuJapD1xXicFOsmfUK ...@@ -502,6 +502,20 @@ AtlErSqafbECNDSwS5BX8yDpu5yRBJ4xegO/rNlmb8ICRYkuJapD1xXicFOsmfUK
end end
end end
describe '#default_attributes' do
it 'includes the configured uid attribute in the username attributes' do
stub_ldap_config(options: { 'uid' => 'my_uid_attr' })
expect(config.default_attributes['username']).to include('my_uid_attr')
end
it 'only includes unique values for username attributes' do
stub_ldap_config(options: { 'uid' => 'uid' })
expect(config.default_attributes['username']).to contain_exactly('uid', 'sAMAccountName', 'userid')
end
end
describe '#base' do describe '#base' do
context 'when the configured base is not normalized' do context 'when the configured base is not normalized' do
it 'returns the normalized base' do it 'returns the normalized base' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment