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
a652a631
Commit
a652a631
authored
Feb 22, 2019
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix parser and add more specs
parent
ac4f3c52
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
12 deletions
+68
-12
ee/lib/ee/gitlab/scim/params_parser.rb
ee/lib/ee/gitlab/scim/params_parser.rb
+36
-12
ee/spec/lib/gitlab/scim/params_parser_spec.rb
ee/spec/lib/gitlab/scim/params_parser_spec.rb
+32
-0
No files found.
ee/lib/ee/gitlab/scim/params_parser.rb
View file @
a652a631
...
...
@@ -4,30 +4,48 @@ module EE
module
Gitlab
module
Scim
class
ParamsParser
FILTER_OPERATORS
=
%w[eq]
OPERATIONS_OPERATORS
=
%w[Replace Add]
FILTER_OPERATORS
=
%w[eq]
.
freeze
OPERATIONS_OPERATORS
=
%w[Replace Add]
.
freeze
ATTRIBUTE_MAP
=
{
id: :extern_uid
,
'name.formatted'
:
:name
,
'emails[type eq "work".value'
:
:mail
'emails[type eq "work".value'
:
:mail
,
active: :active
}.
with_indifferent_access
COERCED_VALUES
=
{
'True'
=>
true
,
'False'
=>
false
}.
freeze
def
initialize
(
params
)
@filter
=
params
[
:filter
]
@operations
=
params
[
:operations
]
@hash
=
{}
end
def
deprovision_user?
hash
[
:active
]
==
false
end
def
to_hash
process_filter
process_operations
@hash
||=
begin
hash
=
{}
process_filter
(
hash
)
process_operations
(
hash
)
@hash
hash
end
end
alias_method
:hash
,
:to_hash
private
:hash
private
def
process_filter
def
process_filter
(
hash
)
return
unless
@filter
attribute
,
operator
,
value
=
@filter
.
split
...
...
@@ -35,20 +53,26 @@ module EE
return
unless
FILTER_OPERATORS
.
include?
(
operator
)
return
unless
ATTRIBUTE_MAP
[
attribute
]
@hash
[
ATTRIBUTE_MAP
[
attribute
]]
=
value
.
tr
(
'\"'
,
''
)
hash
[
ATTRIBUTE_MAP
[
attribute
]]
=
coerce
(
value
.
tr
(
'\"'
,
''
)
)
end
def
process_operations
def
process_operations
(
hash
)
return
unless
@operations
@operations
.
each
do
|
operation
|
next
unless
OPERATIONS_OPERATORS
.
contains
?
(
operation
[
:op
])
next
unless
OPERATIONS_OPERATORS
.
include
?
(
operation
[
:op
])
attribute
=
ATTRIBUTE_MAP
[
operation
[
:path
]]
@hash
[
attribute
]
=
operation
[
:value
]
if
attribute
hash
[
attribute
]
=
coerce
(
operation
[
:value
])
if
attribute
end
end
def
coerce
(
value
)
coerced
=
COERCED_VALUES
[
value
]
coerced
.
nil?
?
value
:
coerced
end
end
end
end
...
...
ee/spec/lib/gitlab/scim/params_parser_spec.rb
View file @
a652a631
...
...
@@ -9,5 +9,37 @@ describe EE::Gitlab::Scim::ParamsParser do
expect
(
described_class
.
new
(
filter:
filter
).
to_hash
).
to
eq
(
extern_uid:
'6ba81b08-77da'
)
end
it
'returns an empty hash for the wrong filter'
do
filter
=
'blah eq "6ba81b08-77da"'
expect
(
described_class
.
new
(
filter:
filter
).
to_hash
).
to
eq
({})
end
it
'returns the correct operation attributes'
do
operations
=
[{
"op"
:
"Replace"
,
"path"
:
"active"
,
"value"
:
"False"
}]
expect
(
described_class
.
new
(
operations:
operations
).
to_hash
).
to
eq
(
active:
false
)
end
it
'returns an empty hash for the wrong operations'
do
operations
=
[{
"op"
:
"Replace"
,
"path"
:
"test"
,
"value"
:
"False"
}]
expect
(
described_class
.
new
(
operations:
operations
).
to_hash
).
to
eq
({})
end
end
describe
'#deprovision_user?'
do
it
'returns true when deprovisioning'
do
operations
=
[{
"op"
:
"Replace"
,
"path"
:
"active"
,
"value"
:
"False"
}]
expect
(
described_class
.
new
(
operations:
operations
).
deprovision_user?
).
to
be
true
end
it
'returns an empty hash for the wrong operations'
do
operations
=
[{
"op"
:
"Replace"
,
"path"
:
"active"
,
"value"
:
"True"
}]
expect
(
described_class
.
new
(
operations:
operations
).
deprovision_user?
).
to
be
false
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