api4/ldap: add test/sync/getgroups to local mode (#14842)

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Ibrahim Serdar Acikgoz
2020-06-23 11:47:52 +03:00
коммит произвёл GitHub
родитель 7bf6565ed2
Коммит 516ceaed8e
3 изменённых файлов: 40 добавлений и 19 удалений

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

@@ -303,6 +303,7 @@ func InitLocal(configservice configservice.ConfigService, globalOptionsFunc app.
api.BaseRoutes.Groups = api.BaseRoutes.ApiRoot.PathPrefix("/groups").Subrouter()
api.BaseRoutes.LDAP = api.BaseRoutes.ApiRoot.PathPrefix("/ldap").Subrouter()
api.BaseRoutes.Posts = api.BaseRoutes.ApiRoot.PathPrefix("/posts").Subrouter()
api.BaseRoutes.Post = api.BaseRoutes.Posts.PathPrefix("/{post_id:[A-Za-z0-9]+}").Subrouter()
api.BaseRoutes.PostsForChannel = api.BaseRoutes.Channel.PathPrefix("/posts").Subrouter()
@@ -316,6 +317,7 @@ func InitLocal(configservice configservice.ConfigService, globalOptionsFunc app.
api.InitLicenseLocal()
api.InitBotLocal()
api.InitGroupLocal()
api.InitLdapLocal()
api.InitSystemLocal()
api.InitPostLocal()

10
api4/ldap_local.go Обычный файл
Просмотреть файл

@@ -0,0 +1,10 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package api4
func (api *API) InitLdapLocal() {
api.BaseRoutes.LDAP.Handle("/sync", api.ApiLocal(syncLdap)).Methods("POST")
api.BaseRoutes.LDAP.Handle("/test", api.ApiLocal(testLdap)).Methods("POST")
api.BaseRoutes.LDAP.Handle("/groups", api.ApiLocal(getLdapGroups)).Methods("GET")
}

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

@@ -15,39 +15,46 @@ func TestTestLdap(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
_, resp := th.SystemAdminClient.TestLdap()
CheckNotImplementedStatus(t, resp)
require.NotNil(t, resp.Error)
require.Equal(t, "api.ldap_groups.license_error", resp.Error.Id)
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
_, resp := client.TestLdap()
CheckNotImplementedStatus(t, resp)
require.NotNil(t, resp.Error)
require.Equal(t, "api.ldap_groups.license_error", resp.Error.Id)
})
th.App.Srv().SetLicense(model.NewTestLicense("ldap_groups"))
_, resp = th.Client.TestLdap()
_, resp := th.Client.TestLdap()
CheckForbiddenStatus(t, resp)
require.NotNil(t, resp.Error)
require.Equal(t, "api.context.permissions.app_error", resp.Error.Id)
_, resp = th.SystemAdminClient.TestLdap()
CheckNotImplementedStatus(t, resp)
require.NotNil(t, resp.Error)
require.Equal(t, "ent.ldap.disabled.app_error", resp.Error.Id)
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
_, resp = client.TestLdap()
CheckNotImplementedStatus(t, resp)
require.NotNil(t, resp.Error)
require.Equal(t, "ent.ldap.disabled.app_error", resp.Error.Id)
})
}
func TestSyncLdap(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
_, resp := th.SystemAdminClient.SyncLdap()
CheckNotImplementedStatus(t, resp)
require.NotNil(t, resp.Error)
require.Equal(t, "api.ldap_groups.license_error", resp.Error.Id)
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
_, resp := client.TestLdap()
CheckNotImplementedStatus(t, resp)
require.NotNil(t, resp.Error)
require.Equal(t, "api.ldap_groups.license_error", resp.Error.Id)
})
th.App.Srv().SetLicense(model.NewTestLicense("ldap_groups"))
_, resp = th.SystemAdminClient.SyncLdap()
CheckNoError(t, resp)
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
_, resp := client.SyncLdap()
CheckNoError(t, resp)
})
_, resp = th.Client.SyncLdap()
_, resp := th.Client.SyncLdap()
CheckForbiddenStatus(t, resp)
}
@@ -58,8 +65,10 @@ func TestGetLdapGroups(t *testing.T) {
_, resp := th.Client.GetLdapGroups()
CheckForbiddenStatus(t, resp)
_, resp = th.SystemAdminClient.GetLdapGroups()
CheckNotImplementedStatus(t, resp)
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
_, resp := client.GetLdapGroups()
CheckNotImplementedStatus(t, resp)
})
}
func TestLinkLdapGroup(t *testing.T) {