Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
de4eee08
Commit
de4eee08
authored
Jan 05, 2017
by
Drew Blessing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
LDAP attributes needs default values
parent
76bb8ed4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
45 additions
and
12 deletions
+45
-12
lib/gitlab/ldap/auth_hash.rb
lib/gitlab/ldap/auth_hash.rb
+1
-1
lib/gitlab/ldap/config.rb
lib/gitlab/ldap/config.rb
+11
-1
lib/gitlab/ldap/person.rb
lib/gitlab/ldap/person.rb
+3
-5
spec/lib/gitlab/ldap/config_spec.rb
spec/lib/gitlab/ldap/config_spec.rb
+23
-0
spec/lib/gitlab/ldap/person_spec.rb
spec/lib/gitlab/ldap/person_spec.rb
+7
-5
No files found.
lib/gitlab/ldap/auth_hash.rb
View file @
de4eee08
...
...
@@ -25,7 +25,7 @@ module Gitlab
end
def
get_raw
(
key
)
auth_hash
.
extra
[
:raw_info
][
key
]
auth_hash
.
extra
[
:raw_info
][
key
]
if
auth_hash
.
extra
end
def
ldap_config
...
...
lib/gitlab/ldap/config.rb
View file @
de4eee08
...
...
@@ -107,7 +107,7 @@ module Gitlab
end
def
attributes
options
[
'attributes'
]
default_attributes
.
merge
(
options
[
'attributes'
])
end
def
timeout
...
...
@@ -130,6 +130,16 @@ module Gitlab
end
end
def
default_attributes
{
'username'
=>
%w(uid userid sAMAccountName)
,
'email'
=>
%w(mail email userPrincipalName)
,
'name'
=>
'cn'
,
'first_name'
=>
'givenName'
,
'last_name'
=>
'sn'
}
end
protected
def
base_options
...
...
lib/gitlab/ldap/person.rb
View file @
de4eee08
...
...
@@ -28,7 +28,7 @@ module Gitlab
end
def
name
attribute_value
(
:name
)
attribute_value
(
:name
)
.
first
end
def
uid
...
...
@@ -62,14 +62,12 @@ module Gitlab
# this method looks for 'mail', 'email' and 'userPrincipalName' and
# returns the first with a value.
def
attribute_value
(
attribute
)
attributes
=
Array
(
config
.
attributes
[
attribute
.
to_s
ym
])
attributes
=
Array
(
config
.
attributes
[
attribute
.
to_s
])
selected_attr
=
attributes
.
find
{
|
attr
|
entry
.
respond_to?
(
attr
)
}
return
nil
unless
selected_attr
# Some LDAP attributes return an array,
# even if it is a single value (like 'cn')
Array
(
entry
.
public_send
(
selected_attr
)).
first
entry
.
public_send
(
selected_attr
)
end
end
end
...
...
spec/lib/gitlab/ldap/config_spec.rb
View file @
de4eee08
...
...
@@ -129,4 +129,27 @@ describe Gitlab::LDAP::Config, lib: true do
expect
(
config
.
has_auth?
).
to
be_falsey
end
end
describe
'#attributes'
do
it
'uses default attributes when no custom attributes are configured'
do
expect
(
config
.
attributes
).
to
eq
(
config
.
default_attributes
)
end
it
'merges the configuration attributes with default attributes'
do
stub_ldap_config
(
options:
{
'attributes'
=>
{
'username'
=>
%w(sAMAccountName)
,
'email'
=>
%w(userPrincipalName)
}
}
)
expect
(
config
.
attributes
).
to
include
({
'username'
=>
%w(sAMAccountName)
,
'email'
=>
%w(userPrincipalName)
,
'name'
=>
'cn'
})
end
end
end
spec/lib/gitlab/ldap/person_spec.rb
View file @
de4eee08
...
...
@@ -7,9 +7,11 @@ describe Gitlab::LDAP::Person do
before
do
stub_ldap_config
(
attributes:
{
name:
'cn'
,
email:
%w(mail email userPrincipalName)
options:
{
'attributes'
=>
{
'name'
=>
'cn'
,
'email'
=>
%w(mail email userPrincipalName)
}
}
)
end
...
...
@@ -30,7 +32,7 @@ describe Gitlab::LDAP::Person do
entry
[
'mail'
]
=
mail
person
=
Gitlab
::
LDAP
::
Person
.
new
(
entry
,
'ldapmain'
)
expect
(
person
.
email
).
to
eq
(
mail
)
expect
(
person
.
email
).
to
eq
(
[
mail
]
)
end
it
'returns the value of userPrincipalName, if mail and email are not present'
do
...
...
@@ -38,7 +40,7 @@ describe Gitlab::LDAP::Person do
entry
[
'userPrincipalName'
]
=
user_principal_name
person
=
Gitlab
::
LDAP
::
Person
.
new
(
entry
,
'ldapmain'
)
expect
(
person
.
email
).
to
eq
(
user_principal_name
)
expect
(
person
.
email
).
to
eq
(
[
user_principal_name
]
)
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment