From 516ceaed8e76f26118651faf04ffb413a87446dd Mon Sep 17 00:00:00 2001 From: Ibrahim Serdar Acikgoz Date: Tue, 23 Jun 2020 11:47:52 +0300 Subject: [PATCH] api4/ldap: add test/sync/getgroups to local mode (#14842) Co-authored-by: Mattermod --- api4/api.go | 2 ++ api4/ldap_local.go | 10 ++++++++++ api4/ldap_test.go | 47 +++++++++++++++++++++++++++------------------- 3 files changed, 40 insertions(+), 19 deletions(-) create mode 100644 api4/ldap_local.go diff --git a/api4/api.go b/api4/api.go index fe4686640e..8deb72c025 100644 --- a/api4/api.go +++ b/api4/api.go @@ -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() diff --git a/api4/ldap_local.go b/api4/ldap_local.go new file mode 100644 index 0000000000..fbf82ffe70 --- /dev/null +++ b/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") +} diff --git a/api4/ldap_test.go b/api4/ldap_test.go index 404a53d055..4979538c13 100644 --- a/api4/ldap_test.go +++ b/api4/ldap_test.go @@ -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) {