graph: Add unit test for LDAP identity backend

This reworks the LDAP backend a bit to allow for mocking the ldap.Client
interface. It also add a couple of unit test for the backend
This commit is contained in:
Ralf Haferkamp
2021-11-23 14:47:46 +01:00
parent b7ec12735b
commit d21ca0658f
4 changed files with 397 additions and 6 deletions

View File

@@ -5,7 +5,9 @@ import (
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/owncloud/ocis/graph/pkg/identity"
"github.com/owncloud/ocis/graph/pkg/identity/ldap"
"github.com/owncloud/ocis/ocis-pkg/account"
opkgm "github.com/owncloud/ocis/ocis-pkg/middleware"
)
@@ -34,7 +36,12 @@ func NewService(opts ...Option) Service {
}
case "ldap":
var err error
if backend, err = identity.NewLDAPBackend(options.Config.Identity.LDAP, &options.Logger); err != nil {
conn := ldap.NewLDAPWithReconnect(&options.Logger,
options.Config.Identity.LDAP.URI,
options.Config.Identity.LDAP.BindDN,
options.Config.Identity.LDAP.BindPassword,
)
if backend, err = identity.NewLDAPBackend(conn, options.Config.Identity.LDAP, &options.Logger); err != nil {
options.Logger.Error().Msgf("Error initializing LDAP Backend: '%s'", err)
return nil
}