Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dex
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hdacloud
dex
Commits
d31f6eab
Unverified
Commit
d31f6eab
authored
5 years ago
by
Andrew Block
Browse files
Options
Downloads
Patches
Plain Diff
Corrected logic in group verification
parent
296659cb
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
connector/openshift/openshift.go
+8
-6
8 additions, 6 deletions
connector/openshift/openshift.go
connector/openshift/openshift_test.go
+21
-3
21 additions, 3 deletions
connector/openshift/openshift_test.go
with
29 additions
and
9 deletions
connector/openshift/openshift.go
+
8
−
6
View file @
d31f6eab
...
@@ -165,10 +165,12 @@ func (c *openshiftConnector) HandleCallback(s connector.Scopes, r *http.Request)
...
@@ -165,10 +165,12 @@ func (c *openshiftConnector) HandleCallback(s connector.Scopes, r *http.Request)
return
identity
,
fmt
.
Errorf
(
"openshift: get user: %v"
,
err
)
return
identity
,
fmt
.
Errorf
(
"openshift: get user: %v"
,
err
)
}
}
validGroups
:=
validateRequiredGroups
(
user
.
Groups
,
c
.
groups
)
if
len
(
c
.
groups
)
>
0
{
validGroups
:=
validateAllowedGroups
(
user
.
Groups
,
c
.
groups
)
if
!
validGroups
{
if
!
validGroups
{
return
identity
,
fmt
.
Errorf
(
"openshift: user %q is not in any of the required groups"
,
user
.
Name
)
return
identity
,
fmt
.
Errorf
(
"openshift: user %q is not in any of the required groups"
,
user
.
Name
)
}
}
}
identity
=
connector
.
Identity
{
identity
=
connector
.
Identity
{
...
@@ -211,10 +213,10 @@ func (c *openshiftConnector) user(ctx context.Context, client *http.Client) (u u
...
@@ -211,10 +213,10 @@ func (c *openshiftConnector) user(ctx context.Context, client *http.Client) (u u
return
u
,
err
return
u
,
err
}
}
func
validate
Requir
edGroups
(
userGroups
,
requir
edGroups
[]
string
)
bool
{
func
validate
Allow
edGroups
(
userGroups
,
allow
edGroups
[]
string
)
bool
{
matchingGroups
:=
groups
.
Filter
(
userGroups
,
requir
edGroups
)
matchingGroups
:=
groups
.
Filter
(
userGroups
,
allow
edGroups
)
return
len
(
requiredGroups
)
==
len
(
matchingGroups
)
return
len
(
matchingGroups
)
!=
0
}
}
// newHTTPClient returns a new HTTP client
// newHTTPClient returns a new HTTP client
...
...
This diff is collapsed.
Click to expand it.
connector/openshift/openshift_test.go
+
21
−
3
View file @
d31f6eab
...
@@ -83,11 +83,29 @@ func TestGetUser(t *testing.T) {
...
@@ -83,11 +83,29 @@ func TestGetUser(t *testing.T) {
expectEquals
(
t
,
len
(
u
.
Groups
),
1
)
expectEquals
(
t
,
len
(
u
.
Groups
),
1
)
}
}
func
TestVerifyGroupFn
(
t
*
testing
.
T
)
{
func
TestVerify
Single
GroupFn
(
t
*
testing
.
T
)
{
requir
edGroups
:=
[]
string
{
"users"
}
allow
edGroups
:=
[]
string
{
"users"
}
groupMembership
:=
[]
string
{
"users"
,
"org1"
}
groupMembership
:=
[]
string
{
"users"
,
"org1"
}
validGroupMembership
:=
validateRequiredGroups
(
groupMembership
,
requiredGroups
)
validGroupMembership
:=
validateAllowedGroups
(
groupMembership
,
allowedGroups
)
expectEquals
(
t
,
validGroupMembership
,
true
)
}
func
TestVerifySingleGroupFailureFn
(
t
*
testing
.
T
)
{
allowedGroups
:=
[]
string
{
"admins"
}
groupMembership
:=
[]
string
{
"users"
}
validGroupMembership
:=
validateAllowedGroups
(
groupMembership
,
allowedGroups
)
expectEquals
(
t
,
validGroupMembership
,
false
)
}
func
TestVerifyMultipleGroupFn
(
t
*
testing
.
T
)
{
allowedGroups
:=
[]
string
{
"users"
,
"admins"
}
groupMembership
:=
[]
string
{
"users"
,
"org1"
}
validGroupMembership
:=
validateAllowedGroups
(
groupMembership
,
allowedGroups
)
expectEquals
(
t
,
validGroupMembership
,
true
)
expectEquals
(
t
,
validGroupMembership
,
true
)
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment