Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dex
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
dex
Commits
49fa5ee6
Commit
49fa5ee6
authored
Nov 12, 2018
by
Cosmin Cojocar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid overwriting exiting redirect URI and trusted peers when updating the client
Also skip configure the Public field.
parent
6536d978
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
3 deletions
+58
-3
api.go
server/api.go
+19
-3
api_test.go
server/api_test.go
+39
-0
No files found.
server/api.go
View file @
49fa5ee6
...
@@ -87,12 +87,11 @@ func (d dexAPI) UpdateClient(ctx context.Context, req *api.UpdateClientReq) (*ap
...
@@ -87,12 +87,11 @@ func (d dexAPI) UpdateClient(ctx context.Context, req *api.UpdateClientReq) (*ap
err
:=
d
.
s
.
UpdateClient
(
req
.
Id
,
func
(
old
storage
.
Client
)
(
storage
.
Client
,
error
)
{
err
:=
d
.
s
.
UpdateClient
(
req
.
Id
,
func
(
old
storage
.
Client
)
(
storage
.
Client
,
error
)
{
if
req
.
RedirectUris
!=
nil
&&
len
(
req
.
RedirectUris
)
>
0
{
if
req
.
RedirectUris
!=
nil
&&
len
(
req
.
RedirectUris
)
>
0
{
old
.
RedirectURIs
=
req
.
RedirectUris
old
.
RedirectURIs
=
mergeSlice
(
old
.
RedirectURIs
,
req
.
RedirectUris
)
}
}
if
req
.
TrustedPeers
!=
nil
&&
len
(
req
.
TrustedPeers
)
>
0
{
if
req
.
TrustedPeers
!=
nil
&&
len
(
req
.
TrustedPeers
)
>
0
{
old
.
TrustedPeers
=
req
.
TrustedPeers
old
.
TrustedPeers
=
mergeSlice
(
old
.
TrustedPeers
,
req
.
TrustedPeers
)
}
}
old
.
Public
=
req
.
Public
if
req
.
Name
!=
""
{
if
req
.
Name
!=
""
{
old
.
Name
=
req
.
Name
old
.
Name
=
req
.
Name
}
}
...
@@ -112,6 +111,23 @@ func (d dexAPI) UpdateClient(ctx context.Context, req *api.UpdateClientReq) (*ap
...
@@ -112,6 +111,23 @@ func (d dexAPI) UpdateClient(ctx context.Context, req *api.UpdateClientReq) (*ap
return
&
api
.
UpdateClientResp
{},
nil
return
&
api
.
UpdateClientResp
{},
nil
}
}
func
mergeSlice
(
s1
[]
string
,
s2
[]
string
)
[]
string
{
isPresent
:=
func
(
i
string
,
s
[]
string
)
bool
{
for
_
,
j
:=
range
s
{
if
j
==
i
{
return
true
}
}
return
false
}
for
_
,
i
:=
range
s2
{
if
!
isPresent
(
i
,
s1
)
{
s1
=
append
(
s1
,
i
)
}
}
return
s1
}
func
(
d
dexAPI
)
DeleteClient
(
ctx
context
.
Context
,
req
*
api
.
DeleteClientReq
)
(
*
api
.
DeleteClientResp
,
error
)
{
func
(
d
dexAPI
)
DeleteClient
(
ctx
context
.
Context
,
req
*
api
.
DeleteClientReq
)
(
*
api
.
DeleteClientResp
,
error
)
{
err
:=
d
.
s
.
DeleteClient
(
req
.
Id
)
err
:=
d
.
s
.
DeleteClient
(
req
.
Id
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
server/api_test.go
View file @
49fa5ee6
...
@@ -461,3 +461,42 @@ func find(item string, items []string) bool {
...
@@ -461,3 +461,42 @@ func find(item string, items []string) bool {
}
}
return
false
return
false
}
}
func
TestMergeSlice
(
t
*
testing
.
T
)
{
tests
:=
map
[
string
]
struct
{
s1
[]
string
s2
[]
string
want
[]
string
}{
"merge slice"
:
{
s1
:
[]
string
{
"t1"
,
"t2"
},
s2
:
[]
string
{
"t3"
},
want
:
[]
string
{
"t1"
,
"t2"
,
"t3"
},
},
"merge slice with duplicates"
:
{
s1
:
[]
string
{
"t1"
,
"t2"
},
s2
:
[]
string
{
"t3"
,
"t2"
},
want
:
[]
string
{
"t1"
,
"t2"
,
"t3"
},
},
"merge slice with empty slice"
:
{
s1
:
[]
string
{
"t1"
,
"t2"
},
s2
:
[]
string
{},
want
:
[]
string
{
"t1"
,
"t2"
},
},
}
for
name
,
tc
:=
range
tests
{
t
.
Run
(
name
,
func
(
t
*
testing
.
T
)
{
got
:=
mergeSlice
(
tc
.
s1
,
tc
.
s2
)
if
len
(
got
)
!=
len
(
tc
.
want
)
{
t
.
Errorf
(
"expected equal slice"
)
}
for
_
,
want
:=
range
tc
.
want
{
found
:=
find
(
want
,
got
)
if
!
found
{
t
.
Errorf
(
"missing element: %s"
,
want
)
}
}
})
}
}
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