Files
portainer/api/http/handler/auth/authenticate_test.go
T
Hui e03ede1dfb feat(ldap): update get user groups func EE-1148 (#5321)
* feat(ldap): update get user groups func

* cleanup
2021-07-19 09:25:38 +12:00

38 lines
834 B
Go

package auth
import (
"testing"
portainer "github.com/portainer/portainer/api"
"github.com/portainer/portainer/api/internal/testhelpers"
"github.com/stretchr/testify/assert"
)
func TestIsLDAPAdmin_Match(t *testing.T) {
h := Handler{
LDAPService: testhelpers.NewLDAPService(),
}
mockLDAPSettings := &portainer.LDAPSettings{
AdminGroups: []string{"manager", "operator"},
}
matched, err := h.isLDAPAdmin("username", mockLDAPSettings)
assert.NoError(t, err)
assert.Equal(t, true, matched)
}
func TestIsLDAPAdmin_NotMatch(t *testing.T) {
h := Handler{
LDAPService: testhelpers.NewLDAPService(),
}
mockLDAPSettings := &portainer.LDAPSettings{
AdminGroups: []string{"admin", "operator"},
}
matched, err := h.isLDAPAdmin("username", mockLDAPSettings)
assert.NoError(t, err)
assert.Equal(t, false, matched)
}