2017-04-12 08:27:57 -04:00
|
|
|
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
2017-03-14 08:43:40 -04:00
|
|
|
// See License.txt for license information.
|
|
|
|
|
|
|
|
|
|
package api4
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
2019-04-01 10:48:58 -04:00
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
2019-11-28 14:39:38 +01:00
|
|
|
"github.com/mattermost/mattermost-server/v5/model"
|
2017-03-14 08:43:40 -04:00
|
|
|
)
|
|
|
|
|
|
2019-01-10 15:17:31 -05:00
|
|
|
func TestTestLdap(t *testing.T) {
|
2018-11-20 20:16:25 -05:00
|
|
|
th := Setup().InitBasic()
|
2017-10-02 03:50:56 -05:00
|
|
|
defer th.TearDown()
|
2017-03-14 08:43:40 -04:00
|
|
|
|
2019-04-01 10:48:58 -04:00
|
|
|
_, 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()
|
2017-03-14 08:43:40 -04:00
|
|
|
CheckForbiddenStatus(t, resp)
|
2019-04-01 10:48:58 -04:00
|
|
|
require.NotNil(t, resp.Error)
|
|
|
|
|
require.Equal(t, "api.context.permissions.app_error", resp.Error.Id)
|
2017-03-14 08:43:40 -04:00
|
|
|
|
|
|
|
|
_, resp = th.SystemAdminClient.TestLdap()
|
|
|
|
|
CheckNotImplementedStatus(t, resp)
|
2019-04-01 10:48:58 -04:00
|
|
|
require.NotNil(t, resp.Error)
|
|
|
|
|
require.Equal(t, "ent.ldap.disabled.app_error", resp.Error.Id)
|
2017-03-14 08:43:40 -04:00
|
|
|
}
|
|
|
|
|
|
2019-01-10 15:17:31 -05:00
|
|
|
func TestSyncLdap(t *testing.T) {
|
2018-11-20 20:16:25 -05:00
|
|
|
th := Setup().InitBasic()
|
2017-10-02 03:50:56 -05:00
|
|
|
defer th.TearDown()
|
2017-03-14 08:43:40 -04:00
|
|
|
|
|
|
|
|
_, resp := th.SystemAdminClient.SyncLdap()
|
2019-04-01 10:48:58 -04:00
|
|
|
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()
|
2017-03-14 08:43:40 -04:00
|
|
|
CheckNoError(t, resp)
|
|
|
|
|
|
|
|
|
|
_, resp = th.Client.SyncLdap()
|
|
|
|
|
CheckForbiddenStatus(t, resp)
|
|
|
|
|
}
|
2019-01-10 15:17:31 -05:00
|
|
|
|
|
|
|
|
func TestGetLdapGroups(t *testing.T) {
|
|
|
|
|
th := Setup().InitBasic()
|
|
|
|
|
defer th.TearDown()
|
|
|
|
|
|
|
|
|
|
_, resp := th.Client.GetLdapGroups()
|
|
|
|
|
CheckForbiddenStatus(t, resp)
|
|
|
|
|
|
|
|
|
|
_, resp = th.SystemAdminClient.GetLdapGroups()
|
|
|
|
|
CheckNotImplementedStatus(t, resp)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestLinkLdapGroup(t *testing.T) {
|
|
|
|
|
const entryUUID string = "foo"
|
|
|
|
|
|
|
|
|
|
th := Setup().InitBasic()
|
|
|
|
|
defer th.TearDown()
|
|
|
|
|
|
|
|
|
|
_, resp := th.Client.LinkLdapGroup(entryUUID)
|
|
|
|
|
CheckForbiddenStatus(t, resp)
|
|
|
|
|
|
|
|
|
|
_, resp = th.SystemAdminClient.LinkLdapGroup(entryUUID)
|
|
|
|
|
CheckNotImplementedStatus(t, resp)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestUnlinkLdapGroup(t *testing.T) {
|
|
|
|
|
const entryUUID string = "foo"
|
|
|
|
|
|
|
|
|
|
th := Setup().InitBasic()
|
|
|
|
|
defer th.TearDown()
|
|
|
|
|
|
|
|
|
|
_, resp := th.Client.UnlinkLdapGroup(entryUUID)
|
|
|
|
|
CheckForbiddenStatus(t, resp)
|
|
|
|
|
|
|
|
|
|
_, resp = th.SystemAdminClient.UnlinkLdapGroup(entryUUID)
|
|
|
|
|
CheckNotImplementedStatus(t, resp)
|
|
|
|
|
}
|