MM-14590: Adds license check to LDAP test and LDAP sync API endpoints. (#10519)

* MM-14590: Adds license check to LDAP test and LDAP sync API endpoints.

* MM-14590: Improves the LdapSync and LdapTest API tests.
Этот коммит содержится в:
Martin Kraft
2019-04-01 10:48:58 -04:00
коммит произвёл GitHub
родитель 4c8bac38bb
Коммит d14235b4e0
2 изменённых файлов: 33 добавлений и 1 удалений

Просмотреть файл

@@ -33,6 +33,11 @@ func (api *API) InitLdap() {
} }
func syncLdap(c *Context, w http.ResponseWriter, r *http.Request) { func syncLdap(c *Context, w http.ResponseWriter, r *http.Request) {
if c.App.License() == nil || !*c.App.License().Features.LDAP {
c.Err = model.NewAppError("Api4.syncLdap", "api.ldap_groups.license_error", nil, "", http.StatusNotImplemented)
return
}
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) { if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM) c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
return return
@@ -44,6 +49,11 @@ func syncLdap(c *Context, w http.ResponseWriter, r *http.Request) {
} }
func testLdap(c *Context, w http.ResponseWriter, r *http.Request) { func testLdap(c *Context, w http.ResponseWriter, r *http.Request) {
if c.App.License() == nil || !*c.App.License().Features.LDAP {
c.Err = model.NewAppError("Api4.testLdap", "api.ldap_groups.license_error", nil, "", http.StatusNotImplemented)
return
}
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) { if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM) c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
return return

Просмотреть файл

@@ -5,17 +5,32 @@ package api4
import ( import (
"testing" "testing"
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost-server/model"
) )
func TestTestLdap(t *testing.T) { func TestTestLdap(t *testing.T) {
th := Setup().InitBasic() th := Setup().InitBasic()
defer th.TearDown() defer th.TearDown()
_, resp := th.Client.TestLdap() _, resp := th.SystemAdminClient.TestLdap()
CheckNotImplementedStatus(t, resp)
require.NotNil(t, resp.Error)
require.Equal(t, "api.ldap_groups.license_error", resp.Error.Id)
th.App.SetLicense(model.NewTestLicense("ldap_groups"))
_, resp = th.Client.TestLdap()
CheckForbiddenStatus(t, resp) CheckForbiddenStatus(t, resp)
require.NotNil(t, resp.Error)
require.Equal(t, "api.context.permissions.app_error", resp.Error.Id)
_, resp = th.SystemAdminClient.TestLdap() _, resp = th.SystemAdminClient.TestLdap()
CheckNotImplementedStatus(t, resp) CheckNotImplementedStatus(t, resp)
require.NotNil(t, resp.Error)
require.Equal(t, "ent.ldap.disabled.app_error", resp.Error.Id)
} }
func TestSyncLdap(t *testing.T) { func TestSyncLdap(t *testing.T) {
@@ -23,6 +38,13 @@ func TestSyncLdap(t *testing.T) {
defer th.TearDown() defer th.TearDown()
_, resp := th.SystemAdminClient.SyncLdap() _, resp := th.SystemAdminClient.SyncLdap()
CheckNotImplementedStatus(t, resp)
require.NotNil(t, resp.Error)
require.Equal(t, "api.ldap_groups.license_error", resp.Error.Id)
th.App.SetLicense(model.NewTestLicense("ldap_groups"))
_, resp = th.SystemAdminClient.SyncLdap()
CheckNoError(t, resp) CheckNoError(t, resp)
_, resp = th.Client.SyncLdap() _, resp = th.Client.SyncLdap()