mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 11:02:55 +08:00

* LDAP:Docs: `active_sync_enabled` setting Mention `active_sync_enabled` setting and enable it by default * LDAP: move "disableExternalUser" method Idea behind new design of the LDAP module is to minimise conflation between other parts of the system, so it would decoupled as much as possible from stuff like database, HTTP transport and etc. Following "Do One Thing and Do It Well" Unix philosophy principal, other things could be better fitted on the consumer side of things. Which what this commit trying to archive * LDAP: correct user/admin binding The second binding was not happening, so if the admin login/password in LDAP configuration was correct, anyone could had login as anyone using incorrect password
92 lines
1.9 KiB
Go
92 lines
1.9 KiB
Go
package ldap
|
|
|
|
import (
|
|
"crypto/tls"
|
|
|
|
"gopkg.in/ldap.v3"
|
|
)
|
|
|
|
// MockConnection struct for testing
|
|
type MockConnection struct {
|
|
SearchResult *ldap.SearchResult
|
|
SearchError error
|
|
SearchCalled bool
|
|
SearchAttributes []string
|
|
|
|
AddParams *ldap.AddRequest
|
|
AddCalled bool
|
|
|
|
DelParams *ldap.DelRequest
|
|
DelCalled bool
|
|
|
|
UnauthenticatedBindCalled bool
|
|
BindCalled bool
|
|
|
|
BindProvider func(username, password string) error
|
|
UnauthenticatedBindProvider func() error
|
|
}
|
|
|
|
// Bind mocks Bind connection function
|
|
func (c *MockConnection) Bind(username, password string) error {
|
|
c.BindCalled = true
|
|
|
|
if c.BindProvider != nil {
|
|
return c.BindProvider(username, password)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// UnauthenticatedBind mocks UnauthenticatedBind connection function
|
|
func (c *MockConnection) UnauthenticatedBind(username string) error {
|
|
c.UnauthenticatedBindCalled = true
|
|
|
|
if c.UnauthenticatedBindProvider != nil {
|
|
return c.UnauthenticatedBindProvider()
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// Close mocks Close connection function
|
|
func (c *MockConnection) Close() {}
|
|
|
|
func (c *MockConnection) setSearchResult(result *ldap.SearchResult) {
|
|
c.SearchResult = result
|
|
}
|
|
|
|
func (c *MockConnection) setSearchError(err error) {
|
|
c.SearchError = err
|
|
}
|
|
|
|
// Search mocks Search connection function
|
|
func (c *MockConnection) Search(sr *ldap.SearchRequest) (*ldap.SearchResult, error) {
|
|
c.SearchCalled = true
|
|
c.SearchAttributes = sr.Attributes
|
|
|
|
if c.SearchError != nil {
|
|
return nil, c.SearchError
|
|
}
|
|
|
|
return c.SearchResult, nil
|
|
}
|
|
|
|
// Add mocks Add connection function
|
|
func (c *MockConnection) Add(request *ldap.AddRequest) error {
|
|
c.AddCalled = true
|
|
c.AddParams = request
|
|
return nil
|
|
}
|
|
|
|
// Del mocks Del connection function
|
|
func (c *MockConnection) Del(request *ldap.DelRequest) error {
|
|
c.DelCalled = true
|
|
c.DelParams = request
|
|
return nil
|
|
}
|
|
|
|
// StartTLS mocks StartTLS connection function
|
|
func (c *MockConnection) StartTLS(*tls.Config) error {
|
|
return nil
|
|
}
|