Commit 5a9ca9e4 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'jej/scim-name-fallback' into 'master'

SCIM uses fallbacks when name.formatted not present

Closes #13016 and #13093

See merge request gitlab-org/gitlab-ee!14878
parents 043aacf1 ccc97d0d
---
title: SCIM uses fallbacks when name.formatted not present
merge_request: 14878
author:
type: fixed
......@@ -9,6 +9,7 @@ module EE
ATTRIBUTE_MAP = {
id: :extern_uid,
displayName: :name,
'name.formatted': :name,
'emails[type eq "work"].value': :email,
active: :active,
......@@ -67,10 +68,8 @@ module EE
end
def process_params
parse_params.merge(
email: parse_emails,
name: parse_name
).compact # so if parse_emails returns nil, it'll be removed from the hash
overwrites = { email: parse_emails, name: parse_name }.compact
parse_params.merge(overwrites)
end
# rubocop: disable CodeReuse/ActiveRecord
......@@ -96,7 +95,11 @@ module EE
def parse_name
name = @params.delete(:name)
@hash[:name] = name[:formatted] if name
return unless name
formatted_name = name[:formatted]&.presence
formatted_name ||= [name[:givenName], name[:familyName]].compact.join(' ')
@hash[:name] = formatted_name
end
def coerce(value)
......
......@@ -28,6 +28,12 @@ describe EE::Gitlab::Scim::ParamsParser do
expect(described_class.new(Operations: operations).result).to eq({})
end
it 'can update name from displayName' do
operations = [{ 'op': 'Replace', 'path': 'displayName', 'value': 'My Name Is' }]
expect(described_class.new(Operations: operations).result).to include(name: 'My Name Is')
end
it 'returns a parsed hash for POST params' do
params = {
externalId: 'test',
......@@ -37,15 +43,28 @@ describe EE::Gitlab::Scim::ParamsParser do
{ primary: nil, type: 'work', value: 'work@example.com' },
{ primary: nil, type: 'home', value: 'home@example.com' }
],
name: { formatted: 'Test Name', familyName: 'Name', givenName: 'Test' },
name: { formatted: 'Test A. Name', familyName: 'Name', givenName: 'Test' },
displayName: 'Test A',
extra: true
}
expect(described_class.new(params).result).to eq(email: 'work@example.com',
extern_uid: 'test',
name: 'Test Name',
name: 'Test A. Name',
username: 'username')
end
it 'can construct a name from givenName and familyName' do
params = { name: { givenName: 'Fred', familyName: 'Nurk' } }
expect(described_class.new(params).result).to include(name: 'Fred Nurk')
end
it 'falls back to displayName when other names are missing' do
params = { displayName: 'My Name' }
expect(described_class.new(params).result).to include(name: 'My Name')
end
end
describe '#deprovision_user?' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment