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
Tatuya Kamada
gitlab-ce
Commits
11bb67c3
Commit
11bb67c3
authored
Sep 08, 2014
by
Jan-Willem van der Meer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test authenticate method for Gitlab::LDAP::User
parent
f27830fa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
11 deletions
+32
-11
lib/gitlab/ldap/user.rb
lib/gitlab/ldap/user.rb
+16
-11
spec/lib/gitlab/ldap/user_spec.rb
spec/lib/gitlab/ldap/user_spec.rb
+16
-0
No files found.
lib/gitlab/ldap/user.rb
View file @
11bb67c3
...
...
@@ -41,17 +41,8 @@ module Gitlab
# Only check with valid login and password to prevent anonymous bind results
return
nil
unless
ldap_conf
.
enabled
&&
login
.
present?
&&
password
.
present?
ldap
=
OmniAuth
::
LDAP
::
Adaptor
.
new
(
ldap_conf
)
filter
=
Net
::
LDAP
::
Filter
.
eq
(
ldap
.
uid
,
login
)
# Apply LDAP user filter if present
if
ldap_conf
[
'user_filter'
].
present?
user_filter
=
Net
::
LDAP
::
Filter
.
construct
(
ldap_conf
[
'user_filter'
])
filter
=
Net
::
LDAP
::
Filter
.
join
(
filter
,
user_filter
)
end
ldap_user
=
ldap
.
bind_as
(
filter:
filter
,
ldap_user
=
adapter
.
bind_as
(
filter:
user_filter
(
login
),
size:
1
,
password:
password
)
...
...
@@ -59,6 +50,10 @@ module Gitlab
find_by_uid
(
ldap_user
.
dn
)
if
ldap_user
end
def
adapter
@adapter
||=
OmniAuth
::
LDAP
::
Adaptor
.
new
(
ldap_conf
)
end
protected
def
find_by_uid_and_provider
...
...
@@ -81,6 +76,16 @@ module Gitlab
def
ldap_conf
Gitlab
.
config
.
ldap
end
def
user_filter
(
login
)
filter
=
Net
::
LDAP
::
Filter
.
eq
(
adapter
.
uid
,
login
)
# Apply LDAP user filter if present
if
ldap_conf
[
'user_filter'
].
present?
user_filter
=
Net
::
LDAP
::
Filter
.
construct
(
ldap_conf
[
'user_filter'
])
filter
=
Net
::
LDAP
::
Filter
.
join
(
filter
,
user_filter
)
end
filter
end
end
def
needs_blocking?
...
...
spec/lib/gitlab/ldap/user_spec.rb
View file @
11bb67c3
...
...
@@ -35,4 +35,20 @@ describe Gitlab::LDAP::User do
expect
{
gl_user
.
find_or_create
(
auth
)
}.
to
change
{
User
.
count
}.
by
(
1
)
end
end
describe
"authenticate"
do
let
(
:login
)
{
'john'
}
let
(
:password
)
{
'my-secret'
}
before
{
Gitlab
.
config
.
ldap
[
'enabled'
]
=
true
Gitlab
.
config
.
ldap
[
'user_filter'
]
=
'employeeType=developer'
}
after
{
Gitlab
.
config
.
ldap
[
'enabled'
]
=
false
}
it
"send an authentication request to ldap"
do
expect
(
Gitlab
::
LDAP
::
User
.
adapter
).
to
receive
(
:bind_as
)
Gitlab
::
LDAP
::
User
.
authenticate
(
login
,
password
)
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