LDAP: Move LDAP globals to Config (#63255)

* structure dtos and private methods

* add basic LDAP service

* use LDAP service in ldap debug API

* lower non fatal error

* remove unused globals

* wip

* remove final globals

* fix tests to use cfg enabled

* restructure errors

* remove logger from globals

* use ldap service in authn

* use ldap service in context handler

* fix failed tests

* fix ldap middleware provides

* fix provides in auth_test.go
This commit is contained in:
Jo
2023-02-10 19:01:55 +01:00
committed by GitHub
parent 8520a8614c
commit d4cfbd9fd3
30 changed files with 664 additions and 506 deletions

View File

@ -10,6 +10,7 @@ import (
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/services/login"
"github.com/grafana/grafana/pkg/services/org"
"github.com/grafana/grafana/pkg/setting"
)
func TestServer_getSearchRequest(t *testing.T) {
@ -52,7 +53,11 @@ func TestServer_getSearchRequest(t *testing.T) {
func TestSerializeUsers(t *testing.T) {
t.Run("simple case", func(t *testing.T) {
cfg := setting.NewCfg()
cfg.LDAPEnabled = true
server := &Server{
cfg: cfg,
Config: &ServerConfig{
Attr: AttributeMap{
Username: "username",
@ -87,7 +92,11 @@ func TestSerializeUsers(t *testing.T) {
})
t.Run("without lastname", func(t *testing.T) {
cfg := setting.NewCfg()
cfg.LDAPEnabled = true
server := &Server{
cfg: cfg,
Config: &ServerConfig{
Attr: AttributeMap{
Username: "username",
@ -120,7 +129,11 @@ func TestSerializeUsers(t *testing.T) {
})
t.Run("mark user without matching group as disabled", func(t *testing.T) {
cfg := setting.NewCfg()
cfg.LDAPEnabled = true
server := &Server{
cfg: cfg,
Config: &ServerConfig{
Groups: []*GroupToOrgRole{{
GroupDN: "foo",
@ -150,7 +163,11 @@ func TestSerializeUsers(t *testing.T) {
func TestServer_validateGrafanaUser(t *testing.T) {
t.Run("no group config", func(t *testing.T) {
cfg := setting.NewCfg()
cfg.LDAPEnabled = true
server := &Server{
cfg: cfg,
Config: &ServerConfig{
Groups: []*GroupToOrgRole{},
},
@ -166,7 +183,11 @@ func TestServer_validateGrafanaUser(t *testing.T) {
})
t.Run("user in group", func(t *testing.T) {
cfg := setting.NewCfg()
cfg.LDAPEnabled = true
server := &Server{
cfg: cfg,
Config: &ServerConfig{
Groups: []*GroupToOrgRole{
{
@ -189,7 +210,11 @@ func TestServer_validateGrafanaUser(t *testing.T) {
})
t.Run("user not in group", func(t *testing.T) {
cfg := setting.NewCfg()
cfg.LDAPEnabled = true
server := &Server{
cfg: cfg,
Config: &ServerConfig{
Groups: []*GroupToOrgRole{
{