Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
857830d9
Unverified
Commit
857830d9
authored
Apr 16, 2018
by
Dan Cech
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
org role sync tests
parent
52503d9c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
121 additions
and
0 deletions
+121
-0
pkg/login/ldap_test.go
+121
-0
No files found.
pkg/login/ldap_test.go
View file @
857830d9
...
...
@@ -91,6 +91,127 @@ func TestLdapAuther(t *testing.T) {
})
Convey
(
"When syncing ldap groups to grafana org roles"
,
t
,
func
()
{
ldapAutherScenario
(
"given no current user orgs"
,
func
(
sc
*
scenarioContext
)
{
ldapAuther
:=
NewLdapAuthenticator
(
&
LdapServerConf
{
LdapGroups
:
[]
*
LdapGroupToOrgRole
{
{
GroupDN
:
"cn=users"
,
OrgRole
:
"Admin"
},
},
})
sc
.
userOrgsQueryReturns
([]
*
m
.
UserOrgDTO
{})
_
,
err
:=
ldapAuther
.
GetGrafanaUserFor
(
nil
,
&
LdapUserInfo
{
MemberOf
:
[]
string
{
"cn=users"
},
})
Convey
(
"Should create new org user"
,
func
()
{
So
(
err
,
ShouldBeNil
)
So
(
sc
.
addOrgUserCmd
,
ShouldNotBeNil
)
So
(
sc
.
addOrgUserCmd
.
Role
,
ShouldEqual
,
m
.
ROLE_ADMIN
)
})
})
ldapAutherScenario
(
"given different current org role"
,
func
(
sc
*
scenarioContext
)
{
ldapAuther
:=
NewLdapAuthenticator
(
&
LdapServerConf
{
LdapGroups
:
[]
*
LdapGroupToOrgRole
{
{
GroupDN
:
"cn=users"
,
OrgId
:
1
,
OrgRole
:
"Admin"
},
},
})
sc
.
userOrgsQueryReturns
([]
*
m
.
UserOrgDTO
{{
OrgId
:
1
,
Role
:
m
.
ROLE_EDITOR
}})
_
,
err
:=
ldapAuther
.
GetGrafanaUserFor
(
nil
,
&
LdapUserInfo
{
MemberOf
:
[]
string
{
"cn=users"
},
})
Convey
(
"Should update org role"
,
func
()
{
So
(
err
,
ShouldBeNil
)
So
(
sc
.
updateOrgUserCmd
,
ShouldNotBeNil
)
So
(
sc
.
updateOrgUserCmd
.
Role
,
ShouldEqual
,
m
.
ROLE_ADMIN
)
})
})
ldapAutherScenario
(
"given current org role is removed in ldap"
,
func
(
sc
*
scenarioContext
)
{
ldapAuther
:=
NewLdapAuthenticator
(
&
LdapServerConf
{
LdapGroups
:
[]
*
LdapGroupToOrgRole
{
{
GroupDN
:
"cn=users"
,
OrgId
:
1
,
OrgRole
:
"Admin"
},
},
})
sc
.
userOrgsQueryReturns
([]
*
m
.
UserOrgDTO
{
{
OrgId
:
1
,
Role
:
m
.
ROLE_EDITOR
},
{
OrgId
:
2
,
Role
:
m
.
ROLE_EDITOR
},
})
_
,
err
:=
ldapAuther
.
GetGrafanaUserFor
(
nil
,
&
LdapUserInfo
{
MemberOf
:
[]
string
{
"cn=users"
},
})
Convey
(
"Should remove org role"
,
func
()
{
So
(
err
,
ShouldBeNil
)
So
(
sc
.
removeOrgUserCmd
,
ShouldNotBeNil
)
})
})
ldapAutherScenario
(
"given org role is updated in config"
,
func
(
sc
*
scenarioContext
)
{
ldapAuther
:=
NewLdapAuthenticator
(
&
LdapServerConf
{
LdapGroups
:
[]
*
LdapGroupToOrgRole
{
{
GroupDN
:
"cn=admin"
,
OrgId
:
1
,
OrgRole
:
"Admin"
},
{
GroupDN
:
"cn=users"
,
OrgId
:
1
,
OrgRole
:
"Viewer"
},
},
})
sc
.
userOrgsQueryReturns
([]
*
m
.
UserOrgDTO
{{
OrgId
:
1
,
Role
:
m
.
ROLE_EDITOR
}})
_
,
err
:=
ldapAuther
.
GetGrafanaUserFor
(
nil
,
&
LdapUserInfo
{
MemberOf
:
[]
string
{
"cn=users"
},
})
Convey
(
"Should update org role"
,
func
()
{
So
(
err
,
ShouldBeNil
)
So
(
sc
.
removeOrgUserCmd
,
ShouldBeNil
)
So
(
sc
.
updateOrgUserCmd
,
ShouldNotBeNil
)
})
})
ldapAutherScenario
(
"given multiple matching ldap groups"
,
func
(
sc
*
scenarioContext
)
{
ldapAuther
:=
NewLdapAuthenticator
(
&
LdapServerConf
{
LdapGroups
:
[]
*
LdapGroupToOrgRole
{
{
GroupDN
:
"cn=admins"
,
OrgId
:
1
,
OrgRole
:
"Admin"
},
{
GroupDN
:
"*"
,
OrgId
:
1
,
OrgRole
:
"Viewer"
},
},
})
sc
.
userOrgsQueryReturns
([]
*
m
.
UserOrgDTO
{{
OrgId
:
1
,
Role
:
m
.
ROLE_ADMIN
}})
_
,
err
:=
ldapAuther
.
GetGrafanaUserFor
(
nil
,
&
LdapUserInfo
{
MemberOf
:
[]
string
{
"cn=admins"
},
})
Convey
(
"Should take first match, and ignore subsequent matches"
,
func
()
{
So
(
err
,
ShouldBeNil
)
So
(
sc
.
updateOrgUserCmd
,
ShouldBeNil
)
})
})
ldapAutherScenario
(
"given multiple matching ldap groups and no existing groups"
,
func
(
sc
*
scenarioContext
)
{
ldapAuther
:=
NewLdapAuthenticator
(
&
LdapServerConf
{
LdapGroups
:
[]
*
LdapGroupToOrgRole
{
{
GroupDN
:
"cn=admins"
,
OrgId
:
1
,
OrgRole
:
"Admin"
},
{
GroupDN
:
"*"
,
OrgId
:
1
,
OrgRole
:
"Viewer"
},
},
})
sc
.
userOrgsQueryReturns
([]
*
m
.
UserOrgDTO
{})
_
,
err
:=
ldapAuther
.
GetGrafanaUserFor
(
nil
,
&
LdapUserInfo
{
MemberOf
:
[]
string
{
"cn=admins"
},
})
Convey
(
"Should take first match, and ignore subsequent matches"
,
func
()
{
So
(
err
,
ShouldBeNil
)
So
(
sc
.
addOrgUserCmd
.
Role
,
ShouldEqual
,
m
.
ROLE_ADMIN
)
})
})
})
Convey
(
"When calling SyncUser"
,
t
,
func
()
{
mockLdapConnection
:=
&
mockLdapConn
{}
...
...
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