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
Hide 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,39 +230,56 @@ RSpec.describe Gitlab::Auth::OAuth::User do
end
context
"and no account for the LDAP user"
do
before
do
allow
(
Gitlab
::
Auth
::
Ldap
::
Person
).
to
receive
(
:find_by_uid
).
and_return
(
ldap_user
)
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
)
oauth_user
.
save
end
oauth_user
.
save
end
it
"creates a user with dual LDAP and omniauth identities"
do
expect
(
gl_user
).
to
be_valid
expect
(
gl_user
.
username
).
to
eql
uid
expect
(
gl_user
.
name
).
to
eql
'John Doe'
expect
(
gl_user
.
email
).
to
eql
'johndoe@example.com'
expect
(
gl_user
.
identities
.
length
).
to
be
2
identities_as_hash
=
gl_user
.
identities
.
map
{
|
id
|
{
provider:
id
.
provider
,
extern_uid:
id
.
extern_uid
}
}
expect
(
identities_as_hash
).
to
match_array
(
[
{
provider:
'ldapmain'
,
extern_uid:
dn
},
{
provider:
'twitter'
,
extern_uid:
uid
}
]
)
end
it
"creates a user with dual LDAP and omniauth identities"
do
expect
(
gl_user
).
to
be_valid
expect
(
gl_user
.
username
).
to
eql
uid
expect
(
gl_user
.
name
).
to
eql
'John Doe'
expect
(
gl_user
.
email
).
to
eql
'johndoe@example.com'
expect
(
gl_user
.
identities
.
length
).
to
be
2
identities_as_hash
=
gl_user
.
identities
.
map
{
|
id
|
{
provider:
id
.
provider
,
extern_uid:
id
.
extern_uid
}
}
expect
(
identities_as_hash
).
to
match_array
(
[
{
provider:
'ldapmain'
,
extern_uid:
dn
},
{
provider:
'twitter'
,
extern_uid:
uid
}
]
)
end
it
"has name and email set as synced"
do
expect
(
gl_user
.
user_synced_attributes_metadata
.
name_synced
).
to
be_truthy
expect
(
gl_user
.
user_synced_attributes_metadata
.
email_synced
).
to
be_truthy
end
it
"has name and email set as synced"
do
expect
(
gl_user
.
user_synced_attributes_metadata
.
name_synced
).
to
be_truthy
expect
(
gl_user
.
user_synced_attributes_metadata
.
email_synced
).
to
be_truthy
end
it
"has name and email set as read-only"
do
expect
(
gl_user
.
read_only_attribute?
(
:name
)).
to
be_truthy
expect
(
gl_user
.
read_only_attribute?
(
:email
)).
to
be_truthy
end
it
"has name and email set as read-only
"
do
expect
(
gl_user
.
read_only_attribute?
(
:name
)).
to
be_truthy
e
xpect
(
gl_user
.
read_only_attribute?
(
:email
)).
to
be_truthy
it
"has synced attributes provider set to ldapmain
"
do
expect
(
gl_user
.
user_synced_attributes_metadata
.
provider
).
to
eql
'ldapmain'
e
nd
end
it
"has synced attributes provider set to ldapmain"
do
expect
(
gl_user
.
user_synced_attributes_metadata
.
provider
).
to
eql
'ldapmain'
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
...
...
@@ -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