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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
54594ab9
Commit
54594ab9
authored
Aug 19, 2020
by
Niko
Committed by
Michael Kozono
Aug 19, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lookup for users in LDAP based on their e-mail by their e-mail-address instead of only uid.
parent
1ea531ad
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
28 deletions
+51
-28
changelogs/unreleased/33767-search-users-in-LDAP-by-their-e-mail-address.yml
...ed/33767-search-users-in-LDAP-by-their-e-mail-address.yml
+5
-0
lib/gitlab/auth/o_auth/user.rb
lib/gitlab/auth/o_auth/user.rb
+1
-0
spec/lib/gitlab/auth/o_auth/user_spec.rb
spec/lib/gitlab/auth/o_auth/user_spec.rb
+45
-28
No files found.
changelogs/unreleased/33767-search-users-in-LDAP-by-their-e-mail-address.yml
0 → 100644
View file @
54594ab9
---
title
:
"
Allow
OAuth
to
auto
link
LDAP
users
via
email
address"
merge_request
:
33767
author
:
Niko Wenselowski
type
:
changed
lib/gitlab/auth/o_auth/user.rb
View file @
54594ab9
...
...
@@ -150,6 +150,7 @@ module Gitlab
def
find_ldap_person
(
auth_hash
,
adapter
)
Gitlab
::
Auth
::
Ldap
::
Person
.
find_by_uid
(
auth_hash
.
uid
,
adapter
)
||
Gitlab
::
Auth
::
Ldap
::
Person
.
find_by_email
(
auth_hash
.
uid
,
adapter
)
||
Gitlab
::
Auth
::
Ldap
::
Person
.
find_by_email
(
auth_hash
.
email
,
adapter
)
||
Gitlab
::
Auth
::
Ldap
::
Person
.
find_by_dn
(
auth_hash
.
uid
,
adapter
)
rescue
Gitlab
::
Auth
::
Ldap
::
LdapConnectionError
nil
...
...
spec/lib/gitlab/auth/o_auth/user_spec.rb
View file @
54594ab9
...
...
@@ -230,6 +230,7 @@ RSpec.describe Gitlab::Auth::OAuth::User do
end
context
"and no account for the LDAP user"
do
context
'when the LDAP user is found by UID'
do
before
do
allow
(
Gitlab
::
Auth
::
Ldap
::
Person
).
to
receive
(
:find_by_uid
).
and_return
(
ldap_user
)
...
...
@@ -266,6 +267,22 @@ RSpec.describe Gitlab::Auth::OAuth::User do
end
end
context
'when the LDAP user is found by email address'
do
before
do
allow
(
Gitlab
::
Auth
::
Ldap
::
Person
).
to
receive
(
:find_by_uid
).
and_return
(
nil
)
allow
(
Gitlab
::
Auth
::
Ldap
::
Person
).
to
receive
(
:find_by_email
).
with
(
uid
,
any_args
).
and_return
(
nil
)
allow
(
Gitlab
::
Auth
::
Ldap
::
Person
).
to
receive
(
:find_by_email
).
with
(
info_hash
[
:email
],
any_args
).
and_return
(
ldap_user
)
oauth_user
.
save
end
it
'creates the LDAP identity'
do
identities_as_hash
=
gl_user
.
identities
.
map
{
|
id
|
{
provider:
id
.
provider
,
extern_uid:
id
.
extern_uid
}
}
expect
(
identities_as_hash
).
to
include
({
provider:
'ldapmain'
,
extern_uid:
dn
})
end
end
end
context
"and LDAP user has an account already"
do
let!
(
:existing_user
)
{
create
(
:omniauth_user
,
name:
'John Doe'
,
email:
'john@example.com'
,
extern_uid:
dn
,
provider:
'ldapmain'
,
username:
'john'
)
}
...
...
@@ -791,7 +808,7 @@ RSpec.describe Gitlab::Auth::OAuth::User do
end
end
describe
'.
find_by
_uid_and_provider'
do
describe
'._uid_and_provider'
do
let!
(
:existing_user
)
{
create
(
:omniauth_user
,
extern_uid:
'my-uid'
,
provider:
'my-provider'
)
}
it
'normalizes extern_uid'
do
...
...
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