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
a745349f
Commit
a745349f
authored
Aug 06, 2020
by
Imre Farkas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ScimFinder to support local part email as username
parent
f6e53638
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
6 deletions
+29
-6
ee/app/finders/scim_finder.rb
ee/app/finders/scim_finder.rb
+13
-1
ee/changelogs/233139-scim_finder_to_support_email_fragment_as_username.yml
...139-scim_finder_to_support_email_fragment_as_username.yml
+5
-0
ee/spec/finders/scim_finder_spec.rb
ee/spec/finders/scim_finder_spec.rb
+11
-5
No files found.
ee/app/finders/scim_finder.rb
View file @
a745349f
...
...
@@ -73,10 +73,22 @@ class ScimFinder
end
def
by_username
(
username
)
user
=
User
.
find_by_username
(
username
)
||
User
.
find_by_any_email
(
username
)
user
=
User
.
find_by_username
(
username
)
if
!
user
&&
email?
(
username
)
user
||=
User
.
find_by_any_email
(
username
)
||
User
.
find_by_username
(
email_local_part
(
username
))
end
return
group
.
scim_identities
.
for_user
(
user
)
if
scim_identities_enabled?
saml_provider
.
identities
.
for_user
(
user
)
end
def
email?
(
email
)
::
ValidateEmail
.
valid?
(
email
)
end
def
email_local_part
(
email
)
::
Mail
::
Address
.
new
(
email
).
local
end
end
ee/changelogs/233139-scim_finder_to_support_email_fragment_as_username.yml
0 → 100644
View file @
a745349f
---
title
:
SCIM get users API to search for email fragment as username
merge_request
:
38807
author
:
type
:
changed
ee/spec/finders/scim_finder_spec.rb
View file @
a745349f
...
...
@@ -3,7 +3,7 @@
require
'spec_helper'
RSpec
.
describe
ScimFinder
do
let
(
:group
)
{
create
(
:group
)
}
let
_it_be
(
:group
)
{
create
(
:group
)
}
let
(
:unused_params
)
{
double
}
subject
(
:finder
)
{
described_class
.
new
(
group
)
}
...
...
@@ -42,7 +42,7 @@ RSpec.describe ScimFinder do
end
context
'with SCIM enabled'
do
let
!
(
:saml_provider
)
{
create
(
:saml_provider
,
group:
group
)
}
let
_it_be
(
:saml_provider
)
{
create
(
:saml_provider
,
group:
group
)
}
context
'with an eq filter'
do
shared_examples
'valid lookups'
do
...
...
@@ -57,10 +57,15 @@ RSpec.describe ScimFinder do
end
context
'allows lookup by userName'
do
it
'finds user
when userName is
an email address'
do
it
'finds user
by
an email address'
do
expect
(
finder
.
search
(
filter:
"userName eq
#{
id
.
user
.
email
}
"
).
first
).
to
eq
id
end
it
'finds user by using local part of email address as username'
do
email
=
"
#{
id
.
user
.
username
}
@example.com"
expect
(
finder
.
search
(
filter:
"userName eq
#{
email
}
"
).
first
).
to
eq
id
end
it
'finds user by username'
do
expect
(
finder
.
search
(
filter:
"userName eq
\"
#{
id
.
user
.
username
}
\"
"
).
first
).
to
eq
id
end
...
...
@@ -75,7 +80,7 @@ RSpec.describe ScimFinder do
before
do
stub_feature_flags
(
scim_identities:
false
)
end
let
(
:id
)
{
create
(
:group_saml_identity
,
saml_provider:
saml_provider
)
}
let
_it_be
(
:id
)
{
create
(
:group_saml_identity
,
saml_provider:
saml_provider
)
}
it_behaves_like
'valid lookups'
end
...
...
@@ -84,7 +89,8 @@ RSpec.describe ScimFinder do
before
do
stub_feature_flags
(
scim_identities:
true
)
end
let
(
:id
)
{
create
(
:scim_identity
,
group:
group
)
}
let_it_be
(
:user
)
{
create
(
:user
,
username:
'foo'
,
email:
'bar@example.com'
)
}
let_it_be
(
:id
)
{
create
(
:scim_identity
,
group:
group
,
user:
user
)
}
it_behaves_like
'valid lookups'
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