|
@@ -13,7 +13,9 @@ func TestLdapAuther(t *testing.T) {
|
|
|
Convey("When translating ldap user to grafana user", t, func() {
|
|
Convey("When translating ldap user to grafana user", t, func() {
|
|
|
|
|
|
|
|
Convey("Given no ldap group map match", func() {
|
|
Convey("Given no ldap group map match", func() {
|
|
|
- ldapAuther := NewLdapAuthenticator(&LdapServerConf{})
|
|
|
|
|
|
|
+ ldapAuther := NewLdapAuthenticator(&LdapServerConf{
|
|
|
|
|
+ LdapGroups: []*LdapGroupToOrgRole{{}},
|
|
|
|
|
+ })
|
|
|
_, err := ldapAuther.getGrafanaUserFor(&ldapUserInfo{})
|
|
_, err := ldapAuther.getGrafanaUserFor(&ldapUserInfo{})
|
|
|
|
|
|
|
|
So(err, ShouldEqual, ErrInvalidCredentials)
|
|
So(err, ShouldEqual, ErrInvalidCredentials)
|
|
@@ -24,7 +26,7 @@ func TestLdapAuther(t *testing.T) {
|
|
|
ldapAutherScenario("Given wildcard group match", func(sc *scenarioContext) {
|
|
ldapAutherScenario("Given wildcard group match", func(sc *scenarioContext) {
|
|
|
ldapAuther := NewLdapAuthenticator(&LdapServerConf{
|
|
ldapAuther := NewLdapAuthenticator(&LdapServerConf{
|
|
|
LdapGroups: []*LdapGroupToOrgRole{
|
|
LdapGroups: []*LdapGroupToOrgRole{
|
|
|
- {GroupDN: "*", OrgRole: "Admin", OrgName: "Main"},
|
|
|
|
|
|
|
+ {GroupDN: "*", OrgRole: "Admin"},
|
|
|
},
|
|
},
|
|
|
})
|
|
})
|
|
|
|
|
|
|
@@ -38,7 +40,7 @@ func TestLdapAuther(t *testing.T) {
|
|
|
ldapAutherScenario("Given exact group match", func(sc *scenarioContext) {
|
|
ldapAutherScenario("Given exact group match", func(sc *scenarioContext) {
|
|
|
ldapAuther := NewLdapAuthenticator(&LdapServerConf{
|
|
ldapAuther := NewLdapAuthenticator(&LdapServerConf{
|
|
|
LdapGroups: []*LdapGroupToOrgRole{
|
|
LdapGroups: []*LdapGroupToOrgRole{
|
|
|
- {GroupDN: "cn=users", OrgRole: "Admin", OrgName: "Main"},
|
|
|
|
|
|
|
+ {GroupDN: "cn=users", OrgRole: "Admin"},
|
|
|
},
|
|
},
|
|
|
})
|
|
})
|
|
|
|
|
|
|
@@ -52,7 +54,7 @@ func TestLdapAuther(t *testing.T) {
|
|
|
ldapAutherScenario("Given no existing grafana user", func(sc *scenarioContext) {
|
|
ldapAutherScenario("Given no existing grafana user", func(sc *scenarioContext) {
|
|
|
ldapAuther := NewLdapAuthenticator(&LdapServerConf{
|
|
ldapAuther := NewLdapAuthenticator(&LdapServerConf{
|
|
|
LdapGroups: []*LdapGroupToOrgRole{
|
|
LdapGroups: []*LdapGroupToOrgRole{
|
|
|
- {GroupDN: "cn=users", OrgRole: "Admin", OrgName: "Main"},
|
|
|
|
|
|
|
+ {GroupDN: "cn=users", OrgRole: "Admin"},
|
|
|
},
|
|
},
|
|
|
})
|
|
})
|
|
|
|
|
|
|
@@ -78,6 +80,28 @@ 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.syncOrgRoles(&m.User{}, &ldapUserInfo{
|
|
|
|
|
+ MemberOf: []string{"cn=users"},
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ Convey("Should create new org user", func() {
|
|
|
|
|
+ So(err, ShouldBeNil)
|
|
|
|
|
+ So(sc.addOrgUserCommand, ShouldNotBeNil)
|
|
|
|
|
+ So(sc.addOrgUserCommand.Role, ShouldEqual, m.ROLE_ADMIN)
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func ldapAutherScenario(desc string, fn scenarioFunc) {
|
|
func ldapAutherScenario(desc string, fn scenarioFunc) {
|
|
@@ -85,18 +109,25 @@ func ldapAutherScenario(desc string, fn scenarioFunc) {
|
|
|
defer bus.ClearBusHandlers()
|
|
defer bus.ClearBusHandlers()
|
|
|
|
|
|
|
|
sc := &scenarioContext{}
|
|
sc := &scenarioContext{}
|
|
|
|
|
+
|
|
|
bus.AddHandler("test", func(cmd *m.CreateUserCommand) error {
|
|
bus.AddHandler("test", func(cmd *m.CreateUserCommand) error {
|
|
|
sc.createUserCmd = cmd
|
|
sc.createUserCmd = cmd
|
|
|
sc.createUserCmd.Result = m.User{Login: cmd.Login}
|
|
sc.createUserCmd.Result = m.User{Login: cmd.Login}
|
|
|
return nil
|
|
return nil
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+ bus.AddHandler("test", func(cmd *m.AddOrgUserCommand) error {
|
|
|
|
|
+ sc.addOrgUserCommand = cmd
|
|
|
|
|
+ return nil
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
fn(sc)
|
|
fn(sc)
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
type scenarioContext struct {
|
|
type scenarioContext struct {
|
|
|
- createUserCmd *m.CreateUserCommand
|
|
|
|
|
|
|
+ createUserCmd *m.CreateUserCommand
|
|
|
|
|
+ addOrgUserCommand *m.AddOrgUserCommand
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (sc *scenarioContext) userQueryReturns(user *m.User) {
|
|
func (sc *scenarioContext) userQueryReturns(user *m.User) {
|
|
@@ -110,4 +141,11 @@ func (sc *scenarioContext) userQueryReturns(user *m.User) {
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func (sc *scenarioContext) userOrgsQueryReturns(orgs []*m.UserOrgDTO) {
|
|
|
|
|
+ bus.AddHandler("test", func(query *m.GetUserOrgListQuery) error {
|
|
|
|
|
+ query.Result = orgs
|
|
|
|
|
+ return nil
|
|
|
|
|
+ })
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
type scenarioFunc func(c *scenarioContext)
|
|
type scenarioFunc func(c *scenarioContext)
|