mirror of https://github.com/grafana/grafana
prometheushacktoberfestmetricsmonitoringalertinggrafanagoinfluxdbmysqlpostgresanalyticsdata-visualizationdashboardbusiness-intelligenceelasticsearch
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
497 lines
14 KiB
497 lines
14 KiB
![]()
6 years ago
|
package ldap
|
||
![]()
10 years ago
|
|
||
|
import (
|
||
![]()
7 years ago
|
"context"
|
||
![]()
10 years ago
|
"testing"
|
||
|
|
||
![]()
6 years ago
|
. "github.com/smartystreets/goconvey/convey"
|
||
|
"gopkg.in/ldap.v3"
|
||
|
|
||
![]()
10 years ago
|
"github.com/grafana/grafana/pkg/bus"
|
||
![]()
7 years ago
|
"github.com/grafana/grafana/pkg/log"
|
||
![]()
10 years ago
|
m "github.com/grafana/grafana/pkg/models"
|
||
|
)
|
||
|
|
||
![]()
6 years ago
|
func TestAuth(t *testing.T) {
|
||
![]()
6 years ago
|
Convey("initialBind", t, func() {
|
||
|
Convey("Given bind dn and password configured", func() {
|
||
|
conn := &mockLdapConn{}
|
||
|
var actualUsername, actualPassword string
|
||
|
conn.bindProvider = func(username, password string) error {
|
||
|
actualUsername = username
|
||
|
actualPassword = password
|
||
|
return nil
|
||
|
}
|
||
![]()
6 years ago
|
Auth := &Auth{
|
||
![]()
6 years ago
|
conn: conn,
|
||
![]()
6 years ago
|
server: &ServerConfig{
|
||
![]()
6 years ago
|
BindDN: "cn=%s,o=users,dc=grafana,dc=org",
|
||
|
BindPassword: "bindpwd",
|
||
|
},
|
||
|
}
|
||
![]()
6 years ago
|
err := Auth.initialBind("user", "pwd")
|
||
![]()
6 years ago
|
So(err, ShouldBeNil)
|
||
![]()
6 years ago
|
So(Auth.requireSecondBind, ShouldBeTrue)
|
||
![]()
6 years ago
|
So(actualUsername, ShouldEqual, "cn=user,o=users,dc=grafana,dc=org")
|
||
|
So(actualPassword, ShouldEqual, "bindpwd")
|
||
|
})
|
||
|
|
||
|
Convey("Given bind dn configured", func() {
|
||
|
conn := &mockLdapConn{}
|
||
|
var actualUsername, actualPassword string
|
||
|
conn.bindProvider = func(username, password string) error {
|
||
|
actualUsername = username
|
||
|
actualPassword = password
|
||
|
return nil
|
||
|
}
|
||
![]()
6 years ago
|
Auth := &Auth{
|
||
![]()
6 years ago
|
conn: conn,
|
||
![]()
6 years ago
|
server: &ServerConfig{
|
||
![]()
6 years ago
|
BindDN: "cn=%s,o=users,dc=grafana,dc=org",
|
||
|
},
|
||
|
}
|
||
![]()
6 years ago
|
err := Auth.initialBind("user", "pwd")
|
||
![]()
6 years ago
|
So(err, ShouldBeNil)
|
||
![]()
6 years ago
|
So(Auth.requireSecondBind, ShouldBeFalse)
|
||
![]()
6 years ago
|
So(actualUsername, ShouldEqual, "cn=user,o=users,dc=grafana,dc=org")
|
||
|
So(actualPassword, ShouldEqual, "pwd")
|
||
|
})
|
||
|
|
||
|
Convey("Given empty bind dn and password", func() {
|
||
|
conn := &mockLdapConn{}
|
||
|
unauthenticatedBindWasCalled := false
|
||
|
var actualUsername string
|
||
|
conn.unauthenticatedBindProvider = func(username string) error {
|
||
|
unauthenticatedBindWasCalled = true
|
||
|
actualUsername = username
|
||
|
return nil
|
||
|
}
|
||
![]()
6 years ago
|
Auth := &Auth{
|
||
![]()
6 years ago
|
conn: conn,
|
||
![]()
6 years ago
|
server: &ServerConfig{},
|
||
![]()
6 years ago
|
}
|
||
![]()
6 years ago
|
err := Auth.initialBind("user", "pwd")
|
||
![]()
6 years ago
|
So(err, ShouldBeNil)
|
||
![]()
6 years ago
|
So(Auth.requireSecondBind, ShouldBeTrue)
|
||
![]()
6 years ago
|
So(unauthenticatedBindWasCalled, ShouldBeTrue)
|
||
|
So(actualUsername, ShouldBeEmpty)
|
||
|
})
|
||
|
})
|
||
![]()
10 years ago
|
|
||
![]()
6 years ago
|
Convey("serverBind", t, func() {
|
||
|
Convey("Given bind dn and password configured", func() {
|
||
|
conn := &mockLdapConn{}
|
||
|
var actualUsername, actualPassword string
|
||
|
conn.bindProvider = func(username, password string) error {
|
||
|
actualUsername = username
|
||
|
actualPassword = password
|
||
|
return nil
|
||
|
}
|
||
![]()
6 years ago
|
Auth := &Auth{
|
||
![]()
6 years ago
|
conn: conn,
|
||
![]()
6 years ago
|
server: &ServerConfig{
|
||
![]()
6 years ago
|
BindDN: "o=users,dc=grafana,dc=org",
|
||
|
BindPassword: "bindpwd",
|
||
|
},
|
||
|
}
|
||
![]()
6 years ago
|
err := Auth.serverBind()
|
||
![]()
6 years ago
|
So(err, ShouldBeNil)
|
||
|
So(actualUsername, ShouldEqual, "o=users,dc=grafana,dc=org")
|
||
|
So(actualPassword, ShouldEqual, "bindpwd")
|
||
|
})
|
||
|
|
||
|
Convey("Given bind dn configured", func() {
|
||
|
conn := &mockLdapConn{}
|
||
|
unauthenticatedBindWasCalled := false
|
||
|
var actualUsername string
|
||
|
conn.unauthenticatedBindProvider = func(username string) error {
|
||
|
unauthenticatedBindWasCalled = true
|
||
|
actualUsername = username
|
||
|
return nil
|
||
|
}
|
||
![]()
6 years ago
|
Auth := &Auth{
|
||
![]()
6 years ago
|
conn: conn,
|
||
![]()
6 years ago
|
server: &ServerConfig{
|
||
![]()
6 years ago
|
BindDN: "o=users,dc=grafana,dc=org",
|
||
|
},
|
||
|
}
|
||
![]()
6 years ago
|
err := Auth.serverBind()
|
||
![]()
6 years ago
|
So(err, ShouldBeNil)
|
||
|
So(unauthenticatedBindWasCalled, ShouldBeTrue)
|
||
|
So(actualUsername, ShouldEqual, "o=users,dc=grafana,dc=org")
|
||
|
})
|
||
|
|
||
|
Convey("Given empty bind dn and password", func() {
|
||
|
conn := &mockLdapConn{}
|
||
|
unauthenticatedBindWasCalled := false
|
||
|
var actualUsername string
|
||
|
conn.unauthenticatedBindProvider = func(username string) error {
|
||
|
unauthenticatedBindWasCalled = true
|
||
|
actualUsername = username
|
||
|
return nil
|
||
|
}
|
||
![]()
6 years ago
|
Auth := &Auth{
|
||
![]()
6 years ago
|
conn: conn,
|
||
![]()
6 years ago
|
server: &ServerConfig{},
|
||
![]()
6 years ago
|
}
|
||
![]()
6 years ago
|
err := Auth.serverBind()
|
||
![]()
6 years ago
|
So(err, ShouldBeNil)
|
||
|
So(unauthenticatedBindWasCalled, ShouldBeTrue)
|
||
|
So(actualUsername, ShouldBeEmpty)
|
||
|
})
|
||
|
})
|
||
|
|
||
![]()
10 years ago
|
Convey("When translating ldap user to grafana user", t, func() {
|
||
|
|
||
![]()
7 years ago
|
var user1 = &m.User{}
|
||
|
|
||
|
bus.AddHandlerCtx("test", func(ctx context.Context, cmd *m.UpsertUserCommand) error {
|
||
|
cmd.Result = user1
|
||
|
cmd.Result.Login = "torkelo"
|
||
|
return nil
|
||
|
})
|
||
|
|
||
![]()
10 years ago
|
Convey("Given no ldap group map match", func() {
|
||
![]()
6 years ago
|
Auth := New(&ServerConfig{
|
||
|
Groups: []*GroupToOrgRole{{}},
|
||
![]()
10 years ago
|
})
|
||
![]()
6 years ago
|
_, err := Auth.GetGrafanaUserFor(nil, &UserInfo{})
|
||
![]()
10 years ago
|
|
||
|
So(err, ShouldEqual, ErrInvalidCredentials)
|
||
|
})
|
||
|
|
||
![]()
6 years ago
|
AuthScenario("Given wildcard group match", func(sc *scenarioContext) {
|
||
|
Auth := New(&ServerConfig{
|
||
|
Groups: []*GroupToOrgRole{
|
||
![]()
10 years ago
|
{GroupDN: "*", OrgRole: "Admin"},
|
||
![]()
10 years ago
|
},
|
||
|
})
|
||
|
|
||
|
sc.userQueryReturns(user1)
|
||
|
|
||
![]()
6 years ago
|
result, err := Auth.GetGrafanaUserFor(nil, &UserInfo{})
|
||
![]()
10 years ago
|
So(err, ShouldBeNil)
|
||
|
So(result, ShouldEqual, user1)
|
||
|
})
|
||
|
|
||
![]()
6 years ago
|
AuthScenario("Given exact group match", func(sc *scenarioContext) {
|
||
|
Auth := New(&ServerConfig{
|
||
|
Groups: []*GroupToOrgRole{
|
||
![]()
10 years ago
|
{GroupDN: "cn=users", OrgRole: "Admin"},
|
||
![]()
10 years ago
|
},
|
||
|
})
|
||
|
|
||
|
sc.userQueryReturns(user1)
|
||
|
|
||
![]()
6 years ago
|
result, err := Auth.GetGrafanaUserFor(nil, &UserInfo{MemberOf: []string{"cn=users"}})
|
||
![]()
10 years ago
|
So(err, ShouldBeNil)
|
||
|
So(result, ShouldEqual, user1)
|
||
|
})
|
||
|
|
||
![]()
6 years ago
|
AuthScenario("Given group match with different case", func(sc *scenarioContext) {
|
||
|
Auth := New(&ServerConfig{
|
||
|
Groups: []*GroupToOrgRole{
|
||
![]()
7 years ago
|
{GroupDN: "cn=users", OrgRole: "Admin"},
|
||
|
},
|
||
|
})
|
||
|
|
||
|
sc.userQueryReturns(user1)
|
||
|
|
||
![]()
6 years ago
|
result, err := Auth.GetGrafanaUserFor(nil, &UserInfo{MemberOf: []string{"CN=users"}})
|
||
![]()
7 years ago
|
So(err, ShouldBeNil)
|
||
|
So(result, ShouldEqual, user1)
|
||
|
})
|
||
|
|
||
![]()
6 years ago
|
AuthScenario("Given no existing grafana user", func(sc *scenarioContext) {
|
||
|
Auth := New(&ServerConfig{
|
||
|
Groups: []*GroupToOrgRole{
|
||
![]()
10 years ago
|
{GroupDN: "cn=admin", OrgRole: "Admin"},
|
||
|
{GroupDN: "cn=editor", OrgRole: "Editor"},
|
||
|
{GroupDN: "*", OrgRole: "Viewer"},
|
||
![]()
10 years ago
|
},
|
||
|
})
|
||
|
|
||
|
sc.userQueryReturns(nil)
|
||
|
|
||
![]()
6 years ago
|
result, err := Auth.GetGrafanaUserFor(nil, &UserInfo{
|
||
![]()
7 years ago
|
DN: "torkelo",
|
||
![]()
10 years ago
|
Username: "torkelo",
|
||
|
Email: "my@email.com",
|
||
![]()
10 years ago
|
MemberOf: []string{"cn=editor"},
|
||
![]()
10 years ago
|
})
|
||
|
|
||
|
So(err, ShouldBeNil)
|
||
|
|
||
|
Convey("Should return new user", func() {
|
||
|
So(result.Login, ShouldEqual, "torkelo")
|
||
|
})
|
||
|
|
||
![]()
7 years ago
|
Convey("Should set isGrafanaAdmin to false by default", func() {
|
||
|
So(result.IsAdmin, ShouldBeFalse)
|
||
|
})
|
||
|
|
||
![]()
10 years ago
|
})
|
||
|
|
||
![]()
10 years ago
|
})
|
||
![]()
9 years ago
|
|
||
![]()
7 years ago
|
Convey("When syncing ldap groups to grafana org roles", t, func() {
|
||
![]()
6 years ago
|
AuthScenario("given no current user orgs", func(sc *scenarioContext) {
|
||
|
Auth := New(&ServerConfig{
|
||
|
Groups: []*GroupToOrgRole{
|
||
![]()
7 years ago
|
{GroupDN: "cn=users", OrgRole: "Admin"},
|
||
|
},
|
||
|
})
|
||
|
|
||
|
sc.userOrgsQueryReturns([]*m.UserOrgDTO{})
|
||
![]()
6 years ago
|
_, err := Auth.GetGrafanaUserFor(nil, &UserInfo{
|
||
![]()
7 years ago
|
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)
|
||
|
})
|
||
|
})
|
||
|
|
||
![]()
6 years ago
|
AuthScenario("given different current org role", func(sc *scenarioContext) {
|
||
|
Auth := New(&ServerConfig{
|
||
|
Groups: []*GroupToOrgRole{
|
||
![]()
7 years ago
|
{GroupDN: "cn=users", OrgId: 1, OrgRole: "Admin"},
|
||
|
},
|
||
|
})
|
||
|
|
||
|
sc.userOrgsQueryReturns([]*m.UserOrgDTO{{OrgId: 1, Role: m.ROLE_EDITOR}})
|
||
![]()
6 years ago
|
_, err := Auth.GetGrafanaUserFor(nil, &UserInfo{
|
||
![]()
7 years ago
|
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)
|
||
![]()
7 years ago
|
So(sc.setUsingOrgCmd.OrgId, ShouldEqual, 1)
|
||
![]()
7 years ago
|
})
|
||
|
})
|
||
|
|
||
![]()
6 years ago
|
AuthScenario("given current org role is removed in ldap", func(sc *scenarioContext) {
|
||
|
Auth := New(&ServerConfig{
|
||
|
Groups: []*GroupToOrgRole{
|
||
![]()
7 years ago
|
{GroupDN: "cn=users", OrgId: 2, OrgRole: "Admin"},
|
||
![]()
7 years ago
|
},
|
||
|
})
|
||
|
|
||
|
sc.userOrgsQueryReturns([]*m.UserOrgDTO{
|
||
|
{OrgId: 1, Role: m.ROLE_EDITOR},
|
||
|
{OrgId: 2, Role: m.ROLE_EDITOR},
|
||
|
})
|
||
![]()
6 years ago
|
_, err := Auth.GetGrafanaUserFor(nil, &UserInfo{
|
||
![]()
7 years ago
|
MemberOf: []string{"cn=users"},
|
||
|
})
|
||
|
|
||
|
Convey("Should remove org role", func() {
|
||
|
So(err, ShouldBeNil)
|
||
|
So(sc.removeOrgUserCmd, ShouldNotBeNil)
|
||
![]()
7 years ago
|
So(sc.setUsingOrgCmd.OrgId, ShouldEqual, 2)
|
||
![]()
7 years ago
|
})
|
||
|
})
|
||
|
|
||
![]()
6 years ago
|
AuthScenario("given org role is updated in config", func(sc *scenarioContext) {
|
||
|
Auth := New(&ServerConfig{
|
||
|
Groups: []*GroupToOrgRole{
|
||
![]()
7 years ago
|
{GroupDN: "cn=admin", OrgId: 1, OrgRole: "Admin"},
|
||
|
{GroupDN: "cn=users", OrgId: 1, OrgRole: "Viewer"},
|
||
|
},
|
||
|
})
|
||
|
|
||
|
sc.userOrgsQueryReturns([]*m.UserOrgDTO{{OrgId: 1, Role: m.ROLE_EDITOR}})
|
||
![]()
6 years ago
|
_, err := Auth.GetGrafanaUserFor(nil, &UserInfo{
|
||
![]()
7 years ago
|
MemberOf: []string{"cn=users"},
|
||
|
})
|
||
|
|
||
|
Convey("Should update org role", func() {
|
||
|
So(err, ShouldBeNil)
|
||
|
So(sc.removeOrgUserCmd, ShouldBeNil)
|
||
|
So(sc.updateOrgUserCmd, ShouldNotBeNil)
|
||
![]()
7 years ago
|
So(sc.setUsingOrgCmd.OrgId, ShouldEqual, 1)
|
||
![]()
7 years ago
|
})
|
||
|
})
|
||
|
|
||
![]()
6 years ago
|
AuthScenario("given multiple matching ldap groups", func(sc *scenarioContext) {
|
||
|
Auth := New(&ServerConfig{
|
||
|
Groups: []*GroupToOrgRole{
|
||
![]()
7 years ago
|
{GroupDN: "cn=admins", OrgId: 1, OrgRole: "Admin"},
|
||
|
{GroupDN: "*", OrgId: 1, OrgRole: "Viewer"},
|
||
|
},
|
||
|
})
|
||
|
|
||
|
sc.userOrgsQueryReturns([]*m.UserOrgDTO{{OrgId: 1, Role: m.ROLE_ADMIN}})
|
||
![]()
6 years ago
|
_, err := Auth.GetGrafanaUserFor(nil, &UserInfo{
|
||
![]()
7 years ago
|
MemberOf: []string{"cn=admins"},
|
||
|
})
|
||
|
|
||
|
Convey("Should take first match, and ignore subsequent matches", func() {
|
||
|
So(err, ShouldBeNil)
|
||
|
So(sc.updateOrgUserCmd, ShouldBeNil)
|
||
![]()
7 years ago
|
So(sc.setUsingOrgCmd.OrgId, ShouldEqual, 1)
|
||
![]()
7 years ago
|
})
|
||
|
})
|
||
|
|
||
![]()
6 years ago
|
AuthScenario("given multiple matching ldap groups and no existing groups", func(sc *scenarioContext) {
|
||
|
Auth := New(&ServerConfig{
|
||
|
Groups: []*GroupToOrgRole{
|
||
![]()
7 years ago
|
{GroupDN: "cn=admins", OrgId: 1, OrgRole: "Admin"},
|
||
|
{GroupDN: "*", OrgId: 1, OrgRole: "Viewer"},
|
||
|
},
|
||
|
})
|
||
|
|
||
|
sc.userOrgsQueryReturns([]*m.UserOrgDTO{})
|
||
![]()
6 years ago
|
_, err := Auth.GetGrafanaUserFor(nil, &UserInfo{
|
||
![]()
7 years ago
|
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)
|
||
![]()
7 years ago
|
So(sc.setUsingOrgCmd.OrgId, ShouldEqual, 1)
|
||
![]()
7 years ago
|
})
|
||
![]()
7 years ago
|
|
||
|
Convey("Should not update permissions unless specified", func() {
|
||
|
So(err, ShouldBeNil)
|
||
|
So(sc.updateUserPermissionsCmd, ShouldBeNil)
|
||
|
})
|
||
![]()
7 years ago
|
})
|
||
|
|
||
![]()
6 years ago
|
AuthScenario("given ldap groups with grafana_admin=true", func(sc *scenarioContext) {
|
||
![]()
7 years ago
|
trueVal := true
|
||
|
|
||
![]()
6 years ago
|
Auth := New(&ServerConfig{
|
||
|
Groups: []*GroupToOrgRole{
|
||
![]()
7 years ago
|
{GroupDN: "cn=admins", OrgId: 1, OrgRole: "Admin", IsGrafanaAdmin: &trueVal},
|
||
|
},
|
||
|
})
|
||
|
|
||
|
sc.userOrgsQueryReturns([]*m.UserOrgDTO{})
|
||
![]()
6 years ago
|
_, err := Auth.GetGrafanaUserFor(nil, &UserInfo{
|
||
![]()
7 years ago
|
MemberOf: []string{"cn=admins"},
|
||
|
})
|
||
|
|
||
|
Convey("Should create user with admin set to true", func() {
|
||
|
So(err, ShouldBeNil)
|
||
|
So(sc.updateUserPermissionsCmd.IsGrafanaAdmin, ShouldBeTrue)
|
||
|
})
|
||
|
})
|
||
![]()
7 years ago
|
})
|
||
|
|
||
![]()
7 years ago
|
Convey("When calling SyncUser", t, func() {
|
||
![]()
9 years ago
|
mockLdapConnection := &mockLdapConn{}
|
||
![]()
6 years ago
|
|
||
|
auth := &Auth{
|
||
|
server: &ServerConfig{
|
||
![]()
9 years ago
|
Host: "",
|
||
|
RootCACert: "",
|
||
![]()
6 years ago
|
Groups: []*GroupToOrgRole{
|
||
![]()
9 years ago
|
{GroupDN: "*", OrgRole: "Admin"},
|
||
|
},
|
||
![]()
6 years ago
|
Attr: AttributeMap{
|
||
![]()
9 years ago
|
Username: "username",
|
||
|
Surname: "surname",
|
||
|
Email: "email",
|
||
|
Name: "name",
|
||
|
MemberOf: "memberof",
|
||
|
},
|
||
|
SearchBaseDNs: []string{"BaseDNHere"},
|
||
|
},
|
||
![]()
6 years ago
|
conn: mockLdapConnection,
|
||
|
log: log.New("test-logger"),
|
||
|
}
|
||
![]()
9 years ago
|
|
||
|
dialCalled := false
|
||
![]()
6 years ago
|
dial = func(network, addr string) (IConnection, error) {
|
||
![]()
9 years ago
|
dialCalled = true
|
||
|
return mockLdapConnection, nil
|
||
|
}
|
||
|
|
||
|
entry := ldap.Entry{
|
||
|
DN: "dn", Attributes: []*ldap.EntryAttribute{
|
||
|
{Name: "username", Values: []string{"roelgerrits"}},
|
||
|
{Name: "surname", Values: []string{"Gerrits"}},
|
||
|
{Name: "email", Values: []string{"roel@test.com"}},
|
||
|
{Name: "name", Values: []string{"Roel"}},
|
||
|
{Name: "memberof", Values: []string{"admins"}},
|
||
|
}}
|
||
|
result := ldap.SearchResult{Entries: []*ldap.Entry{&entry}}
|
||
|
mockLdapConnection.setSearchResult(&result)
|
||
|
|
||
![]()
6 years ago
|
AuthScenario("When ldapUser found call syncInfo and orgRoles", func(sc *scenarioContext) {
|
||
![]()
9 years ago
|
// arrange
|
||
![]()
7 years ago
|
query := &m.LoginUserQuery{
|
||
|
Username: "roelgerrits",
|
||
![]()
9 years ago
|
}
|
||
|
|
||
![]()
6 years ago
|
hookDial = nil
|
||
|
|
||
![]()
7 years ago
|
sc.userQueryReturns(&m.User{
|
||
|
Id: 1,
|
||
|
Email: "roel@test.net",
|
||
|
Name: "Roel Gerrits",
|
||
|
Login: "roelgerrits",
|
||
|
})
|
||
![]()
9 years ago
|
sc.userOrgsQueryReturns([]*m.UserOrgDTO{})
|
||
|
|
||
|
// act
|
||
![]()
6 years ago
|
syncErrResult := auth.SyncUser(query)
|
||
![]()
9 years ago
|
|
||
|
// assert
|
||
|
So(dialCalled, ShouldBeTrue)
|
||
|
So(syncErrResult, ShouldBeNil)
|
||
|
// User should be searched in ldap
|
||
|
So(mockLdapConnection.searchCalled, ShouldBeTrue)
|
||
|
// Info should be updated (email differs)
|
||
|
So(sc.updateUserCmd.Email, ShouldEqual, "roel@test.com")
|
||
|
// User should have admin privileges
|
||
|
So(sc.addOrgUserCmd.UserId, ShouldEqual, 1)
|
||
|
So(sc.addOrgUserCmd.Role, ShouldEqual, "Admin")
|
||
|
})
|
||
|
})
|
||
![]()
7 years ago
|
|
||
|
Convey("When searching for a user and not all five attributes are mapped", t, func() {
|
||
|
mockLdapConnection := &mockLdapConn{}
|
||
|
entry := ldap.Entry{
|
||
|
DN: "dn", Attributes: []*ldap.EntryAttribute{
|
||
|
{Name: "username", Values: []string{"roelgerrits"}},
|
||
|
{Name: "surname", Values: []string{"Gerrits"}},
|
||
|
{Name: "email", Values: []string{"roel@test.com"}},
|
||
|
{Name: "name", Values: []string{"Roel"}},
|
||
|
{Name: "memberof", Values: []string{"admins"}},
|
||
|
}}
|
||
|
result := ldap.SearchResult{Entries: []*ldap.Entry{&entry}}
|
||
|
mockLdapConnection.setSearchResult(&result)
|
||
|
|
||
|
// Set up attribute map without surname and email
|
||
![]()
6 years ago
|
Auth := &Auth{
|
||
|
server: &ServerConfig{
|
||
|
Attr: AttributeMap{
|
||
![]()
7 years ago
|
Username: "username",
|
||
|
Name: "name",
|
||
|
MemberOf: "memberof",
|
||
|
},
|
||
|
SearchBaseDNs: []string{"BaseDNHere"},
|
||
|
},
|
||
|
conn: mockLdapConnection,
|
||
|
log: log.New("test-logger"),
|
||
|
}
|
||
|
|
||
![]()
6 years ago
|
searchResult, err := Auth.searchForUser("roelgerrits")
|
||
![]()
7 years ago
|
|
||
|
So(err, ShouldBeNil)
|
||
|
So(searchResult, ShouldNotBeNil)
|
||
|
|
||
|
// User should be searched in ldap
|
||
|
So(mockLdapConnection.searchCalled, ShouldBeTrue)
|
||
|
|
||
|
// No empty attributes should be added to the search request
|
||
|
So(len(mockLdapConnection.searchAttributes), ShouldEqual, 3)
|
||
|
})
|
||
![]()
9 years ago
|
}
|