Files
mattermost/api4/ldap_test.go
Agniva De Sarker 4a2715974d MM-27149: optimize initBasic (#15063)
* MM-27149: optimize initBasic

Mostly, all tests just needed the user initialization part and not
the channel and group creation. So we move the user initialization inside
the Setup call. This avoids unnecessary DB calls which take around 250-300ms
on average.

And we make the login requests concurrently to shave off a few more ms.
According to my tests, the 2 login calls take 140 ms on average, which
shaves off 70ms.

So approximately, we shave off 350ms per test. And there are 114 occurences
of these. So around 39 seconds.

* make initlogin only for Setup/SetupEnterprise

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2020-07-22 13:50:33 +05:30

115 lines
2.8 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package api4
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost-server/v5/model"
)
func TestTestLdap(t *testing.T) {
th := Setup(t)
defer th.TearDown()
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()
CheckForbiddenStatus(t, resp)
require.NotNil(t, resp.Error)
require.Equal(t, "api.context.permissions.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)
defer th.TearDown()
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"))
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
_, resp := client.SyncLdap()
CheckNoError(t, resp)
})
_, resp := th.Client.SyncLdap()
CheckForbiddenStatus(t, resp)
}
func TestGetLdapGroups(t *testing.T) {
th := Setup(t)
defer th.TearDown()
_, resp := th.Client.GetLdapGroups()
CheckForbiddenStatus(t, resp)
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
_, resp := client.GetLdapGroups()
CheckNotImplementedStatus(t, resp)
})
}
func TestLinkLdapGroup(t *testing.T) {
const entryUUID string = "foo"
th := Setup(t)
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(t)
defer th.TearDown()
_, resp := th.Client.UnlinkLdapGroup(entryUUID)
CheckForbiddenStatus(t, resp)
_, resp = th.SystemAdminClient.UnlinkLdapGroup(entryUUID)
CheckNotImplementedStatus(t, resp)
}
func TestMigrateIdLdap(t *testing.T) {
th := Setup(t)
defer th.TearDown()
_, resp := th.Client.MigrateIdLdap("objectGUID")
CheckForbiddenStatus(t, resp)
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
_, resp = client.MigrateIdLdap("")
CheckBadRequestStatus(t, resp)
_, resp = client.MigrateIdLdap("objectGUID")
CheckNotImplementedStatus(t, resp)
})
}