[MM-49989] Pass a context.Context to Client4 methods (#22922)
* Migrate all method in model/client4.go to accept a context.Context * Fix th.*Client * Fix remaining issues * Empty commit to triger CI * Fix test * Add cancellation test * Test that returned error is context.Canceled * Fix bad merge * Update mmctl code --------- Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
7116e9267a
Коммит
6c82605df0
@@ -478,7 +478,7 @@ func (th *TestHelper) InitBasic() *TestHelper {
|
||||
th.App.AddUserToChannel(th.Context, th.BasicUser, th.BasicDeletedChannel, false)
|
||||
th.App.AddUserToChannel(th.Context, th.BasicUser2, th.BasicDeletedChannel, false)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId, false)
|
||||
th.Client.DeleteChannel(th.BasicDeletedChannel.Id)
|
||||
th.Client.DeleteChannel(context.Background(), th.BasicDeletedChannel.Id)
|
||||
th.LoginBasic()
|
||||
th.Group = th.CreateGroup()
|
||||
|
||||
@@ -552,7 +552,7 @@ func (th *TestHelper) CreateBotWithClient(client *model.Client4) *model.Bot {
|
||||
Description: "bot",
|
||||
}
|
||||
|
||||
rbot, _, err := client.CreateBot(bot)
|
||||
rbot, _, err := client.CreateBot(context.Background(), bot)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -576,7 +576,7 @@ func (th *TestHelper) CreateTeamWithClient(client *model.Client4) *model.Team {
|
||||
Type: model.TeamOpen,
|
||||
}
|
||||
|
||||
rteam, _, err := client.CreateTeam(team)
|
||||
rteam, _, err := client.CreateTeam(context.Background(), team)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -595,7 +595,7 @@ func (th *TestHelper) CreateUserWithClient(client *model.Client4) *model.User {
|
||||
Password: "Pa$$word11",
|
||||
}
|
||||
|
||||
ruser, _, err := client.CreateUser(user)
|
||||
ruser, _, err := client.CreateUser(context.Background(), user)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -696,7 +696,7 @@ func (th *TestHelper) CreateChannelWithClientAndTeam(client *model.Client4, chan
|
||||
TeamId: teamId,
|
||||
}
|
||||
|
||||
rchannel, _, err := client.CreateChannel(channel)
|
||||
rchannel, _, err := client.CreateChannel(context.Background(), channel)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -735,7 +735,7 @@ func (th *TestHelper) CreatePostWithFilesWithClient(client *model.Client4, chann
|
||||
FileIds: fileIds,
|
||||
}
|
||||
|
||||
rpost, _, err := client.CreatePost(post)
|
||||
rpost, _, err := client.CreatePost(context.Background(), post)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -750,7 +750,7 @@ func (th *TestHelper) CreatePostWithClient(client *model.Client4, channel *model
|
||||
Message: "message_" + id,
|
||||
}
|
||||
|
||||
rpost, _, err := client.CreatePost(post)
|
||||
rpost, _, err := client.CreatePost(context.Background(), post)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -766,7 +766,7 @@ func (th *TestHelper) CreatePinnedPostWithClient(client *model.Client4, channel
|
||||
IsPinned: true,
|
||||
}
|
||||
|
||||
rpost, _, err := client.CreatePost(post)
|
||||
rpost, _, err := client.CreatePost(context.Background(), post)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -779,7 +779,7 @@ func (th *TestHelper) CreateMessagePostWithClient(client *model.Client4, channel
|
||||
Message: message,
|
||||
}
|
||||
|
||||
rpost, _, err := client.CreatePost(post)
|
||||
rpost, _, err := client.CreatePost(context.Background(), post)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -837,7 +837,7 @@ func (th *TestHelper) LoginSystemManager() {
|
||||
}
|
||||
|
||||
func (th *TestHelper) LoginBasicWithClient(client *model.Client4) {
|
||||
_, _, err := client.Login(th.BasicUser.Email, th.BasicUser.Password)
|
||||
_, _, err := client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -851,28 +851,28 @@ func (th *TestHelper) LoginBasicWithGraphQL() {
|
||||
}
|
||||
|
||||
func (th *TestHelper) LoginBasic2WithClient(client *model.Client4) {
|
||||
_, _, err := client.Login(th.BasicUser2.Email, th.BasicUser2.Password)
|
||||
_, _, err := client.Login(context.Background(), th.BasicUser2.Email, th.BasicUser2.Password)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (th *TestHelper) LoginTeamAdminWithClient(client *model.Client4) {
|
||||
_, _, err := client.Login(th.TeamAdminUser.Email, th.TeamAdminUser.Password)
|
||||
_, _, err := client.Login(context.Background(), th.TeamAdminUser.Email, th.TeamAdminUser.Password)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (th *TestHelper) LoginSystemManagerWithClient(client *model.Client4) {
|
||||
_, _, err := client.Login(th.SystemManagerUser.Email, th.SystemManagerUser.Password)
|
||||
_, _, err := client.Login(context.Background(), th.SystemManagerUser.Email, th.SystemManagerUser.Password)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (th *TestHelper) LoginSystemAdminWithClient(client *model.Client4) {
|
||||
_, _, err := client.Login(th.SystemAdminUser.Email, th.SystemAdminUser.Password)
|
||||
_, _, err := client.Login(context.Background(), th.SystemAdminUser.Email, th.SystemAdminUser.Password)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -16,7 +17,7 @@ func TestBlevePurgeIndexes(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
t.Run("as system user", func(t *testing.T) {
|
||||
resp, err := th.Client.PurgeBleveIndexes()
|
||||
resp, err := th.Client.PurgeBleveIndexes(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
@@ -24,13 +25,13 @@ func TestBlevePurgeIndexes(t *testing.T) {
|
||||
t.Run("as system user with write experimental permission", func(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionPurgeBleveIndexes.Id, model.SystemUserRoleId)
|
||||
defer th.RemovePermissionFromRole(model.PermissionSysconsoleWriteExperimental.Id, model.SystemUserRoleId)
|
||||
resp, err := th.Client.PurgeBleveIndexes()
|
||||
resp, err := th.Client.PurgeBleveIndexes(context.Background())
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("as system admin", func(t *testing.T) {
|
||||
resp, err := th.SystemAdminClient.PurgeBleveIndexes()
|
||||
resp, err := th.SystemAdminClient.PurgeBleveIndexes(context.Background())
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
})
|
||||
@@ -38,7 +39,7 @@ func TestBlevePurgeIndexes(t *testing.T) {
|
||||
t.Run("as restricted system admin", func(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ExperimentalSettings.RestrictSystemAdmin = true })
|
||||
|
||||
resp, err := th.SystemAdminClient.PurgeBleveIndexes()
|
||||
resp, err := th.SystemAdminClient.PurgeBleveIndexes(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"strings"
|
||||
@@ -23,7 +24,7 @@ func TestCreateBot(t *testing.T) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
|
||||
_, _, err := th.Client.CreateBot(&model.Bot{
|
||||
_, _, err := th.Client.CreateBot(context.Background(), &model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
DisplayName: "a bot",
|
||||
Description: "bot",
|
||||
@@ -40,7 +41,7 @@ func TestCreateBot(t *testing.T) {
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
th.App.Config().ServiceSettings.EnableBotAccountCreation = model.NewBool(false)
|
||||
|
||||
_, _, err := th.Client.CreateBot(&model.Bot{
|
||||
_, _, err := th.Client.CreateBot(context.Background(), &model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
DisplayName: "a bot",
|
||||
Description: "bot",
|
||||
@@ -66,7 +67,7 @@ func TestCreateBot(t *testing.T) {
|
||||
Description: "bot",
|
||||
}
|
||||
|
||||
createdBot, resp, err := th.Client.CreateBot(bot)
|
||||
createdBot, resp, err := th.Client.CreateBot(context.Background(), bot)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
@@ -86,7 +87,7 @@ func TestCreateBot(t *testing.T) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
|
||||
_, _, err := th.Client.CreateBot(&model.Bot{
|
||||
_, _, err := th.Client.CreateBot(context.Background(), &model.Bot{
|
||||
Username: "username",
|
||||
DisplayName: "a bot",
|
||||
Description: strings.Repeat("x", 1025),
|
||||
@@ -108,7 +109,7 @@ func TestCreateBot(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionEditOtherUsers.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
|
||||
bot, resp, err := th.Client.CreateBot(&model.Bot{
|
||||
bot, resp, err := th.Client.CreateBot(context.Background(), &model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
DisplayName: "a bot",
|
||||
Description: "bot",
|
||||
@@ -118,11 +119,11 @@ func TestCreateBot(t *testing.T) {
|
||||
defer th.App.PermanentDeleteBot(bot.UserId)
|
||||
th.App.UpdateUserRoles(th.Context, bot.UserId, model.TeamUserRoleId+" "+model.SystemUserAccessTokenRoleId, false)
|
||||
|
||||
rtoken, _, err := th.Client.CreateUserAccessToken(bot.UserId, "test token")
|
||||
rtoken, _, err := th.Client.CreateUserAccessToken(context.Background(), bot.UserId, "test token")
|
||||
require.NoError(t, err)
|
||||
th.Client.AuthToken = rtoken.Token
|
||||
|
||||
_, _, err = th.Client.CreateBot(&model.Bot{
|
||||
_, _, err = th.Client.CreateBot(context.Background(), &model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
OwnerId: bot.UserId,
|
||||
DisplayName: "a bot2",
|
||||
@@ -140,7 +141,7 @@ func TestPatchBot(t *testing.T) {
|
||||
defer th.RestoreDefaultRolePermissions(th.SaveDefaultRolePermissions())
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
_, resp, err := client.PatchBot(model.NewId(), &model.BotPatch{})
|
||||
_, resp, err := client.PatchBot(context.Background(), model.NewId(), &model.BotPatch{})
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
})
|
||||
@@ -157,7 +158,7 @@ func TestPatchBot(t *testing.T) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
|
||||
createdBot, resp, err := th.Client.CreateBot(&model.Bot{
|
||||
createdBot, resp, err := th.Client.CreateBot(context.Background(), &model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
DisplayName: "a bot",
|
||||
Description: "bot created by a user",
|
||||
@@ -172,7 +173,7 @@ func TestPatchBot(t *testing.T) {
|
||||
DisplayName: sToP("an updated bot"),
|
||||
Description: sToP("updated bot"),
|
||||
}
|
||||
patchedBot, patchResp, err2 := client.PatchBot(createdBot.UserId, botPatch)
|
||||
patchedBot, patchResp, err2 := client.PatchBot(context.Background(), createdBot.UserId, botPatch)
|
||||
require.NoError(t, err2)
|
||||
CheckOKStatus(t, patchResp)
|
||||
require.Equal(t, *botPatch.Username, patchedBot.Username)
|
||||
@@ -181,7 +182,7 @@ func TestPatchBot(t *testing.T) {
|
||||
require.Equal(t, th.BasicUser.Id, patchedBot.OwnerId)
|
||||
}, "bot created by user")
|
||||
|
||||
createdBotSystemAdmin, resp, err := th.SystemAdminClient.CreateBot(&model.Bot{
|
||||
createdBotSystemAdmin, resp, err := th.SystemAdminClient.CreateBot(context.Background(), &model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
DisplayName: "another bot",
|
||||
Description: "bot created by system admin user",
|
||||
@@ -196,7 +197,7 @@ func TestPatchBot(t *testing.T) {
|
||||
DisplayName: sToP("an updated bot"),
|
||||
Description: sToP("updated bot"),
|
||||
}
|
||||
patchedBot, patchResp, err := client.PatchBot(createdBotSystemAdmin.UserId, botPatch)
|
||||
patchedBot, patchResp, err := client.PatchBot(context.Background(), createdBotSystemAdmin.UserId, botPatch)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, patchResp)
|
||||
require.Equal(t, *botPatch.Username, patchedBot.Username)
|
||||
@@ -215,7 +216,7 @@ func TestPatchBot(t *testing.T) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
|
||||
createdBot, resp, err := th.SystemAdminClient.CreateBot(&model.Bot{
|
||||
createdBot, resp, err := th.SystemAdminClient.CreateBot(context.Background(), &model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
DisplayName: "a bot",
|
||||
Description: "bot",
|
||||
@@ -224,7 +225,7 @@ func TestPatchBot(t *testing.T) {
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
|
||||
_, _, err = th.Client.PatchBot(createdBot.UserId, &model.BotPatch{})
|
||||
_, _, err = th.Client.PatchBot(context.Background(), createdBot.UserId, &model.BotPatch{})
|
||||
CheckErrorID(t, err, "store.sql_bot.get.missing.app_error")
|
||||
})
|
||||
|
||||
@@ -239,7 +240,7 @@ func TestPatchBot(t *testing.T) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
|
||||
createdBot, resp, err := th.SystemAdminClient.CreateBot(&model.Bot{
|
||||
createdBot, resp, err := th.SystemAdminClient.CreateBot(context.Background(), &model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
DisplayName: "a bot",
|
||||
Description: "bot",
|
||||
@@ -248,7 +249,7 @@ func TestPatchBot(t *testing.T) {
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
|
||||
_, _, err = th.Client.PatchBot(createdBot.UserId, &model.BotPatch{})
|
||||
_, _, err = th.Client.PatchBot(context.Background(), createdBot.UserId, &model.BotPatch{})
|
||||
CheckErrorID(t, err, "api.context.permissions.app_error")
|
||||
})
|
||||
|
||||
@@ -263,7 +264,7 @@ func TestPatchBot(t *testing.T) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
|
||||
createdBot, resp, err := th.SystemAdminClient.CreateBot(&model.Bot{
|
||||
createdBot, resp, err := th.SystemAdminClient.CreateBot(context.Background(), &model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
DisplayName: "a bot",
|
||||
Description: "bot",
|
||||
@@ -278,7 +279,7 @@ func TestPatchBot(t *testing.T) {
|
||||
Description: sToP("updated bot"),
|
||||
}
|
||||
|
||||
patchedBot, resp, err := th.Client.PatchBot(createdBot.UserId, botPatch)
|
||||
patchedBot, resp, err := th.Client.PatchBot(context.Background(), createdBot.UserId, botPatch)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
require.Equal(t, *botPatch.Username, patchedBot.Username)
|
||||
@@ -293,11 +294,11 @@ func TestPatchBot(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionManageRoles.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
|
||||
resp, err = th.Client.UpdateUserRoles(createdBot.UserId, model.SystemUserRoleId)
|
||||
resp, err = th.Client.UpdateUserRoles(context.Background(), createdBot.UserId, model.SystemUserRoleId)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
|
||||
bot, resp, err := th.Client.GetBot(createdBot.UserId, "")
|
||||
bot, resp, err := th.Client.GetBot(context.Background(), createdBot.UserId, "")
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
require.Equal(t, patchedBot, bot)
|
||||
@@ -314,7 +315,7 @@ func TestPatchBot(t *testing.T) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
|
||||
createdBot, resp, err := th.Client.CreateBot(&model.Bot{
|
||||
createdBot, resp, err := th.Client.CreateBot(context.Background(), &model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
DisplayName: "a bot",
|
||||
Description: "bot",
|
||||
@@ -329,7 +330,7 @@ func TestPatchBot(t *testing.T) {
|
||||
Description: sToP("updated bot"),
|
||||
}
|
||||
|
||||
_, _, err = th.Client.PatchBot(createdBot.UserId, botPatch)
|
||||
_, _, err = th.Client.PatchBot(context.Background(), createdBot.UserId, botPatch)
|
||||
CheckErrorID(t, err, "store.sql_bot.get.missing.app_error")
|
||||
})
|
||||
|
||||
@@ -345,7 +346,7 @@ func TestPatchBot(t *testing.T) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
|
||||
createdBot, resp, err := th.Client.CreateBot(&model.Bot{
|
||||
createdBot, resp, err := th.Client.CreateBot(context.Background(), &model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
DisplayName: "a bot",
|
||||
Description: "bot",
|
||||
@@ -360,7 +361,7 @@ func TestPatchBot(t *testing.T) {
|
||||
Description: sToP("updated bot"),
|
||||
}
|
||||
|
||||
_, _, err = th.Client.PatchBot(createdBot.UserId, botPatch)
|
||||
_, _, err = th.Client.PatchBot(context.Background(), createdBot.UserId, botPatch)
|
||||
CheckErrorID(t, err, "api.context.permissions.app_error")
|
||||
})
|
||||
|
||||
@@ -376,7 +377,7 @@ func TestPatchBot(t *testing.T) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
|
||||
createdBot, resp, err := th.Client.CreateBot(&model.Bot{
|
||||
createdBot, resp, err := th.Client.CreateBot(context.Background(), &model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
DisplayName: "a bot",
|
||||
Description: "bot",
|
||||
@@ -391,7 +392,7 @@ func TestPatchBot(t *testing.T) {
|
||||
Description: sToP("updated bot"),
|
||||
}
|
||||
|
||||
patchedBot, resp, err := th.Client.PatchBot(createdBot.UserId, botPatch)
|
||||
patchedBot, resp, err := th.Client.PatchBot(context.Background(), createdBot.UserId, botPatch)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
require.Equal(t, *botPatch.Username, patchedBot.Username)
|
||||
@@ -418,7 +419,7 @@ func TestPatchBot(t *testing.T) {
|
||||
Description: "bot",
|
||||
}
|
||||
|
||||
createdBot, resp, err := th.Client.CreateBot(bot)
|
||||
createdBot, resp, err := th.Client.CreateBot(context.Background(), bot)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
@@ -427,7 +428,7 @@ func TestPatchBot(t *testing.T) {
|
||||
Username: sToP(GenerateTestUsername()),
|
||||
}
|
||||
|
||||
patchedBot, resp, err := th.Client.PatchBot(createdBot.UserId, botPatch)
|
||||
patchedBot, resp, err := th.Client.PatchBot(context.Background(), createdBot.UserId, botPatch)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
require.Equal(t, *botPatch.Username, patchedBot.Username)
|
||||
@@ -448,7 +449,7 @@ func TestPatchBot(t *testing.T) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
|
||||
createdBot, resp, err := th.Client.CreateBot(&model.Bot{
|
||||
createdBot, resp, err := th.Client.CreateBot(context.Background(), &model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
DisplayName: "a bot",
|
||||
Description: "bot",
|
||||
@@ -457,7 +458,7 @@ func TestPatchBot(t *testing.T) {
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
|
||||
r, err := th.Client.DoAPIPut("/bots/"+createdBot.UserId, `{"creator_id":"`+th.BasicUser2.Id+`"}`)
|
||||
r, err := th.Client.DoAPIPut(context.Background(), "/bots/"+createdBot.UserId, `{"creator_id":"`+th.BasicUser2.Id+`"}`)
|
||||
require.NoError(t, err)
|
||||
defer func() {
|
||||
_, _ = io.ReadAll(r.Body)
|
||||
@@ -482,7 +483,7 @@ func TestGetBot(t *testing.T) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
|
||||
bot1, resp, err := th.SystemAdminClient.CreateBot(&model.Bot{
|
||||
bot1, resp, err := th.SystemAdminClient.CreateBot(context.Background(), &model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
DisplayName: "a bot",
|
||||
Description: "the first bot",
|
||||
@@ -491,7 +492,7 @@ func TestGetBot(t *testing.T) {
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(bot1.UserId)
|
||||
|
||||
bot2, resp, err := th.SystemAdminClient.CreateBot(&model.Bot{
|
||||
bot2, resp, err := th.SystemAdminClient.CreateBot(context.Background(), &model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
DisplayName: "another bot",
|
||||
Description: "the second bot",
|
||||
@@ -500,14 +501,14 @@ func TestGetBot(t *testing.T) {
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(bot2.UserId)
|
||||
|
||||
deletedBot, resp, err := th.SystemAdminClient.CreateBot(&model.Bot{
|
||||
deletedBot, resp, err := th.SystemAdminClient.CreateBot(context.Background(), &model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
Description: "a deleted bot",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(deletedBot.UserId)
|
||||
deletedBot, resp, err = th.SystemAdminClient.DisableBot(deletedBot.UserId)
|
||||
deletedBot, resp, err = th.SystemAdminClient.DisableBot(context.Background(), deletedBot.UserId)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
|
||||
@@ -517,7 +518,7 @@ func TestGetBot(t *testing.T) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
|
||||
myBot, resp, err := th.Client.CreateBot(&model.Bot{
|
||||
myBot, resp, err := th.Client.CreateBot(context.Background(), &model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
DisplayName: "my bot",
|
||||
Description: "a bot created by non-admin",
|
||||
@@ -534,7 +535,7 @@ func TestGetBot(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionReadOthersBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
|
||||
_, resp, err := th.Client.GetBot(model.NewId(), "")
|
||||
_, resp, err := th.Client.GetBot(context.Background(), model.NewId(), "")
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
})
|
||||
@@ -546,12 +547,12 @@ func TestGetBot(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionReadOthersBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
|
||||
bot, resp, err := th.Client.GetBot(bot1.UserId, "")
|
||||
bot, resp, err := th.Client.GetBot(context.Background(), bot1.UserId, "")
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
require.Equal(t, bot1, bot)
|
||||
|
||||
bot, resp, _ = th.Client.GetBot(bot1.UserId, bot.Etag())
|
||||
bot, resp, _ = th.Client.GetBot(context.Background(), bot1.UserId, bot.Etag())
|
||||
CheckEtag(t, bot, resp)
|
||||
})
|
||||
|
||||
@@ -562,12 +563,12 @@ func TestGetBot(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionReadOthersBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
|
||||
bot, resp, err := th.Client.GetBot(bot2.UserId, "")
|
||||
bot, resp, err := th.Client.GetBot(context.Background(), bot2.UserId, "")
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
require.Equal(t, bot2, bot)
|
||||
|
||||
bot, resp, _ = th.Client.GetBot(bot2.UserId, bot.Etag())
|
||||
bot, resp, _ = th.Client.GetBot(context.Background(), bot2.UserId, bot.Etag())
|
||||
CheckEtag(t, bot, resp)
|
||||
})
|
||||
|
||||
@@ -580,7 +581,7 @@ func TestGetBot(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionManageOthersBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
|
||||
_, _, err := th.Client.GetBot(bot1.UserId, "")
|
||||
_, _, err := th.Client.GetBot(context.Background(), bot1.UserId, "")
|
||||
CheckErrorID(t, err, "store.sql_bot.get.missing.app_error")
|
||||
})
|
||||
|
||||
@@ -592,7 +593,7 @@ func TestGetBot(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionManageOthersBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
|
||||
_, _, err := th.Client.GetBot(myBot.UserId, "")
|
||||
_, _, err := th.Client.GetBot(context.Background(), myBot.UserId, "")
|
||||
CheckErrorID(t, err, "store.sql_bot.get.missing.app_error")
|
||||
})
|
||||
|
||||
@@ -603,7 +604,7 @@ func TestGetBot(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionReadOthersBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
|
||||
_, resp, err := th.Client.GetBot(deletedBot.UserId, "")
|
||||
_, resp, err := th.Client.GetBot(context.Background(), deletedBot.UserId, "")
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
})
|
||||
@@ -615,7 +616,7 @@ func TestGetBot(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionReadOthersBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
|
||||
bot, resp, err := th.Client.GetBotIncludeDeleted(deletedBot.UserId, "")
|
||||
bot, resp, err := th.Client.GetBotIncludeDeleted(context.Background(), deletedBot.UserId, "")
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
require.NotEqual(t, 0, bot.DeleteAt)
|
||||
@@ -623,7 +624,7 @@ func TestGetBot(t *testing.T) {
|
||||
deletedBot.DeleteAt = bot.DeleteAt
|
||||
require.Equal(t, deletedBot, bot)
|
||||
|
||||
bot, resp, _ = th.Client.GetBotIncludeDeleted(deletedBot.UserId, bot.Etag())
|
||||
bot, resp, _ = th.Client.GetBotIncludeDeleted(context.Background(), deletedBot.UserId, bot.Etag())
|
||||
CheckEtag(t, bot, resp)
|
||||
})
|
||||
}
|
||||
@@ -636,7 +637,7 @@ func TestGetBots(t *testing.T) {
|
||||
*cfg.ServiceSettings.EnableBotAccountCreation = true
|
||||
})
|
||||
|
||||
bot1, resp, err := th.SystemAdminClient.CreateBot(&model.Bot{
|
||||
bot1, resp, err := th.SystemAdminClient.CreateBot(context.Background(), &model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
DisplayName: "a bot",
|
||||
Description: "the first bot",
|
||||
@@ -645,18 +646,18 @@ func TestGetBots(t *testing.T) {
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(bot1.UserId)
|
||||
|
||||
deletedBot1, resp, err := th.SystemAdminClient.CreateBot(&model.Bot{
|
||||
deletedBot1, resp, err := th.SystemAdminClient.CreateBot(context.Background(), &model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
Description: "a deleted bot",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(deletedBot1.UserId)
|
||||
deletedBot1, resp, err = th.SystemAdminClient.DisableBot(deletedBot1.UserId)
|
||||
deletedBot1, resp, err = th.SystemAdminClient.DisableBot(context.Background(), deletedBot1.UserId)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
|
||||
bot2, resp, err := th.SystemAdminClient.CreateBot(&model.Bot{
|
||||
bot2, resp, err := th.SystemAdminClient.CreateBot(context.Background(), &model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
DisplayName: "another bot",
|
||||
Description: "the second bot",
|
||||
@@ -665,7 +666,7 @@ func TestGetBots(t *testing.T) {
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(bot2.UserId)
|
||||
|
||||
bot3, resp, err := th.SystemAdminClient.CreateBot(&model.Bot{
|
||||
bot3, resp, err := th.SystemAdminClient.CreateBot(context.Background(), &model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
DisplayName: "another bot",
|
||||
Description: "the third bot",
|
||||
@@ -674,21 +675,21 @@ func TestGetBots(t *testing.T) {
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(bot3.UserId)
|
||||
|
||||
deletedBot2, resp, err := th.SystemAdminClient.CreateBot(&model.Bot{
|
||||
deletedBot2, resp, err := th.SystemAdminClient.CreateBot(context.Background(), &model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
Description: "a deleted bot",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(deletedBot2.UserId)
|
||||
deletedBot2, resp, err = th.SystemAdminClient.DisableBot(deletedBot2.UserId)
|
||||
deletedBot2, resp, err = th.SystemAdminClient.DisableBot(context.Background(), deletedBot2.UserId)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
|
||||
th.AddPermissionToRole(model.PermissionCreateBot.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser2.Id, model.TeamUserRoleId, false)
|
||||
th.LoginBasic2()
|
||||
orphanedBot, resp, err := th.Client.CreateBot(&model.Bot{
|
||||
orphanedBot, resp, err := th.Client.CreateBot(context.Background(), &model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
Description: "an orphaned bot",
|
||||
})
|
||||
@@ -700,7 +701,7 @@ func TestGetBots(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.ServiceSettings.DisableBotsWhenOwnerIsDeactivated = false
|
||||
})
|
||||
resp, err = th.SystemAdminClient.DeleteUser(th.BasicUser2.Id)
|
||||
resp, err = th.SystemAdminClient.DeleteUser(context.Background(), th.BasicUser2.Id)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
|
||||
@@ -713,14 +714,14 @@ func TestGetBots(t *testing.T) {
|
||||
|
||||
expectedBotList := []*model.Bot{bot1, bot2, bot3, orphanedBot}
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
bots, resp, err := client.GetBots(0, 10, "")
|
||||
bots, resp, err := client.GetBots(context.Background(), 0, 10, "")
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
require.Equal(t, expectedBotList, bots)
|
||||
})
|
||||
|
||||
botList := model.BotList(expectedBotList)
|
||||
bots, resp, _ := th.Client.GetBots(0, 10, botList.Etag())
|
||||
bots, resp, _ := th.Client.GetBots(context.Background(), 0, 10, botList.Etag())
|
||||
CheckEtag(t, bots, resp)
|
||||
})
|
||||
|
||||
@@ -733,14 +734,14 @@ func TestGetBots(t *testing.T) {
|
||||
|
||||
expectedBotList := []*model.Bot{bot1}
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
bots, resp, err := client.GetBots(0, 1, "")
|
||||
bots, resp, err := client.GetBots(context.Background(), 0, 1, "")
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
require.Equal(t, expectedBotList, bots)
|
||||
})
|
||||
|
||||
botList := model.BotList(expectedBotList)
|
||||
bots, resp, _ := th.Client.GetBots(0, 1, botList.Etag())
|
||||
bots, resp, _ := th.Client.GetBots(context.Background(), 0, 1, botList.Etag())
|
||||
CheckEtag(t, bots, resp)
|
||||
})
|
||||
|
||||
@@ -753,14 +754,14 @@ func TestGetBots(t *testing.T) {
|
||||
|
||||
expectedBotList := []*model.Bot{bot3, orphanedBot}
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
bots, resp, err := client.GetBots(1, 2, "")
|
||||
bots, resp, err := client.GetBots(context.Background(), 1, 2, "")
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
require.Equal(t, expectedBotList, bots)
|
||||
})
|
||||
|
||||
botList := model.BotList(expectedBotList)
|
||||
bots, resp, _ := th.Client.GetBots(1, 2, botList.Etag())
|
||||
bots, resp, _ := th.Client.GetBots(context.Background(), 1, 2, botList.Etag())
|
||||
CheckEtag(t, bots, resp)
|
||||
})
|
||||
|
||||
@@ -773,14 +774,14 @@ func TestGetBots(t *testing.T) {
|
||||
|
||||
expectedBotList := []*model.Bot{}
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
bots, resp, err := client.GetBots(2, 2, "")
|
||||
bots, resp, err := client.GetBots(context.Background(), 2, 2, "")
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
require.Equal(t, expectedBotList, bots)
|
||||
})
|
||||
|
||||
botList := model.BotList(expectedBotList)
|
||||
bots, resp, _ := th.Client.GetBots(2, 2, botList.Etag())
|
||||
bots, resp, _ := th.Client.GetBots(context.Background(), 2, 2, botList.Etag())
|
||||
CheckEtag(t, bots, resp)
|
||||
})
|
||||
|
||||
@@ -793,14 +794,14 @@ func TestGetBots(t *testing.T) {
|
||||
|
||||
expectedBotList := []*model.Bot{bot1, deletedBot1, bot2, bot3, deletedBot2, orphanedBot}
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
bots, resp, err := client.GetBotsIncludeDeleted(0, 10, "")
|
||||
bots, resp, err := client.GetBotsIncludeDeleted(context.Background(), 0, 10, "")
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
require.Equal(t, expectedBotList, bots)
|
||||
})
|
||||
|
||||
botList := model.BotList(expectedBotList)
|
||||
bots, resp, _ := th.Client.GetBotsIncludeDeleted(0, 10, botList.Etag())
|
||||
bots, resp, _ := th.Client.GetBotsIncludeDeleted(context.Background(), 0, 10, botList.Etag())
|
||||
CheckEtag(t, bots, resp)
|
||||
})
|
||||
|
||||
@@ -813,14 +814,14 @@ func TestGetBots(t *testing.T) {
|
||||
|
||||
expectedBotList := []*model.Bot{bot1}
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
bots, resp, err := client.GetBotsIncludeDeleted(0, 1, "")
|
||||
bots, resp, err := client.GetBotsIncludeDeleted(context.Background(), 0, 1, "")
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
require.Equal(t, expectedBotList, bots)
|
||||
})
|
||||
|
||||
botList := model.BotList(expectedBotList)
|
||||
bots, resp, _ := th.Client.GetBotsIncludeDeleted(0, 1, botList.Etag())
|
||||
bots, resp, _ := th.Client.GetBotsIncludeDeleted(context.Background(), 0, 1, botList.Etag())
|
||||
CheckEtag(t, bots, resp)
|
||||
})
|
||||
|
||||
@@ -833,14 +834,14 @@ func TestGetBots(t *testing.T) {
|
||||
|
||||
expectedBotList := []*model.Bot{bot2, bot3}
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
bots, resp, err := client.GetBotsIncludeDeleted(1, 2, "")
|
||||
bots, resp, err := client.GetBotsIncludeDeleted(context.Background(), 1, 2, "")
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
require.Equal(t, expectedBotList, bots)
|
||||
})
|
||||
|
||||
botList := model.BotList(expectedBotList)
|
||||
bots, resp, _ := th.Client.GetBotsIncludeDeleted(1, 2, botList.Etag())
|
||||
bots, resp, _ := th.Client.GetBotsIncludeDeleted(context.Background(), 1, 2, botList.Etag())
|
||||
CheckEtag(t, bots, resp)
|
||||
})
|
||||
|
||||
@@ -853,14 +854,14 @@ func TestGetBots(t *testing.T) {
|
||||
|
||||
expectedBotList := []*model.Bot{deletedBot2, orphanedBot}
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
bots, resp, err := client.GetBotsIncludeDeleted(2, 2, "")
|
||||
bots, resp, err := client.GetBotsIncludeDeleted(context.Background(), 2, 2, "")
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
require.Equal(t, expectedBotList, bots)
|
||||
})
|
||||
|
||||
botList := model.BotList(expectedBotList)
|
||||
bots, resp, _ := th.Client.GetBotsIncludeDeleted(2, 2, botList.Etag())
|
||||
bots, resp, _ := th.Client.GetBotsIncludeDeleted(context.Background(), 2, 2, botList.Etag())
|
||||
CheckEtag(t, bots, resp)
|
||||
})
|
||||
|
||||
@@ -873,14 +874,14 @@ func TestGetBots(t *testing.T) {
|
||||
|
||||
expectedBotList := []*model.Bot{orphanedBot}
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
bots, resp, err := client.GetBotsOrphaned(0, 10, "")
|
||||
bots, resp, err := client.GetBotsOrphaned(context.Background(), 0, 10, "")
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
require.Equal(t, expectedBotList, bots)
|
||||
})
|
||||
|
||||
botList := model.BotList(expectedBotList)
|
||||
bots, resp, _ := th.Client.GetBotsOrphaned(0, 10, botList.Etag())
|
||||
bots, resp, _ := th.Client.GetBotsOrphaned(context.Background(), 0, 10, botList.Etag())
|
||||
CheckEtag(t, bots, resp)
|
||||
})
|
||||
|
||||
@@ -892,7 +893,7 @@ func TestGetBots(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionManageOthersBots.Id, model.TeamUserRoleId)
|
||||
th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false)
|
||||
|
||||
_, _, err := th.Client.GetBots(0, 10, "")
|
||||
_, _, err := th.Client.GetBots(context.Background(), 0, 10, "")
|
||||
CheckErrorID(t, err, "api.context.permissions.app_error")
|
||||
})
|
||||
}
|
||||
@@ -903,7 +904,7 @@ func TestDisableBot(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
_, resp, err := client.DisableBot(model.NewId())
|
||||
_, resp, err := client.DisableBot(context.Background(), model.NewId())
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
})
|
||||
@@ -925,12 +926,12 @@ func TestDisableBot(t *testing.T) {
|
||||
Description: "bot",
|
||||
}
|
||||
|
||||
createdBot, resp, err := th.Client.CreateBot(bot)
|
||||
createdBot, resp, err := th.Client.CreateBot(context.Background(), bot)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
|
||||
_, _, err = th.Client.DisableBot(createdBot.UserId)
|
||||
_, _, err = th.Client.DisableBot(context.Background(), createdBot.UserId)
|
||||
CheckErrorID(t, err, "store.sql_bot.get.missing.app_error")
|
||||
})
|
||||
|
||||
@@ -951,12 +952,12 @@ func TestDisableBot(t *testing.T) {
|
||||
Description: "bot",
|
||||
}
|
||||
|
||||
createdBot, resp, err := th.Client.CreateBot(bot)
|
||||
createdBot, resp, err := th.Client.CreateBot(context.Background(), bot)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
|
||||
_, _, err = th.Client.DisableBot(createdBot.UserId)
|
||||
_, _, err = th.Client.DisableBot(context.Background(), createdBot.UserId)
|
||||
CheckErrorID(t, err, "api.context.permissions.app_error")
|
||||
})
|
||||
|
||||
@@ -973,7 +974,7 @@ func TestDisableBot(t *testing.T) {
|
||||
})
|
||||
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
bot, resp, err := th.Client.CreateBot(&model.Bot{
|
||||
bot, resp, err := th.Client.CreateBot(context.Background(), &model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
Description: "bot",
|
||||
})
|
||||
@@ -981,7 +982,7 @@ func TestDisableBot(t *testing.T) {
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(bot.UserId)
|
||||
|
||||
disabledBot, resp, err := client.DisableBot(bot.UserId)
|
||||
disabledBot, resp, err := client.DisableBot(context.Background(), bot.UserId)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
bot.UpdateAt = disabledBot.UpdateAt
|
||||
@@ -989,13 +990,13 @@ func TestDisableBot(t *testing.T) {
|
||||
require.Equal(t, bot, disabledBot)
|
||||
|
||||
// Check bot disabled
|
||||
disab, resp, err := th.SystemAdminClient.GetBotIncludeDeleted(bot.UserId, "")
|
||||
disab, resp, err := th.SystemAdminClient.GetBotIncludeDeleted(context.Background(), bot.UserId, "")
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
require.NotZero(t, disab.DeleteAt)
|
||||
|
||||
// Disabling should be idempotent.
|
||||
disabledBot2, resp, err := client.DisableBot(bot.UserId)
|
||||
disabledBot2, resp, err := client.DisableBot(context.Background(), bot.UserId)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
require.Equal(t, bot, disabledBot2)
|
||||
@@ -1008,7 +1009,7 @@ func TestEnableBot(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
_, resp, err := th.Client.EnableBot(model.NewId())
|
||||
_, resp, err := th.Client.EnableBot(context.Background(), model.NewId())
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
})
|
||||
@@ -1030,16 +1031,16 @@ func TestEnableBot(t *testing.T) {
|
||||
Description: "bot",
|
||||
}
|
||||
|
||||
createdBot, resp, err := th.Client.CreateBot(bot)
|
||||
createdBot, resp, err := th.Client.CreateBot(context.Background(), bot)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
|
||||
_, resp, err = th.SystemAdminClient.DisableBot(createdBot.UserId)
|
||||
_, resp, err = th.SystemAdminClient.DisableBot(context.Background(), createdBot.UserId)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
|
||||
_, _, err = th.Client.EnableBot(createdBot.UserId)
|
||||
_, _, err = th.Client.EnableBot(context.Background(), createdBot.UserId)
|
||||
CheckErrorID(t, err, "store.sql_bot.get.missing.app_error")
|
||||
})
|
||||
|
||||
@@ -1060,16 +1061,16 @@ func TestEnableBot(t *testing.T) {
|
||||
Description: "bot",
|
||||
}
|
||||
|
||||
createdBot, resp, err := th.Client.CreateBot(bot)
|
||||
createdBot, resp, err := th.Client.CreateBot(context.Background(), bot)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
|
||||
_, resp, err = th.SystemAdminClient.DisableBot(createdBot.UserId)
|
||||
_, resp, err = th.SystemAdminClient.DisableBot(context.Background(), createdBot.UserId)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
|
||||
_, _, err = th.Client.EnableBot(createdBot.UserId)
|
||||
_, _, err = th.Client.EnableBot(context.Background(), createdBot.UserId)
|
||||
CheckErrorID(t, err, "api.context.permissions.app_error")
|
||||
})
|
||||
|
||||
@@ -1086,7 +1087,7 @@ func TestEnableBot(t *testing.T) {
|
||||
})
|
||||
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
bot, resp, err := th.Client.CreateBot(&model.Bot{
|
||||
bot, resp, err := th.Client.CreateBot(context.Background(), &model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
Description: "bot",
|
||||
})
|
||||
@@ -1094,11 +1095,11 @@ func TestEnableBot(t *testing.T) {
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(bot.UserId)
|
||||
|
||||
_, resp, err = th.SystemAdminClient.DisableBot(bot.UserId)
|
||||
_, resp, err = th.SystemAdminClient.DisableBot(context.Background(), bot.UserId)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
|
||||
enabledBot1, resp, err := client.EnableBot(bot.UserId)
|
||||
enabledBot1, resp, err := client.EnableBot(context.Background(), bot.UserId)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
bot.UpdateAt = enabledBot1.UpdateAt
|
||||
@@ -1106,13 +1107,13 @@ func TestEnableBot(t *testing.T) {
|
||||
require.Equal(t, bot, enabledBot1)
|
||||
|
||||
// Check bot enabled
|
||||
enab, resp, err := th.SystemAdminClient.GetBotIncludeDeleted(bot.UserId, "")
|
||||
enab, resp, err := th.SystemAdminClient.GetBotIncludeDeleted(context.Background(), bot.UserId, "")
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
require.Zero(t, enab.DeleteAt)
|
||||
|
||||
// Disabling should be idempotent.
|
||||
enabledBot2, resp, err := client.EnableBot(bot.UserId)
|
||||
enabledBot2, resp, err := client.EnableBot(context.Background(), bot.UserId)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
require.Equal(t, bot, enabledBot2)
|
||||
@@ -1126,7 +1127,7 @@ func TestAssignBot(t *testing.T) {
|
||||
|
||||
t.Run("claim non-existent bot", func(t *testing.T) {
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
_, resp, err := client.AssignBot(model.NewId(), model.NewId())
|
||||
_, resp, err := client.AssignBot(context.Background(), model.NewId(), model.NewId())
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
})
|
||||
@@ -1145,37 +1146,37 @@ func TestAssignBot(t *testing.T) {
|
||||
Username: GenerateTestUsername(),
|
||||
Description: "bot",
|
||||
}
|
||||
bot, resp, err := th.Client.CreateBot(bot)
|
||||
bot, resp, err := th.Client.CreateBot(context.Background(), bot)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(bot.UserId)
|
||||
|
||||
before, resp, err := th.Client.GetBot(bot.UserId, "")
|
||||
before, resp, err := th.Client.GetBot(context.Background(), bot.UserId, "")
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
require.Equal(t, th.BasicUser.Id, before.OwnerId)
|
||||
|
||||
_, resp, err = th.SystemAdminClient.AssignBot(bot.UserId, th.SystemAdminUser.Id)
|
||||
_, resp, err = th.SystemAdminClient.AssignBot(context.Background(), bot.UserId, th.SystemAdminUser.Id)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
|
||||
// Original owner doesn't have read others bots permission, therefore can't see bot anymore
|
||||
_, resp, err = th.Client.GetBot(bot.UserId, "")
|
||||
_, resp, err = th.Client.GetBot(context.Background(), bot.UserId, "")
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
// System admin can see creator ID has changed
|
||||
after, resp, err := th.SystemAdminClient.GetBot(bot.UserId, "")
|
||||
after, resp, err := th.SystemAdminClient.GetBot(context.Background(), bot.UserId, "")
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
require.Equal(t, th.SystemAdminUser.Id, after.OwnerId)
|
||||
|
||||
// Assign back to user without permissions to manage, using local mode
|
||||
_, resp, err = th.LocalClient.AssignBot(bot.UserId, th.BasicUser.Id)
|
||||
_, resp, err = th.LocalClient.AssignBot(context.Background(), bot.UserId, th.BasicUser.Id)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
|
||||
after, resp, err = th.SystemAdminClient.GetBot(bot.UserId, "")
|
||||
after, resp, err = th.SystemAdminClient.GetBot(context.Background(), bot.UserId, "")
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
require.Equal(t, th.BasicUser.Id, after.OwnerId)
|
||||
@@ -1194,7 +1195,7 @@ func TestAssignBot(t *testing.T) {
|
||||
Username: GenerateTestUsername(),
|
||||
Description: "bot",
|
||||
}
|
||||
createdBot, resp, err := th.Client.CreateBot(bot)
|
||||
createdBot, resp, err := th.Client.CreateBot(context.Background(), bot)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
@@ -1202,12 +1203,12 @@ func TestAssignBot(t *testing.T) {
|
||||
th.LoginBasic2()
|
||||
|
||||
// Without permission to read others bots it doesn't exist
|
||||
_, _, err = th.Client.AssignBot(createdBot.UserId, th.BasicUser2.Id)
|
||||
_, _, err = th.Client.AssignBot(context.Background(), createdBot.UserId, th.BasicUser2.Id)
|
||||
CheckErrorID(t, err, "store.sql_bot.get.missing.app_error")
|
||||
|
||||
// With permissions to read we don't have permissions to modify
|
||||
th.AddPermissionToRole(model.PermissionReadOthersBots.Id, model.SystemUserRoleId)
|
||||
_, _, err = th.Client.AssignBot(createdBot.UserId, th.BasicUser2.Id)
|
||||
_, _, err = th.Client.AssignBot(context.Background(), createdBot.UserId, th.BasicUser2.Id)
|
||||
CheckErrorID(t, err, "api.context.permissions.app_error")
|
||||
|
||||
th.LoginBasic()
|
||||
@@ -1226,7 +1227,7 @@ func TestAssignBot(t *testing.T) {
|
||||
Username: GenerateTestUsername(),
|
||||
Description: "bot",
|
||||
}
|
||||
bot, resp, err := th.Client.CreateBot(bot)
|
||||
bot, resp, err := th.Client.CreateBot(context.Background(), bot)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(bot.UserId)
|
||||
@@ -1239,11 +1240,11 @@ func TestAssignBot(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionManageOthersBots.Id, model.SystemUserRoleId)
|
||||
th.LoginBasic2()
|
||||
|
||||
_, resp, err = th.Client.AssignBot(bot.UserId, th.BasicUser2.Id)
|
||||
_, resp, err = th.Client.AssignBot(context.Background(), bot.UserId, th.BasicUser2.Id)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
|
||||
after, resp, err := th.SystemAdminClient.GetBot(bot.UserId, "")
|
||||
after, resp, err := th.SystemAdminClient.GetBot(context.Background(), bot.UserId, "")
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
require.Equal(t, th.BasicUser2.Id, after.OwnerId)
|
||||
@@ -1262,12 +1263,12 @@ func TestAssignBot(t *testing.T) {
|
||||
Username: GenerateTestUsername(),
|
||||
Description: "bot",
|
||||
}
|
||||
bot, resp, err := th.Client.CreateBot(bot)
|
||||
bot, resp, err := th.Client.CreateBot(context.Background(), bot)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(bot.UserId)
|
||||
|
||||
bot2, resp, err := th.Client.CreateBot(&model.Bot{
|
||||
bot2, resp, err := th.Client.CreateBot(context.Background(), &model.Bot{
|
||||
Username: GenerateTestUsername(),
|
||||
DisplayName: "a bot",
|
||||
Description: "bot",
|
||||
@@ -1276,7 +1277,7 @@ func TestAssignBot(t *testing.T) {
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(bot2.UserId)
|
||||
|
||||
_, _, err = th.Client.AssignBot(bot.UserId, bot2.UserId)
|
||||
_, _, err = th.Client.AssignBot(context.Background(), bot.UserId, bot2.UserId)
|
||||
CheckErrorID(t, err, "api.context.permissions.app_error")
|
||||
|
||||
})
|
||||
@@ -1296,16 +1297,16 @@ func TestConvertBotToUser(t *testing.T) {
|
||||
Username: GenerateTestUsername(),
|
||||
Description: "bot",
|
||||
}
|
||||
bot, resp, err := th.Client.CreateBot(bot)
|
||||
bot, resp, err := th.Client.CreateBot(context.Background(), bot)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(bot.UserId)
|
||||
|
||||
_, resp, err = th.Client.ConvertBotToUser(bot.UserId, &model.UserPatch{}, false)
|
||||
_, resp, err = th.Client.ConvertBotToUser(context.Background(), bot.UserId, &model.UserPatch{}, false)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
user, resp, err := th.Client.ConvertBotToUser(bot.UserId, &model.UserPatch{Password: model.NewString("password")}, false)
|
||||
user, resp, err := th.Client.ConvertBotToUser(context.Background(), bot.UserId, &model.UserPatch{Password: model.NewString("password")}, false)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
require.Nil(t, user)
|
||||
@@ -1315,21 +1316,21 @@ func TestConvertBotToUser(t *testing.T) {
|
||||
Username: GenerateTestUsername(),
|
||||
Description: "bot",
|
||||
}
|
||||
bot, resp, err := th.SystemAdminClient.CreateBot(bot)
|
||||
bot, resp, err := th.SystemAdminClient.CreateBot(context.Background(), bot)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
|
||||
user, resp, err := client.ConvertBotToUser(bot.UserId, &model.UserPatch{}, false)
|
||||
user, resp, err := client.ConvertBotToUser(context.Background(), bot.UserId, &model.UserPatch{}, false)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
require.Nil(t, user)
|
||||
|
||||
user, _, err = client.ConvertBotToUser(bot.UserId, &model.UserPatch{Password: model.NewString("password")}, false)
|
||||
user, _, err = client.ConvertBotToUser(context.Background(), bot.UserId, &model.UserPatch{Password: model.NewString("password")}, false)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, user)
|
||||
require.Equal(t, bot.UserId, user.Id)
|
||||
|
||||
_, resp, err = client.GetBot(bot.UserId, "")
|
||||
_, resp, err = client.GetBot(context.Background(), bot.UserId, "")
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
@@ -1337,17 +1338,17 @@ func TestConvertBotToUser(t *testing.T) {
|
||||
Username: GenerateTestUsername(),
|
||||
Description: "systemAdminBot",
|
||||
}
|
||||
bot, resp, err = th.SystemAdminClient.CreateBot(bot)
|
||||
bot, resp, err = th.SystemAdminClient.CreateBot(context.Background(), bot)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
|
||||
user, _, err = client.ConvertBotToUser(bot.UserId, &model.UserPatch{Password: model.NewString("password")}, true)
|
||||
user, _, err = client.ConvertBotToUser(context.Background(), bot.UserId, &model.UserPatch{Password: model.NewString("password")}, true)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, user)
|
||||
require.Equal(t, bot.UserId, user.Id)
|
||||
require.Contains(t, user.GetRoles(), model.SystemAdminRoleId)
|
||||
|
||||
_, resp, err = client.GetBot(bot.UserId, "")
|
||||
_, resp, err = client.GetBot(context.Background(), bot.UserId, "")
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
})
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
@@ -17,16 +18,16 @@ func TestGetBrandImage(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
client := th.Client
|
||||
|
||||
_, resp, err := client.GetBrandImage()
|
||||
_, resp, err := client.GetBrandImage(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
client.Logout()
|
||||
_, resp, err = client.GetBrandImage()
|
||||
client.Logout(context.Background())
|
||||
_, resp, err = client.GetBrandImage(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
_, resp, err = th.SystemAdminClient.GetBrandImage()
|
||||
_, resp, err = th.SystemAdminClient.GetBrandImage(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
}
|
||||
@@ -39,14 +40,14 @@ func TestUploadBrandImage(t *testing.T) {
|
||||
data, err := testutils.ReadTestFile("test.png")
|
||||
require.NoError(t, err)
|
||||
|
||||
resp, err := client.UploadBrandImage(data)
|
||||
resp, err := client.UploadBrandImage(context.Background(), data)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
// status code returns either forbidden or unauthorized
|
||||
// note: forbidden is set as default at Client4.SetProfileImage when request is terminated early by server
|
||||
client.Logout()
|
||||
resp, err = client.UploadBrandImage(data)
|
||||
client.Logout(context.Background())
|
||||
resp, err = client.UploadBrandImage(context.Background(), data)
|
||||
require.Error(t, err)
|
||||
if resp.StatusCode == http.StatusForbidden {
|
||||
CheckForbiddenStatus(t, resp)
|
||||
@@ -56,7 +57,7 @@ func TestUploadBrandImage(t *testing.T) {
|
||||
require.Fail(t, "Should have failed either forbidden or unauthorized")
|
||||
}
|
||||
|
||||
resp, err = th.SystemAdminClient.UploadBrandImage(data)
|
||||
resp, err = th.SystemAdminClient.UploadBrandImage(context.Background(), data)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
}
|
||||
@@ -68,25 +69,25 @@ func TestDeleteBrandImage(t *testing.T) {
|
||||
data, err := testutils.ReadTestFile("test.png")
|
||||
require.NoError(t, err)
|
||||
|
||||
resp, err := th.SystemAdminClient.UploadBrandImage(data)
|
||||
resp, err := th.SystemAdminClient.UploadBrandImage(context.Background(), data)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
|
||||
resp, err = th.Client.DeleteBrandImage()
|
||||
resp, err = th.Client.DeleteBrandImage(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
th.Client.Logout()
|
||||
th.Client.Logout(context.Background())
|
||||
|
||||
resp, err = th.Client.DeleteBrandImage()
|
||||
resp, err = th.Client.DeleteBrandImage(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
|
||||
resp, err = th.SystemAdminClient.DeleteBrandImage()
|
||||
resp, err = th.SystemAdminClient.DeleteBrandImage(context.Background())
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
|
||||
resp, err = th.SystemAdminClient.DeleteBrandImage()
|
||||
resp, err = th.SystemAdminClient.DeleteBrandImage(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
@@ -22,7 +23,7 @@ func TestCreateCategoryForTeamForUser(t *testing.T) {
|
||||
t.Run("should silently prevent the user from creating a category with an invalid channel ID", func(t *testing.T) {
|
||||
user, client := setupUserForSubtest(t, th)
|
||||
|
||||
categories, _, err := client.GetSidebarCategoriesForTeamForUser(user.Id, th.BasicTeam.Id, "")
|
||||
categories, _, err := client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, categories.Categories, 3)
|
||||
require.Len(t, categories.Order, 3)
|
||||
@@ -37,7 +38,7 @@ func TestCreateCategoryForTeamForUser(t *testing.T) {
|
||||
Channels: []string{th.BasicChannel.Id, "notachannel", th.BasicChannel2.Id},
|
||||
}
|
||||
|
||||
received, _, err := client.CreateSidebarCategoryForTeamForUser(user.Id, th.BasicTeam.Id, category)
|
||||
received, _, err := client.CreateSidebarCategoryForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, category)
|
||||
require.NoError(t, err)
|
||||
assert.NotContains(t, received.Channels, "notachannel")
|
||||
assert.Equal(t, []string{th.BasicChannel.Id, th.BasicChannel2.Id}, received.Channels)
|
||||
@@ -46,13 +47,13 @@ func TestCreateCategoryForTeamForUser(t *testing.T) {
|
||||
t.Run("should silently prevent the user from creating a category with a channel that they're not a member of", func(t *testing.T) {
|
||||
user, client := setupUserForSubtest(t, th)
|
||||
|
||||
categories, _, err := client.GetSidebarCategoriesForTeamForUser(user.Id, th.BasicTeam.Id, "")
|
||||
categories, _, err := client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, categories.Categories, 3)
|
||||
require.Len(t, categories.Order, 3)
|
||||
|
||||
// Have another user create a channel that user isn't a part of
|
||||
channel, _, err := th.SystemAdminClient.CreateChannel(&model.Channel{
|
||||
channel, _, err := th.SystemAdminClient.CreateChannel(context.Background(), &model.Channel{
|
||||
TeamId: th.BasicTeam.Id,
|
||||
Type: model.ChannelTypeOpen,
|
||||
Name: "testchannel",
|
||||
@@ -69,7 +70,7 @@ func TestCreateCategoryForTeamForUser(t *testing.T) {
|
||||
Channels: []string{th.BasicChannel.Id, channel.Id},
|
||||
}
|
||||
|
||||
received, _, err := client.CreateSidebarCategoryForTeamForUser(user.Id, th.BasicTeam.Id, category)
|
||||
received, _, err := client.CreateSidebarCategoryForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, category)
|
||||
require.NoError(t, err)
|
||||
assert.NotContains(t, received.Channels, channel.Id)
|
||||
assert.Equal(t, []string{th.BasicChannel.Id}, received.Channels)
|
||||
@@ -78,7 +79,7 @@ func TestCreateCategoryForTeamForUser(t *testing.T) {
|
||||
t.Run("should return expected sort order value", func(t *testing.T) {
|
||||
user, client := setupUserForSubtest(t, th)
|
||||
|
||||
customCategory, _, err := client.CreateSidebarCategoryForTeamForUser(user.Id, th.BasicTeam.Id, &model.SidebarCategoryWithChannels{
|
||||
customCategory, _, err := client.CreateSidebarCategoryForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, &model.SidebarCategoryWithChannels{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
UserId: user.Id,
|
||||
TeamId: th.BasicTeam.Id,
|
||||
@@ -96,7 +97,7 @@ func TestCreateCategoryForTeamForUser(t *testing.T) {
|
||||
user, client := setupUserForSubtest(t, th)
|
||||
payload := []byte(`null`)
|
||||
route := fmt.Sprintf("/users/%s/teams/%s/channels/categories", user.Id, th.BasicTeam.Id)
|
||||
r, err := client.DoAPIPostBytes(route, payload)
|
||||
r, err := client.DoAPIPostBytes(context.Background(), route, payload)
|
||||
require.Error(t, err)
|
||||
closeBody(r)
|
||||
})
|
||||
@@ -118,7 +119,7 @@ func TestCreateCategoryForTeamForUser(t *testing.T) {
|
||||
Channels: []string{th.BasicChannel.Id, "notachannel", th.BasicChannel2.Id},
|
||||
}
|
||||
|
||||
received, _, err := th.Client.CreateSidebarCategoryForTeamForUser(th.BasicUser.Id, th.BasicTeam.Id, category)
|
||||
received, _, err := th.Client.CreateSidebarCategoryForTeamForUser(context.Background(), th.BasicUser.Id, th.BasicTeam.Id, category)
|
||||
require.NoError(t, err)
|
||||
|
||||
testCategories := []*model.SidebarCategoryWithChannels{
|
||||
@@ -134,7 +135,7 @@ func TestCreateCategoryForTeamForUser(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
testCategories, _, err = th.Client.UpdateSidebarCategoriesForTeamForUser(th.BasicUser.Id, th.BasicTeam.Id, testCategories)
|
||||
testCategories, _, err = th.Client.UpdateSidebarCategoriesForTeamForUser(context.Background(), th.BasicUser.Id, th.BasicTeam.Id, testCategories)
|
||||
require.NoError(t, err)
|
||||
|
||||
b, err := json.Marshal(testCategories)
|
||||
@@ -171,7 +172,7 @@ func TestUpdateCategoryForTeamForUser(t *testing.T) {
|
||||
t.Run("should update the channel order of the Channels category", func(t *testing.T) {
|
||||
user, client := setupUserForSubtest(t, th)
|
||||
|
||||
categories, _, err := client.GetSidebarCategoriesForTeamForUser(user.Id, th.BasicTeam.Id, "")
|
||||
categories, _, err := client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, categories.Categories, 3)
|
||||
require.Len(t, categories.Order, 3)
|
||||
@@ -186,13 +187,13 @@ func TestUpdateCategoryForTeamForUser(t *testing.T) {
|
||||
Channels: []string{channelsCategory.Channels[1], channelsCategory.Channels[0], channelsCategory.Channels[4], channelsCategory.Channels[3], channelsCategory.Channels[2]},
|
||||
}
|
||||
|
||||
received, _, err := client.UpdateSidebarCategoryForTeamForUser(user.Id, th.BasicTeam.Id, channelsCategory.Id, updatedCategory)
|
||||
received, _, err := client.UpdateSidebarCategoryForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, channelsCategory.Id, updatedCategory)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, channelsCategory.Id, received.Id)
|
||||
assert.Equal(t, updatedCategory.Channels, received.Channels)
|
||||
|
||||
// And when requesting the category later
|
||||
received, _, err = client.GetSidebarCategoryForTeamForUser(user.Id, th.BasicTeam.Id, channelsCategory.Id, "")
|
||||
received, _, err = client.GetSidebarCategoryForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, channelsCategory.Id, "")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, channelsCategory.Id, received.Id)
|
||||
assert.Equal(t, updatedCategory.Channels, received.Channels)
|
||||
@@ -201,7 +202,7 @@ func TestUpdateCategoryForTeamForUser(t *testing.T) {
|
||||
t.Run("should update the sort order of the DM category", func(t *testing.T) {
|
||||
user, client := setupUserForSubtest(t, th)
|
||||
|
||||
categories, _, err := client.GetSidebarCategoriesForTeamForUser(user.Id, th.BasicTeam.Id, "")
|
||||
categories, _, err := client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, categories.Categories, 3)
|
||||
require.Len(t, categories.Order, 3)
|
||||
@@ -217,13 +218,13 @@ func TestUpdateCategoryForTeamForUser(t *testing.T) {
|
||||
}
|
||||
updatedCategory.Sorting = model.SidebarCategorySortAlphabetical
|
||||
|
||||
received, _, err := client.UpdateSidebarCategoryForTeamForUser(user.Id, th.BasicTeam.Id, dmsCategory.Id, updatedCategory)
|
||||
received, _, err := client.UpdateSidebarCategoryForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, dmsCategory.Id, updatedCategory)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, dmsCategory.Id, received.Id)
|
||||
assert.Equal(t, model.SidebarCategorySortAlphabetical, received.Sorting)
|
||||
|
||||
// And when requesting the category later
|
||||
received, _, err = client.GetSidebarCategoryForTeamForUser(user.Id, th.BasicTeam.Id, dmsCategory.Id, "")
|
||||
received, _, err = client.GetSidebarCategoryForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, dmsCategory.Id, "")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, dmsCategory.Id, received.Id)
|
||||
assert.Equal(t, model.SidebarCategorySortAlphabetical, received.Sorting)
|
||||
@@ -232,7 +233,7 @@ func TestUpdateCategoryForTeamForUser(t *testing.T) {
|
||||
t.Run("should update the display name of a custom category", func(t *testing.T) {
|
||||
user, client := setupUserForSubtest(t, th)
|
||||
|
||||
customCategory, _, err := client.CreateSidebarCategoryForTeamForUser(user.Id, th.BasicTeam.Id, &model.SidebarCategoryWithChannels{
|
||||
customCategory, _, err := client.CreateSidebarCategoryForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, &model.SidebarCategoryWithChannels{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
UserId: user.Id,
|
||||
TeamId: th.BasicTeam.Id,
|
||||
@@ -249,13 +250,13 @@ func TestUpdateCategoryForTeamForUser(t *testing.T) {
|
||||
}
|
||||
updatedCategory.DisplayName = "abcCustom"
|
||||
|
||||
received, _, err := client.UpdateSidebarCategoryForTeamForUser(user.Id, th.BasicTeam.Id, customCategory.Id, updatedCategory)
|
||||
received, _, err := client.UpdateSidebarCategoryForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, customCategory.Id, updatedCategory)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, customCategory.Id, received.Id)
|
||||
assert.Equal(t, updatedCategory.DisplayName, received.DisplayName)
|
||||
|
||||
// And when requesting the category later
|
||||
received, _, err = client.GetSidebarCategoryForTeamForUser(user.Id, th.BasicTeam.Id, customCategory.Id, "")
|
||||
received, _, err = client.GetSidebarCategoryForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, customCategory.Id, "")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, customCategory.Id, received.Id)
|
||||
assert.Equal(t, updatedCategory.DisplayName, received.DisplayName)
|
||||
@@ -264,7 +265,7 @@ func TestUpdateCategoryForTeamForUser(t *testing.T) {
|
||||
t.Run("should update the channel order of the category even if it contains archived channels", func(t *testing.T) {
|
||||
user, client := setupUserForSubtest(t, th)
|
||||
|
||||
categories, _, err := client.GetSidebarCategoriesForTeamForUser(user.Id, th.BasicTeam.Id, "")
|
||||
categories, _, err := client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, categories.Categories, 3)
|
||||
require.Len(t, categories.Order, 3)
|
||||
@@ -274,7 +275,7 @@ func TestUpdateCategoryForTeamForUser(t *testing.T) {
|
||||
require.Len(t, channelsCategory.Channels, 5) // Town Square, Off Topic, and the 3 channels created by InitBasic
|
||||
|
||||
// Delete one of the channels
|
||||
_, err = client.DeleteChannel(th.BasicChannel.Id)
|
||||
_, err = client.DeleteChannel(context.Background(), th.BasicChannel.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Should still be able to reorder the channels
|
||||
@@ -283,7 +284,7 @@ func TestUpdateCategoryForTeamForUser(t *testing.T) {
|
||||
Channels: []string{channelsCategory.Channels[1], channelsCategory.Channels[0], channelsCategory.Channels[4], channelsCategory.Channels[3], channelsCategory.Channels[2]},
|
||||
}
|
||||
|
||||
received, _, err := client.UpdateSidebarCategoryForTeamForUser(user.Id, th.BasicTeam.Id, channelsCategory.Id, updatedCategory)
|
||||
received, _, err := client.UpdateSidebarCategoryForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, channelsCategory.Id, updatedCategory)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, channelsCategory.Id, received.Id)
|
||||
assert.Equal(t, updatedCategory.Channels, received.Channels)
|
||||
@@ -292,7 +293,7 @@ func TestUpdateCategoryForTeamForUser(t *testing.T) {
|
||||
t.Run("should silently prevent the user from adding an invalid channel ID", func(t *testing.T) {
|
||||
user, client := setupUserForSubtest(t, th)
|
||||
|
||||
categories, _, err := client.GetSidebarCategoriesForTeamForUser(user.Id, th.BasicTeam.Id, "")
|
||||
categories, _, err := client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, categories.Categories, 3)
|
||||
require.Len(t, categories.Order, 3)
|
||||
@@ -305,7 +306,7 @@ func TestUpdateCategoryForTeamForUser(t *testing.T) {
|
||||
Channels: append(channelsCategory.Channels, "notachannel"),
|
||||
}
|
||||
|
||||
received, _, err := client.UpdateSidebarCategoryForTeamForUser(user.Id, th.BasicTeam.Id, channelsCategory.Id, updatedCategory)
|
||||
received, _, err := client.UpdateSidebarCategoryForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, channelsCategory.Id, updatedCategory)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, channelsCategory.Id, received.Id)
|
||||
assert.NotContains(t, received.Channels, "notachannel")
|
||||
@@ -315,7 +316,7 @@ func TestUpdateCategoryForTeamForUser(t *testing.T) {
|
||||
t.Run("should silently prevent the user from adding a channel that they're not a member of", func(t *testing.T) {
|
||||
user, client := setupUserForSubtest(t, th)
|
||||
|
||||
categories, _, err := client.GetSidebarCategoriesForTeamForUser(user.Id, th.BasicTeam.Id, "")
|
||||
categories, _, err := client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, categories.Categories, 3)
|
||||
require.Len(t, categories.Order, 3)
|
||||
@@ -324,7 +325,7 @@ func TestUpdateCategoryForTeamForUser(t *testing.T) {
|
||||
require.Equal(t, model.SidebarCategoryChannels, channelsCategory.Type)
|
||||
|
||||
// Have another user create a channel that user isn't a part of
|
||||
channel, _, err := th.SystemAdminClient.CreateChannel(&model.Channel{
|
||||
channel, _, err := th.SystemAdminClient.CreateChannel(context.Background(), &model.Channel{
|
||||
TeamId: th.BasicTeam.Id,
|
||||
Type: model.ChannelTypeOpen,
|
||||
Name: "testchannel",
|
||||
@@ -337,7 +338,7 @@ func TestUpdateCategoryForTeamForUser(t *testing.T) {
|
||||
Channels: append(channelsCategory.Channels, channel.Id),
|
||||
}
|
||||
|
||||
received, _, err := client.UpdateSidebarCategoryForTeamForUser(user.Id, th.BasicTeam.Id, channelsCategory.Id, updatedCategory)
|
||||
received, _, err := client.UpdateSidebarCategoryForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, channelsCategory.Id, updatedCategory)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, channelsCategory.Id, received.Id)
|
||||
assert.NotContains(t, received.Channels, channel.Id)
|
||||
@@ -347,7 +348,7 @@ func TestUpdateCategoryForTeamForUser(t *testing.T) {
|
||||
t.Run("muting a category should mute all of its channels", func(t *testing.T) {
|
||||
user, client := setupUserForSubtest(t, th)
|
||||
|
||||
categories, _, err := client.GetSidebarCategoriesForTeamForUser(user.Id, th.BasicTeam.Id, "")
|
||||
categories, _, err := client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, categories.Categories, 3)
|
||||
require.Len(t, categories.Order, 3)
|
||||
@@ -368,19 +369,19 @@ func TestUpdateCategoryForTeamForUser(t *testing.T) {
|
||||
Channels: channelsCategory.Channels,
|
||||
}
|
||||
|
||||
received, _, err := client.UpdateSidebarCategoryForTeamForUser(user.Id, th.BasicTeam.Id, channelsCategory.Id, updatedCategory)
|
||||
received, _, err := client.UpdateSidebarCategoryForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, channelsCategory.Id, updatedCategory)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, channelsCategory.Id, received.Id)
|
||||
assert.True(t, received.Muted)
|
||||
|
||||
// Check that the muted category was saved in the database
|
||||
received, _, err = client.GetSidebarCategoryForTeamForUser(user.Id, th.BasicTeam.Id, channelsCategory.Id, "")
|
||||
received, _, err = client.GetSidebarCategoryForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, channelsCategory.Id, "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, channelsCategory.Id, received.Id)
|
||||
assert.True(t, received.Muted)
|
||||
|
||||
// Confirm that the channels in the category were muted
|
||||
member, _, err := client.GetChannelMember(channelsCategory.Channels[0], user.Id, "")
|
||||
member, _, err := client.GetChannelMember(context.Background(), channelsCategory.Channels[0], user.Id, "")
|
||||
require.NoError(t, err)
|
||||
assert.True(t, member.IsChannelMuted())
|
||||
})
|
||||
@@ -388,7 +389,7 @@ func TestUpdateCategoryForTeamForUser(t *testing.T) {
|
||||
t.Run("should not be able to mute DM category", func(t *testing.T) {
|
||||
user, client := setupUserForSubtest(t, th)
|
||||
|
||||
categories, _, err := client.GetSidebarCategoriesForTeamForUser(user.Id, th.BasicTeam.Id, "")
|
||||
categories, _, err := client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, categories.Categories, 3)
|
||||
require.Len(t, categories.Order, 3)
|
||||
@@ -398,7 +399,7 @@ func TestUpdateCategoryForTeamForUser(t *testing.T) {
|
||||
require.Len(t, dmsCategory.Channels, 0)
|
||||
|
||||
// Ensure a DM channel exists
|
||||
dmChannel, _, err := client.CreateDirectChannel(user.Id, th.BasicUser.Id)
|
||||
dmChannel, _, err := client.CreateDirectChannel(context.Background(), user.Id, th.BasicUser.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Attempt to mute the category
|
||||
@@ -413,19 +414,19 @@ func TestUpdateCategoryForTeamForUser(t *testing.T) {
|
||||
Channels: []string{dmChannel.Id},
|
||||
}
|
||||
|
||||
received, _, err := client.UpdateSidebarCategoryForTeamForUser(user.Id, th.BasicTeam.Id, dmsCategory.Id, updatedCategory)
|
||||
received, _, err := client.UpdateSidebarCategoryForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, dmsCategory.Id, updatedCategory)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, dmsCategory.Id, received.Id)
|
||||
assert.False(t, received.Muted)
|
||||
|
||||
// Check that the muted category was not saved in the database
|
||||
received, _, err = client.GetSidebarCategoryForTeamForUser(user.Id, th.BasicTeam.Id, dmsCategory.Id, "")
|
||||
received, _, err = client.GetSidebarCategoryForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, dmsCategory.Id, "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, dmsCategory.Id, received.Id)
|
||||
assert.False(t, received.Muted)
|
||||
|
||||
// Confirm that the channels in the category were not muted
|
||||
member, _, err := client.GetChannelMember(dmChannel.Id, user.Id, "")
|
||||
member, _, err := client.GetChannelMember(context.Background(), dmChannel.Id, user.Id, "")
|
||||
require.NoError(t, err)
|
||||
assert.False(t, member.IsChannelMuted())
|
||||
})
|
||||
@@ -434,7 +435,7 @@ func TestUpdateCategoryForTeamForUser(t *testing.T) {
|
||||
require.NotPanics(t, func() {
|
||||
user, client := setupUserForSubtest(t, th)
|
||||
|
||||
categories, _, err := client.GetSidebarCategoriesForTeamForUser(user.Id, th.BasicTeam.Id, "")
|
||||
categories, _, err := client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, categories.Categories, 3)
|
||||
require.Len(t, categories.Order, 3)
|
||||
@@ -443,7 +444,7 @@ func TestUpdateCategoryForTeamForUser(t *testing.T) {
|
||||
|
||||
payload := []byte(`null`)
|
||||
route := fmt.Sprintf("/users/%s/teams/%s/channels/categories/%s", user.Id, th.BasicTeam.Id, dmsCategory.Id)
|
||||
r, err := client.DoAPIPutBytes(route, payload)
|
||||
r, err := client.DoAPIPutBytes(context.Background(), route, payload)
|
||||
require.Error(t, err)
|
||||
closeBody(r)
|
||||
})
|
||||
@@ -457,7 +458,7 @@ func TestUpdateCategoriesForTeamForUser(t *testing.T) {
|
||||
t.Run("should silently prevent the user from adding an invalid channel ID", func(t *testing.T) {
|
||||
user, client := setupUserForSubtest(t, th)
|
||||
|
||||
categories, _, err := client.GetSidebarCategoriesForTeamForUser(user.Id, th.BasicTeam.Id, "")
|
||||
categories, _, err := client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, categories.Categories, 3)
|
||||
require.Len(t, categories.Order, 3)
|
||||
@@ -470,7 +471,7 @@ func TestUpdateCategoriesForTeamForUser(t *testing.T) {
|
||||
Channels: append(channelsCategory.Channels, "notachannel"),
|
||||
}
|
||||
|
||||
received, _, err := client.UpdateSidebarCategoriesForTeamForUser(user.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{updatedCategory})
|
||||
received, _, err := client.UpdateSidebarCategoriesForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{updatedCategory})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, channelsCategory.Id, received[0].Id)
|
||||
assert.NotContains(t, received[0].Channels, "notachannel")
|
||||
@@ -480,7 +481,7 @@ func TestUpdateCategoriesForTeamForUser(t *testing.T) {
|
||||
t.Run("should silently prevent the user from adding a channel that they're not a member of", func(t *testing.T) {
|
||||
user, client := setupUserForSubtest(t, th)
|
||||
|
||||
categories, _, err := client.GetSidebarCategoriesForTeamForUser(user.Id, th.BasicTeam.Id, "")
|
||||
categories, _, err := client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, categories.Categories, 3)
|
||||
require.Len(t, categories.Order, 3)
|
||||
@@ -489,7 +490,7 @@ func TestUpdateCategoriesForTeamForUser(t *testing.T) {
|
||||
require.Equal(t, model.SidebarCategoryChannels, channelsCategory.Type)
|
||||
|
||||
// Have another user create a channel that user isn't a part of
|
||||
channel, _, err := th.SystemAdminClient.CreateChannel(&model.Channel{
|
||||
channel, _, err := th.SystemAdminClient.CreateChannel(context.Background(), &model.Channel{
|
||||
TeamId: th.BasicTeam.Id,
|
||||
Type: model.ChannelTypeOpen,
|
||||
Name: "testchannel",
|
||||
@@ -502,7 +503,7 @@ func TestUpdateCategoriesForTeamForUser(t *testing.T) {
|
||||
Channels: append(channelsCategory.Channels, channel.Id),
|
||||
}
|
||||
|
||||
received, _, err := client.UpdateSidebarCategoriesForTeamForUser(user.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{updatedCategory})
|
||||
received, _, err := client.UpdateSidebarCategoriesForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{updatedCategory})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, channelsCategory.Id, received[0].Id)
|
||||
assert.NotContains(t, received[0].Channels, channel.Id)
|
||||
@@ -512,7 +513,7 @@ func TestUpdateCategoriesForTeamForUser(t *testing.T) {
|
||||
t.Run("should update order", func(t *testing.T) {
|
||||
user, client := setupUserForSubtest(t, th)
|
||||
|
||||
categories, _, err := client.GetSidebarCategoriesForTeamForUser(user.Id, th.BasicTeam.Id, "")
|
||||
categories, _, err := client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, categories.Categories, 3)
|
||||
require.Len(t, categories.Order, 3)
|
||||
@@ -520,10 +521,10 @@ func TestUpdateCategoriesForTeamForUser(t *testing.T) {
|
||||
channelsCategory := categories.Categories[1]
|
||||
require.Equal(t, model.SidebarCategoryChannels, channelsCategory.Type)
|
||||
|
||||
_, _, err = client.UpdateSidebarCategoryOrderForTeamForUser(user.Id, th.BasicTeam.Id, []string{categories.Order[1], categories.Order[0], categories.Order[2]})
|
||||
_, _, err = client.UpdateSidebarCategoryOrderForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, []string{categories.Order[1], categories.Order[0], categories.Order[2]})
|
||||
require.NoError(t, err)
|
||||
|
||||
categories, _, err = client.GetSidebarCategoriesForTeamForUser(user.Id, th.BasicTeam.Id, "")
|
||||
categories, _, err = client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, categories.Categories, 3)
|
||||
require.Len(t, categories.Order, 3)
|
||||
@@ -532,16 +533,16 @@ func TestUpdateCategoriesForTeamForUser(t *testing.T) {
|
||||
require.Equal(t, model.SidebarCategoryChannels, channelsCategory.Type)
|
||||
|
||||
// validate order
|
||||
newOrder, _, err := client.GetSidebarCategoryOrderForTeamForUser(user.Id, th.BasicTeam.Id, "")
|
||||
newOrder, _, err := client.GetSidebarCategoryOrderForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, newOrder, categories.Order)
|
||||
|
||||
// try to update with missing category
|
||||
_, _, err = client.UpdateSidebarCategoryOrderForTeamForUser(user.Id, th.BasicTeam.Id, []string{categories.Order[1], categories.Order[0]})
|
||||
_, _, err = client.UpdateSidebarCategoryOrderForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, []string{categories.Order[1], categories.Order[0]})
|
||||
require.Error(t, err)
|
||||
|
||||
// try to update with invalid category
|
||||
_, _, err = client.UpdateSidebarCategoryOrderForTeamForUser(user.Id, th.BasicTeam.Id, []string{categories.Order[1], categories.Order[0], "asd"})
|
||||
_, _, err = client.UpdateSidebarCategoryOrderForTeamForUser(context.Background(), user.Id, th.BasicTeam.Id, []string{categories.Order[1], categories.Order[0], "asd"})
|
||||
require.Error(t, err)
|
||||
})
|
||||
}
|
||||
@@ -561,7 +562,7 @@ func setupUserForSubtest(t *testing.T, th *TestHelper) (*model.User, *model.Clie
|
||||
th.AddUserToChannel(user, th.BasicPrivateChannel)
|
||||
|
||||
client := th.CreateClient()
|
||||
user, _, err := client.Login(user.Email, password)
|
||||
user, _, err := client.Login(context.Background(), user.Email, password)
|
||||
require.NoError(t, err)
|
||||
|
||||
return user, client
|
||||
|
||||
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"testing"
|
||||
@@ -31,9 +32,9 @@ func Test_getCloudLimits(t *testing.T) {
|
||||
|
||||
th.App.Srv().RemoveLicense()
|
||||
|
||||
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
|
||||
th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password)
|
||||
|
||||
limits, r, err := th.Client.GetProductLimits()
|
||||
limits, r, err := th.Client.GetProductLimits(context.Background())
|
||||
require.Error(t, err)
|
||||
require.Nil(t, limits)
|
||||
require.Equal(t, http.StatusForbidden, r.StatusCode, "Expected 403 forbidden")
|
||||
@@ -54,9 +55,9 @@ func Test_getCloudLimits(t *testing.T) {
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense())
|
||||
|
||||
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
|
||||
th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password)
|
||||
|
||||
limits, r, err := th.Client.GetProductLimits()
|
||||
limits, r, err := th.Client.GetProductLimits(context.Background())
|
||||
require.Error(t, err)
|
||||
require.Nil(t, limits)
|
||||
require.Equal(t, http.StatusForbidden, r.StatusCode, "Expected 403 forbidden")
|
||||
@@ -77,9 +78,9 @@ func Test_getCloudLimits(t *testing.T) {
|
||||
}()
|
||||
th.App.Srv().Cloud = cloud
|
||||
|
||||
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
|
||||
th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password)
|
||||
|
||||
limits, r, err := th.Client.GetProductLimits()
|
||||
limits, r, err := th.Client.GetProductLimits(context.Background())
|
||||
require.Error(t, err)
|
||||
require.Nil(t, limits)
|
||||
require.Equal(t, http.StatusInternalServerError, r.StatusCode, "Expected 500 Internal Server Error")
|
||||
@@ -89,9 +90,9 @@ func Test_getCloudLimits(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.Client.Logout()
|
||||
th.Client.Logout(context.Background())
|
||||
|
||||
limits, r, err := th.Client.GetProductLimits()
|
||||
limits, r, err := th.Client.GetProductLimits(context.Background())
|
||||
require.Error(t, err)
|
||||
require.Nil(t, limits)
|
||||
require.Equal(t, http.StatusUnauthorized, r.StatusCode, "Expected 401 Unauthorized")
|
||||
@@ -118,9 +119,9 @@ func Test_getCloudLimits(t *testing.T) {
|
||||
}()
|
||||
th.App.Srv().Cloud = cloud
|
||||
|
||||
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
|
||||
th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password)
|
||||
|
||||
limits, r, err := th.Client.GetProductLimits()
|
||||
limits, r, err := th.Client.GetProductLimits(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, r.StatusCode, "Expected 200 OK")
|
||||
require.Equal(t, mockLimits, limits)
|
||||
@@ -167,7 +168,7 @@ func Test_GetSubscription(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
|
||||
th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
|
||||
@@ -181,7 +182,7 @@ func Test_GetSubscription(t *testing.T) {
|
||||
}()
|
||||
th.App.Srv().Cloud = &cloud
|
||||
|
||||
subscriptionReturned, r, err := th.Client.GetSubscription()
|
||||
subscriptionReturned, r, err := th.Client.GetSubscription(context.Background())
|
||||
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, subscriptionReturned, userFacingSubscription)
|
||||
@@ -192,7 +193,7 @@ func Test_GetSubscription(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
|
||||
th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
|
||||
@@ -206,7 +207,7 @@ func Test_GetSubscription(t *testing.T) {
|
||||
}()
|
||||
th.App.Srv().Cloud = &cloud
|
||||
|
||||
subscriptionReturned, r, err := th.SystemAdminClient.GetSubscription()
|
||||
subscriptionReturned, r, err := th.SystemAdminClient.GetSubscription(context.Background())
|
||||
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, subscriptionReturned, subscription)
|
||||
@@ -233,7 +234,7 @@ func Test_requestTrial(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
|
||||
th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
|
||||
@@ -249,7 +250,7 @@ func Test_requestTrial(t *testing.T) {
|
||||
}()
|
||||
th.App.Srv().Cloud = &cloud
|
||||
|
||||
subscriptionChanged, r, err := th.Client.RequestCloudTrial(&newValidBusinessEmail)
|
||||
subscriptionChanged, r, err := th.Client.RequestCloudTrial(context.Background(), &newValidBusinessEmail)
|
||||
require.Error(t, err)
|
||||
require.Nil(t, subscriptionChanged)
|
||||
require.Equal(t, http.StatusForbidden, r.StatusCode, "403 Forbidden")
|
||||
@@ -259,7 +260,7 @@ func Test_requestTrial(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
|
||||
th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
|
||||
@@ -275,7 +276,7 @@ func Test_requestTrial(t *testing.T) {
|
||||
}()
|
||||
th.App.Srv().Cloud = &cloud
|
||||
|
||||
subscriptionChanged, r, err := th.SystemAdminClient.RequestCloudTrial(&newValidBusinessEmail)
|
||||
subscriptionChanged, r, err := th.SystemAdminClient.RequestCloudTrial(context.Background(), &newValidBusinessEmail)
|
||||
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, subscriptionChanged, subscription)
|
||||
@@ -289,7 +290,7 @@ func Test_requestTrial(t *testing.T) {
|
||||
// patch the customer with the additional contact updated with the valid business email
|
||||
newValidBusinessEmail.Email = *model.NewString("valid.email@mattermost.com")
|
||||
|
||||
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
|
||||
th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
|
||||
@@ -305,7 +306,7 @@ func Test_requestTrial(t *testing.T) {
|
||||
}()
|
||||
th.App.Srv().Cloud = &cloud
|
||||
|
||||
subscriptionChanged, r, err := th.SystemAdminClient.RequestCloudTrial(&newValidBusinessEmail)
|
||||
subscriptionChanged, r, err := th.SystemAdminClient.RequestCloudTrial(context.Background(), &newValidBusinessEmail)
|
||||
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, subscriptionChanged, subscription)
|
||||
@@ -316,11 +317,11 @@ func Test_requestTrial(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
|
||||
th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
|
||||
r, err := th.SystemAdminClient.DoAPIPutBytes("/cloud/request-trial", nil)
|
||||
r, err := th.SystemAdminClient.DoAPIPutBytes(context.Background(), "/cloud/request-trial", nil)
|
||||
require.Error(t, err)
|
||||
closeBody(r)
|
||||
require.Equal(t, http.StatusBadRequest, r.StatusCode, "Status Bad Request")
|
||||
@@ -333,7 +334,7 @@ func Test_validateBusinessEmail(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
|
||||
th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password)
|
||||
|
||||
validBusinessEmail := model.ValidateBusinessEmailRequest{Email: "invalid@slacker.com"}
|
||||
|
||||
@@ -349,7 +350,7 @@ func Test_validateBusinessEmail(t *testing.T) {
|
||||
}()
|
||||
th.App.Srv().Cloud = &cloud
|
||||
|
||||
res, err := th.SystemAdminClient.ValidateBusinessEmail(&validBusinessEmail)
|
||||
res, err := th.SystemAdminClient.ValidateBusinessEmail(context.Background(), &validBusinessEmail)
|
||||
require.Error(t, err)
|
||||
require.Equal(t, http.StatusForbidden, res.StatusCode, "403")
|
||||
})
|
||||
@@ -358,7 +359,7 @@ func Test_validateBusinessEmail(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
|
||||
th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password)
|
||||
|
||||
validBusinessEmail := model.ValidateBusinessEmailRequest{Email: "valid@mattermost.com"}
|
||||
|
||||
@@ -374,7 +375,7 @@ func Test_validateBusinessEmail(t *testing.T) {
|
||||
}()
|
||||
th.App.Srv().Cloud = &cloud
|
||||
|
||||
res, err := th.SystemAdminClient.ValidateBusinessEmail(&validBusinessEmail)
|
||||
res, err := th.SystemAdminClient.ValidateBusinessEmail(context.Background(), &validBusinessEmail)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, res.StatusCode, "200")
|
||||
})
|
||||
@@ -383,11 +384,11 @@ func Test_validateBusinessEmail(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
|
||||
th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
|
||||
r, err := th.SystemAdminClient.DoAPIPostBytes("/cloud/validate-business-email", nil)
|
||||
r, err := th.SystemAdminClient.DoAPIPostBytes(context.Background(), "/cloud/validate-business-email", nil)
|
||||
require.Error(t, err)
|
||||
closeBody(r)
|
||||
require.Equal(t, http.StatusBadRequest, r.StatusCode, "Status Bad Request")
|
||||
@@ -399,7 +400,7 @@ func Test_validateWorkspaceBusinessEmail(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
|
||||
th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
|
||||
@@ -422,7 +423,7 @@ func Test_validateWorkspaceBusinessEmail(t *testing.T) {
|
||||
}()
|
||||
th.App.Srv().Cloud = &cloud
|
||||
|
||||
_, err := th.SystemAdminClient.ValidateWorkspaceBusinessEmail()
|
||||
_, err := th.SystemAdminClient.ValidateWorkspaceBusinessEmail(context.Background())
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
@@ -430,7 +431,7 @@ func Test_validateWorkspaceBusinessEmail(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
|
||||
th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
|
||||
@@ -458,7 +459,7 @@ func Test_validateWorkspaceBusinessEmail(t *testing.T) {
|
||||
}()
|
||||
th.App.Srv().Cloud = &cloud
|
||||
|
||||
_, err := th.SystemAdminClient.ValidateWorkspaceBusinessEmail()
|
||||
_, err := th.SystemAdminClient.ValidateWorkspaceBusinessEmail(context.Background())
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
@@ -466,7 +467,7 @@ func Test_validateWorkspaceBusinessEmail(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
|
||||
th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
|
||||
@@ -489,7 +490,7 @@ func Test_validateWorkspaceBusinessEmail(t *testing.T) {
|
||||
}()
|
||||
th.App.Srv().Cloud = &cloud
|
||||
|
||||
r, err := th.SystemAdminClient.DoAPIPostBytes("/cloud/validate-workspace-business-email", nil)
|
||||
r, err := th.SystemAdminClient.DoAPIPostBytes(context.Background(), "/cloud/validate-workspace-business-email", nil)
|
||||
require.Error(t, err)
|
||||
closeBody(r)
|
||||
require.Equal(t, http.StatusBadRequest, r.StatusCode, "Status Bad Request")
|
||||
@@ -566,7 +567,7 @@ func TestGetCloudProducts(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.Client.Login(th.SystemAdminUser.Email, th.SystemAdminUser.Password)
|
||||
th.Client.Login(context.Background(), th.SystemAdminUser.Email, th.SystemAdminUser.Password)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
|
||||
@@ -578,7 +579,7 @@ func TestGetCloudProducts(t *testing.T) {
|
||||
}()
|
||||
th.App.Srv().Cloud = &cloud
|
||||
|
||||
returnedProducts, r, err := th.Client.GetCloudProducts()
|
||||
returnedProducts, r, err := th.Client.GetCloudProducts(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, r.StatusCode, "Status OK")
|
||||
require.Equal(t, returnedProducts, cloudProducts)
|
||||
@@ -588,7 +589,7 @@ func TestGetCloudProducts(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
|
||||
th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
|
||||
@@ -602,7 +603,7 @@ func TestGetCloudProducts(t *testing.T) {
|
||||
}()
|
||||
th.App.Srv().Cloud = &cloud
|
||||
|
||||
returnedProducts, r, err := th.Client.GetCloudProducts()
|
||||
returnedProducts, r, err := th.Client.GetCloudProducts(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, r.StatusCode, "Status OK")
|
||||
require.Equal(t, returnedProducts, sanitizedProducts)
|
||||
@@ -654,7 +655,7 @@ func Test_GetExpandStatsForSubscription(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
|
||||
th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password)
|
||||
|
||||
cloud := mocks.CloudInterface{}
|
||||
|
||||
@@ -666,7 +667,7 @@ func Test_GetExpandStatsForSubscription(t *testing.T) {
|
||||
}()
|
||||
th.App.Srv().Cloud = &cloud
|
||||
|
||||
checksMade, r, err := th.Client.GetSubscriptionStatus(licenseId)
|
||||
checksMade, r, err := th.Client.GetSubscriptionStatus(context.Background(), licenseId)
|
||||
require.Error(t, err)
|
||||
require.Nil(t, checksMade)
|
||||
require.Equal(t, http.StatusForbidden, r.StatusCode, "403 Forbidden")
|
||||
@@ -676,7 +677,7 @@ func Test_GetExpandStatsForSubscription(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.Client.Login(th.SystemAdminUser.Email, th.SystemAdminUser.Password)
|
||||
th.Client.Login(context.Background(), th.SystemAdminUser.Email, th.SystemAdminUser.Password)
|
||||
|
||||
cloud := mocks.CloudInterface{}
|
||||
|
||||
@@ -688,7 +689,7 @@ func Test_GetExpandStatsForSubscription(t *testing.T) {
|
||||
}()
|
||||
th.App.Srv().Cloud = &cloud
|
||||
|
||||
checks, r, err := th.Client.GetSubscriptionStatus("")
|
||||
checks, r, err := th.Client.GetSubscriptionStatus(context.Background(), "")
|
||||
require.Error(t, err)
|
||||
require.Nil(t, checks)
|
||||
require.Equal(t, http.StatusBadRequest, r.StatusCode, "400 Bad Request")
|
||||
@@ -740,7 +741,7 @@ func TestGetSelfHostedProducts(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.Client.Login(th.SystemAdminUser.Email, th.SystemAdminUser.Password)
|
||||
th.Client.Login(context.Background(), th.SystemAdminUser.Email, th.SystemAdminUser.Password)
|
||||
|
||||
cloud := mocks.CloudInterface{}
|
||||
cloud.Mock.On("GetSelfHostedProducts", mock.Anything, mock.Anything).Return(products, nil)
|
||||
@@ -750,7 +751,7 @@ func TestGetSelfHostedProducts(t *testing.T) {
|
||||
}()
|
||||
th.App.Srv().Cloud = &cloud
|
||||
|
||||
returnedProducts, r, err := th.Client.GetSelfHostedProducts()
|
||||
returnedProducts, r, err := th.Client.GetSelfHostedProducts(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, r.StatusCode, "Status OK")
|
||||
require.Equal(t, returnedProducts, products)
|
||||
@@ -760,7 +761,7 @@ func TestGetSelfHostedProducts(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
|
||||
th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password)
|
||||
|
||||
cloud := mocks.CloudInterface{}
|
||||
|
||||
@@ -772,7 +773,7 @@ func TestGetSelfHostedProducts(t *testing.T) {
|
||||
}()
|
||||
th.App.Srv().Cloud = &cloud
|
||||
|
||||
returnedProducts, r, err := th.Client.GetSelfHostedProducts()
|
||||
returnedProducts, r, err := th.Client.GetSelfHostedProducts(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, r.StatusCode, "Status OK")
|
||||
require.Equal(t, returnedProducts, sanitizedProducts)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -16,13 +17,13 @@ func TestGetClusterStatus(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
t.Run("as system user", func(t *testing.T) {
|
||||
_, resp, err := th.Client.GetClusterStatus()
|
||||
_, resp, err := th.Client.GetClusterStatus(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("as system admin", func(t *testing.T) {
|
||||
infos, _, err := th.SystemAdminClient.GetClusterStatus()
|
||||
infos, _, err := th.SystemAdminClient.GetClusterStatus(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NotNil(t, infos, "cluster status should not be nil")
|
||||
@@ -31,7 +32,7 @@ func TestGetClusterStatus(t *testing.T) {
|
||||
t.Run("as restricted system admin", func(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ExperimentalSettings.RestrictSystemAdmin = true })
|
||||
|
||||
_, resp, err := th.SystemAdminClient.GetClusterStatus()
|
||||
_, resp, err := th.SystemAdminClient.GetClusterStatus(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -25,14 +26,14 @@ func TestHelpCommand(t *testing.T) {
|
||||
}()
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.SupportSettings.HelpLink = "" })
|
||||
rs1, _, err := client.ExecuteCommand(channel.Id, "/help ")
|
||||
rs1, _, err := client.ExecuteCommand(context.Background(), channel.Id, "/help ")
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, rs1.Text, model.SupportSettingsDefaultHelpLink, "failed to default help link")
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.SupportSettings.HelpLink = "https://docs.mattermost.com/guides/user.html"
|
||||
})
|
||||
rs2, _, err := client.ExecuteCommand(channel.Id, "/help ")
|
||||
rs2, _, err := client.ExecuteCommand(context.Background(), channel.Id, "/help ")
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, rs2.Text, "https://docs.mattermost.com/guides/user.html", "failed to help link")
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@@ -38,23 +39,23 @@ func TestCreateCommand(t *testing.T) {
|
||||
Method: model.CommandMethodPost,
|
||||
Trigger: "trigger"}
|
||||
|
||||
_, resp, err := client.CreateCommand(newCmd)
|
||||
_, resp, err := client.CreateCommand(context.Background(), newCmd)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
createdCmd, resp, err := th.SystemAdminClient.CreateCommand(newCmd)
|
||||
createdCmd, resp, err := th.SystemAdminClient.CreateCommand(context.Background(), newCmd)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
require.Equal(t, th.SystemAdminUser.Id, createdCmd.CreatorId, "user ids didn't match")
|
||||
require.Equal(t, th.BasicTeam.Id, createdCmd.TeamId, "team ids didn't match")
|
||||
|
||||
_, resp, err = th.SystemAdminClient.CreateCommand(newCmd)
|
||||
_, resp, err = th.SystemAdminClient.CreateCommand(context.Background(), newCmd)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
CheckErrorID(t, err, "api.command.duplicate_trigger.app_error")
|
||||
|
||||
newCmd.Trigger = "Local"
|
||||
localCreatedCmd, resp, err := LocalClient.CreateCommand(newCmd)
|
||||
localCreatedCmd, resp, err := LocalClient.CreateCommand(context.Background(), newCmd)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
require.Equal(t, th.BasicUser.Id, localCreatedCmd.CreatorId, "local client: user ids didn't match")
|
||||
@@ -62,7 +63,7 @@ func TestCreateCommand(t *testing.T) {
|
||||
|
||||
newCmd.Method = "Wrong"
|
||||
newCmd.Trigger = "testcommand"
|
||||
_, resp, err = th.SystemAdminClient.CreateCommand(newCmd)
|
||||
_, resp, err = th.SystemAdminClient.CreateCommand(context.Background(), newCmd)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
CheckErrorID(t, err, "model.command.is_valid.method.app_error")
|
||||
@@ -70,14 +71,14 @@ func TestCreateCommand(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCommands = false })
|
||||
newCmd.Method = "P"
|
||||
newCmd.Trigger = "testcommand"
|
||||
_, resp, err = th.SystemAdminClient.CreateCommand(newCmd)
|
||||
_, resp, err = th.SystemAdminClient.CreateCommand(context.Background(), newCmd)
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
CheckErrorID(t, err, "api.command.disabled.app_error")
|
||||
|
||||
// Confirm that local clients can't override disable command setting
|
||||
newCmd.Trigger = "LocalOverride"
|
||||
_, _, err = LocalClient.CreateCommand(newCmd)
|
||||
_, _, err = LocalClient.CreateCommand(context.Background(), newCmd)
|
||||
CheckErrorID(t, err, "api.command.disabled.app_error")
|
||||
}
|
||||
|
||||
@@ -114,7 +115,7 @@ func TestUpdateCommand(t *testing.T) {
|
||||
}
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
rcmd, _, err := client.UpdateCommand(cmd2)
|
||||
rcmd, _, err := client.UpdateCommand(context.Background(), cmd2)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, cmd2.Trigger, rcmd.Trigger, "Trigger should have updated")
|
||||
@@ -129,7 +130,7 @@ func TestUpdateCommand(t *testing.T) {
|
||||
|
||||
cmd2.Id = GenerateTestId()
|
||||
|
||||
rcmd, resp, err := client.UpdateCommand(cmd2)
|
||||
rcmd, resp, err := client.UpdateCommand(context.Background(), cmd2)
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
@@ -137,25 +138,25 @@ func TestUpdateCommand(t *testing.T) {
|
||||
|
||||
cmd2.Id = "junk"
|
||||
|
||||
_, resp, err = client.UpdateCommand(cmd2)
|
||||
_, resp, err = client.UpdateCommand(context.Background(), cmd2)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
cmd2.Id = cmd1.Id
|
||||
cmd2.TeamId = GenerateTestId()
|
||||
|
||||
_, resp, err = client.UpdateCommand(cmd2)
|
||||
_, resp, err = client.UpdateCommand(context.Background(), cmd2)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
cmd2.TeamId = team.Id
|
||||
|
||||
_, resp, err = th.Client.UpdateCommand(cmd2)
|
||||
_, resp, err = th.Client.UpdateCommand(context.Background(), cmd2)
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
})
|
||||
th.SystemAdminClient.Logout()
|
||||
_, resp, err := th.SystemAdminClient.UpdateCommand(cmd2)
|
||||
th.SystemAdminClient.Logout(context.Background())
|
||||
_, resp, err := th.SystemAdminClient.UpdateCommand(context.Background(), cmd2)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
}
|
||||
@@ -183,18 +184,18 @@ func TestMoveCommand(t *testing.T) {
|
||||
|
||||
rcmd1, _ := th.App.CreateCommand(cmd1)
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
_, err := client.MoveCommand(newTeam.Id, rcmd1.Id)
|
||||
_, err := client.MoveCommand(context.Background(), newTeam.Id, rcmd1.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
rcmd1, _ = th.App.GetCommand(rcmd1.Id)
|
||||
require.NotNil(t, rcmd1)
|
||||
require.Equal(t, newTeam.Id, rcmd1.TeamId)
|
||||
|
||||
resp, err := client.MoveCommand(newTeam.Id, "bogus")
|
||||
resp, err := client.MoveCommand(context.Background(), newTeam.Id, "bogus")
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
resp, err = client.MoveCommand(GenerateTestId(), rcmd1.Id)
|
||||
resp, err = client.MoveCommand(context.Background(), GenerateTestId(), rcmd1.Id)
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
})
|
||||
@@ -208,12 +209,12 @@ func TestMoveCommand(t *testing.T) {
|
||||
|
||||
rcmd2, _ := th.App.CreateCommand(cmd2)
|
||||
|
||||
resp, err := th.Client.MoveCommand(newTeam.Id, rcmd2.Id)
|
||||
resp, err := th.Client.MoveCommand(context.Background(), newTeam.Id, rcmd2.Id)
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
th.SystemAdminClient.Logout()
|
||||
resp, err = th.SystemAdminClient.MoveCommand(newTeam.Id, rcmd2.Id)
|
||||
th.SystemAdminClient.Logout(context.Background())
|
||||
resp, err = th.SystemAdminClient.MoveCommand(context.Background(), newTeam.Id, rcmd2.Id)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
}
|
||||
@@ -242,17 +243,17 @@ func TestDeleteCommand(t *testing.T) {
|
||||
cmd1.Id = ""
|
||||
rcmd1, appErr := th.App.CreateCommand(cmd1)
|
||||
require.Nil(t, appErr)
|
||||
_, err := client.DeleteCommand(rcmd1.Id)
|
||||
_, err := client.DeleteCommand(context.Background(), rcmd1.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
rcmd1, _ = th.App.GetCommand(rcmd1.Id)
|
||||
require.Nil(t, rcmd1)
|
||||
|
||||
resp, err := client.DeleteCommand("junk")
|
||||
resp, err := client.DeleteCommand(context.Background(), "junk")
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
resp, err = client.DeleteCommand(GenerateTestId())
|
||||
resp, err = client.DeleteCommand(context.Background(), GenerateTestId())
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
})
|
||||
@@ -266,12 +267,12 @@ func TestDeleteCommand(t *testing.T) {
|
||||
|
||||
rcmd2, _ := th.App.CreateCommand(cmd2)
|
||||
|
||||
resp, err := th.Client.DeleteCommand(rcmd2.Id)
|
||||
resp, err := th.Client.DeleteCommand(context.Background(), rcmd2.Id)
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
th.SystemAdminClient.Logout()
|
||||
resp, err = th.SystemAdminClient.DeleteCommand(rcmd2.Id)
|
||||
th.SystemAdminClient.Logout(context.Background())
|
||||
resp, err = th.SystemAdminClient.DeleteCommand(context.Background(), rcmd2.Id)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
}
|
||||
@@ -294,11 +295,11 @@ func TestListCommands(t *testing.T) {
|
||||
Method: model.CommandMethodPost,
|
||||
Trigger: "custom_command"}
|
||||
|
||||
_, _, err := th.SystemAdminClient.CreateCommand(newCmd)
|
||||
_, _, err := th.SystemAdminClient.CreateCommand(context.Background(), newCmd)
|
||||
require.NoError(t, err)
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
|
||||
listCommands, _, err := c.ListCommands(th.BasicTeam.Id, false)
|
||||
listCommands, _, err := c.ListCommands(context.Background(), th.BasicTeam.Id, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
foundEcho := false
|
||||
@@ -316,7 +317,7 @@ func TestListCommands(t *testing.T) {
|
||||
}, "ListSystemAndCustomCommands")
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
|
||||
listCommands, _, err := c.ListCommands(th.BasicTeam.Id, true)
|
||||
listCommands, _, err := c.ListCommands(context.Background(), th.BasicTeam.Id, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, listCommands, 1, "Should list just one custom command")
|
||||
@@ -324,13 +325,13 @@ func TestListCommands(t *testing.T) {
|
||||
}, "ListCustomOnlyCommands")
|
||||
|
||||
t.Run("UserWithNoPermissionForCustomCommands", func(t *testing.T) {
|
||||
_, resp, err := client.ListCommands(th.BasicTeam.Id, true)
|
||||
_, resp, err := client.ListCommands(context.Background(), th.BasicTeam.Id, true)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("RegularUserCanListOnlySystemCommands", func(t *testing.T) {
|
||||
listCommands, _, err := client.ListCommands(th.BasicTeam.Id, false)
|
||||
listCommands, _, err := client.ListCommands(context.Background(), th.BasicTeam.Id, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
foundEcho := false
|
||||
@@ -348,24 +349,24 @@ func TestListCommands(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("NoMember", func(t *testing.T) {
|
||||
client.Logout()
|
||||
client.Logout(context.Background())
|
||||
user := th.CreateUser()
|
||||
th.SystemAdminClient.RemoveTeamMember(th.BasicTeam.Id, user.Id)
|
||||
client.Login(user.Email, user.Password)
|
||||
_, resp, err := client.ListCommands(th.BasicTeam.Id, false)
|
||||
th.SystemAdminClient.RemoveTeamMember(context.Background(), th.BasicTeam.Id, user.Id)
|
||||
client.Login(context.Background(), user.Email, user.Password)
|
||||
_, resp, err := client.ListCommands(context.Background(), th.BasicTeam.Id, false)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
_, resp, err = client.ListCommands(th.BasicTeam.Id, true)
|
||||
_, resp, err = client.ListCommands(context.Background(), th.BasicTeam.Id, true)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("NotLoggedIn", func(t *testing.T) {
|
||||
client.Logout()
|
||||
_, resp, err := client.ListCommands(th.BasicTeam.Id, false)
|
||||
client.Logout(context.Background())
|
||||
_, resp, err := client.ListCommands(context.Background(), th.BasicTeam.Id, false)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
_, resp, err = client.ListCommands(th.BasicTeam.Id, true)
|
||||
_, resp, err = client.ListCommands(context.Background(), th.BasicTeam.Id, true)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
})
|
||||
@@ -383,11 +384,11 @@ func TestListAutocompleteCommands(t *testing.T) {
|
||||
Method: model.CommandMethodPost,
|
||||
Trigger: "custom_command"}
|
||||
|
||||
_, _, err := th.SystemAdminClient.CreateCommand(newCmd)
|
||||
_, _, err := th.SystemAdminClient.CreateCommand(context.Background(), newCmd)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Run("ListAutocompleteCommandsOnly", func(t *testing.T) {
|
||||
listCommands, _, err := th.SystemAdminClient.ListAutocompleteCommands(th.BasicTeam.Id)
|
||||
listCommands, _, err := th.SystemAdminClient.ListAutocompleteCommands(context.Background(), th.BasicTeam.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
foundEcho := false
|
||||
@@ -405,7 +406,7 @@ func TestListAutocompleteCommands(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("RegularUserCanListOnlySystemCommands", func(t *testing.T) {
|
||||
listCommands, _, err := client.ListAutocompleteCommands(th.BasicTeam.Id)
|
||||
listCommands, _, err := client.ListAutocompleteCommands(context.Background(), th.BasicTeam.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
foundEcho := false
|
||||
@@ -423,18 +424,18 @@ func TestListAutocompleteCommands(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("NoMember", func(t *testing.T) {
|
||||
client.Logout()
|
||||
client.Logout(context.Background())
|
||||
user := th.CreateUser()
|
||||
th.SystemAdminClient.RemoveTeamMember(th.BasicTeam.Id, user.Id)
|
||||
client.Login(user.Email, user.Password)
|
||||
_, resp, err := client.ListAutocompleteCommands(th.BasicTeam.Id)
|
||||
th.SystemAdminClient.RemoveTeamMember(context.Background(), th.BasicTeam.Id, user.Id)
|
||||
client.Login(context.Background(), user.Email, user.Password)
|
||||
_, resp, err := client.ListAutocompleteCommands(context.Background(), th.BasicTeam.Id)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("NotLoggedIn", func(t *testing.T) {
|
||||
client.Logout()
|
||||
_, resp, err := client.ListAutocompleteCommands(th.BasicTeam.Id)
|
||||
client.Logout(context.Background())
|
||||
_, resp, err := client.ListAutocompleteCommands(context.Background(), th.BasicTeam.Id)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
})
|
||||
@@ -452,11 +453,11 @@ func TestListCommandAutocompleteSuggestions(t *testing.T) {
|
||||
Method: model.CommandMethodPost,
|
||||
Trigger: "custom_command"}
|
||||
|
||||
_, _, err := th.SystemAdminClient.CreateCommand(newCmd)
|
||||
_, _, err := th.SystemAdminClient.CreateCommand(context.Background(), newCmd)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Run("ListAutocompleteSuggestionsOnly", func(t *testing.T) {
|
||||
suggestions, _, err := th.SystemAdminClient.ListCommandAutocompleteSuggestions("/", th.BasicTeam.Id)
|
||||
suggestions, _, err := th.SystemAdminClient.ListCommandAutocompleteSuggestions(context.Background(), "/", th.BasicTeam.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
foundEcho := false
|
||||
@@ -479,7 +480,7 @@ func TestListCommandAutocompleteSuggestions(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("ListAutocompleteSuggestionsOnlyWithInput", func(t *testing.T) {
|
||||
suggestions, _, err := th.SystemAdminClient.ListCommandAutocompleteSuggestions("/e", th.BasicTeam.Id)
|
||||
suggestions, _, err := th.SystemAdminClient.ListCommandAutocompleteSuggestions(context.Background(), "/e", th.BasicTeam.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
foundEcho := false
|
||||
@@ -497,7 +498,7 @@ func TestListCommandAutocompleteSuggestions(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("RegularUserCanListOnlySystemCommands", func(t *testing.T) {
|
||||
suggestions, _, err := client.ListCommandAutocompleteSuggestions("/", th.BasicTeam.Id)
|
||||
suggestions, _, err := client.ListCommandAutocompleteSuggestions(context.Background(), "/", th.BasicTeam.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
foundEcho := false
|
||||
@@ -515,18 +516,18 @@ func TestListCommandAutocompleteSuggestions(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("NoMember", func(t *testing.T) {
|
||||
client.Logout()
|
||||
client.Logout(context.Background())
|
||||
user := th.CreateUser()
|
||||
th.SystemAdminClient.RemoveTeamMember(th.BasicTeam.Id, user.Id)
|
||||
client.Login(user.Email, user.Password)
|
||||
_, resp, err := client.ListCommandAutocompleteSuggestions("/", th.BasicTeam.Id)
|
||||
th.SystemAdminClient.RemoveTeamMember(context.Background(), th.BasicTeam.Id, user.Id)
|
||||
client.Login(context.Background(), user.Email, user.Password)
|
||||
_, resp, err := client.ListCommandAutocompleteSuggestions(context.Background(), "/", th.BasicTeam.Id)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("NotLoggedIn", func(t *testing.T) {
|
||||
client.Logout()
|
||||
_, resp, err := client.ListCommandAutocompleteSuggestions("/", th.BasicTeam.Id)
|
||||
client.Logout(context.Background())
|
||||
_, resp, err := client.ListCommandAutocompleteSuggestions(context.Background(), "/", th.BasicTeam.Id)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
})
|
||||
@@ -549,12 +550,12 @@ func TestGetCommand(t *testing.T) {
|
||||
Method: model.CommandMethodPost,
|
||||
Trigger: "roger"}
|
||||
|
||||
newCmd, _, err := th.SystemAdminClient.CreateCommand(newCmd)
|
||||
newCmd, _, err := th.SystemAdminClient.CreateCommand(context.Background(), newCmd)
|
||||
require.NoError(t, err)
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
|
||||
t.Run("ValidId", func(t *testing.T) {
|
||||
cmd, _, err := client.GetCommandById(newCmd.Id)
|
||||
cmd, _, err := client.GetCommandById(context.Background(), newCmd.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, newCmd.Id, cmd.Id)
|
||||
@@ -566,29 +567,29 @@ func TestGetCommand(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("InvalidId", func(t *testing.T) {
|
||||
_, _, err := client.GetCommandById(strings.Repeat("z", len(newCmd.Id)))
|
||||
_, _, err := client.GetCommandById(context.Background(), strings.Repeat("z", len(newCmd.Id)))
|
||||
require.Error(t, err)
|
||||
})
|
||||
})
|
||||
t.Run("UserWithNoPermissionForCustomCommands", func(t *testing.T) {
|
||||
_, resp, err := th.Client.GetCommandById(newCmd.Id)
|
||||
_, resp, err := th.Client.GetCommandById(context.Background(), newCmd.Id)
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("NoMember", func(t *testing.T) {
|
||||
th.Client.Logout()
|
||||
th.Client.Logout(context.Background())
|
||||
user := th.CreateUser()
|
||||
th.SystemAdminClient.RemoveTeamMember(th.BasicTeam.Id, user.Id)
|
||||
th.Client.Login(user.Email, user.Password)
|
||||
_, resp, err := th.Client.GetCommandById(newCmd.Id)
|
||||
th.SystemAdminClient.RemoveTeamMember(context.Background(), th.BasicTeam.Id, user.Id)
|
||||
th.Client.Login(context.Background(), user.Email, user.Password)
|
||||
_, resp, err := th.Client.GetCommandById(context.Background(), newCmd.Id)
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("NotLoggedIn", func(t *testing.T) {
|
||||
th.Client.Logout()
|
||||
_, resp, err := th.Client.GetCommandById(newCmd.Id)
|
||||
th.Client.Logout(context.Background())
|
||||
_, resp, err := th.Client.GetCommandById(context.Background(), newCmd.Id)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
})
|
||||
@@ -612,15 +613,15 @@ func TestRegenToken(t *testing.T) {
|
||||
Method: model.CommandMethodPost,
|
||||
Trigger: "trigger"}
|
||||
|
||||
createdCmd, resp, err := th.SystemAdminClient.CreateCommand(newCmd)
|
||||
createdCmd, resp, err := th.SystemAdminClient.CreateCommand(context.Background(), newCmd)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
|
||||
token, _, err := th.SystemAdminClient.RegenCommandToken(createdCmd.Id)
|
||||
token, _, err := th.SystemAdminClient.RegenCommandToken(context.Background(), createdCmd.Id)
|
||||
require.NoError(t, err)
|
||||
require.NotEqual(t, createdCmd.Token, token, "should update the token")
|
||||
|
||||
token, resp, err = client.RegenCommandToken(createdCmd.Id)
|
||||
token, resp, err = client.RegenCommandToken(context.Background(), createdCmd.Id)
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
require.Empty(t, token, "should not return the token")
|
||||
@@ -663,36 +664,36 @@ func TestExecuteInvalidCommand(t *testing.T) {
|
||||
_, appErr := th.App.CreateCommand(getCmd)
|
||||
require.Nil(t, appErr, "failed to create get command")
|
||||
|
||||
_, resp, err := client.ExecuteCommand(channel.Id, "")
|
||||
_, resp, err := client.ExecuteCommand(context.Background(), channel.Id, "")
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
_, resp, err = client.ExecuteCommand(channel.Id, "/")
|
||||
_, resp, err = client.ExecuteCommand(context.Background(), channel.Id, "/")
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
_, resp, err = client.ExecuteCommand(channel.Id, "getcommand")
|
||||
_, resp, err = client.ExecuteCommand(context.Background(), channel.Id, "getcommand")
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
_, resp, err = client.ExecuteCommand(channel.Id, "/junk")
|
||||
_, resp, err = client.ExecuteCommand(context.Background(), channel.Id, "/junk")
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
otherUser := th.CreateUser()
|
||||
client.Login(otherUser.Email, otherUser.Password)
|
||||
client.Login(context.Background(), otherUser.Email, otherUser.Password)
|
||||
|
||||
_, resp, err = client.ExecuteCommand(channel.Id, "/getcommand")
|
||||
_, resp, err = client.ExecuteCommand(context.Background(), channel.Id, "/getcommand")
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
client.Logout()
|
||||
client.Logout(context.Background())
|
||||
|
||||
_, resp, err = client.ExecuteCommand(channel.Id, "/getcommand")
|
||||
_, resp, err = client.ExecuteCommand(context.Background(), channel.Id, "/getcommand")
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
|
||||
_, _, err = th.SystemAdminClient.ExecuteCommand(channel.Id, "/getcommand")
|
||||
_, _, err = th.SystemAdminClient.ExecuteCommand(context.Background(), channel.Id, "/getcommand")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -750,7 +751,7 @@ func TestExecuteGetCommand(t *testing.T) {
|
||||
_, appErr := th.App.CreateCommand(getCmd)
|
||||
require.Nil(t, appErr, "failed to create get command")
|
||||
|
||||
commandResponse, _, err := client.ExecuteCommand(channel.Id, "/getcommand")
|
||||
commandResponse, _, err := client.ExecuteCommand(context.Background(), channel.Id, "/getcommand")
|
||||
require.NoError(t, err)
|
||||
assert.True(t, len(commandResponse.TriggerId) == 26)
|
||||
|
||||
@@ -810,7 +811,7 @@ func TestExecutePostCommand(t *testing.T) {
|
||||
_, appErr := th.App.CreateCommand(postCmd)
|
||||
require.Nil(t, appErr, "failed to create get command")
|
||||
|
||||
commandResponse, _, err := client.ExecuteCommand(channel.Id, "/postcommand")
|
||||
commandResponse, _, err := client.ExecuteCommand(context.Background(), channel.Id, "/postcommand")
|
||||
require.NoError(t, err)
|
||||
assert.True(t, len(commandResponse.TriggerId) == 26)
|
||||
|
||||
@@ -866,7 +867,7 @@ func TestExecuteCommandAgainstChannelOnAnotherTeam(t *testing.T) {
|
||||
|
||||
// the execute command endpoint will always search for the command by trigger and team id, inferring team id from the
|
||||
// channel id, so there is no way to use that slash command on a channel that belongs to some other team
|
||||
_, resp, err := client.ExecuteCommand(channel.Id, "/postcommand")
|
||||
_, resp, err := client.ExecuteCommand(context.Background(), channel.Id, "/postcommand")
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
}
|
||||
@@ -918,11 +919,11 @@ func TestExecuteCommandAgainstChannelUserIsNotIn(t *testing.T) {
|
||||
|
||||
// make a channel on that team, ensuring that our test user isn't in it
|
||||
channel2 := th.CreateChannelWithClientAndTeam(client, model.ChannelTypeOpen, team2.Id)
|
||||
_, err := th.Client.RemoveUserFromChannel(channel2.Id, th.BasicUser.Id)
|
||||
_, err := th.Client.RemoveUserFromChannel(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
require.NoError(t, err, "Failed to remove user from channel")
|
||||
|
||||
// we should not be able to run the slash command in channel2, because we aren't in it
|
||||
_, resp, err := client.ExecuteCommandWithTeam(channel2.Id, team2.Id, "/postcommand")
|
||||
_, resp, err := client.ExecuteCommandWithTeam(context.Background(), channel2.Id, team2.Id, "/postcommand")
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
}
|
||||
@@ -976,17 +977,17 @@ func TestExecuteCommandInDirectMessageChannel(t *testing.T) {
|
||||
require.Nil(t, appErr, "failed to create post command")
|
||||
|
||||
// make a direct message channel
|
||||
dmChannel, response, err := client.CreateDirectChannel(th.BasicUser.Id, th.BasicUser2.Id)
|
||||
dmChannel, response, err := client.CreateDirectChannel(context.Background(), th.BasicUser.Id, th.BasicUser2.Id)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, response)
|
||||
|
||||
// we should be able to run the slash command in the DM channel
|
||||
_, resp, err := client.ExecuteCommandWithTeam(dmChannel.Id, team2.Id, "/postcommand")
|
||||
_, resp, err := client.ExecuteCommandWithTeam(context.Background(), dmChannel.Id, team2.Id, "/postcommand")
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
|
||||
// but we can't run the slash command in the DM channel if we sub in some other team's id
|
||||
_, resp, err = client.ExecuteCommandWithTeam(dmChannel.Id, th.BasicTeam.Id, "/postcommand")
|
||||
_, resp, err = client.ExecuteCommandWithTeam(context.Background(), dmChannel.Id, th.BasicTeam.Id, "/postcommand")
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
}
|
||||
@@ -1043,26 +1044,26 @@ func TestExecuteCommandInTeamUserIsNotOn(t *testing.T) {
|
||||
require.Nil(t, appErr, "failed to create post command")
|
||||
|
||||
// make a direct message channel
|
||||
dmChannel, response, err := client.CreateDirectChannel(th.BasicUser.Id, th.BasicUser2.Id)
|
||||
dmChannel, response, err := client.CreateDirectChannel(context.Background(), th.BasicUser.Id, th.BasicUser2.Id)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, response)
|
||||
|
||||
// we should be able to run the slash command in the DM channel
|
||||
_, resp, err := client.ExecuteCommandWithTeam(dmChannel.Id, team2.Id, "/postcommand")
|
||||
_, resp, err := client.ExecuteCommandWithTeam(context.Background(), dmChannel.Id, team2.Id, "/postcommand")
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
|
||||
// if the user is removed from the team, they should NOT be able to run the slash command in the DM channel
|
||||
_, err = th.Client.RemoveTeamMember(team2.Id, th.BasicUser.Id)
|
||||
_, err = th.Client.RemoveTeamMember(context.Background(), team2.Id, th.BasicUser.Id)
|
||||
require.NoError(t, err, "Failed to remove user from team")
|
||||
|
||||
_, resp, err = client.ExecuteCommandWithTeam(dmChannel.Id, team2.Id, "/postcommand")
|
||||
_, resp, err = client.ExecuteCommandWithTeam(context.Background(), dmChannel.Id, team2.Id, "/postcommand")
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
// if we omit the team id from the request, the slash command will fail because this is a DM channel, and the
|
||||
// team id can't be inherited from the channel
|
||||
_, resp, err = client.ExecuteCommand(dmChannel.Id, "/postcommand")
|
||||
_, resp, err = client.ExecuteCommand(context.Background(), dmChannel.Id, "/postcommand")
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
}
|
||||
@@ -1117,7 +1118,7 @@ func TestExecuteCommandReadOnly(t *testing.T) {
|
||||
require.Nil(t, appErr, "failed to create post command")
|
||||
|
||||
// Confirm that the command works when the channel is not read only
|
||||
_, resp, err := client.ExecuteCommandWithTeam(th.BasicChannel.Id, th.BasicChannel.TeamId, "/postcommand")
|
||||
_, resp, err := client.ExecuteCommandWithTeam(context.Background(), th.BasicChannel.Id, th.BasicChannel.TeamId, "/postcommand")
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
|
||||
@@ -1139,7 +1140,7 @@ func TestExecuteCommandReadOnly(t *testing.T) {
|
||||
require.Nil(t, appErr)
|
||||
|
||||
// Confirm that the command fails when the channel is read only
|
||||
_, resp, err = client.ExecuteCommandWithTeam(th.BasicChannel.Id, th.BasicChannel.TeamId, "/postcommand")
|
||||
_, resp, err = client.ExecuteCommandWithTeam(context.Background(), th.BasicChannel.Id, th.BasicChannel.TeamId, "/postcommand")
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -24,17 +25,17 @@ func TestEchoCommand(t *testing.T) {
|
||||
|
||||
echoTestString := "/echo test"
|
||||
|
||||
r1, _, err := client.ExecuteCommand(channel1.Id, echoTestString)
|
||||
r1, _, err := client.ExecuteCommand(context.Background(), channel1.Id, echoTestString)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, r1, "Echo command failed to execute")
|
||||
|
||||
r1, _, err = client.ExecuteCommand(channel1.Id, "/echo ")
|
||||
r1, _, err = client.ExecuteCommand(context.Background(), channel1.Id, "/echo ")
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, r1, "Echo command failed to execute")
|
||||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
p1, _, err := client.GetPostsForChannel(channel1.Id, 0, 2, "", false, false)
|
||||
p1, _, err := client.GetPostsForChannel(context.Background(), channel1.Id, 0, 2, "", false, false)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, p1.Order, 2, "Echo command failed to send")
|
||||
}
|
||||
@@ -57,33 +58,33 @@ func TestGroupmsgCommands(t *testing.T) {
|
||||
th.LinkUserToTeam(user3, team)
|
||||
th.LinkUserToTeam(user4, team)
|
||||
|
||||
rs1, _, err := client.ExecuteCommand(th.BasicChannel.Id, "/groupmsg "+user2.Username+","+user3.Username)
|
||||
rs1, _, err := client.ExecuteCommand(context.Background(), th.BasicChannel.Id, "/groupmsg "+user2.Username+","+user3.Username)
|
||||
require.NoError(t, err)
|
||||
|
||||
group1 := model.GetGroupNameFromUserIds([]string{user1.Id, user2.Id, user3.Id})
|
||||
require.True(t, strings.HasSuffix(rs1.GotoLocation, "/"+team.Name+"/channels/"+group1), "failed to create group channel")
|
||||
|
||||
rs2, _, err := client.ExecuteCommand(th.BasicChannel.Id, "/groupmsg "+user3.Username+","+user4.Username+" foobar")
|
||||
rs2, _, err := client.ExecuteCommand(context.Background(), th.BasicChannel.Id, "/groupmsg "+user3.Username+","+user4.Username+" foobar")
|
||||
require.NoError(t, err)
|
||||
group2 := model.GetGroupNameFromUserIds([]string{user1.Id, user3.Id, user4.Id})
|
||||
|
||||
require.True(t, strings.HasSuffix(rs2.GotoLocation, "/"+team.Name+"/channels/"+group2), "failed to create second direct channel")
|
||||
|
||||
result, _, err := client.SearchPosts(team.Id, "foobar", false)
|
||||
result, _, err := client.SearchPosts(context.Background(), team.Id, "foobar", false)
|
||||
require.NoError(t, err)
|
||||
require.NotEqual(t, 0, len(result.Order), "post did not get sent to direct message")
|
||||
|
||||
rs3, _, err := client.ExecuteCommand(th.BasicChannel.Id, "/groupmsg "+user2.Username+","+user3.Username)
|
||||
rs3, _, err := client.ExecuteCommand(context.Background(), th.BasicChannel.Id, "/groupmsg "+user2.Username+","+user3.Username)
|
||||
require.NoError(t, err)
|
||||
require.True(t, strings.HasSuffix(rs3.GotoLocation, "/"+team.Name+"/channels/"+group1), "failed to go back to existing group channel")
|
||||
|
||||
_, _, err = client.ExecuteCommand(th.BasicChannel.Id, "/groupmsg "+user2.Username+" foobar")
|
||||
_, _, err = client.ExecuteCommand(context.Background(), th.BasicChannel.Id, "/groupmsg "+user2.Username+" foobar")
|
||||
require.NoError(t, err)
|
||||
_, _, err = client.ExecuteCommand(th.BasicChannel.Id, "/groupmsg "+user2.Username+","+user3.Username+","+user4.Username+","+user5.Username+","+user6.Username+","+user7.Username+","+user8.Username+","+user9.Username+" foobar")
|
||||
_, _, err = client.ExecuteCommand(context.Background(), th.BasicChannel.Id, "/groupmsg "+user2.Username+","+user3.Username+","+user4.Username+","+user5.Username+","+user6.Username+","+user7.Username+","+user8.Username+","+user9.Username+" foobar")
|
||||
require.NoError(t, err)
|
||||
_, _, err = client.ExecuteCommand(th.BasicChannel.Id, "/groupmsg junk foobar")
|
||||
_, _, err = client.ExecuteCommand(context.Background(), th.BasicChannel.Id, "/groupmsg junk foobar")
|
||||
require.NoError(t, err)
|
||||
_, _, err = client.ExecuteCommand(th.BasicChannel.Id, "/groupmsg junk,junk2 foobar")
|
||||
_, _, err = client.ExecuteCommand(context.Background(), th.BasicChannel.Id, "/groupmsg junk,junk2 foobar")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -94,15 +95,15 @@ func TestInvitePeopleCommand(t *testing.T) {
|
||||
client := th.Client
|
||||
channel := th.BasicChannel
|
||||
|
||||
r1, _, err := client.ExecuteCommand(channel.Id, "/invite_people test@example.com")
|
||||
r1, _, err := client.ExecuteCommand(context.Background(), channel.Id, "/invite_people test@example.com")
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, r1, "Command failed to execute")
|
||||
|
||||
r2, _, err := client.ExecuteCommand(channel.Id, "/invite_people test1@example.com test2@example.com")
|
||||
r2, _, err := client.ExecuteCommand(context.Background(), channel.Id, "/invite_people test1@example.com test2@example.com")
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, r2, "Command failed to execute")
|
||||
|
||||
r3, _, err := client.ExecuteCommand(channel.Id, "/invite_people")
|
||||
r3, _, err := client.ExecuteCommand(context.Background(), channel.Id, "/invite_people")
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, r3, "Command failed to execute")
|
||||
}
|
||||
@@ -117,33 +118,33 @@ func testJoinCommands(t *testing.T, alias string) {
|
||||
user2 := th.BasicUser2
|
||||
|
||||
channel0 := &model.Channel{DisplayName: "00", Name: "00" + model.NewId() + "a", Type: model.ChannelTypeOpen, TeamId: team.Id}
|
||||
channel0, _, err := client.CreateChannel(channel0)
|
||||
channel0, _, err := client.CreateChannel(context.Background(), channel0)
|
||||
require.NoError(t, err)
|
||||
|
||||
channel1 := &model.Channel{DisplayName: "AA", Name: "aa" + model.NewId() + "a", Type: model.ChannelTypeOpen, TeamId: team.Id}
|
||||
channel1, _, err = client.CreateChannel(channel1)
|
||||
channel1, _, err = client.CreateChannel(context.Background(), channel1)
|
||||
require.NoError(t, err)
|
||||
_, err = client.RemoveUserFromChannel(channel1.Id, th.BasicUser.Id)
|
||||
_, err = client.RemoveUserFromChannel(context.Background(), channel1.Id, th.BasicUser.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
channel2 := &model.Channel{DisplayName: "BB", Name: "bb" + model.NewId() + "a", Type: model.ChannelTypeOpen, TeamId: team.Id}
|
||||
channel2, _, err = client.CreateChannel(channel2)
|
||||
channel2, _, err = client.CreateChannel(context.Background(), channel2)
|
||||
require.NoError(t, err)
|
||||
_, err = client.RemoveUserFromChannel(channel2.Id, th.BasicUser.Id)
|
||||
_, err = client.RemoveUserFromChannel(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
channel3, _, err := client.CreateDirectChannel(th.BasicUser.Id, user2.Id)
|
||||
channel3, _, err := client.CreateDirectChannel(context.Background(), th.BasicUser.Id, user2.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
rs5, _, err := client.ExecuteCommand(channel0.Id, "/"+alias+" "+channel2.Name)
|
||||
rs5, _, err := client.ExecuteCommand(context.Background(), channel0.Id, "/"+alias+" "+channel2.Name)
|
||||
require.NoError(t, err)
|
||||
require.True(t, strings.HasSuffix(rs5.GotoLocation, "/"+team.Name+"/channels/"+channel2.Name), "failed to join channel")
|
||||
|
||||
rs6, _, err := client.ExecuteCommand(channel0.Id, "/"+alias+" "+channel3.Name)
|
||||
rs6, _, err := client.ExecuteCommand(context.Background(), channel0.Id, "/"+alias+" "+channel3.Name)
|
||||
require.NoError(t, err)
|
||||
require.False(t, strings.HasSuffix(rs6.GotoLocation, "/"+team.Name+"/channels/"+channel3.Name), "should not have joined direct message channel")
|
||||
|
||||
c1, _, err := client.GetChannelsForTeamForUser(th.BasicTeam.Id, th.BasicUser.Id, false, "")
|
||||
c1, _, err := client.GetChannelsForTeamForUser(context.Background(), th.BasicTeam.Id, th.BasicUser.Id, false, "")
|
||||
require.NoError(t, err)
|
||||
|
||||
found := false
|
||||
@@ -156,11 +157,11 @@ func testJoinCommands(t *testing.T, alias string) {
|
||||
|
||||
// test case insensitively
|
||||
channel4 := &model.Channel{DisplayName: "BB", Name: "bb" + model.NewId() + "a", Type: model.ChannelTypeOpen, TeamId: team.Id}
|
||||
channel4, _, err = client.CreateChannel(channel4)
|
||||
channel4, _, err = client.CreateChannel(context.Background(), channel4)
|
||||
require.NoError(t, err)
|
||||
_, err = client.RemoveUserFromChannel(channel4.Id, th.BasicUser.Id)
|
||||
_, err = client.RemoveUserFromChannel(context.Background(), channel4.Id, th.BasicUser.Id)
|
||||
require.NoError(t, err)
|
||||
rs7, _, err := client.ExecuteCommand(channel0.Id, "/"+alias+" "+strings.ToUpper(channel4.Name))
|
||||
rs7, _, err := client.ExecuteCommand(context.Background(), channel0.Id, "/"+alias+" "+strings.ToUpper(channel4.Name))
|
||||
require.NoError(t, err)
|
||||
require.True(t, strings.HasSuffix(rs7.GotoLocation, "/"+team.Name+"/channels/"+channel4.Name), "failed to join channel")
|
||||
}
|
||||
@@ -183,7 +184,7 @@ func TestLoadTestHelpCommands(t *testing.T) {
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableTesting = true })
|
||||
|
||||
rs, _, err := client.ExecuteCommand(channel.Id, "/test help")
|
||||
rs, _, err := client.ExecuteCommand(context.Background(), channel.Id, "/test help")
|
||||
require.NoError(t, err)
|
||||
require.True(t, strings.Contains(rs.Text, "Mattermost testing commands to help"), rs.Text)
|
||||
|
||||
@@ -204,7 +205,7 @@ func TestLoadTestSetupCommands(t *testing.T) {
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableTesting = true })
|
||||
|
||||
rs, _, err := client.ExecuteCommand(channel.Id, "/test setup fuzz 1 1 1")
|
||||
rs, _, err := client.ExecuteCommand(context.Background(), channel.Id, "/test setup fuzz 1 1 1")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "Created environment", rs.Text, rs.Text)
|
||||
|
||||
@@ -225,7 +226,7 @@ func TestLoadTestUsersCommands(t *testing.T) {
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableTesting = true })
|
||||
|
||||
rs, _, err := client.ExecuteCommand(channel.Id, "/test users fuzz 1 2")
|
||||
rs, _, err := client.ExecuteCommand(context.Background(), channel.Id, "/test users fuzz 1 2")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "Added users", rs.Text, rs.Text)
|
||||
|
||||
@@ -246,7 +247,7 @@ func TestLoadTestChannelsCommands(t *testing.T) {
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableTesting = true })
|
||||
|
||||
rs, _, err := client.ExecuteCommand(channel.Id, "/test channels fuzz 1 2")
|
||||
rs, _, err := client.ExecuteCommand(context.Background(), channel.Id, "/test channels fuzz 1 2")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "Added channels", rs.Text, rs.Text)
|
||||
|
||||
@@ -267,7 +268,7 @@ func TestLoadTestPostsCommands(t *testing.T) {
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableTesting = true })
|
||||
|
||||
rs, _, err := client.ExecuteCommand(channel.Id, "/test posts fuzz 2 3 2")
|
||||
rs, _, err := client.ExecuteCommand(context.Background(), channel.Id, "/test posts fuzz 2 3 2")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "Added posts", rs.Text, rs.Text)
|
||||
|
||||
@@ -283,34 +284,34 @@ func TestLeaveCommands(t *testing.T) {
|
||||
user2 := th.BasicUser2
|
||||
|
||||
channel1 := &model.Channel{DisplayName: "AA", Name: "aa" + model.NewId() + "a", Type: model.ChannelTypeOpen, TeamId: team.Id}
|
||||
channel1, _, err := client.CreateChannel(channel1)
|
||||
channel1, _, err := client.CreateChannel(context.Background(), channel1)
|
||||
require.NoError(t, err)
|
||||
_, _, err = client.AddChannelMember(channel1.Id, th.BasicUser.Id)
|
||||
_, _, err = client.AddChannelMember(context.Background(), channel1.Id, th.BasicUser.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
channel2 := &model.Channel{DisplayName: "BB", Name: "bb" + model.NewId() + "a", Type: model.ChannelTypePrivate, TeamId: team.Id}
|
||||
channel2, _, err = client.CreateChannel(channel2)
|
||||
channel2, _, err = client.CreateChannel(context.Background(), channel2)
|
||||
require.NoError(t, err)
|
||||
_, _, err = client.AddChannelMember(channel2.Id, th.BasicUser.Id)
|
||||
_, _, err = client.AddChannelMember(context.Background(), channel2.Id, th.BasicUser.Id)
|
||||
require.NoError(t, err)
|
||||
_, _, err = client.AddChannelMember(channel2.Id, user2.Id)
|
||||
_, _, err = client.AddChannelMember(context.Background(), channel2.Id, user2.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
channel3, _, err := client.CreateDirectChannel(th.BasicUser.Id, user2.Id)
|
||||
channel3, _, err := client.CreateDirectChannel(context.Background(), th.BasicUser.Id, user2.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
rs1, _, err := client.ExecuteCommand(channel1.Id, "/leave")
|
||||
rs1, _, err := client.ExecuteCommand(context.Background(), channel1.Id, "/leave")
|
||||
require.NoError(t, err)
|
||||
require.True(t, strings.HasSuffix(rs1.GotoLocation, "/"+team.Name+"/channels/"+model.DefaultChannelName), "failed to leave open channel 1")
|
||||
|
||||
rs2, _, err := client.ExecuteCommand(channel2.Id, "/leave")
|
||||
rs2, _, err := client.ExecuteCommand(context.Background(), channel2.Id, "/leave")
|
||||
require.NoError(t, err)
|
||||
require.True(t, strings.HasSuffix(rs2.GotoLocation, "/"+team.Name+"/channels/"+model.DefaultChannelName), "failed to leave private channel 1")
|
||||
|
||||
_, _, err = client.ExecuteCommand(channel3.Id, "/leave")
|
||||
_, _, err = client.ExecuteCommand(context.Background(), channel3.Id, "/leave")
|
||||
require.Error(t, err)
|
||||
|
||||
cdata, _, err := client.GetChannelsForTeamForUser(th.BasicTeam.Id, th.BasicUser.Id, false, "")
|
||||
cdata, _, err := client.GetChannelsForTeamForUser(context.Background(), th.BasicTeam.Id, th.BasicUser.Id, false, "")
|
||||
require.NoError(t, err)
|
||||
|
||||
found := false
|
||||
@@ -323,7 +324,7 @@ func TestLeaveCommands(t *testing.T) {
|
||||
|
||||
for _, c := range cdata {
|
||||
if c.Name == model.DefaultChannelName {
|
||||
_, err := client.RemoveUserFromChannel(c.Id, th.BasicUser.Id)
|
||||
_, err := client.RemoveUserFromChannel(context.Background(), c.Id, th.BasicUser.Id)
|
||||
require.Error(t, err, "should have errored on leaving default channel")
|
||||
break
|
||||
}
|
||||
@@ -334,7 +335,7 @@ func TestLogoutTestCommand(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
_, _, err := th.Client.ExecuteCommand(th.BasicChannel.Id, "/logout")
|
||||
_, _, err := th.Client.ExecuteCommand(context.Background(), th.BasicChannel.Id, "/logout")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -347,13 +348,13 @@ func TestMeCommand(t *testing.T) {
|
||||
|
||||
testString := "/me hello"
|
||||
|
||||
r1, _, err := client.ExecuteCommand(channel.Id, testString)
|
||||
r1, _, err := client.ExecuteCommand(context.Background(), channel.Id, testString)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, r1, "Command failed to execute")
|
||||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
p1, _, err := client.GetPostsForChannel(channel.Id, 0, 2, "", false, false)
|
||||
p1, _, err := client.GetPostsForChannel(context.Background(), channel.Id, 0, 2, "", false, false)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, p1.Order, 2, "Command failed to send")
|
||||
|
||||
@@ -376,39 +377,39 @@ func TestMsgCommands(t *testing.T) {
|
||||
user3 := th.CreateUser()
|
||||
th.LinkUserToTeam(user3, team)
|
||||
|
||||
_, _, err := client.CreateDirectChannel(th.BasicUser.Id, user2.Id)
|
||||
_, _, err := client.CreateDirectChannel(context.Background(), th.BasicUser.Id, user2.Id)
|
||||
require.NoError(t, err)
|
||||
_, _, err = client.CreateDirectChannel(th.BasicUser.Id, user3.Id)
|
||||
_, _, err = client.CreateDirectChannel(context.Background(), th.BasicUser.Id, user3.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
rs1, _, err := client.ExecuteCommand(th.BasicChannel.Id, "/msg "+user2.Username)
|
||||
rs1, _, err := client.ExecuteCommand(context.Background(), th.BasicChannel.Id, "/msg "+user2.Username)
|
||||
require.NoError(t, err)
|
||||
require.Condition(t, func() bool {
|
||||
return strings.HasSuffix(rs1.GotoLocation, "/"+team.Name+"/channels/"+user1.Id+"__"+user2.Id) ||
|
||||
strings.HasSuffix(rs1.GotoLocation, "/"+team.Name+"/channels/"+user2.Id+"__"+user1.Id)
|
||||
}, "failed to create direct channel")
|
||||
|
||||
rs2, _, err := client.ExecuteCommand(th.BasicChannel.Id, "/msg "+user3.Username+" foobar")
|
||||
rs2, _, err := client.ExecuteCommand(context.Background(), th.BasicChannel.Id, "/msg "+user3.Username+" foobar")
|
||||
require.NoError(t, err)
|
||||
require.Condition(t, func() bool {
|
||||
return strings.HasSuffix(rs2.GotoLocation, "/"+team.Name+"/channels/"+user1.Id+"__"+user3.Id) ||
|
||||
strings.HasSuffix(rs2.GotoLocation, "/"+team.Name+"/channels/"+user3.Id+"__"+user1.Id)
|
||||
}, "failed to create second direct channel")
|
||||
|
||||
result, _, err := client.SearchPosts(th.BasicTeam.Id, "foobar", false)
|
||||
result, _, err := client.SearchPosts(context.Background(), th.BasicTeam.Id, "foobar", false)
|
||||
require.NoError(t, err)
|
||||
require.NotEqual(t, 0, len(result.Order), "post did not get sent to direct message")
|
||||
|
||||
rs3, _, err := client.ExecuteCommand(th.BasicChannel.Id, "/msg "+user2.Username)
|
||||
rs3, _, err := client.ExecuteCommand(context.Background(), th.BasicChannel.Id, "/msg "+user2.Username)
|
||||
require.NoError(t, err)
|
||||
require.Condition(t, func() bool {
|
||||
return strings.HasSuffix(rs3.GotoLocation, "/"+team.Name+"/channels/"+user1.Id+"__"+user2.Id) ||
|
||||
strings.HasSuffix(rs3.GotoLocation, "/"+team.Name+"/channels/"+user2.Id+"__"+user1.Id)
|
||||
}, "failed to go back to existing direct channel")
|
||||
|
||||
_, _, err = client.ExecuteCommand(th.BasicChannel.Id, "/msg "+th.BasicUser.Username+" foobar")
|
||||
_, _, err = client.ExecuteCommand(context.Background(), th.BasicChannel.Id, "/msg "+th.BasicUser.Username+" foobar")
|
||||
require.NoError(t, err)
|
||||
_, _, err = client.ExecuteCommand(th.BasicChannel.Id, "/msg junk foobar")
|
||||
_, _, err = client.ExecuteCommand(context.Background(), th.BasicChannel.Id, "/msg junk foobar")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -420,7 +421,7 @@ func TestSearchCommand(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
_, _, err := th.Client.ExecuteCommand(th.BasicChannel.Id, "/search")
|
||||
_, _, err := th.Client.ExecuteCommand(context.Background(), th.BasicChannel.Id, "/search")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -428,7 +429,7 @@ func TestSettingsCommand(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
_, _, err := th.Client.ExecuteCommand(th.BasicChannel.Id, "/settings")
|
||||
_, _, err := th.Client.ExecuteCommand(context.Background(), th.BasicChannel.Id, "/settings")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -436,7 +437,7 @@ func TestShortcutsCommand(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
_, _, err := th.Client.ExecuteCommand(th.BasicChannel.Id, "/shortcuts")
|
||||
_, _, err := th.Client.ExecuteCommand(context.Background(), th.BasicChannel.Id, "/shortcuts")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -449,13 +450,13 @@ func TestShrugCommand(t *testing.T) {
|
||||
|
||||
testString := "/shrug"
|
||||
|
||||
r1, _, err := client.ExecuteCommand(channel.Id, testString)
|
||||
r1, _, err := client.ExecuteCommand(context.Background(), channel.Id, testString)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, r1, "Command failed to execute")
|
||||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
p1, _, err := client.GetPostsForChannel(channel.Id, 0, 2, "", false, false)
|
||||
p1, _, err := client.GetPostsForChannel(context.Background(), channel.Id, 0, 2, "", false, false)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, p1.Order, 2, "Command failed to send")
|
||||
require.Equal(t, `¯\\\_(ツ)\_/¯`, p1.Posts[p1.Order[0]].Message, "invalid shrug response")
|
||||
@@ -475,13 +476,13 @@ func commandAndTest(t *testing.T, th *TestHelper, status string) {
|
||||
channel := th.BasicChannel
|
||||
user := th.BasicUser
|
||||
|
||||
r1, _, err := client.ExecuteCommand(channel.Id, "/"+status)
|
||||
r1, _, err := client.ExecuteCommand(context.Background(), channel.Id, "/"+status)
|
||||
require.NoError(t, err)
|
||||
require.NotEqual(t, "Command failed to execute", r1)
|
||||
|
||||
time.Sleep(1000 * time.Millisecond)
|
||||
|
||||
rstatus, _, err := client.GetUserStatus(user.Id, "")
|
||||
rstatus, _, err := client.GetUserStatus(context.Background(), user.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, status, rstatus.Status, "Error setting status")
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -25,12 +26,12 @@ func TestGetConfig(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
client := th.Client
|
||||
|
||||
_, resp, err := client.GetConfig()
|
||||
_, resp, err := client.GetConfig(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
cfg, _, err := client.GetConfig()
|
||||
cfg, _, err := client.GetConfig(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NotEqual(t, "", cfg.TeamSettings.SiteName)
|
||||
@@ -72,13 +73,13 @@ func TestGetConfigWithAccessTag(t *testing.T) {
|
||||
cfg.SupportSettings.SupportEmail = &mockSupportEmail
|
||||
})
|
||||
|
||||
th.Client.Login(th.BasicUser.Username, th.BasicUser.Password)
|
||||
th.Client.Login(context.Background(), th.BasicUser.Username, th.BasicUser.Password)
|
||||
|
||||
// add read sysconsole environment config
|
||||
th.AddPermissionToRole(model.PermissionSysconsoleReadEnvironmentRateLimiting.Id, model.SystemUserRoleId)
|
||||
defer th.RemovePermissionFromRole(model.PermissionSysconsoleReadEnvironmentRateLimiting.Id, model.SystemUserRoleId)
|
||||
|
||||
cfg, _, err := th.Client.GetConfig()
|
||||
cfg, _, err := th.Client.GetConfig(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Run("Cannot read value without permission", func(t *testing.T) {
|
||||
@@ -98,8 +99,8 @@ func TestGetConfigAnyFlagsAccess(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
th.Client.Login(th.BasicUser.Username, th.BasicUser.Password)
|
||||
_, resp, _ := th.Client.GetConfig()
|
||||
th.Client.Login(context.Background(), th.BasicUser.Username, th.BasicUser.Password)
|
||||
_, resp, _ := th.Client.GetConfig(context.Background())
|
||||
|
||||
t.Run("Check permissions error with no sysconsole read permission", func(t *testing.T) {
|
||||
CheckForbiddenStatus(t, resp)
|
||||
@@ -109,7 +110,7 @@ func TestGetConfigAnyFlagsAccess(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionSysconsoleReadEnvironmentRateLimiting.Id, model.SystemUserRoleId)
|
||||
defer th.RemovePermissionFromRole(model.PermissionSysconsoleReadEnvironmentRateLimiting.Id, model.SystemUserRoleId)
|
||||
|
||||
cfg, _, err := th.Client.GetConfig()
|
||||
cfg, _, err := th.Client.GetConfig(context.Background())
|
||||
require.NoError(t, err)
|
||||
t.Run("Can read value with permission", func(t *testing.T) {
|
||||
assert.NotNil(t, cfg.FeatureFlags)
|
||||
@@ -122,20 +123,20 @@ func TestReloadConfig(t *testing.T) {
|
||||
client := th.Client
|
||||
|
||||
t.Run("as system user", func(t *testing.T) {
|
||||
resp, err := client.ReloadConfig()
|
||||
resp, err := client.ReloadConfig(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
_, err := client.ReloadConfig()
|
||||
_, err := client.ReloadConfig(context.Background())
|
||||
require.NoError(t, err)
|
||||
}, "as system admin and local mode")
|
||||
|
||||
t.Run("as restricted system admin", func(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ExperimentalSettings.RestrictSystemAdmin = true })
|
||||
|
||||
resp, err := client.ReloadConfig()
|
||||
resp, err := client.ReloadConfig(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
@@ -146,10 +147,10 @@ func TestUpdateConfig(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
client := th.Client
|
||||
|
||||
cfg, _, err := th.SystemAdminClient.GetConfig()
|
||||
cfg, _, err := th.SystemAdminClient.GetConfig(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
_, resp, err := client.UpdateConfig(cfg)
|
||||
_, resp, err := client.UpdateConfig(context.Background(), cfg)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
@@ -157,20 +158,20 @@ func TestUpdateConfig(t *testing.T) {
|
||||
SiteName := th.App.Config().TeamSettings.SiteName
|
||||
|
||||
*cfg.TeamSettings.SiteName = "MyFancyName"
|
||||
cfg, _, err = client.UpdateConfig(cfg)
|
||||
cfg, _, err = client.UpdateConfig(context.Background(), cfg)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, "MyFancyName", *cfg.TeamSettings.SiteName, "It should update the SiteName")
|
||||
|
||||
//Revert the change
|
||||
cfg.TeamSettings.SiteName = SiteName
|
||||
cfg, _, err = client.UpdateConfig(cfg)
|
||||
cfg, _, err = client.UpdateConfig(context.Background(), cfg)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, SiteName, cfg.TeamSettings.SiteName, "It should update the SiteName")
|
||||
|
||||
t.Run("Should set defaults for missing fields", func(t *testing.T) {
|
||||
_, err = th.SystemAdminClient.DoAPIPut("/config", "{}")
|
||||
_, err = th.SystemAdminClient.DoAPIPut(context.Background(), "/config", "{}")
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
@@ -179,7 +180,7 @@ func TestUpdateConfig(t *testing.T) {
|
||||
badcfg := cfg.Clone()
|
||||
badcfg.PasswordSettings.MinimumLength = model.NewInt(4)
|
||||
badcfg.PasswordSettings.MinimumLength = model.NewInt(4)
|
||||
_, resp, err = client.UpdateConfig(badcfg)
|
||||
_, resp, err = client.UpdateConfig(context.Background(), badcfg)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
CheckErrorID(t, err, "model.config.is_valid.password_length.app_error")
|
||||
@@ -189,13 +190,13 @@ func TestUpdateConfig(t *testing.T) {
|
||||
oldEnableUploads := *th.App.Config().PluginSettings.EnableUploads
|
||||
*cfg.PluginSettings.EnableUploads = !oldEnableUploads
|
||||
|
||||
cfg, _, err = client.UpdateConfig(cfg)
|
||||
cfg, _, err = client.UpdateConfig(context.Background(), cfg)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, oldEnableUploads, *cfg.PluginSettings.EnableUploads)
|
||||
assert.Equal(t, oldEnableUploads, *th.App.Config().PluginSettings.EnableUploads)
|
||||
|
||||
cfg.PluginSettings.EnableUploads = nil
|
||||
cfg, _, err = client.UpdateConfig(cfg)
|
||||
cfg, _, err = client.UpdateConfig(context.Background(), cfg)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, oldEnableUploads, *cfg.PluginSettings.EnableUploads)
|
||||
assert.Equal(t, oldEnableUploads, *th.App.Config().PluginSettings.EnableUploads)
|
||||
@@ -205,13 +206,13 @@ func TestUpdateConfig(t *testing.T) {
|
||||
oldPublicKeys := th.App.Config().PluginSettings.SignaturePublicKeyFiles
|
||||
cfg.PluginSettings.SignaturePublicKeyFiles = append(cfg.PluginSettings.SignaturePublicKeyFiles, "new_signature")
|
||||
|
||||
cfg, _, err = client.UpdateConfig(cfg)
|
||||
cfg, _, err = client.UpdateConfig(context.Background(), cfg)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, oldPublicKeys, cfg.PluginSettings.SignaturePublicKeyFiles)
|
||||
assert.Equal(t, oldPublicKeys, th.App.Config().PluginSettings.SignaturePublicKeyFiles)
|
||||
|
||||
cfg.PluginSettings.SignaturePublicKeyFiles = nil
|
||||
cfg, _, err = client.UpdateConfig(cfg)
|
||||
cfg, _, err = client.UpdateConfig(context.Background(), cfg)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, oldPublicKeys, cfg.PluginSettings.SignaturePublicKeyFiles)
|
||||
assert.Equal(t, oldPublicKeys, th.App.Config().PluginSettings.SignaturePublicKeyFiles)
|
||||
@@ -229,7 +230,7 @@ func TestUpdateConfig(t *testing.T) {
|
||||
cfg2 := th.App.Config().Clone()
|
||||
*cfg2.PluginSettings.MarketplaceURL = newURL
|
||||
|
||||
cfg2, _, err = th.SystemAdminClient.UpdateConfig(cfg2)
|
||||
cfg2, _, err = th.SystemAdminClient.UpdateConfig(context.Background(), cfg2)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, oldURL, *cfg2.PluginSettings.MarketplaceURL)
|
||||
|
||||
@@ -242,7 +243,7 @@ func TestUpdateConfig(t *testing.T) {
|
||||
cfg2 = th.App.Config().Clone()
|
||||
*cfg2.PluginSettings.MarketplaceURL = newURL
|
||||
|
||||
cfg2, _, err = th.SystemAdminClient.UpdateConfig(cfg2)
|
||||
cfg2, _, err = th.SystemAdminClient.UpdateConfig(context.Background(), cfg2)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, newURL, *cfg2.PluginSettings.MarketplaceURL)
|
||||
})
|
||||
@@ -254,7 +255,7 @@ func TestUpdateConfig(t *testing.T) {
|
||||
cfg2 := th.App.Config().Clone()
|
||||
*cfg2.ComplianceSettings.Directory = "hellodir"
|
||||
|
||||
_, resp, err = th.SystemAdminClient.UpdateConfig(cfg2)
|
||||
_, resp, err = th.SystemAdminClient.UpdateConfig(context.Background(), cfg2)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
@@ -267,18 +268,18 @@ func TestUpdateConfig(t *testing.T) {
|
||||
cfg.ServiceSettings.SiteURL = &nonEmptyURL
|
||||
|
||||
// Set the SiteURL
|
||||
cfg, _, err = th.SystemAdminClient.UpdateConfig(cfg)
|
||||
cfg, _, err = th.SystemAdminClient.UpdateConfig(context.Background(), cfg)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, nonEmptyURL, *cfg.ServiceSettings.SiteURL)
|
||||
|
||||
// Check that the Site URL can't be cleared
|
||||
cfg.ServiceSettings.SiteURL = sToP("")
|
||||
cfg, resp, err = th.SystemAdminClient.UpdateConfig(cfg)
|
||||
cfg, resp, err = th.SystemAdminClient.UpdateConfig(context.Background(), cfg)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
CheckErrorID(t, err, "api.config.update_config.clear_siteurl.app_error")
|
||||
// Check that the Site URL wasn't cleared
|
||||
cfg, _, err = th.SystemAdminClient.GetConfig()
|
||||
cfg, _, err = th.SystemAdminClient.GetConfig(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, nonEmptyURL, *cfg.ServiceSettings.SiteURL)
|
||||
})
|
||||
@@ -287,17 +288,17 @@ func TestUpdateConfig(t *testing.T) {
|
||||
func TestGetConfigWithoutManageSystemPermission(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
th.Client.Login(th.BasicUser.Username, th.BasicUser.Password)
|
||||
th.Client.Login(context.Background(), th.BasicUser.Username, th.BasicUser.Password)
|
||||
|
||||
t.Run("any sysconsole read permission provides config read access", func(t *testing.T) {
|
||||
// forbidden by default
|
||||
_, resp, err := th.Client.GetConfig()
|
||||
_, resp, err := th.Client.GetConfig(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
// add any sysconsole read permission
|
||||
th.AddPermissionToRole(model.SysconsoleReadPermissions[0].Id, model.SystemUserRoleId)
|
||||
_, _, err = th.Client.GetConfig()
|
||||
_, _, err = th.Client.GetConfig(context.Background())
|
||||
// should be readable now
|
||||
require.NoError(t, err)
|
||||
})
|
||||
@@ -306,7 +307,7 @@ func TestGetConfigWithoutManageSystemPermission(t *testing.T) {
|
||||
func TestUpdateConfigWithoutManageSystemPermission(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
th.Client.Login(th.BasicUser.Username, th.BasicUser.Password)
|
||||
th.Client.Login(context.Background(), th.BasicUser.Username, th.BasicUser.Password)
|
||||
|
||||
// add read sysconsole integrations config
|
||||
th.AddPermissionToRole(model.PermissionSysconsoleReadIntegrationsIntegrationManagement.Id, model.SystemUserRoleId)
|
||||
@@ -314,17 +315,17 @@ func TestUpdateConfigWithoutManageSystemPermission(t *testing.T) {
|
||||
|
||||
t.Run("sysconsole read permission does not provides config write access", func(t *testing.T) {
|
||||
// should be readable because has a sysconsole read permission
|
||||
cfg, _, err := th.Client.GetConfig()
|
||||
cfg, _, err := th.Client.GetConfig(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
_, resp, err := th.Client.UpdateConfig(cfg)
|
||||
_, resp, err := th.Client.UpdateConfig(context.Background(), cfg)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("the wrong write permission does not grant access", func(t *testing.T) {
|
||||
// should be readable because has a sysconsole read permission
|
||||
cfg, _, err := th.SystemAdminClient.GetConfig()
|
||||
cfg, _, err := th.SystemAdminClient.GetConfig(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
originalValue := *cfg.ServiceSettings.AllowCorsFrom
|
||||
@@ -336,18 +337,18 @@ func TestUpdateConfigWithoutManageSystemPermission(t *testing.T) {
|
||||
// try update a config value allowed by sysconsole WRITE integrations
|
||||
mockVal := model.NewId()
|
||||
cfg.ServiceSettings.AllowCorsFrom = &mockVal
|
||||
_, _, err = th.Client.UpdateConfig(cfg)
|
||||
_, _, err = th.Client.UpdateConfig(context.Background(), cfg)
|
||||
require.NoError(t, err)
|
||||
|
||||
// ensure the config setting was not updated
|
||||
cfg, _, err = th.SystemAdminClient.GetConfig()
|
||||
cfg, _, err = th.SystemAdminClient.GetConfig(context.Background())
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, *cfg.ServiceSettings.AllowCorsFrom, originalValue)
|
||||
})
|
||||
|
||||
t.Run("config value is writeable by specific system console permission", func(t *testing.T) {
|
||||
// should be readable because has a sysconsole read permission
|
||||
cfg, _, err := th.SystemAdminClient.GetConfig()
|
||||
cfg, _, err := th.SystemAdminClient.GetConfig(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
th.AddPermissionToRole(model.PermissionSysconsoleWriteIntegrationsCors.Id, model.SystemUserRoleId)
|
||||
@@ -358,11 +359,11 @@ func TestUpdateConfigWithoutManageSystemPermission(t *testing.T) {
|
||||
// try update a config value allowed by sysconsole WRITE integrations
|
||||
mockVal := model.NewId()
|
||||
cfg.ServiceSettings.AllowCorsFrom = &mockVal
|
||||
_, _, err = th.Client.UpdateConfig(cfg)
|
||||
_, _, err = th.Client.UpdateConfig(context.Background(), cfg)
|
||||
require.NoError(t, err)
|
||||
|
||||
// ensure the config setting was updated
|
||||
cfg, _, err = th.Client.GetConfig()
|
||||
cfg, _, err = th.Client.GetConfig(context.Background())
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, *cfg.ServiceSettings.AllowCorsFrom, mockVal)
|
||||
})
|
||||
@@ -386,22 +387,22 @@ func TestUpdateConfigMessageExportSpecialHandling(t *testing.T) {
|
||||
})
|
||||
|
||||
// Turn it on, timestamp should be updated.
|
||||
cfg, _, err := th.SystemAdminClient.GetConfig()
|
||||
cfg, _, err := th.SystemAdminClient.GetConfig(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
*cfg.MessageExportSettings.EnableExport = true
|
||||
_, _, err = th.SystemAdminClient.UpdateConfig(cfg)
|
||||
_, _, err = th.SystemAdminClient.UpdateConfig(context.Background(), cfg)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.True(t, *th.App.Config().MessageExportSettings.EnableExport)
|
||||
assert.NotEqual(t, int64(0), *th.App.Config().MessageExportSettings.ExportFromTimestamp)
|
||||
|
||||
// Turn it off, timestamp should be cleared.
|
||||
cfg, _, err = th.SystemAdminClient.GetConfig()
|
||||
cfg, _, err = th.SystemAdminClient.GetConfig(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
*cfg.MessageExportSettings.EnableExport = false
|
||||
_, _, err = th.SystemAdminClient.UpdateConfig(cfg)
|
||||
_, _, err = th.SystemAdminClient.UpdateConfig(context.Background(), cfg)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.False(t, *th.App.Config().MessageExportSettings.EnableExport)
|
||||
@@ -414,22 +415,22 @@ func TestUpdateConfigMessageExportSpecialHandling(t *testing.T) {
|
||||
})
|
||||
|
||||
// Turn it on, timestamp should *not* be updated.
|
||||
cfg, _, err = th.SystemAdminClient.GetConfig()
|
||||
cfg, _, err = th.SystemAdminClient.GetConfig(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
*cfg.MessageExportSettings.EnableExport = true
|
||||
_, _, err = th.SystemAdminClient.UpdateConfig(cfg)
|
||||
_, _, err = th.SystemAdminClient.UpdateConfig(context.Background(), cfg)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.True(t, *th.App.Config().MessageExportSettings.EnableExport)
|
||||
assert.Equal(t, int64(12345), *th.App.Config().MessageExportSettings.ExportFromTimestamp)
|
||||
|
||||
// Turn it off, timestamp should be cleared.
|
||||
cfg, _, err = th.SystemAdminClient.GetConfig()
|
||||
cfg, _, err = th.SystemAdminClient.GetConfig(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
*cfg.MessageExportSettings.EnableExport = false
|
||||
_, _, err = th.SystemAdminClient.UpdateConfig(cfg)
|
||||
_, _, err = th.SystemAdminClient.UpdateConfig(context.Background(), cfg)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.False(t, *th.App.Config().MessageExportSettings.EnableExport)
|
||||
@@ -442,34 +443,34 @@ func TestUpdateConfigRestrictSystemAdmin(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ExperimentalSettings.RestrictSystemAdmin = true })
|
||||
|
||||
t.Run("Restrict flag should be honored for sysadmin", func(t *testing.T) {
|
||||
originalCfg, _, err := th.SystemAdminClient.GetConfig()
|
||||
originalCfg, _, err := th.SystemAdminClient.GetConfig(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
cfg := originalCfg.Clone()
|
||||
*cfg.TeamSettings.SiteName = "MyFancyName" // Allowed
|
||||
*cfg.ServiceSettings.SiteURL = "http://example.com" // Ignored
|
||||
|
||||
returnedCfg, _, err := th.SystemAdminClient.UpdateConfig(cfg)
|
||||
returnedCfg, _, err := th.SystemAdminClient.UpdateConfig(context.Background(), cfg)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, "MyFancyName", *returnedCfg.TeamSettings.SiteName)
|
||||
require.Equal(t, *originalCfg.ServiceSettings.SiteURL, *returnedCfg.ServiceSettings.SiteURL)
|
||||
|
||||
actualCfg, _, err := th.SystemAdminClient.GetConfig()
|
||||
actualCfg, _, err := th.SystemAdminClient.GetConfig(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, returnedCfg, actualCfg)
|
||||
})
|
||||
|
||||
t.Run("Restrict flag should be ignored by local mode", func(t *testing.T) {
|
||||
originalCfg, _, err := th.LocalClient.GetConfig()
|
||||
originalCfg, _, err := th.LocalClient.GetConfig(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
cfg := originalCfg.Clone()
|
||||
*cfg.TeamSettings.SiteName = "MyFancyName" // Allowed
|
||||
*cfg.ServiceSettings.SiteURL = "http://example.com" // Ignored
|
||||
|
||||
returnedCfg, _, err := th.LocalClient.UpdateConfig(cfg)
|
||||
returnedCfg, _, err := th.LocalClient.UpdateConfig(context.Background(), cfg)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, "MyFancyName", *returnedCfg.TeamSettings.SiteName)
|
||||
@@ -491,12 +492,12 @@ func TestUpdateConfigDiffInAuditRecord(t *testing.T) {
|
||||
th := SetupWithServerOptions(t, options)
|
||||
defer th.TearDown()
|
||||
|
||||
cfg, _, err := th.SystemAdminClient.GetConfig()
|
||||
cfg, _, err := th.SystemAdminClient.GetConfig(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
timeoutVal := *cfg.ServiceSettings.ReadTimeout
|
||||
cfg.ServiceSettings.ReadTimeout = model.NewInt(timeoutVal + 1)
|
||||
cfg, _, err = th.SystemAdminClient.UpdateConfig(cfg)
|
||||
cfg, _, err = th.SystemAdminClient.UpdateConfig(context.Background(), cfg)
|
||||
require.NoError(t, err)
|
||||
defer th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
cfg.ServiceSettings.ReadTimeout = model.NewInt(timeoutVal)
|
||||
@@ -530,7 +531,7 @@ func TestGetEnvironmentConfig(t *testing.T) {
|
||||
t.Run("as system admin", func(t *testing.T) {
|
||||
SystemAdminClient := th.SystemAdminClient
|
||||
|
||||
envConfig, _, err := SystemAdminClient.GetEnvironmentConfig()
|
||||
envConfig, _, err := SystemAdminClient.GetEnvironmentConfig(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
serviceSettings, ok := envConfig["ServiceSettings"]
|
||||
@@ -561,7 +562,7 @@ func TestGetEnvironmentConfig(t *testing.T) {
|
||||
TeamAdminClient := th.CreateClient()
|
||||
th.LoginTeamAdminWithClient(TeamAdminClient)
|
||||
|
||||
envConfig, _, err := TeamAdminClient.GetEnvironmentConfig()
|
||||
envConfig, _, err := TeamAdminClient.GetEnvironmentConfig(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, envConfig)
|
||||
})
|
||||
@@ -569,7 +570,7 @@ func TestGetEnvironmentConfig(t *testing.T) {
|
||||
t.Run("as regular user", func(t *testing.T) {
|
||||
client := th.Client
|
||||
|
||||
envConfig, _, err := client.GetEnvironmentConfig()
|
||||
envConfig, _, err := client.GetEnvironmentConfig(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, envConfig)
|
||||
})
|
||||
@@ -577,7 +578,7 @@ func TestGetEnvironmentConfig(t *testing.T) {
|
||||
t.Run("as not-regular user", func(t *testing.T) {
|
||||
client := th.CreateClient()
|
||||
|
||||
_, resp, err := client.GetEnvironmentConfig()
|
||||
_, resp, err := client.GetEnvironmentConfig(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
})
|
||||
@@ -597,7 +598,7 @@ func TestGetOldClientConfig(t *testing.T) {
|
||||
|
||||
client := th.Client
|
||||
|
||||
config, _, err := client.GetOldClientConfig("")
|
||||
config, _, err := client.GetOldClientConfig(context.Background(), "")
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NotEmpty(t, config["Version"], "config not returned correctly")
|
||||
@@ -611,7 +612,7 @@ func TestGetOldClientConfig(t *testing.T) {
|
||||
|
||||
client := th.CreateClient()
|
||||
|
||||
config, _, err := client.GetOldClientConfig("")
|
||||
config, _, err := client.GetOldClientConfig(context.Background(), "")
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NotEmpty(t, config["Version"], "config not returned correctly")
|
||||
@@ -621,7 +622,7 @@ func TestGetOldClientConfig(t *testing.T) {
|
||||
t.Run("missing format", func(t *testing.T) {
|
||||
client := th.Client
|
||||
|
||||
resp, err := client.DoAPIGet("/config/client", "")
|
||||
resp, err := client.DoAPIGet(context.Background(), "/config/client", "")
|
||||
require.Error(t, err)
|
||||
require.Equal(t, http.StatusNotImplemented, resp.StatusCode)
|
||||
})
|
||||
@@ -629,7 +630,7 @@ func TestGetOldClientConfig(t *testing.T) {
|
||||
t.Run("invalid format", func(t *testing.T) {
|
||||
client := th.Client
|
||||
|
||||
resp, err := client.DoAPIGet("/config/client?format=junk", "")
|
||||
resp, err := client.DoAPIGet(context.Background(), "/config/client?format=junk", "")
|
||||
require.Error(t, err)
|
||||
require.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
||||
})
|
||||
@@ -640,13 +641,13 @@ func TestPatchConfig(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
t.Run("config is missing", func(t *testing.T) {
|
||||
_, response, err := th.Client.PatchConfig(nil)
|
||||
_, response, err := th.Client.PatchConfig(context.Background(), nil)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, response)
|
||||
})
|
||||
|
||||
t.Run("user is not system admin", func(t *testing.T) {
|
||||
_, response, err := th.Client.PatchConfig(&model.Config{})
|
||||
_, response, err := th.Client.PatchConfig(context.Background(), &model.Config{})
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, response)
|
||||
})
|
||||
@@ -658,7 +659,7 @@ func TestPatchConfig(t *testing.T) {
|
||||
ConsoleLevel: model.NewString("INFO"),
|
||||
}}
|
||||
|
||||
updatedConfig, _, _ := th.SystemAdminClient.PatchConfig(&config)
|
||||
updatedConfig, _, _ := th.SystemAdminClient.PatchConfig(context.Background(), &config)
|
||||
|
||||
assert.Equal(t, "DEBUG", *updatedConfig.LogSettings.ConsoleLevel)
|
||||
})
|
||||
@@ -670,12 +671,12 @@ func TestPatchConfig(t *testing.T) {
|
||||
ConsoleLevel: model.NewString("INFO"),
|
||||
}}
|
||||
|
||||
oldConfig, _, _ := th.LocalClient.GetConfig()
|
||||
updatedConfig, _, _ := th.LocalClient.PatchConfig(&config)
|
||||
oldConfig, _, _ := th.LocalClient.GetConfig(context.Background())
|
||||
updatedConfig, _, _ := th.LocalClient.PatchConfig(context.Background(), &config)
|
||||
|
||||
assert.Equal(t, "INFO", *updatedConfig.LogSettings.ConsoleLevel)
|
||||
// reset the config
|
||||
_, _, err := th.LocalClient.UpdateConfig(oldConfig)
|
||||
_, _, err := th.LocalClient.UpdateConfig(context.Background(), oldConfig)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
@@ -685,7 +686,7 @@ func TestPatchConfig(t *testing.T) {
|
||||
MinimumLength: model.NewInt(4),
|
||||
}}
|
||||
|
||||
_, response, err := client.PatchConfig(&config)
|
||||
_, response, err := client.PatchConfig(context.Background(), &config)
|
||||
|
||||
assert.Equal(t, http.StatusBadRequest, response.StatusCode)
|
||||
assert.Error(t, err)
|
||||
@@ -696,7 +697,7 @@ func TestPatchConfig(t *testing.T) {
|
||||
*th.App.Config().ExperimentalSettings.RestrictSystemAdmin = false
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.ExperimentalDefaultChannels = []string{"some-channel"} })
|
||||
|
||||
oldConfig, _, err := client.GetConfig()
|
||||
oldConfig, _, err := client.GetConfig(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.False(t, *oldConfig.PasswordSettings.Lowercase)
|
||||
@@ -720,10 +721,10 @@ func TestPatchConfig(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
_, response, err := client.PatchConfig(&config)
|
||||
_, response, err := client.PatchConfig(context.Background(), &config)
|
||||
require.NoError(t, err)
|
||||
|
||||
updatedConfig, _, err := client.GetConfig()
|
||||
updatedConfig, _, err := client.GetConfig(context.Background())
|
||||
require.NoError(t, err)
|
||||
assert.True(t, *updatedConfig.PasswordSettings.Lowercase)
|
||||
assert.Equal(t, "INFO", *updatedConfig.LogSettings.ConsoleLevel)
|
||||
@@ -732,7 +733,7 @@ func TestPatchConfig(t *testing.T) {
|
||||
assert.Equal(t, "no-cache, no-store, must-revalidate", response.Header.Get("Cache-Control"))
|
||||
|
||||
// reset the config
|
||||
_, _, err = client.UpdateConfig(oldConfig)
|
||||
_, _, err = client.UpdateConfig(context.Background(), oldConfig)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
@@ -741,7 +742,7 @@ func TestPatchConfig(t *testing.T) {
|
||||
Symbol: model.NewBool(true),
|
||||
}}
|
||||
|
||||
updatedConfig, _, err := client.PatchConfig(&config)
|
||||
updatedConfig, _, err := client.PatchConfig(context.Background(), &config)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, model.FakeSetting, *updatedConfig.SqlSettings.DataSource)
|
||||
@@ -752,7 +753,7 @@ func TestPatchConfig(t *testing.T) {
|
||||
EnableUploads: model.NewBool(true),
|
||||
}}
|
||||
|
||||
updatedConfig, resp, err := client.PatchConfig(&config)
|
||||
updatedConfig, resp, err := client.PatchConfig(context.Background(), &config)
|
||||
if client == th.LocalClient {
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
@@ -775,7 +776,7 @@ func TestPatchConfig(t *testing.T) {
|
||||
cfg := th.App.Config().Clone()
|
||||
*cfg.PluginSettings.MarketplaceURL = newURL
|
||||
|
||||
_, _, err := th.SystemAdminClient.PatchConfig(cfg)
|
||||
_, _, err := th.SystemAdminClient.PatchConfig(context.Background(), cfg)
|
||||
require.Error(t, err)
|
||||
|
||||
// Allowing uploads
|
||||
@@ -787,13 +788,13 @@ func TestPatchConfig(t *testing.T) {
|
||||
cfg = th.App.Config().Clone()
|
||||
*cfg.PluginSettings.MarketplaceURL = newURL
|
||||
|
||||
cfg, _, err = th.SystemAdminClient.PatchConfig(cfg)
|
||||
cfg, _, err = th.SystemAdminClient.PatchConfig(context.Background(), cfg)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, newURL, *cfg.PluginSettings.MarketplaceURL)
|
||||
})
|
||||
|
||||
t.Run("System Admin should not be able to clear Site URL", func(t *testing.T) {
|
||||
cfg, _, err := th.SystemAdminClient.GetConfig()
|
||||
cfg, _, err := th.SystemAdminClient.GetConfig(context.Background())
|
||||
require.NoError(t, err)
|
||||
siteURL := cfg.ServiceSettings.SiteURL
|
||||
defer th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.SiteURL = siteURL })
|
||||
@@ -805,7 +806,7 @@ func TestPatchConfig(t *testing.T) {
|
||||
SiteURL: model.NewString(nonEmptyURL),
|
||||
},
|
||||
}
|
||||
updatedConfig, _, err := th.SystemAdminClient.PatchConfig(&config)
|
||||
updatedConfig, _, err := th.SystemAdminClient.PatchConfig(context.Background(), &config)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, nonEmptyURL, *updatedConfig.ServiceSettings.SiteURL)
|
||||
|
||||
@@ -815,18 +816,18 @@ func TestPatchConfig(t *testing.T) {
|
||||
SiteURL: model.NewString(""),
|
||||
},
|
||||
}
|
||||
_, resp, err := th.SystemAdminClient.PatchConfig(&config)
|
||||
_, resp, err := th.SystemAdminClient.PatchConfig(context.Background(), &config)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
CheckErrorID(t, err, "api.config.update_config.clear_siteurl.app_error")
|
||||
|
||||
// Check that the Site URL wasn't cleared
|
||||
cfg, _, err = th.SystemAdminClient.GetConfig()
|
||||
cfg, _, err = th.SystemAdminClient.GetConfig(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, nonEmptyURL, *cfg.ServiceSettings.SiteURL)
|
||||
|
||||
// Check that sending an empty config returns no error.
|
||||
_, _, err = th.SystemAdminClient.PatchConfig(&model.Config{})
|
||||
_, _, err = th.SystemAdminClient.PatchConfig(context.Background(), &model.Config{})
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
@@ -855,7 +856,7 @@ func TestMigrateConfig(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
defer f.RemoveFile("to.json")
|
||||
|
||||
_, err = th.LocalClient.MigrateConfig("from.json", "to.json")
|
||||
_, err = th.LocalClient.MigrateConfig(context.Background(), "from.json", "to.json")
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -13,7 +14,7 @@ func TestDataRetentionGetPolicy(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
_, resp, err := th.Client.GetDataRetentionPolicy()
|
||||
_, resp, err := th.Client.GetDataRetentionPolicy(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
@@ -40,7 +41,7 @@ func TestUpsertDraft(t *testing.T) {
|
||||
}
|
||||
|
||||
// try to upsert draft
|
||||
draftResp, _, err := client.UpsertDraft(draft)
|
||||
draftResp, _, err := client.UpsertDraft(context.Background(), draft)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, draft.UserId, draftResp.UserId)
|
||||
@@ -51,14 +52,14 @@ func TestUpsertDraft(t *testing.T) {
|
||||
sent, err := testutils.ReadTestFile("test.png")
|
||||
require.NoError(t, err)
|
||||
|
||||
fileResp, _, err := client.UploadFile(sent, channel.Id, "test.png")
|
||||
fileResp, _, err := client.UploadFile(context.Background(), sent, channel.Id, "test.png")
|
||||
require.NoError(t, err)
|
||||
|
||||
draftWithFiles := draft
|
||||
draftWithFiles.FileIds = []string{fileResp.FileInfos[0].Id}
|
||||
|
||||
// try to upsert draft with file
|
||||
draftResp, _, err = client.UpsertDraft(draftWithFiles)
|
||||
draftResp, _, err = client.UpsertDraft(context.Background(), draftWithFiles)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, draftWithFiles.UserId, draftResp.UserId)
|
||||
@@ -70,7 +71,7 @@ func TestUpsertDraft(t *testing.T) {
|
||||
draftInvalidChannel := draft
|
||||
draftInvalidChannel.ChannelId = "12345"
|
||||
|
||||
_, resp, err := client.UpsertDraft(draft)
|
||||
_, resp, err := client.UpsertDraft(context.Background(), draft)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
@@ -79,7 +80,7 @@ func TestUpsertDraft(t *testing.T) {
|
||||
defer os.Unsetenv("MM_SERVICESETTINGS_ALLOWSYNCEDDRAFTS")
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowSyncedDrafts = false })
|
||||
|
||||
_, resp, err = client.UpsertDraft(draft)
|
||||
_, resp, err = client.UpsertDraft(context.Background(), draft)
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
}
|
||||
@@ -122,15 +123,15 @@ func TestGetDrafts(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowSyncedDrafts = true })
|
||||
|
||||
// upsert draft1
|
||||
_, _, err := client.UpsertDraft(draft1)
|
||||
_, _, err := client.UpsertDraft(context.Background(), draft1)
|
||||
require.NoError(t, err)
|
||||
|
||||
// upsert draft2
|
||||
_, _, err = client.UpsertDraft(draft2)
|
||||
_, _, err = client.UpsertDraft(context.Background(), draft2)
|
||||
require.NoError(t, err)
|
||||
|
||||
// try to get drafts
|
||||
draftResp, _, err := client.GetDrafts(user.Id, team.Id)
|
||||
draftResp, _, err := client.GetDrafts(context.Background(), user.Id, team.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, draft2.UserId, draftResp[0].UserId)
|
||||
@@ -144,7 +145,7 @@ func TestGetDrafts(t *testing.T) {
|
||||
assert.Len(t, draftResp, 2)
|
||||
|
||||
// try to get drafts on invalid team
|
||||
_, resp, err := client.GetDrafts(user.Id, "12345")
|
||||
_, resp, err := client.GetDrafts(context.Background(), user.Id, "12345")
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
@@ -152,7 +153,7 @@ func TestGetDrafts(t *testing.T) {
|
||||
os.Setenv("MM_SERVICESETTINGS_ALLOWSYNCEDDRAFTS", "false")
|
||||
defer os.Unsetenv("MM_SERVICESETTINGS_ALLOWSYNCEDDRAFTS")
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowSyncedDrafts = false })
|
||||
_, resp, err = client.GetDrafts(user.Id, team.Id)
|
||||
_, resp, err = client.GetDrafts(context.Background(), user.Id, team.Id)
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
}
|
||||
@@ -194,15 +195,15 @@ func TestDeleteDraft(t *testing.T) {
|
||||
}
|
||||
|
||||
// upsert draft1
|
||||
_, _, err := client.UpsertDraft(draft1)
|
||||
_, _, err := client.UpsertDraft(context.Background(), draft1)
|
||||
require.NoError(t, err)
|
||||
|
||||
// upsert draft2
|
||||
_, _, err = client.UpsertDraft(draft2)
|
||||
_, _, err = client.UpsertDraft(context.Background(), draft2)
|
||||
require.NoError(t, err)
|
||||
|
||||
//get drafts
|
||||
draftResp, _, err := client.GetDrafts(user.Id, team.Id)
|
||||
draftResp, _, err := client.GetDrafts(context.Background(), user.Id, team.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, draft2.UserId, draftResp[0].UserId)
|
||||
@@ -214,11 +215,11 @@ func TestDeleteDraft(t *testing.T) {
|
||||
assert.Equal(t, draft1.ChannelId, draftResp[1].ChannelId)
|
||||
|
||||
// try to delete draft1
|
||||
_, _, err = client.DeleteDraft(user.Id, channel1.Id, draft1.RootId)
|
||||
_, _, err = client.DeleteDraft(context.Background(), user.Id, channel1.Id, draft1.RootId)
|
||||
require.NoError(t, err)
|
||||
|
||||
//get drafts
|
||||
draftResp, _, err = client.GetDrafts(user.Id, team.Id)
|
||||
draftResp, _, err = client.GetDrafts(context.Background(), user.Id, team.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, draft2.UserId, draftResp[0].UserId)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"testing"
|
||||
@@ -18,13 +19,13 @@ func TestElasticsearchTest(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
t.Run("as system user", func(t *testing.T) {
|
||||
resp, err := th.Client.TestElasticsearch()
|
||||
resp, err := th.Client.TestElasticsearch(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("as system admin", func(t *testing.T) {
|
||||
resp, err := th.SystemAdminClient.TestElasticsearch()
|
||||
resp, err := th.SystemAdminClient.TestElasticsearch(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
})
|
||||
@@ -37,7 +38,7 @@ func TestElasticsearchTest(t *testing.T) {
|
||||
data, err := json.Marshal(cfg)
|
||||
require.NoError(t, err)
|
||||
|
||||
resp, err := th.SystemAdminClient.DoAPIPost("/elasticsearch/test", string(data))
|
||||
resp, err := th.SystemAdminClient.DoAPIPost(context.Background(), "/elasticsearch/test", string(data))
|
||||
require.Error(t, err)
|
||||
require.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
||||
})
|
||||
@@ -48,7 +49,7 @@ func TestElasticsearchTest(t *testing.T) {
|
||||
*cfg.ExperimentalSettings.RestrictSystemAdmin = true
|
||||
})
|
||||
|
||||
resp, err := th.SystemAdminClient.TestElasticsearch()
|
||||
resp, err := th.SystemAdminClient.TestElasticsearch(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
@@ -59,13 +60,13 @@ func TestElasticsearchPurgeIndexes(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
t.Run("as system user", func(t *testing.T) {
|
||||
resp, err := th.Client.PurgeElasticsearchIndexes()
|
||||
resp, err := th.Client.PurgeElasticsearchIndexes(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("as system admin", func(t *testing.T) {
|
||||
resp, err := th.SystemAdminClient.PurgeElasticsearchIndexes()
|
||||
resp, err := th.SystemAdminClient.PurgeElasticsearchIndexes(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
})
|
||||
@@ -73,7 +74,7 @@ func TestElasticsearchPurgeIndexes(t *testing.T) {
|
||||
t.Run("as restricted system admin", func(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ExperimentalSettings.RestrictSystemAdmin = true })
|
||||
|
||||
resp, err := th.SystemAdminClient.PurgeElasticsearchIndexes()
|
||||
resp, err := th.SystemAdminClient.PurgeElasticsearchIndexes(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
@@ -5,6 +5,7 @@ package api4
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"image"
|
||||
_ "image/gif"
|
||||
"os"
|
||||
@@ -58,7 +59,7 @@ func TestCreateEmoji(t *testing.T) {
|
||||
}
|
||||
|
||||
// try to create an emoji when they're disabled
|
||||
_, resp, err := client.CreateEmoji(emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
_, resp, err := client.CreateEmoji(context.Background(), emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
|
||||
@@ -66,7 +67,7 @@ func TestCreateEmoji(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCustomEmoji = true })
|
||||
|
||||
// try to create a valid gif emoji when they're enabled
|
||||
newEmoji, _, err := client.CreateEmoji(emoji, utils.CreateTestGif(t, emojiWidth, emojiHeight), "image.gif")
|
||||
newEmoji, _, err := client.CreateEmoji(context.Background(), emoji, utils.CreateTestGif(t, emojiWidth, emojiHeight), "image.gif")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, newEmoji.Name, emoji.Name, "create with wrong name")
|
||||
checkEmojiFile(newEmoji.Id, "gif")
|
||||
@@ -76,7 +77,7 @@ func TestCreateEmoji(t *testing.T) {
|
||||
CreatorId: th.BasicUser.Id,
|
||||
Name: newEmoji.Name,
|
||||
}
|
||||
_, resp, err = client.CreateEmoji(emoji2, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
_, resp, err = client.CreateEmoji(context.Background(), emoji2, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
CheckErrorID(t, err, "api.emoji.create.duplicate.app_error")
|
||||
@@ -87,7 +88,7 @@ func TestCreateEmoji(t *testing.T) {
|
||||
Name: model.NewId(),
|
||||
}
|
||||
|
||||
newEmoji, _, err = client.CreateEmoji(emoji, utils.CreateTestAnimatedGif(t, emojiWidth, emojiHeight, 10), "image.gif")
|
||||
newEmoji, _, err = client.CreateEmoji(context.Background(), emoji, utils.CreateTestAnimatedGif(t, emojiWidth, emojiHeight, 10), "image.gif")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, newEmoji.Name, emoji.Name, "create with wrong name")
|
||||
checkEmojiFile(newEmoji.Id, "gif")
|
||||
@@ -101,7 +102,7 @@ func TestCreateEmoji(t *testing.T) {
|
||||
path, _ := fileutils.FindDir("tests")
|
||||
bytes, err := os.ReadFile(filepath.Join(path, "testwebp.webp"))
|
||||
require.NoError(t, err)
|
||||
newEmoji, _, err = client.CreateEmoji(emoji, bytes, "image.webp")
|
||||
newEmoji, _, err = client.CreateEmoji(context.Background(), emoji, bytes, "image.webp")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, newEmoji.Name, emoji.Name, "create with wrong name")
|
||||
checkEmojiFile(newEmoji.Id, "png") // emoji must be converted from webp to png
|
||||
@@ -112,7 +113,7 @@ func TestCreateEmoji(t *testing.T) {
|
||||
Name: model.NewId(),
|
||||
}
|
||||
|
||||
newEmoji, _, err = client.CreateEmoji(emoji, utils.CreateTestJpeg(t, emojiWidth, emojiHeight), "image.jpeg")
|
||||
newEmoji, _, err = client.CreateEmoji(context.Background(), emoji, utils.CreateTestJpeg(t, emojiWidth, emojiHeight), "image.jpeg")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, newEmoji.Name, emoji.Name, "create with wrong name")
|
||||
checkEmojiFile(newEmoji.Id, "png") // emoji must be converted from jpeg to png
|
||||
@@ -123,7 +124,7 @@ func TestCreateEmoji(t *testing.T) {
|
||||
Name: model.NewId(),
|
||||
}
|
||||
|
||||
newEmoji, _, err = client.CreateEmoji(emoji, utils.CreateTestPng(t, emojiWidth, emojiHeight), "image.png")
|
||||
newEmoji, _, err = client.CreateEmoji(context.Background(), emoji, utils.CreateTestPng(t, emojiWidth, emojiHeight), "image.png")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, newEmoji.Name, emoji.Name, "create with wrong name")
|
||||
checkEmojiFile(newEmoji.Id, "png")
|
||||
@@ -134,7 +135,7 @@ func TestCreateEmoji(t *testing.T) {
|
||||
Name: model.NewId(),
|
||||
}
|
||||
|
||||
newEmoji, _, err = client.CreateEmoji(emoji, utils.CreateTestGif(t, 1000, 10), "image.gif")
|
||||
newEmoji, _, err = client.CreateEmoji(context.Background(), emoji, utils.CreateTestGif(t, 1000, 10), "image.gif")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, newEmoji.Name, emoji.Name, "create with wrong name")
|
||||
|
||||
@@ -144,7 +145,7 @@ func TestCreateEmoji(t *testing.T) {
|
||||
Name: model.NewId(),
|
||||
}
|
||||
|
||||
_, _, err = client.CreateEmoji(emoji, utils.CreateTestGif(t, 10, app.MaxEmojiOriginalWidth+1), "image.gif")
|
||||
_, _, err = client.CreateEmoji(context.Background(), emoji, utils.CreateTestGif(t, 10, app.MaxEmojiOriginalWidth+1), "image.gif")
|
||||
require.Error(t, err, "should fail - emoji is too wide")
|
||||
|
||||
// try to create an emoji that's too tall
|
||||
@@ -153,7 +154,7 @@ func TestCreateEmoji(t *testing.T) {
|
||||
Name: model.NewId(),
|
||||
}
|
||||
|
||||
_, _, err = client.CreateEmoji(emoji, utils.CreateTestGif(t, app.MaxEmojiOriginalHeight+1, 10), "image.gif")
|
||||
_, _, err = client.CreateEmoji(context.Background(), emoji, utils.CreateTestGif(t, app.MaxEmojiOriginalHeight+1, 10), "image.gif")
|
||||
require.Error(t, err, "should fail - emoji is too tall")
|
||||
|
||||
// try to create an emoji that's too large
|
||||
@@ -162,7 +163,7 @@ func TestCreateEmoji(t *testing.T) {
|
||||
Name: model.NewId(),
|
||||
}
|
||||
|
||||
_, _, err = client.CreateEmoji(emoji, utils.CreateTestAnimatedGif(t, 100, 100, 10000), "image.gif")
|
||||
_, _, err = client.CreateEmoji(context.Background(), emoji, utils.CreateTestAnimatedGif(t, 100, 100, 10000), "image.gif")
|
||||
require.Error(t, err, "should fail - emoji is too big")
|
||||
|
||||
// try to create an emoji with data that isn't an image
|
||||
@@ -171,7 +172,7 @@ func TestCreateEmoji(t *testing.T) {
|
||||
Name: model.NewId(),
|
||||
}
|
||||
|
||||
_, resp, err = client.CreateEmoji(emoji, make([]byte, 100), "image.gif")
|
||||
_, resp, err = client.CreateEmoji(context.Background(), emoji, make([]byte, 100), "image.gif")
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
CheckErrorID(t, err, "api.emoji.upload.image.app_error")
|
||||
@@ -182,7 +183,7 @@ func TestCreateEmoji(t *testing.T) {
|
||||
Name: model.NewId(),
|
||||
}
|
||||
|
||||
_, resp, err = client.CreateEmoji(emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
_, resp, err = client.CreateEmoji(context.Background(), emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
@@ -194,7 +195,7 @@ func TestCreateEmoji(t *testing.T) {
|
||||
Name: model.NewId(),
|
||||
}
|
||||
|
||||
_, resp, err = client.CreateEmoji(emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
_, resp, err = client.CreateEmoji(context.Background(), emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
@@ -206,7 +207,7 @@ func TestCreateEmoji(t *testing.T) {
|
||||
Name: model.NewId(),
|
||||
}
|
||||
|
||||
_, _, err = client.CreateEmoji(emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
_, _, err = client.CreateEmoji(context.Background(), emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -237,12 +238,12 @@ func TestGetEmojiList(t *testing.T) {
|
||||
}
|
||||
|
||||
for idx, emoji := range emojis {
|
||||
newEmoji, _, err := client.CreateEmoji(emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
newEmoji, _, err := client.CreateEmoji(context.Background(), emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
require.NoError(t, err)
|
||||
emojis[idx] = newEmoji
|
||||
}
|
||||
|
||||
listEmoji, _, err := client.GetEmojiList(0, 100)
|
||||
listEmoji, _, err := client.GetEmojiList(context.Background(), 0, 100)
|
||||
require.NoError(t, err)
|
||||
for _, emoji := range emojis {
|
||||
found := false
|
||||
@@ -255,9 +256,9 @@ func TestGetEmojiList(t *testing.T) {
|
||||
require.Truef(t, found, "failed to get emoji with id %v, %v", emoji.Id, len(listEmoji))
|
||||
}
|
||||
|
||||
_, err = client.DeleteEmoji(emojis[0].Id)
|
||||
_, err = client.DeleteEmoji(context.Background(), emojis[0].Id)
|
||||
require.NoError(t, err)
|
||||
listEmoji, _, err = client.GetEmojiList(0, 100)
|
||||
listEmoji, _, err = client.GetEmojiList(context.Background(), 0, 100)
|
||||
require.NoError(t, err)
|
||||
found := false
|
||||
for _, savedEmoji := range listEmoji {
|
||||
@@ -268,12 +269,12 @@ func TestGetEmojiList(t *testing.T) {
|
||||
}
|
||||
require.Falsef(t, found, "should not get a deleted emoji %v", emojis[0].Id)
|
||||
|
||||
listEmoji, _, err = client.GetEmojiList(0, 1)
|
||||
listEmoji, _, err = client.GetEmojiList(context.Background(), 0, 1)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, listEmoji, 1, "should only return 1")
|
||||
|
||||
listEmoji, _, err = client.GetSortedEmojiList(0, 100, model.EmojiSortByName)
|
||||
listEmoji, _, err = client.GetSortedEmojiList(context.Background(), 0, 100, model.EmojiSortByName)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Greater(t, len(listEmoji), 0, "should return more than 0")
|
||||
@@ -300,46 +301,46 @@ func TestDeleteEmoji(t *testing.T) {
|
||||
Name: model.NewId(),
|
||||
}
|
||||
|
||||
newEmoji, _, err := client.CreateEmoji(emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
newEmoji, _, err := client.CreateEmoji(context.Background(), emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = client.DeleteEmoji(newEmoji.Id)
|
||||
_, err = client.DeleteEmoji(context.Background(), newEmoji.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, err = client.GetEmoji(newEmoji.Id)
|
||||
_, _, err = client.GetEmoji(context.Background(), newEmoji.Id)
|
||||
require.Error(t, err, "expected error fetching deleted emoji")
|
||||
|
||||
//Admin can delete other users emoji
|
||||
newEmoji, _, err = client.CreateEmoji(emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
newEmoji, _, err = client.CreateEmoji(context.Background(), emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = th.SystemAdminClient.DeleteEmoji(newEmoji.Id)
|
||||
_, err = th.SystemAdminClient.DeleteEmoji(context.Background(), newEmoji.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, err = th.SystemAdminClient.GetEmoji(newEmoji.Id)
|
||||
_, _, err = th.SystemAdminClient.GetEmoji(context.Background(), newEmoji.Id)
|
||||
require.Error(t, err, "expected error fetching deleted emoji")
|
||||
|
||||
// Try to delete just deleted emoji
|
||||
resp, err := client.DeleteEmoji(newEmoji.Id)
|
||||
resp, err := client.DeleteEmoji(context.Background(), newEmoji.Id)
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
//Try to delete non-existing emoji
|
||||
resp, err = client.DeleteEmoji(model.NewId())
|
||||
resp, err = client.DeleteEmoji(context.Background(), model.NewId())
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
//Try to delete without Id
|
||||
resp, err = client.DeleteEmoji("")
|
||||
resp, err = client.DeleteEmoji(context.Background(), "")
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
//Try to delete my custom emoji without permissions
|
||||
newEmoji, _, err = client.CreateEmoji(emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
newEmoji, _, err = client.CreateEmoji(context.Background(), emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
require.NoError(t, err)
|
||||
|
||||
th.RemovePermissionFromRole(model.PermissionDeleteEmojis.Id, model.SystemUserRoleId)
|
||||
resp, err = client.DeleteEmoji(newEmoji.Id)
|
||||
resp, err = client.DeleteEmoji(context.Background(), newEmoji.Id)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
th.AddPermissionToRole(model.PermissionDeleteEmojis.Id, model.SystemUserRoleId)
|
||||
@@ -350,23 +351,23 @@ func TestDeleteEmoji(t *testing.T) {
|
||||
Name: model.NewId(),
|
||||
}
|
||||
|
||||
newEmoji, _, err = client.CreateEmoji(emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
newEmoji, _, err = client.CreateEmoji(context.Background(), emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
require.NoError(t, err)
|
||||
|
||||
th.RemovePermissionFromRole(model.PermissionDeleteEmojis.Id, model.SystemUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionDeleteOthersEmojis.Id, model.SystemUserRoleId)
|
||||
|
||||
client.Logout()
|
||||
client.Logout(context.Background())
|
||||
th.LoginBasic2()
|
||||
|
||||
resp, err = client.DeleteEmoji(newEmoji.Id)
|
||||
resp, err = client.DeleteEmoji(context.Background(), newEmoji.Id)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
th.RemovePermissionFromRole(model.PermissionDeleteOthersEmojis.Id, model.SystemUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionDeleteEmojis.Id, model.SystemUserRoleId)
|
||||
|
||||
client.Logout()
|
||||
client.Logout(context.Background())
|
||||
th.LoginBasic()
|
||||
|
||||
//Try to delete other user's custom emoji without DELETE_OTHERS_EMOJIS permissions
|
||||
@@ -375,17 +376,17 @@ func TestDeleteEmoji(t *testing.T) {
|
||||
Name: model.NewId(),
|
||||
}
|
||||
|
||||
newEmoji, _, err = client.CreateEmoji(emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
newEmoji, _, err = client.CreateEmoji(context.Background(), emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
require.NoError(t, err)
|
||||
|
||||
client.Logout()
|
||||
client.Logout(context.Background())
|
||||
th.LoginBasic2()
|
||||
|
||||
resp, err = client.DeleteEmoji(newEmoji.Id)
|
||||
resp, err = client.DeleteEmoji(context.Background(), newEmoji.Id)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
client.Logout()
|
||||
client.Logout(context.Background())
|
||||
th.LoginBasic()
|
||||
|
||||
//Try to delete other user's custom emoji with permissions
|
||||
@@ -394,28 +395,28 @@ func TestDeleteEmoji(t *testing.T) {
|
||||
Name: model.NewId(),
|
||||
}
|
||||
|
||||
newEmoji, _, err = client.CreateEmoji(emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
newEmoji, _, err = client.CreateEmoji(context.Background(), emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
require.NoError(t, err)
|
||||
|
||||
th.AddPermissionToRole(model.PermissionDeleteEmojis.Id, model.SystemUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionDeleteOthersEmojis.Id, model.SystemUserRoleId)
|
||||
|
||||
client.Logout()
|
||||
client.Logout(context.Background())
|
||||
th.LoginBasic2()
|
||||
|
||||
_, err = client.DeleteEmoji(newEmoji.Id)
|
||||
_, err = client.DeleteEmoji(context.Background(), newEmoji.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
client.Logout()
|
||||
client.Logout(context.Background())
|
||||
th.LoginBasic()
|
||||
|
||||
//Try to delete my custom emoji with permissions at team level
|
||||
newEmoji, _, err = client.CreateEmoji(emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
newEmoji, _, err = client.CreateEmoji(context.Background(), emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
require.NoError(t, err)
|
||||
|
||||
th.RemovePermissionFromRole(model.PermissionDeleteEmojis.Id, model.SystemUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionDeleteEmojis.Id, model.TeamUserRoleId)
|
||||
_, err = client.DeleteEmoji(newEmoji.Id)
|
||||
_, err = client.DeleteEmoji(context.Background(), newEmoji.Id)
|
||||
require.NoError(t, err)
|
||||
th.AddPermissionToRole(model.PermissionDeleteEmojis.Id, model.SystemUserRoleId)
|
||||
th.RemovePermissionFromRole(model.PermissionDeleteEmojis.Id, model.TeamUserRoleId)
|
||||
@@ -426,7 +427,7 @@ func TestDeleteEmoji(t *testing.T) {
|
||||
Name: model.NewId(),
|
||||
}
|
||||
|
||||
newEmoji, _, err = client.CreateEmoji(emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
newEmoji, _, err = client.CreateEmoji(context.Background(), emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
require.NoError(t, err)
|
||||
|
||||
th.RemovePermissionFromRole(model.PermissionDeleteEmojis.Id, model.SystemUserRoleId)
|
||||
@@ -435,10 +436,10 @@ func TestDeleteEmoji(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionDeleteEmojis.Id, model.TeamUserRoleId)
|
||||
th.AddPermissionToRole(model.PermissionDeleteOthersEmojis.Id, model.TeamUserRoleId)
|
||||
|
||||
client.Logout()
|
||||
client.Logout(context.Background())
|
||||
th.LoginBasic2()
|
||||
|
||||
_, err = client.DeleteEmoji(newEmoji.Id)
|
||||
_, err = client.DeleteEmoji(context.Background(), newEmoji.Id)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -458,14 +459,14 @@ func TestGetEmoji(t *testing.T) {
|
||||
Name: model.NewId(),
|
||||
}
|
||||
|
||||
newEmoji, _, err := client.CreateEmoji(emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
newEmoji, _, err := client.CreateEmoji(context.Background(), emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
require.NoError(t, err)
|
||||
|
||||
emoji, _, err = client.GetEmoji(newEmoji.Id)
|
||||
emoji, _, err = client.GetEmoji(context.Background(), newEmoji.Id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, newEmoji.Id, emoji.Id, "wrong emoji was returned")
|
||||
|
||||
_, resp, err := client.GetEmoji(model.NewId())
|
||||
_, resp, err := client.GetEmoji(context.Background(), model.NewId())
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
}
|
||||
@@ -482,19 +483,19 @@ func TestGetEmojiByName(t *testing.T) {
|
||||
Name: model.NewId(),
|
||||
}
|
||||
|
||||
newEmoji, _, err := client.CreateEmoji(emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
newEmoji, _, err := client.CreateEmoji(context.Background(), emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
require.NoError(t, err)
|
||||
|
||||
emoji, _, err = client.GetEmojiByName(newEmoji.Name)
|
||||
emoji, _, err = client.GetEmojiByName(context.Background(), newEmoji.Name)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, newEmoji.Name, emoji.Name)
|
||||
|
||||
_, resp, err := client.GetEmojiByName(model.NewId())
|
||||
_, resp, err := client.GetEmojiByName(context.Background(), model.NewId())
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
client.Logout()
|
||||
_, resp, err = client.GetEmojiByName(newEmoji.Name)
|
||||
client.Logout(context.Background())
|
||||
_, resp, err = client.GetEmojiByName(context.Background(), newEmoji.Name)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
}
|
||||
@@ -511,12 +512,12 @@ func TestGetEmojiImage(t *testing.T) {
|
||||
Name: model.NewId(),
|
||||
}
|
||||
|
||||
emoji1, _, err := client.CreateEmoji(emoji1, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
emoji1, _, err := client.CreateEmoji(context.Background(), emoji1, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
require.NoError(t, err)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCustomEmoji = false })
|
||||
|
||||
_, resp, err := client.GetEmojiImage(emoji1.Id)
|
||||
_, resp, err := client.GetEmojiImage(context.Background(), emoji1.Id)
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
CheckErrorID(t, err, "api.emoji.disabled.app_error")
|
||||
@@ -524,7 +525,7 @@ func TestGetEmojiImage(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCustomEmoji = true })
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.DriverName = "local" })
|
||||
|
||||
emojiImage, _, err := client.GetEmojiImage(emoji1.Id)
|
||||
emojiImage, _, err := client.GetEmojiImage(context.Background(), emoji1.Id)
|
||||
require.NoError(t, err)
|
||||
require.Greater(t, len(emojiImage), 0, "should return the image")
|
||||
|
||||
@@ -537,10 +538,10 @@ func TestGetEmojiImage(t *testing.T) {
|
||||
Name: model.NewId(),
|
||||
}
|
||||
|
||||
emoji2, _, err = client.CreateEmoji(emoji2, utils.CreateTestAnimatedGif(t, 10, 10, 10), "image.gif")
|
||||
emoji2, _, err = client.CreateEmoji(context.Background(), emoji2, utils.CreateTestAnimatedGif(t, 10, 10, 10), "image.gif")
|
||||
require.NoError(t, err)
|
||||
|
||||
emojiImage, _, err = client.GetEmojiImage(emoji2.Id)
|
||||
emojiImage, _, err = client.GetEmojiImage(context.Background(), emoji2.Id)
|
||||
require.NoError(t, err)
|
||||
require.Greater(t, len(emojiImage), 0, "no image returned")
|
||||
|
||||
@@ -552,10 +553,10 @@ func TestGetEmojiImage(t *testing.T) {
|
||||
CreatorId: th.BasicUser.Id,
|
||||
Name: model.NewId(),
|
||||
}
|
||||
emoji3, _, err = client.CreateEmoji(emoji3, utils.CreateTestJpeg(t, 10, 10), "image.jpg")
|
||||
emoji3, _, err = client.CreateEmoji(context.Background(), emoji3, utils.CreateTestJpeg(t, 10, 10), "image.jpg")
|
||||
require.NoError(t, err)
|
||||
|
||||
emojiImage, _, err = client.GetEmojiImage(emoji3.Id)
|
||||
emojiImage, _, err = client.GetEmojiImage(context.Background(), emoji3.Id)
|
||||
require.NoError(t, err)
|
||||
require.Greater(t, len(emojiImage), 0, "no image returned")
|
||||
|
||||
@@ -567,10 +568,10 @@ func TestGetEmojiImage(t *testing.T) {
|
||||
CreatorId: th.BasicUser.Id,
|
||||
Name: model.NewId(),
|
||||
}
|
||||
emoji4, _, err = client.CreateEmoji(emoji4, utils.CreateTestPng(t, 10, 10), "image.png")
|
||||
emoji4, _, err = client.CreateEmoji(context.Background(), emoji4, utils.CreateTestPng(t, 10, 10), "image.png")
|
||||
require.NoError(t, err)
|
||||
|
||||
emojiImage, _, err = client.GetEmojiImage(emoji4.Id)
|
||||
emojiImage, _, err = client.GetEmojiImage(context.Background(), emoji4.Id)
|
||||
require.NoError(t, err)
|
||||
require.Greater(t, len(emojiImage), 0, "no image returned")
|
||||
|
||||
@@ -578,18 +579,18 @@ func TestGetEmojiImage(t *testing.T) {
|
||||
require.NoError(t, err, "unable to identify received image")
|
||||
require.Equal(t, imageType, "png", "expected png")
|
||||
|
||||
_, err = client.DeleteEmoji(emoji4.Id)
|
||||
_, err = client.DeleteEmoji(context.Background(), emoji4.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, resp, err = client.GetEmojiImage(emoji4.Id)
|
||||
_, resp, err = client.GetEmojiImage(context.Background(), emoji4.Id)
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
_, resp, err = client.GetEmojiImage(model.NewId())
|
||||
_, resp, err = client.GetEmojiImage(context.Background(), model.NewId())
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
_, resp, err = client.GetEmojiImage("")
|
||||
_, resp, err = client.GetEmojiImage(context.Background(), "")
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
}
|
||||
@@ -616,13 +617,13 @@ func TestSearchEmoji(t *testing.T) {
|
||||
}
|
||||
|
||||
for idx, emoji := range emojis {
|
||||
newEmoji, _, err := client.CreateEmoji(emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
newEmoji, _, err := client.CreateEmoji(context.Background(), emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
require.NoError(t, err)
|
||||
emojis[idx] = newEmoji
|
||||
}
|
||||
|
||||
search := &model.EmojiSearch{Term: searchTerm1}
|
||||
remojis, resp, err := client.SearchEmoji(search)
|
||||
remojis, resp, err := client.SearchEmoji(context.Background(), search)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
|
||||
@@ -637,7 +638,7 @@ func TestSearchEmoji(t *testing.T) {
|
||||
|
||||
search.Term = searchTerm2
|
||||
search.PrefixOnly = true
|
||||
remojis, resp, err = client.SearchEmoji(search)
|
||||
remojis, resp, err = client.SearchEmoji(context.Background(), search)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
|
||||
@@ -651,7 +652,7 @@ func TestSearchEmoji(t *testing.T) {
|
||||
assert.False(t, found)
|
||||
|
||||
search.PrefixOnly = false
|
||||
remojis, resp, err = client.SearchEmoji(search)
|
||||
remojis, resp, err = client.SearchEmoji(context.Background(), search)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
|
||||
@@ -665,12 +666,12 @@ func TestSearchEmoji(t *testing.T) {
|
||||
assert.True(t, found)
|
||||
|
||||
search.Term = ""
|
||||
_, resp, err = client.SearchEmoji(search)
|
||||
_, resp, err = client.SearchEmoji(context.Background(), search)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
client.Logout()
|
||||
_, resp, err = client.SearchEmoji(search)
|
||||
client.Logout(context.Background())
|
||||
_, resp, err = client.SearchEmoji(context.Background(), search)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
}
|
||||
@@ -696,12 +697,12 @@ func TestAutocompleteEmoji(t *testing.T) {
|
||||
}
|
||||
|
||||
for idx, emoji := range emojis {
|
||||
newEmoji, _, err := client.CreateEmoji(emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
newEmoji, _, err := client.CreateEmoji(context.Background(), emoji, utils.CreateTestGif(t, 10, 10), "image.gif")
|
||||
require.NoError(t, err)
|
||||
emojis[idx] = newEmoji
|
||||
}
|
||||
|
||||
remojis, resp, err := client.AutocompleteEmoji(searchTerm1, "")
|
||||
remojis, resp, err := client.AutocompleteEmoji(context.Background(), searchTerm1, "")
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
|
||||
@@ -720,12 +721,12 @@ func TestAutocompleteEmoji(t *testing.T) {
|
||||
assert.True(t, found1)
|
||||
assert.False(t, found2)
|
||||
|
||||
_, resp, err = client.AutocompleteEmoji("", "")
|
||||
_, resp, err = client.AutocompleteEmoji(context.Background(), "", "")
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
client.Logout()
|
||||
_, resp, err = client.AutocompleteEmoji(searchTerm1, "")
|
||||
client.Logout(context.Background())
|
||||
_, resp, err = client.AutocompleteEmoji(context.Background(), searchTerm1, "")
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ package api4
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -21,14 +22,14 @@ func TestListExports(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
t.Run("no permissions", func(t *testing.T) {
|
||||
exports, _, err := th.Client.ListExports()
|
||||
exports, _, err := th.Client.ListExports(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckErrorID(t, err, "api.context.permissions.app_error")
|
||||
require.Nil(t, exports)
|
||||
})
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
|
||||
exports, _, err := c.ListExports()
|
||||
exports, _, err := c.ListExports(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, exports)
|
||||
}, "no exports")
|
||||
@@ -46,7 +47,7 @@ func TestListExports(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
f.Close()
|
||||
|
||||
exports, _, err := c.ListExports()
|
||||
exports, _, err := c.ListExports(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Len(t, exports, 1)
|
||||
require.Equal(t, exports[0], "export.zip")
|
||||
@@ -62,7 +63,7 @@ func TestListExports(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(exportDir)
|
||||
|
||||
exports, _, err := c.ListExports()
|
||||
exports, _, err := c.ListExports(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, exports)
|
||||
|
||||
@@ -70,7 +71,7 @@ func TestListExports(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
f.Close()
|
||||
|
||||
exports, _, err = c.ListExports()
|
||||
exports, _, err = c.ListExports(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Len(t, exports, 1)
|
||||
require.Equal(t, "export.zip", exports[0])
|
||||
@@ -82,7 +83,7 @@ func TestDeleteExport(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
t.Run("no permissions", func(t *testing.T) {
|
||||
_, err := th.Client.DeleteExport("export.zip")
|
||||
_, err := th.Client.DeleteExport(context.Background(), "export.zip")
|
||||
require.Error(t, err)
|
||||
CheckErrorID(t, err, "api.context.permissions.app_error")
|
||||
})
|
||||
@@ -100,20 +101,20 @@ func TestDeleteExport(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
f.Close()
|
||||
|
||||
exports, _, err := c.ListExports()
|
||||
exports, _, err := c.ListExports(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Len(t, exports, 1)
|
||||
require.Equal(t, exports[0], exportName)
|
||||
|
||||
_, err = c.DeleteExport(exportName)
|
||||
_, err = c.DeleteExport(context.Background(), exportName)
|
||||
require.NoError(t, err)
|
||||
|
||||
exports, _, err = c.ListExports()
|
||||
exports, _, err = c.ListExports(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, exports)
|
||||
|
||||
// verify idempotence
|
||||
_, err = c.DeleteExport(exportName)
|
||||
_, err = c.DeleteExport(context.Background(), exportName)
|
||||
require.NoError(t, err)
|
||||
}, "successfully delete export")
|
||||
}
|
||||
@@ -124,7 +125,7 @@ func TestDownloadExport(t *testing.T) {
|
||||
|
||||
t.Run("no permissions", func(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
n, _, err := th.Client.DownloadExport("export.zip", &buf, 0)
|
||||
n, _, err := th.Client.DownloadExport(context.Background(), "export.zip", &buf, 0)
|
||||
require.Error(t, err)
|
||||
CheckErrorID(t, err, "api.context.permissions.app_error")
|
||||
require.Zero(t, n)
|
||||
@@ -136,7 +137,7 @@ func TestDownloadExport(t *testing.T) {
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
|
||||
var buf bytes.Buffer
|
||||
n, _, err := c.DownloadExport("export.zip", &buf, 0)
|
||||
n, _, err := c.DownloadExport(context.Background(), "export.zip", &buf, 0)
|
||||
require.Error(t, err)
|
||||
CheckErrorID(t, err, "api.export.export_not_found.app_error")
|
||||
require.Zero(t, n)
|
||||
@@ -153,7 +154,7 @@ func TestDownloadExport(t *testing.T) {
|
||||
err = os.WriteFile(filepath.Join(exportDir, exportName), data, 0600)
|
||||
require.NoError(t, err)
|
||||
|
||||
n, _, err := c.DownloadExport(exportName, &buf, 0)
|
||||
n, _, err := c.DownloadExport(context.Background(), exportName, &buf, 0)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, len(data), int(n))
|
||||
require.Equal(t, data, buf.Bytes())
|
||||
@@ -171,7 +172,7 @@ func TestDownloadExport(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
offset := 1024 * 512
|
||||
n, _, err := c.DownloadExport(exportName, &buf, int64(offset))
|
||||
n, _, err := c.DownloadExport(context.Background(), exportName, &buf, int64(offset))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, len(data)-offset, int(n))
|
||||
require.Equal(t, data[offset:], buf.Bytes())
|
||||
@@ -202,7 +203,7 @@ func BenchmarkDownloadExport(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
outFilePath := filepath.Join(dataDir, fmt.Sprintf("export%d.zip", i))
|
||||
outFile, _ := os.Create(outFilePath)
|
||||
th.SystemAdminClient.DownloadExport(exportName, outFile, 0)
|
||||
th.SystemAdminClient.DownloadExport(context.Background(), exportName, outFile, 0)
|
||||
outFile.Close()
|
||||
os.Remove(outFilePath)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ package api4
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@@ -699,8 +700,8 @@ func TestUploadFiles(t *testing.T) {
|
||||
}
|
||||
|
||||
if !tc.skipPayloadValidation {
|
||||
compare := func(get func(string) ([]byte, *model.Response, error), name string) {
|
||||
data, _, err := get(ri.Id)
|
||||
compare := func(get func(context.Context, string) ([]byte, *model.Response, error), name string) {
|
||||
data, _, err := get(context.Background(), ri.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
expected, err := os.ReadFile(filepath.Join(testDir, name))
|
||||
@@ -748,12 +749,12 @@ func TestGetFile(t *testing.T) {
|
||||
sent, err := testutils.ReadTestFile("test.png")
|
||||
require.NoError(t, err)
|
||||
|
||||
fileResp, _, err := client.UploadFile(sent, channel.Id, "test.png")
|
||||
fileResp, _, err := client.UploadFile(context.Background(), sent, channel.Id, "test.png")
|
||||
require.NoError(t, err)
|
||||
|
||||
fileId := fileResp.FileInfos[0].Id
|
||||
|
||||
data, _, err := client.GetFile(fileId)
|
||||
data, _, err := client.GetFile(context.Background(), fileId)
|
||||
require.NoError(t, err)
|
||||
require.NotEqual(t, 0, len(data), "should not be empty")
|
||||
|
||||
@@ -761,20 +762,20 @@ func TestGetFile(t *testing.T) {
|
||||
require.Equal(t, sent[i], data[i], "received file didn't match sent one")
|
||||
}
|
||||
|
||||
_, resp, err := client.GetFile("junk")
|
||||
_, resp, err := client.GetFile(context.Background(), "junk")
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
_, resp, err = client.GetFile(model.NewId())
|
||||
_, resp, err = client.GetFile(context.Background(), model.NewId())
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
client.Logout()
|
||||
_, resp, err = client.GetFile(fileId)
|
||||
client.Logout(context.Background())
|
||||
_, resp, err = client.GetFile(context.Background(), fileId)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
|
||||
_, _, err = th.SystemAdminClient.GetFile(fileId)
|
||||
_, _, err = th.SystemAdminClient.GetFile(context.Background(), fileId)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -803,12 +804,12 @@ func TestGetFileHeaders(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
fileResp, _, err := client.UploadFile(data, channel.Id, filename)
|
||||
fileResp, _, err := client.UploadFile(context.Background(), data, channel.Id, filename)
|
||||
require.NoError(t, err)
|
||||
|
||||
fileId := fileResp.FileInfos[0].Id
|
||||
|
||||
_, resp, err := client.GetFile(fileId)
|
||||
_, resp, err := client.GetFile(context.Background(), fileId)
|
||||
require.NoError(t, err)
|
||||
|
||||
CheckStartsWith(t, resp.Header.Get("Content-Type"), expectedContentType, "returned incorrect Content-Type")
|
||||
@@ -819,7 +820,7 @@ func TestGetFileHeaders(t *testing.T) {
|
||||
CheckStartsWith(t, resp.Header.Get("Content-Disposition"), "attachment", "returned incorrect Content-Disposition")
|
||||
}
|
||||
|
||||
_, resp, err = client.DownloadFile(fileId, true)
|
||||
_, resp, err = client.DownloadFile(context.Background(), fileId, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
CheckStartsWith(t, resp.Header.Get("Content-Type"), expectedContentType, "returned incorrect Content-Type")
|
||||
@@ -859,36 +860,36 @@ func TestGetFileThumbnail(t *testing.T) {
|
||||
sent, err := testutils.ReadTestFile("test.png")
|
||||
require.NoError(t, err)
|
||||
|
||||
fileResp, _, err := client.UploadFile(sent, channel.Id, "test.png")
|
||||
fileResp, _, err := client.UploadFile(context.Background(), sent, channel.Id, "test.png")
|
||||
require.NoError(t, err)
|
||||
|
||||
fileId := fileResp.FileInfos[0].Id
|
||||
|
||||
data, _, err := client.GetFileThumbnail(fileId)
|
||||
data, _, err := client.GetFileThumbnail(context.Background(), fileId)
|
||||
require.NoError(t, err)
|
||||
require.NotEqual(t, 0, len(data), "should not be empty")
|
||||
|
||||
_, resp, err := client.GetFileThumbnail("junk")
|
||||
_, resp, err := client.GetFileThumbnail(context.Background(), "junk")
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
_, resp, err = client.GetFileThumbnail(model.NewId())
|
||||
_, resp, err = client.GetFileThumbnail(context.Background(), model.NewId())
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
client.Logout()
|
||||
_, resp, err = client.GetFileThumbnail(fileId)
|
||||
client.Logout(context.Background())
|
||||
_, resp, err = client.GetFileThumbnail(context.Background(), fileId)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
|
||||
otherUser := th.CreateUser()
|
||||
client.Login(otherUser.Email, otherUser.Password)
|
||||
_, resp, err = client.GetFileThumbnail(fileId)
|
||||
client.Login(context.Background(), otherUser.Email, otherUser.Password)
|
||||
_, resp, err = client.GetFileThumbnail(context.Background(), fileId)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
client.Logout()
|
||||
_, _, err = th.SystemAdminClient.GetFileThumbnail(fileId)
|
||||
client.Logout(context.Background())
|
||||
_, _, err = th.SystemAdminClient.GetFileThumbnail(context.Background(), fileId)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -908,12 +909,12 @@ func TestGetFileLink(t *testing.T) {
|
||||
data, err := testutils.ReadTestFile("test.png")
|
||||
require.NoError(t, err)
|
||||
|
||||
fileResp, _, err := client.UploadFile(data, channel.Id, "test.png")
|
||||
fileResp, _, err := client.UploadFile(context.Background(), data, channel.Id, "test.png")
|
||||
require.NoError(t, err)
|
||||
|
||||
fileId := fileResp.FileInfos[0].Id
|
||||
|
||||
_, resp, err := client.GetFileLink(fileId)
|
||||
_, resp, err := client.GetFileLink(context.Background(), fileId)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
@@ -922,36 +923,36 @@ func TestGetFileLink(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.EnablePublicLink = false })
|
||||
_, resp, err = client.GetFileLink(fileId)
|
||||
_, resp, err = client.GetFileLink(context.Background(), fileId)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.EnablePublicLink = true })
|
||||
link, _, err := client.GetFileLink(fileId)
|
||||
link, _, err := client.GetFileLink(context.Background(), fileId)
|
||||
require.NoError(t, err)
|
||||
require.NotEqual(t, "", link, "should've received public link")
|
||||
|
||||
_, resp, err = client.GetFileLink("junk")
|
||||
_, resp, err = client.GetFileLink(context.Background(), "junk")
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
_, resp, err = client.GetFileLink(model.NewId())
|
||||
_, resp, err = client.GetFileLink(context.Background(), model.NewId())
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
client.Logout()
|
||||
_, resp, err = client.GetFileLink(fileId)
|
||||
client.Logout(context.Background())
|
||||
_, resp, err = client.GetFileLink(context.Background(), fileId)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
|
||||
otherUser := th.CreateUser()
|
||||
client.Login(otherUser.Email, otherUser.Password)
|
||||
_, resp, err = client.GetFileLink(fileId)
|
||||
client.Login(context.Background(), otherUser.Email, otherUser.Password)
|
||||
_, resp, err = client.GetFileLink(context.Background(), fileId)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
client.Logout()
|
||||
_, _, err = th.SystemAdminClient.GetFileLink(fileId)
|
||||
client.Logout(context.Background())
|
||||
_, _, err = th.SystemAdminClient.GetFileLink(context.Background(), fileId)
|
||||
require.NoError(t, err)
|
||||
|
||||
fileInfo, err := th.App.Srv().Store().FileInfo().Get(fileId)
|
||||
@@ -972,35 +973,35 @@ func TestGetFilePreview(t *testing.T) {
|
||||
sent, err := testutils.ReadTestFile("test.png")
|
||||
require.NoError(t, err)
|
||||
|
||||
fileResp, _, err := client.UploadFile(sent, channel.Id, "test.png")
|
||||
fileResp, _, err := client.UploadFile(context.Background(), sent, channel.Id, "test.png")
|
||||
require.NoError(t, err)
|
||||
fileId := fileResp.FileInfos[0].Id
|
||||
|
||||
data, _, err := client.GetFilePreview(fileId)
|
||||
data, _, err := client.GetFilePreview(context.Background(), fileId)
|
||||
require.NoError(t, err)
|
||||
require.NotEqual(t, 0, len(data), "should not be empty")
|
||||
|
||||
_, resp, err := client.GetFilePreview("junk")
|
||||
_, resp, err := client.GetFilePreview(context.Background(), "junk")
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
_, resp, err = client.GetFilePreview(model.NewId())
|
||||
_, resp, err = client.GetFilePreview(context.Background(), model.NewId())
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
client.Logout()
|
||||
_, resp, err = client.GetFilePreview(fileId)
|
||||
client.Logout(context.Background())
|
||||
_, resp, err = client.GetFilePreview(context.Background(), fileId)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
|
||||
otherUser := th.CreateUser()
|
||||
client.Login(otherUser.Email, otherUser.Password)
|
||||
_, resp, err = client.GetFilePreview(fileId)
|
||||
client.Login(context.Background(), otherUser.Email, otherUser.Password)
|
||||
_, resp, err = client.GetFilePreview(context.Background(), fileId)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
client.Logout()
|
||||
_, _, err = th.SystemAdminClient.GetFilePreview(fileId)
|
||||
client.Logout(context.Background())
|
||||
_, _, err = th.SystemAdminClient.GetFilePreview(context.Background(), fileId)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -1018,11 +1019,11 @@ func TestGetFileInfo(t *testing.T) {
|
||||
sent, err := testutils.ReadTestFile("test.png")
|
||||
require.NoError(t, err)
|
||||
|
||||
fileResp, _, err := client.UploadFile(sent, channel.Id, "test.png")
|
||||
fileResp, _, err := client.UploadFile(context.Background(), sent, channel.Id, "test.png")
|
||||
require.NoError(t, err)
|
||||
fileId := fileResp.FileInfos[0].Id
|
||||
|
||||
info, _, err := client.GetFileInfo(fileId)
|
||||
info, _, err := client.GetFileInfo(context.Background(), fileId)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NoError(t, err)
|
||||
@@ -1034,27 +1035,27 @@ func TestGetFileInfo(t *testing.T) {
|
||||
require.Equal(t, "", info.PreviewPath, "file preview path shouldn't have been returned to client")
|
||||
require.Equal(t, "image/png", info.MimeType, "mime type should've been image/png")
|
||||
|
||||
_, resp, err := client.GetFileInfo("junk")
|
||||
_, resp, err := client.GetFileInfo(context.Background(), "junk")
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
_, resp, err = client.GetFileInfo(model.NewId())
|
||||
_, resp, err = client.GetFileInfo(context.Background(), model.NewId())
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
client.Logout()
|
||||
_, resp, err = client.GetFileInfo(fileId)
|
||||
client.Logout(context.Background())
|
||||
_, resp, err = client.GetFileInfo(context.Background(), fileId)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
|
||||
otherUser := th.CreateUser()
|
||||
client.Login(otherUser.Email, otherUser.Password)
|
||||
_, resp, err = client.GetFileInfo(fileId)
|
||||
client.Login(context.Background(), otherUser.Email, otherUser.Password)
|
||||
_, resp, err = client.GetFileInfo(context.Background(), fileId)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
client.Logout()
|
||||
_, _, err = th.SystemAdminClient.GetFileInfo(fileId)
|
||||
client.Logout(context.Background())
|
||||
_, _, err = th.SystemAdminClient.GetFileInfo(context.Background(), fileId)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -1070,7 +1071,7 @@ func TestGetPublicFile(t *testing.T) {
|
||||
data, err := testutils.ReadTestFile("test.png")
|
||||
require.NoError(t, err)
|
||||
|
||||
fileResp, _, err := client.UploadFile(data, channel.Id, "test.png")
|
||||
fileResp, _, err := client.UploadFile(context.Background(), data, channel.Id, "test.png")
|
||||
require.NoError(t, err)
|
||||
|
||||
fileId := fileResp.FileInfos[0].Id
|
||||
@@ -1166,11 +1167,11 @@ func TestSearchFiles(t *testing.T) {
|
||||
fileInfo5, appErr := th.App.UploadFile(th.Context, data, archivedChannel.Id, "tagged for fileInfo3")
|
||||
require.Nil(t, appErr)
|
||||
post := &model.Post{ChannelId: archivedChannel.Id, Message: model.NewId() + "a"}
|
||||
rpost, _, err := client.CreatePost(post)
|
||||
rpost, _, err := client.CreatePost(context.Background(), post)
|
||||
require.NoError(t, err)
|
||||
err = th.App.Srv().Store().FileInfo().AttachToPost(fileInfo5.Id, rpost.Id, rpost.ChannelId, th.BasicUser.Id)
|
||||
require.NoError(t, err)
|
||||
th.Client.DeleteChannel(archivedChannel.Id)
|
||||
th.Client.DeleteChannel(context.Background(), archivedChannel.Id)
|
||||
|
||||
terms := "search"
|
||||
isOrSearch := false
|
||||
@@ -1180,7 +1181,7 @@ func TestSearchFiles(t *testing.T) {
|
||||
IsOrSearch: &isOrSearch,
|
||||
TimeZoneOffset: &timezoneOffset,
|
||||
}
|
||||
fileInfos, _, err := client.SearchFilesWithParams(th.BasicTeam.Id, &searchParams)
|
||||
fileInfos, _, err := client.SearchFilesWithParams(context.Background(), th.BasicTeam.Id, &searchParams)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, fileInfos.Order, 3, "wrong search")
|
||||
|
||||
@@ -1194,7 +1195,7 @@ func TestSearchFiles(t *testing.T) {
|
||||
Page: &page,
|
||||
PerPage: &perPage,
|
||||
}
|
||||
fileInfos2, _, err := client.SearchFilesWithParams(th.BasicTeam.Id, &searchParams)
|
||||
fileInfos2, _, err := client.SearchFilesWithParams(context.Background(), th.BasicTeam.Id, &searchParams)
|
||||
require.NoError(t, err)
|
||||
// We don't support paging for DB search yet, modify this when we do.
|
||||
require.Len(t, fileInfos2.Order, 3, "Wrong number of fileInfos")
|
||||
@@ -1209,16 +1210,16 @@ func TestSearchFiles(t *testing.T) {
|
||||
Page: &page,
|
||||
PerPage: &perPage,
|
||||
}
|
||||
fileInfos2, _, err = client.SearchFilesWithParams(th.BasicTeam.Id, &searchParams)
|
||||
fileInfos2, _, err = client.SearchFilesWithParams(context.Background(), th.BasicTeam.Id, &searchParams)
|
||||
require.NoError(t, err)
|
||||
// We don't support paging for DB search yet, modify this when we do.
|
||||
require.Empty(t, fileInfos2.Order, "Wrong number of fileInfos")
|
||||
|
||||
fileInfos, _, err = client.SearchFiles(th.BasicTeam.Id, "search", false)
|
||||
fileInfos, _, err = client.SearchFiles(context.Background(), th.BasicTeam.Id, "search", false)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, fileInfos.Order, 3, "wrong search")
|
||||
|
||||
fileInfos, _, err = client.SearchFiles(th.BasicTeam.Id, "fileInfo2", false)
|
||||
fileInfos, _, err = client.SearchFiles(context.Background(), th.BasicTeam.Id, "fileInfo2", false)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, fileInfos.Order, 1, "wrong number of fileInfos")
|
||||
require.Equal(t, fileInfo2.Id, fileInfos.Order[0], "wrong search")
|
||||
@@ -1231,7 +1232,7 @@ func TestSearchFiles(t *testing.T) {
|
||||
TimeZoneOffset: &timezoneOffset,
|
||||
IncludeDeletedChannels: &includeDeletedChannels,
|
||||
}
|
||||
fileInfos, _, err = client.SearchFilesWithParams(th.BasicTeam.Id, &searchParams)
|
||||
fileInfos, _, err = client.SearchFilesWithParams(context.Background(), th.BasicTeam.Id, &searchParams)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, fileInfos.Order, 3, "wrong search")
|
||||
|
||||
@@ -1239,31 +1240,31 @@ func TestSearchFiles(t *testing.T) {
|
||||
*cfg.TeamSettings.ExperimentalViewArchivedChannels = false
|
||||
})
|
||||
|
||||
fileInfos, _, err = client.SearchFilesWithParams(th.BasicTeam.Id, &searchParams)
|
||||
fileInfos, _, err = client.SearchFilesWithParams(context.Background(), th.BasicTeam.Id, &searchParams)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, fileInfos.Order, 2, "wrong search")
|
||||
|
||||
fileInfos, _, _ = client.SearchFiles(th.BasicTeam.Id, "*", false)
|
||||
fileInfos, _, _ = client.SearchFiles(context.Background(), th.BasicTeam.Id, "*", false)
|
||||
require.Empty(t, fileInfos.Order, "searching for just * shouldn't return any results")
|
||||
|
||||
fileInfos, _, err = client.SearchFiles(th.BasicTeam.Id, "fileInfo1 fileInfo2", true)
|
||||
fileInfos, _, err = client.SearchFiles(context.Background(), th.BasicTeam.Id, "fileInfo1 fileInfo2", true)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, fileInfos.Order, 2, "wrong search results")
|
||||
|
||||
_, resp, err := client.SearchFiles("junk", "#sgtitlereview", false)
|
||||
_, resp, err := client.SearchFiles(context.Background(), "junk", "#sgtitlereview", false)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
_, resp, err = client.SearchFiles(model.NewId(), "#sgtitlereview", false)
|
||||
_, resp, err = client.SearchFiles(context.Background(), model.NewId(), "#sgtitlereview", false)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
_, resp, err = client.SearchFiles(th.BasicTeam.Id, "", false)
|
||||
_, resp, err = client.SearchFiles(context.Background(), th.BasicTeam.Id, "", false)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
client.Logout()
|
||||
_, resp, err = client.SearchFiles(th.BasicTeam.Id, "#sgtitlereview", false)
|
||||
client.Logout(context.Background())
|
||||
_, resp, err = client.SearchFiles(context.Background(), th.BasicTeam.Id, "#sgtitlereview", false)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
}
|
||||
|
||||
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"os"
|
||||
"testing"
|
||||
@@ -30,14 +31,14 @@ func TestSelfHostedBootstrap(t *testing.T) {
|
||||
}()
|
||||
th.App.Srv().Cloud = &cloud
|
||||
|
||||
th.Client.Login(th.SystemAdminUser.Email, th.SystemAdminUser.Password)
|
||||
th.Client.Login(context.Background(), th.SystemAdminUser.Email, th.SystemAdminUser.Password)
|
||||
|
||||
os.Setenv("MM_SERVICESETTINGS_SELFHOSTEDFIRSTTIMEPURCHASE", "false")
|
||||
defer os.Unsetenv("MM_SERVICESETTINGS_SELFHOSTEDFIRSTTIMEPURCHASE")
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.SelfHostedPurchase = &valFalse })
|
||||
th.App.ReloadConfig()
|
||||
|
||||
_, r, err := th.Client.BootstrapSelfHostedSignup(model.BootstrapSelfHostedSignupRequest{Email: th.SystemAdminUser.Email})
|
||||
_, r, err := th.Client.BootstrapSelfHostedSignup(context.Background(), model.BootstrapSelfHostedSignupRequest{Email: th.SystemAdminUser.Email})
|
||||
|
||||
require.Equal(t, http.StatusNotImplemented, r.StatusCode)
|
||||
require.Error(t, err)
|
||||
@@ -54,7 +55,7 @@ func TestSelfHostedBootstrap(t *testing.T) {
|
||||
}()
|
||||
th.App.Srv().Cloud = &cloud
|
||||
|
||||
th.Client.Login(th.SystemAdminUser.Email, th.SystemAdminUser.Password)
|
||||
th.Client.Login(context.Background(), th.SystemAdminUser.Email, th.SystemAdminUser.Password)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
os.Setenv("MM_SERVICESETTINGS_SELFHOSTEDFIRSTTIMEPURCHASE", "true")
|
||||
@@ -62,7 +63,7 @@ func TestSelfHostedBootstrap(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.SelfHostedPurchase = &valTrue })
|
||||
th.App.ReloadConfig()
|
||||
|
||||
_, r, err := th.Client.BootstrapSelfHostedSignup(model.BootstrapSelfHostedSignupRequest{Email: th.SystemAdminUser.Email})
|
||||
_, r, err := th.Client.BootstrapSelfHostedSignup(context.Background(), model.BootstrapSelfHostedSignupRequest{Email: th.SystemAdminUser.Email})
|
||||
|
||||
require.Equal(t, http.StatusBadRequest, r.StatusCode)
|
||||
require.Error(t, err)
|
||||
@@ -79,14 +80,14 @@ func TestSelfHostedBootstrap(t *testing.T) {
|
||||
}()
|
||||
th.App.Srv().Cloud = &cloud
|
||||
|
||||
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
|
||||
th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password)
|
||||
|
||||
os.Setenv("MM_SERVICESETTINGS_SELFHOSTEDFIRSTTIMEPURCHASE", "true")
|
||||
defer os.Unsetenv("MM_SERVICESETTINGS_SELFHOSTEDFIRSTTIMEPURCHASE")
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.SelfHostedPurchase = &valTrue })
|
||||
th.App.ReloadConfig()
|
||||
|
||||
_, r, err := th.Client.BootstrapSelfHostedSignup(model.BootstrapSelfHostedSignupRequest{Email: th.SystemAdminUser.Email})
|
||||
_, r, err := th.Client.BootstrapSelfHostedSignup(context.Background(), model.BootstrapSelfHostedSignupRequest{Email: th.SystemAdminUser.Email})
|
||||
|
||||
require.Equal(t, http.StatusForbidden, r.StatusCode)
|
||||
require.Error(t, err)
|
||||
@@ -96,7 +97,7 @@ func TestSelfHostedBootstrap(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
th.Client.Login(th.SystemAdminUser.Email, th.SystemAdminUser.Password)
|
||||
th.Client.Login(context.Background(), th.SystemAdminUser.Email, th.SystemAdminUser.Password)
|
||||
|
||||
os.Setenv("MM_SERVICESETTINGS_SELFHOSTEDFIRSTTIMEPURCHASE", "true")
|
||||
defer os.Unsetenv("MM_SERVICESETTINGS_SELFHOSTEDFIRSTTIMEPURCHASE")
|
||||
@@ -112,7 +113,7 @@ func TestSelfHostedBootstrap(t *testing.T) {
|
||||
}()
|
||||
th.App.Srv().Cloud = &cloud
|
||||
|
||||
response, r, err := th.Client.BootstrapSelfHostedSignup(model.BootstrapSelfHostedSignupRequest{Email: th.SystemAdminUser.Email})
|
||||
response, r, err := th.Client.BootstrapSelfHostedSignup(context.Background(), model.BootstrapSelfHostedSignupRequest{Email: th.SystemAdminUser.Email})
|
||||
|
||||
require.Equal(t, http.StatusOK, r.StatusCode)
|
||||
require.NoError(t, err)
|
||||
@@ -129,14 +130,14 @@ func TestSelfHostedBootstrap(t *testing.T) {
|
||||
}()
|
||||
th.App.Srv().Cloud = nil
|
||||
|
||||
th.Client.Login(th.SystemAdminUser.Email, th.SystemAdminUser.Password)
|
||||
th.Client.Login(context.Background(), th.SystemAdminUser.Email, th.SystemAdminUser.Password)
|
||||
|
||||
os.Setenv("MM_SERVICESETTINGS_SELFHOSTEDFIRSTTIMEPURCHASE", "true")
|
||||
defer os.Unsetenv("MM_SERVICESETTINGS_SELFHOSTEDFIRSTTIMEPURCHASE")
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.SelfHostedPurchase = &valTrue })
|
||||
th.App.ReloadConfig()
|
||||
|
||||
_, r, err := th.Client.BootstrapSelfHostedSignup(model.BootstrapSelfHostedSignupRequest{Email: th.SystemAdminUser.Email})
|
||||
_, r, err := th.Client.BootstrapSelfHostedSignup(context.Background(), model.BootstrapSelfHostedSignupRequest{Email: th.SystemAdminUser.Email})
|
||||
|
||||
require.Equal(t, http.StatusBadRequest, r.StatusCode)
|
||||
require.Error(t, err)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -38,11 +39,11 @@ func TestListImports(t *testing.T) {
|
||||
us.UserId = model.UploadNoUserID
|
||||
}
|
||||
|
||||
u, _, err := c.CreateUpload(us)
|
||||
u, _, err := c.CreateUpload(context.Background(), us)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, u)
|
||||
|
||||
finfo, _, err := c.UploadData(u.Id, file)
|
||||
finfo, _, err := c.UploadData(context.Background(), u.Id, file)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, finfo)
|
||||
|
||||
@@ -50,7 +51,7 @@ func TestListImports(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("no permissions", func(t *testing.T) {
|
||||
imports, _, err := th.Client.ListImports()
|
||||
imports, _, err := th.Client.ListImports(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckErrorID(t, err, "api.context.permissions.app_error")
|
||||
require.Nil(t, imports)
|
||||
@@ -60,7 +61,7 @@ func TestListImports(t *testing.T) {
|
||||
require.True(t, found)
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
|
||||
imports, _, err := c.ListImports()
|
||||
imports, _, err := c.ListImports(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, imports)
|
||||
}, "no imports")
|
||||
@@ -74,7 +75,7 @@ func TestListImports(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
f.Close()
|
||||
|
||||
imports, _, err := c.ListImports()
|
||||
imports, _, err := c.ListImports(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, imports)
|
||||
require.Len(t, imports, 2)
|
||||
@@ -90,12 +91,12 @@ func TestListImports(t *testing.T) {
|
||||
|
||||
importDir := filepath.Join(dataDir, "import_new")
|
||||
|
||||
imports, _, err := c.ListImports()
|
||||
imports, _, err := c.ListImports(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, imports)
|
||||
|
||||
id := uploadNewImport(c, t)
|
||||
imports, _, err = c.ListImports()
|
||||
imports, _, err = c.ListImports(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, imports)
|
||||
require.Len(t, imports, 1)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -34,11 +35,11 @@ func TestGetTopReactionsForTeamSince(t *testing.T) {
|
||||
post4 := &model.Post{UserId: user2Id, ChannelId: th.BasicChannel.Id, Message: "zz" + model.NewId() + "a"}
|
||||
post5 := &model.Post{UserId: user2Id, ChannelId: th.BasicChannel.Id, Message: "zz" + model.NewId() + "a"}
|
||||
|
||||
post1, _, _ = client.CreatePost(post1)
|
||||
post2, _, _ = client.CreatePost(post2)
|
||||
post3, _, _ = client.CreatePost(post3)
|
||||
post4, _, _ = client.CreatePost(post4)
|
||||
post5, _, _ = client.CreatePost(post5)
|
||||
post1, _, _ = client.CreatePost(context.Background(), post1)
|
||||
post2, _, _ = client.CreatePost(context.Background(), post2)
|
||||
post3, _, _ = client.CreatePost(context.Background(), post3)
|
||||
post4, _, _ = client.CreatePost(context.Background(), post4)
|
||||
post5, _, _ = client.CreatePost(context.Background(), post5)
|
||||
|
||||
userReactions := []*model.Reaction{
|
||||
{
|
||||
@@ -169,7 +170,7 @@ func TestGetTopReactionsForTeamSince(t *testing.T) {
|
||||
expectedTopReactions[4] = &model.TopReaction{EmojiName: "happy", Count: int64(2)}
|
||||
|
||||
t.Run("get-top-reactions-for-team-since", func(t *testing.T) {
|
||||
topReactions, _, err := client.GetTopReactionsForTeamSince(teamId, model.TimeRangeToday, 0, 5)
|
||||
topReactions, _, err := client.GetTopReactionsForTeamSince(context.Background(), teamId, model.TimeRangeToday, 0, 5)
|
||||
require.NoError(t, err)
|
||||
reactions := topReactions.Items
|
||||
|
||||
@@ -178,7 +179,7 @@ func TestGetTopReactionsForTeamSince(t *testing.T) {
|
||||
assert.Equal(t, expectedTopReactions[i].Count, reaction.Count)
|
||||
}
|
||||
|
||||
topReactions, _, err = client.GetTopReactionsForTeamSince(teamId, model.TimeRangeToday, 1, 5)
|
||||
topReactions, _, err = client.GetTopReactionsForTeamSince(context.Background(), teamId, model.TimeRangeToday, 1, 5)
|
||||
require.NoError(t, err)
|
||||
reactions = topReactions.Items
|
||||
|
||||
@@ -190,7 +191,7 @@ func TestGetTopReactionsForTeamSince(t *testing.T) {
|
||||
excludedChannel := th.CreatePrivateChannel()
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
post, _, err := client.CreatePost(&model.Post{UserId: userId, ChannelId: excludedChannel.Id, Message: "zz" + model.NewId() + "a"})
|
||||
post, _, err := client.CreatePost(context.Background(), &model.Post{UserId: userId, ChannelId: excludedChannel.Id, Message: "zz" + model.NewId() + "a"})
|
||||
require.NoError(t, err)
|
||||
|
||||
reaction := &model.Reaction{
|
||||
@@ -205,7 +206,7 @@ func TestGetTopReactionsForTeamSince(t *testing.T) {
|
||||
|
||||
th.RemoveUserFromChannel(th.BasicUser, excludedChannel)
|
||||
|
||||
topReactions, _, err := client.GetTopReactionsForTeamSince(teamId, model.TimeRangeToday, 0, 5)
|
||||
topReactions, _, err := client.GetTopReactionsForTeamSince(context.Background(), teamId, model.TimeRangeToday, 0, 5)
|
||||
require.NoError(t, err)
|
||||
reactions := topReactions.Items
|
||||
|
||||
@@ -214,7 +215,7 @@ func TestGetTopReactionsForTeamSince(t *testing.T) {
|
||||
assert.Equal(t, expectedTopReactions[i].Count, reaction.Count)
|
||||
}
|
||||
|
||||
topReactions, _, err = client.GetTopReactionsForTeamSince(teamId, model.TimeRangeToday, 1, 5)
|
||||
topReactions, _, err = client.GetTopReactionsForTeamSince(context.Background(), teamId, model.TimeRangeToday, 1, 5)
|
||||
require.NoError(t, err)
|
||||
reactions = topReactions.Items
|
||||
|
||||
@@ -223,24 +224,24 @@ func TestGetTopReactionsForTeamSince(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("get-top-reactions-for-team-since invalid team id", func(t *testing.T) {
|
||||
_, resp, err := client.GetTopReactionsForTeamSince("12345", model.TimeRangeToday, 0, 5)
|
||||
_, resp, err := client.GetTopReactionsForTeamSince(context.Background(), "12345", model.TimeRangeToday, 0, 5)
|
||||
assert.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
_, resp, err = client.GetTopReactionsForTeamSince(model.NewId(), model.TimeRangeToday, 0, 5)
|
||||
_, resp, err = client.GetTopReactionsForTeamSince(context.Background(), model.NewId(), model.TimeRangeToday, 0, 5)
|
||||
assert.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("get-top-reactions-for-team-since invalid time range", func(t *testing.T) {
|
||||
_, resp, err := client.GetTopReactionsForTeamSince(teamId, "7_days", 0, 5)
|
||||
_, resp, err := client.GetTopReactionsForTeamSince(context.Background(), teamId, "7_days", 0, 5)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("get-top-reactions-for-team-since not a member of team", func(t *testing.T) {
|
||||
th.UnlinkUserFromTeam(th.BasicUser, th.BasicTeam)
|
||||
_, resp, err := client.GetTopReactionsForTeamSince(teamId, model.TimeRangeToday, 0, 5)
|
||||
_, resp, err := client.GetTopReactionsForTeamSince(context.Background(), teamId, model.TimeRangeToday, 0, 5)
|
||||
assert.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
@@ -248,7 +249,7 @@ func TestGetTopReactionsForTeamSince(t *testing.T) {
|
||||
t.Run("get-top-reactions-for-team-since invalid license", func(t *testing.T) {
|
||||
th.App.Srv().SetLicense(model.NewTestLicense(""))
|
||||
|
||||
_, resp, err := client.GetTopReactionsForTeamSince(teamId, model.TimeRangeToday, 0, 5)
|
||||
_, resp, err := client.GetTopReactionsForTeamSince(context.Background(), teamId, model.TimeRangeToday, 0, 5)
|
||||
assert.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
})
|
||||
@@ -269,12 +270,12 @@ func TestGetTopReactionsForUserSince(t *testing.T) {
|
||||
post5 := &model.Post{UserId: userId, ChannelId: th.BasicChannel.Id, Message: "zz" + model.NewId() + "a"}
|
||||
post6 := &model.Post{UserId: userId, ChannelId: th.BasicChannel.Id, Message: "zz" + model.NewId() + "a"}
|
||||
|
||||
post1, _, _ = client.CreatePost(post1)
|
||||
post2, _, _ = client.CreatePost(post2)
|
||||
post3, _, _ = client.CreatePost(post3)
|
||||
post4, _, _ = client.CreatePost(post4)
|
||||
post5, _, _ = client.CreatePost(post5)
|
||||
post6, _, _ = client.CreatePost(post6)
|
||||
post1, _, _ = client.CreatePost(context.Background(), post1)
|
||||
post2, _, _ = client.CreatePost(context.Background(), post2)
|
||||
post3, _, _ = client.CreatePost(context.Background(), post3)
|
||||
post4, _, _ = client.CreatePost(context.Background(), post4)
|
||||
post5, _, _ = client.CreatePost(context.Background(), post5)
|
||||
post6, _, _ = client.CreatePost(context.Background(), post6)
|
||||
|
||||
userReactions := []*model.Reaction{
|
||||
{
|
||||
@@ -405,7 +406,7 @@ func TestGetTopReactionsForUserSince(t *testing.T) {
|
||||
expectedTopReactions[4] = &model.TopReaction{EmojiName: "blush", Count: int64(2)}
|
||||
|
||||
t.Run("get-top-reactions-for-user-since", func(t *testing.T) {
|
||||
topReactions, _, err := client.GetTopReactionsForUserSince(teamId, model.TimeRangeToday, 0, 5)
|
||||
topReactions, _, err := client.GetTopReactionsForUserSince(context.Background(), teamId, model.TimeRangeToday, 0, 5)
|
||||
require.NoError(t, err)
|
||||
reactions := topReactions.Items
|
||||
|
||||
@@ -414,7 +415,7 @@ func TestGetTopReactionsForUserSince(t *testing.T) {
|
||||
assert.Equal(t, expectedTopReactions[i].Count, reaction.Count)
|
||||
}
|
||||
|
||||
topReactions, _, err = client.GetTopReactionsForUserSince(teamId, model.TimeRangeToday, 1, 5)
|
||||
topReactions, _, err = client.GetTopReactionsForUserSince(context.Background(), teamId, model.TimeRangeToday, 1, 5)
|
||||
require.NoError(t, err)
|
||||
reactions = topReactions.Items
|
||||
assert.Equal(t, "100", reactions[0].EmojiName)
|
||||
@@ -422,24 +423,24 @@ func TestGetTopReactionsForUserSince(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("get-top-reactions-for-user-since invalid team id", func(t *testing.T) {
|
||||
_, resp, err := client.GetTopReactionsForUserSince("invalid_team_id", model.TimeRangeToday, 0, 5)
|
||||
_, resp, err := client.GetTopReactionsForUserSince(context.Background(), "invalid_team_id", model.TimeRangeToday, 0, 5)
|
||||
assert.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
_, resp, err = client.GetTopReactionsForUserSince(model.NewId(), model.TimeRangeToday, 0, 5)
|
||||
_, resp, err = client.GetTopReactionsForUserSince(context.Background(), model.NewId(), model.TimeRangeToday, 0, 5)
|
||||
assert.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("get-top-reactions-for-user-since invalid time range", func(t *testing.T) {
|
||||
_, resp, err := client.GetTopReactionsForUserSince(teamId, "7_days", 0, 5)
|
||||
_, resp, err := client.GetTopReactionsForUserSince(context.Background(), teamId, "7_days", 0, 5)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("get-top-reactions-for-user-since not a member of team", func(t *testing.T) {
|
||||
th.UnlinkUserFromTeam(th.BasicUser, th.BasicTeam)
|
||||
_, resp, err := client.GetTopReactionsForUserSince(teamId, model.TimeRangeToday, 0, 5)
|
||||
_, resp, err := client.GetTopReactionsForUserSince(context.Background(), teamId, model.TimeRangeToday, 0, 5)
|
||||
assert.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
@@ -468,7 +469,7 @@ func TestGetTopChannelsForTeamSince(t *testing.T) {
|
||||
i := len(channelIDs)
|
||||
for _, channelID := range channelIDs {
|
||||
for j := i; j > 0; j-- {
|
||||
_, _, err := client.CreatePost(&model.Post{UserId: userId, ChannelId: channelID, Message: "zz" + model.NewId() + "a"})
|
||||
_, _, err := client.CreatePost(context.Background(), &model.Post{UserId: userId, ChannelId: channelID, Message: "zz" + model.NewId() + "a"})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
i--
|
||||
@@ -488,7 +489,7 @@ func TestGetTopChannelsForTeamSince(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("get-top-channels-for-team-since", func(t *testing.T) {
|
||||
topChannels, _, err := client.GetTopChannelsForTeamSince(teamId, model.TimeRangeToday, 0, 5)
|
||||
topChannels, _, err := client.GetTopChannelsForTeamSince(context.Background(), teamId, model.TimeRangeToday, 0, 5)
|
||||
require.NoError(t, err)
|
||||
|
||||
for i, channel := range topChannels.Items {
|
||||
@@ -496,7 +497,7 @@ func TestGetTopChannelsForTeamSince(t *testing.T) {
|
||||
assert.Equal(t, expectedTopChannels[i].MessageCount, channel.MessageCount)
|
||||
}
|
||||
|
||||
topChannels, _, err = client.GetTopChannelsForTeamSince(teamId, model.TimeRangeToday, 1, 5)
|
||||
topChannels, _, err = client.GetTopChannelsForTeamSince(context.Background(), teamId, model.TimeRangeToday, 1, 5)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, channel6.Id, topChannels.Items[0].ID)
|
||||
assert.Equal(t, int64(1), topChannels.Items[0].MessageCount)
|
||||
@@ -510,13 +511,13 @@ func TestGetTopChannelsForTeamSince(t *testing.T) {
|
||||
excludedChannel := th.CreatePrivateChannel()
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
_, _, err := client.CreatePost(&model.Post{UserId: userId, ChannelId: excludedChannel.Id, Message: "zz" + model.NewId() + "a"})
|
||||
_, _, err := client.CreatePost(context.Background(), &model.Post{UserId: userId, ChannelId: excludedChannel.Id, Message: "zz" + model.NewId() + "a"})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
th.RemoveUserFromChannel(th.BasicUser, excludedChannel)
|
||||
|
||||
topChannels, _, err := client.GetTopChannelsForTeamSince(teamId, model.TimeRangeToday, 0, 5)
|
||||
topChannels, _, err := client.GetTopChannelsForTeamSince(context.Background(), teamId, model.TimeRangeToday, 0, 5)
|
||||
require.NoError(t, err)
|
||||
|
||||
for i, channel := range topChannels.Items {
|
||||
@@ -526,24 +527,24 @@ func TestGetTopChannelsForTeamSince(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("get-top-channels-for-team-since invalid team id", func(t *testing.T) {
|
||||
_, resp, err := client.GetTopChannelsForTeamSince("12345", model.TimeRangeToday, 0, 5)
|
||||
_, resp, err := client.GetTopChannelsForTeamSince(context.Background(), "12345", model.TimeRangeToday, 0, 5)
|
||||
assert.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
_, resp, err = client.GetTopChannelsForTeamSince(model.NewId(), model.TimeRangeToday, 0, 5)
|
||||
_, resp, err = client.GetTopChannelsForTeamSince(context.Background(), model.NewId(), model.TimeRangeToday, 0, 5)
|
||||
assert.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("get-top-channels-for-team-since invalid time range", func(t *testing.T) {
|
||||
_, resp, err := client.GetTopChannelsForTeamSince(teamId, "7_days", 0, 5)
|
||||
_, resp, err := client.GetTopChannelsForTeamSince(context.Background(), teamId, "7_days", 0, 5)
|
||||
assert.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("get-top-channels-for-team-since not a member of team", func(t *testing.T) {
|
||||
th.UnlinkUserFromTeam(th.BasicUser, th.BasicTeam)
|
||||
_, resp, err := client.GetTopChannelsForTeamSince(teamId, model.TimeRangeToday, 0, 5)
|
||||
_, resp, err := client.GetTopChannelsForTeamSince(context.Background(), teamId, model.TimeRangeToday, 0, 5)
|
||||
assert.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
@@ -551,7 +552,7 @@ func TestGetTopChannelsForTeamSince(t *testing.T) {
|
||||
t.Run("get-top-channels-for-team-since invalid license", func(t *testing.T) {
|
||||
th.App.Srv().SetLicense(model.NewTestLicense(""))
|
||||
|
||||
_, resp, err := client.GetTopChannelsForTeamSince(teamId, model.TimeRangeToday, 0, 5)
|
||||
_, resp, err := client.GetTopChannelsForTeamSince(context.Background(), teamId, model.TimeRangeToday, 0, 5)
|
||||
assert.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
})
|
||||
@@ -576,7 +577,7 @@ func TestGetTopChannelsForUserSince(t *testing.T) {
|
||||
i := len(channelIDs)
|
||||
for _, channelID := range channelIDs {
|
||||
for j := i; j > 0; j-- {
|
||||
_, _, err := client.CreatePost(&model.Post{UserId: userId, ChannelId: channelID, Message: "zz" + model.NewId() + "a"})
|
||||
_, _, err := client.CreatePost(context.Background(), &model.Post{UserId: userId, ChannelId: channelID, Message: "zz" + model.NewId() + "a"})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
i--
|
||||
@@ -596,7 +597,7 @@ func TestGetTopChannelsForUserSince(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("get-top-channels-for-user-since", func(t *testing.T) {
|
||||
topChannels, _, err := client.GetTopChannelsForUserSince(teamId, model.TimeRangeToday, 0, 5)
|
||||
topChannels, _, err := client.GetTopChannelsForUserSince(context.Background(), teamId, model.TimeRangeToday, 0, 5)
|
||||
require.NoError(t, err)
|
||||
|
||||
for i, channel := range topChannels.Items {
|
||||
@@ -604,7 +605,7 @@ func TestGetTopChannelsForUserSince(t *testing.T) {
|
||||
assert.Equal(t, expectedTopChannels[i].MessageCount, channel.MessageCount)
|
||||
}
|
||||
|
||||
topChannels, _, err = client.GetTopChannelsForUserSince("", model.TimeRangeToday, 1, 5)
|
||||
topChannels, _, err = client.GetTopChannelsForUserSince(context.Background(), "", model.TimeRangeToday, 1, 5)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, channel6.Id, topChannels.Items[0].ID)
|
||||
assert.Equal(t, int64(1), topChannels.Items[0].MessageCount)
|
||||
@@ -615,24 +616,24 @@ func TestGetTopChannelsForUserSince(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("get-top-channels-for-user-since invalid team id", func(t *testing.T) {
|
||||
_, resp, err := client.GetTopChannelsForUserSince("12345", model.TimeRangeToday, 0, 5)
|
||||
_, resp, err := client.GetTopChannelsForUserSince(context.Background(), "12345", model.TimeRangeToday, 0, 5)
|
||||
assert.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
_, resp, err = client.GetTopChannelsForUserSince(model.NewId(), model.TimeRangeToday, 0, 5)
|
||||
_, resp, err = client.GetTopChannelsForUserSince(context.Background(), model.NewId(), model.TimeRangeToday, 0, 5)
|
||||
assert.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("get-top-channels-for-user-since invalid time range", func(t *testing.T) {
|
||||
_, resp, err := client.GetTopChannelsForUserSince(teamId, "7_days", 0, 5)
|
||||
_, resp, err := client.GetTopChannelsForUserSince(context.Background(), teamId, "7_days", 0, 5)
|
||||
assert.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("get-top-channels-for-user-since not a member of team", func(t *testing.T) {
|
||||
th.UnlinkUserFromTeam(th.BasicUser, th.BasicTeam)
|
||||
_, resp, err := client.GetTopChannelsForUserSince(teamId, model.TimeRangeToday, 0, 5)
|
||||
_, resp, err := client.GetTopChannelsForUserSince(context.Background(), teamId, model.TimeRangeToday, 0, 5)
|
||||
assert.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
@@ -700,33 +701,33 @@ func TestGetTopThreadsForTeamSince(t *testing.T) {
|
||||
// get top threads for team, as user 1 and user 2
|
||||
// user 1, 2 should see both threads
|
||||
|
||||
topTeamThreadsByUser1, _, _ := client.GetTopThreadsForTeamSince(th.BasicTeam.Id, model.TimeRangeToday, 0, 10)
|
||||
topTeamThreadsByUser1, _, _ := client.GetTopThreadsForTeamSince(context.Background(), th.BasicTeam.Id, model.TimeRangeToday, 0, 10)
|
||||
require.Nil(t, appErr)
|
||||
require.Len(t, topTeamThreadsByUser1.Items, 2)
|
||||
require.Equal(t, topTeamThreadsByUser1.Items[0].Post.Id, rootPostPrivateChannel.Id)
|
||||
require.Equal(t, topTeamThreadsByUser1.Items[1].Post.Id, rootPostPublicChannel.Id)
|
||||
|
||||
client.Logout()
|
||||
client.Logout(context.Background())
|
||||
|
||||
th.LoginBasic2()
|
||||
|
||||
client = th.Client
|
||||
|
||||
topTeamThreadsByUser2, _, _ := client.GetTopThreadsForTeamSince(th.BasicTeam.Id, model.TimeRangeToday, 0, 10)
|
||||
topTeamThreadsByUser2, _, _ := client.GetTopThreadsForTeamSince(context.Background(), th.BasicTeam.Id, model.TimeRangeToday, 0, 10)
|
||||
require.Nil(t, appErr)
|
||||
require.Len(t, topTeamThreadsByUser2.Items, 1)
|
||||
require.Equal(t, topTeamThreadsByUser2.Items[0].Post.Id, rootPostPublicChannel.Id)
|
||||
|
||||
// add user2 to private channel and it can see 2 top threads.
|
||||
th.AddUserToChannel(th.BasicUser2, channelPrivate)
|
||||
topTeamThreadsByUser2IncludingPrivate, _, _ := client.GetTopThreadsForTeamSince(th.BasicTeam.Id, model.TimeRangeToday, 0, 10)
|
||||
topTeamThreadsByUser2IncludingPrivate, _, _ := client.GetTopThreadsForTeamSince(context.Background(), th.BasicTeam.Id, model.TimeRangeToday, 0, 10)
|
||||
require.Nil(t, appErr)
|
||||
require.Len(t, topTeamThreadsByUser2IncludingPrivate.Items, 2)
|
||||
|
||||
t.Run("get-top-threads-for-team-since invalid license", func(t *testing.T) {
|
||||
th.App.Srv().SetLicense(model.NewTestLicense(""))
|
||||
|
||||
_, resp, err := client.GetTopThreadsForTeamSince(th.BasicTeam.Id, model.TimeRangeToday, 0, 5)
|
||||
_, resp, err := client.GetTopThreadsForTeamSince(context.Background(), th.BasicTeam.Id, model.TimeRangeToday, 0, 5)
|
||||
assert.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
})
|
||||
@@ -793,7 +794,7 @@ func TestGetTopThreadsForUserSince(t *testing.T) {
|
||||
// user 1 should see both threads, while user 2 should see only thread in public channel
|
||||
// (even if user2 is in the private channel it hasn't interacted with the thread there.)
|
||||
|
||||
topUser1Threads, _, _ := client.GetTopThreadsForUserSince(th.BasicTeam.Id, model.TimeRangeToday, 0, 10)
|
||||
topUser1Threads, _, _ := client.GetTopThreadsForUserSince(context.Background(), th.BasicTeam.Id, model.TimeRangeToday, 0, 10)
|
||||
require.Nil(t, appErr)
|
||||
require.Len(t, topUser1Threads.Items, 2)
|
||||
require.Equal(t, topUser1Threads.Items[0].Post.Id, rootPostPrivateChannel.Id)
|
||||
@@ -802,13 +803,13 @@ func TestGetTopThreadsForUserSince(t *testing.T) {
|
||||
require.Contains(t, topUser1Threads.Items[1].Participants, th.BasicUser2.Id)
|
||||
require.Equal(t, topUser1Threads.Items[1].Post.ReplyCount, int64(1))
|
||||
|
||||
client.Logout()
|
||||
client.Logout(context.Background())
|
||||
|
||||
th.LoginBasic2()
|
||||
|
||||
client = th.Client
|
||||
|
||||
topUser2Threads, _, _ := client.GetTopThreadsForUserSince(th.BasicTeam.Id, model.TimeRangeToday, 0, 10)
|
||||
topUser2Threads, _, _ := client.GetTopThreadsForUserSince(context.Background(), th.BasicTeam.Id, model.TimeRangeToday, 0, 10)
|
||||
require.Nil(t, appErr)
|
||||
require.Len(t, topUser2Threads.Items, 1)
|
||||
require.Equal(t, topUser2Threads.Items[0].Post.Id, rootPostPublicChannel.Id)
|
||||
@@ -818,17 +819,17 @@ func TestGetTopThreadsForUserSince(t *testing.T) {
|
||||
_, appErr = th.App.DeletePost(th.Context, rootPostPublicChannel.Id, th.BasicUser.Id)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
client.Logout()
|
||||
client.Logout(context.Background())
|
||||
|
||||
th.LoginBasic()
|
||||
|
||||
client = th.Client
|
||||
|
||||
topUser1ThreadsAfterPost1Delete, _, _ := client.GetTopThreadsForUserSince(th.BasicTeam.Id, model.TimeRangeToday, 0, 10)
|
||||
topUser1ThreadsAfterPost1Delete, _, _ := client.GetTopThreadsForUserSince(context.Background(), th.BasicTeam.Id, model.TimeRangeToday, 0, 10)
|
||||
require.Nil(t, appErr)
|
||||
require.Len(t, topUser1ThreadsAfterPost1Delete.Items, 1)
|
||||
|
||||
client.Logout()
|
||||
client.Logout(context.Background())
|
||||
|
||||
th.LoginBasic2()
|
||||
|
||||
@@ -843,7 +844,7 @@ func TestGetTopThreadsForUserSince(t *testing.T) {
|
||||
}, channelPrivate, false, true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
topUser2ThreadsAfterPrivateReply, _, _ := client.GetTopThreadsForUserSince(th.BasicTeam.Id, model.TimeRangeToday, 0, 10)
|
||||
topUser2ThreadsAfterPrivateReply, _, _ := client.GetTopThreadsForUserSince(context.Background(), th.BasicTeam.Id, model.TimeRangeToday, 0, 10)
|
||||
require.Nil(t, appErr)
|
||||
require.Len(t, topUser2ThreadsAfterPrivateReply.Items, 1)
|
||||
|
||||
@@ -857,7 +858,7 @@ func TestGetTopThreadsForUserSince(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
topUser2ThreadsAfterPrivateReplyDelete, _, _ := client.GetTopThreadsForUserSince(th.BasicTeam.Id, model.TimeRangeToday, 0, 10)
|
||||
topUser2ThreadsAfterPrivateReplyDelete, _, _ := client.GetTopThreadsForUserSince(context.Background(), th.BasicTeam.Id, model.TimeRangeToday, 0, 10)
|
||||
require.Nil(t, appErr)
|
||||
require.Len(t, topUser2ThreadsAfterPrivateReplyDelete.Items, 0)
|
||||
}
|
||||
@@ -900,7 +901,7 @@ func TestGetTopInactiveChannelsForTeamSince(t *testing.T) {
|
||||
TeamId: th.BasicTeam.Id,
|
||||
CreateAt: 1,
|
||||
}
|
||||
channel4, _, err := client.CreateChannel(channel4Req)
|
||||
channel4, _, err := client.CreateChannel(context.Background(), channel4Req)
|
||||
require.NoError(t, err)
|
||||
|
||||
channel5Req := &model.Channel{
|
||||
@@ -910,7 +911,7 @@ func TestGetTopInactiveChannelsForTeamSince(t *testing.T) {
|
||||
TeamId: th.BasicTeam.Id,
|
||||
CreateAt: 1,
|
||||
}
|
||||
channel5, _, err := client.CreateChannel(channel5Req)
|
||||
channel5, _, err := client.CreateChannel(context.Background(), channel5Req)
|
||||
require.NoError(t, err)
|
||||
|
||||
channel6Req := &model.Channel{
|
||||
@@ -920,7 +921,7 @@ func TestGetTopInactiveChannelsForTeamSince(t *testing.T) {
|
||||
TeamId: th.BasicTeam.Id,
|
||||
CreateAt: 1,
|
||||
}
|
||||
channel6, _, err := client.CreateChannel(channel6Req)
|
||||
channel6, _, err := client.CreateChannel(context.Background(), channel6Req)
|
||||
require.NoError(t, err)
|
||||
|
||||
th.App.AddUserToChannel(th.Context, th.BasicUser, channel4, false)
|
||||
@@ -932,7 +933,7 @@ func TestGetTopInactiveChannelsForTeamSince(t *testing.T) {
|
||||
i := len(channelIDs)
|
||||
for _, channelID := range channelIDs {
|
||||
for j := i; j > 0; j-- {
|
||||
_, _, err := client.CreatePost(&model.Post{UserId: userId, ChannelId: channelID, Message: "zz" + model.NewId() + "a"})
|
||||
_, _, err := client.CreatePost(context.Background(), &model.Post{UserId: userId, ChannelId: channelID, Message: "zz" + model.NewId() + "a"})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
i--
|
||||
@@ -950,14 +951,14 @@ func TestGetTopInactiveChannelsForTeamSince(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("get-top-inactive-channels-for-team-since", func(t *testing.T) {
|
||||
topInactiveChannels, _, err := client.GetTopInactiveChannelsForTeamSince(teamId, model.TimeRangeToday, 0, 2)
|
||||
topInactiveChannels, _, err := client.GetTopInactiveChannelsForTeamSince(context.Background(), teamId, model.TimeRangeToday, 0, 2)
|
||||
require.NoError(t, err)
|
||||
|
||||
for i, channel := range topInactiveChannels.Items {
|
||||
assert.Equal(t, expectedTopChannels[i].ID, channel.ID)
|
||||
}
|
||||
|
||||
topInactiveChannels, _, err = client.GetTopInactiveChannelsForTeamSince(teamId, model.TimeRangeToday, 1, 2)
|
||||
topInactiveChannels, _, err = client.GetTopInactiveChannelsForTeamSince(context.Background(), teamId, model.TimeRangeToday, 1, 2)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, channel4.Id, topInactiveChannels.Items[0].ID)
|
||||
})
|
||||
@@ -966,13 +967,13 @@ func TestGetTopInactiveChannelsForTeamSince(t *testing.T) {
|
||||
excludedChannel := th.CreatePrivateChannel()
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
_, _, err := client.CreatePost(&model.Post{UserId: userId, ChannelId: excludedChannel.Id, Message: "zz" + model.NewId() + "a"})
|
||||
_, _, err := client.CreatePost(context.Background(), &model.Post{UserId: userId, ChannelId: excludedChannel.Id, Message: "zz" + model.NewId() + "a"})
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
th.RemoveUserFromChannel(th.BasicUser, excludedChannel)
|
||||
|
||||
topInactiveChannels, _, err := client.GetTopInactiveChannelsForUserSince(teamId, model.TimeRangeToday, 0, 3)
|
||||
topInactiveChannels, _, err := client.GetTopInactiveChannelsForUserSince(context.Background(), teamId, model.TimeRangeToday, 0, 3)
|
||||
require.NoError(t, err)
|
||||
|
||||
for i, channel := range topInactiveChannels.Items {
|
||||
@@ -983,7 +984,7 @@ func TestGetTopInactiveChannelsForTeamSince(t *testing.T) {
|
||||
t.Run("get-top-inactive-channels-for-team-since invalid license", func(t *testing.T) {
|
||||
th.App.Srv().SetLicense(model.NewTestLicense(""))
|
||||
|
||||
_, resp, err := client.GetTopInactiveChannelsForTeamSince(teamId, model.TimeRangeToday, 0, 5)
|
||||
_, resp, err := client.GetTopInactiveChannelsForTeamSince(context.Background(), teamId, model.TimeRangeToday, 0, 5)
|
||||
assert.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
})
|
||||
@@ -1007,14 +1008,14 @@ func TestGetTopDMsForUserSince(t *testing.T) {
|
||||
|
||||
th.LoginBasic2()
|
||||
client := th.Client
|
||||
channelBu1Bu1, _, err := client.CreateDirectChannel(basicUser1.Id, basicUser1.Id)
|
||||
channelBu1Bu1, _, err := client.CreateDirectChannel(context.Background(), basicUser1.Id, basicUser1.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
th.LoginBasic()
|
||||
client = th.Client
|
||||
channelBuBu, _, err := client.CreateDirectChannel(basicUser.Id, basicUser.Id)
|
||||
channelBuBu, _, err := client.CreateDirectChannel(context.Background(), basicUser.Id, basicUser.Id)
|
||||
require.NoError(t, err)
|
||||
channelBuBu1, _, err := client.CreateDirectChannel(basicUser.Id, basicUser1.Id)
|
||||
channelBuBu1, _, err := client.CreateDirectChannel(context.Background(), basicUser.Id, basicUser1.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
// bot creation with permission
|
||||
@@ -1027,11 +1028,11 @@ func TestGetTopDMsForUserSince(t *testing.T) {
|
||||
UserId: model.NewId(),
|
||||
}
|
||||
|
||||
createdBot, resp, err := th.Client.CreateBot(bot)
|
||||
createdBot, resp, err := th.Client.CreateBot(context.Background(), bot)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
channelBuBot, _, err := client.CreateDirectChannel(basicUser.Id, createdBot.UserId)
|
||||
channelBuBot, _, err := client.CreateDirectChannel(context.Background(), basicUser.Id, createdBot.UserId)
|
||||
require.NoError(t, err)
|
||||
|
||||
// create 2 posts in channelBu, 1 in channelBu1, 3 in channelBu12
|
||||
@@ -1062,14 +1063,14 @@ func TestGetTopDMsForUserSince(t *testing.T) {
|
||||
client = th.Client
|
||||
userId := basicUser1.Id
|
||||
post := &model.Post{UserId: userId, ChannelId: postGen["chId"].(string), Message: "zz" + model.NewId() + "a"}
|
||||
_, _, err = client.CreatePost(post)
|
||||
_, _, err = client.CreatePost(context.Background(), post)
|
||||
require.NoError(t, err)
|
||||
} else {
|
||||
th.LoginBasic()
|
||||
client = th.Client
|
||||
userId := basicUser.Id
|
||||
post := &model.Post{UserId: userId, ChannelId: postGen["chId"].(string), Message: "zz" + model.NewId() + "a"}
|
||||
_, _, err = client.CreatePost(post)
|
||||
_, _, err = client.CreatePost(context.Background(), post)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
}
|
||||
@@ -1079,14 +1080,14 @@ func TestGetTopDMsForUserSince(t *testing.T) {
|
||||
t.Run("get top dms for basic user 1", func(t *testing.T) {
|
||||
th.LoginBasic()
|
||||
client = th.Client
|
||||
topDMs, _, topDmsErr := client.GetTopDMsForUserSince("today", 0, 100)
|
||||
topDMs, _, topDmsErr := client.GetTopDMsForUserSince(context.Background(), "today", 0, 100)
|
||||
require.NoError(t, topDmsErr)
|
||||
require.Len(t, topDMs.Items, 1)
|
||||
require.Equal(t, topDMs.Items[0].MessageCount, int64(3))
|
||||
require.Equal(t, topDMs.Items[0].SecondParticipant.Id, basicUser1.Id)
|
||||
|
||||
// test pagination
|
||||
topDMsPage0PerPage1, _, topDmsErr := client.GetTopDMsForUserSince("today", 0, 2)
|
||||
topDMsPage0PerPage1, _, topDmsErr := client.GetTopDMsForUserSince(context.Background(), "today", 0, 2)
|
||||
require.NoError(t, topDmsErr)
|
||||
require.Len(t, topDMsPage0PerPage1.Items, 1)
|
||||
require.Equal(t, topDMsPage0PerPage1.HasNext, false)
|
||||
@@ -1097,19 +1098,19 @@ func TestGetTopDMsForUserSince(t *testing.T) {
|
||||
t.Run("get top dms for basic user 2", func(t *testing.T) {
|
||||
th.LoginBasic2()
|
||||
client = th.Client
|
||||
topDMs, _, topDmsErr := client.GetTopDMsForUserSince("today", 0, 100)
|
||||
topDMs, _, topDmsErr := client.GetTopDMsForUserSince(context.Background(), "today", 0, 100)
|
||||
require.NoError(t, topDmsErr)
|
||||
require.Len(t, topDMs.Items, 1)
|
||||
require.Equal(t, topDMs.Items[0].MessageCount, int64(3))
|
||||
})
|
||||
// deactivate basicuser1
|
||||
_, err = th.Client.DeleteUser(basicUser1.Id)
|
||||
_, err = th.Client.DeleteUser(context.Background(), basicUser1.Id)
|
||||
require.NoError(t, err)
|
||||
// deactivated users DMs should show in topDMs
|
||||
t.Run("get top dms for basic user 1", func(t *testing.T) {
|
||||
th.LoginBasic()
|
||||
client = th.Client
|
||||
topDMs, _, topDmsErr := client.GetTopDMsForUserSince("today", 0, 100)
|
||||
topDMs, _, topDmsErr := client.GetTopDMsForUserSince(context.Background(), "today", 0, 100)
|
||||
require.NoError(t, topDmsErr)
|
||||
require.Len(t, topDMs.Items, 1)
|
||||
require.Equal(t, topDMs.Items[0].MessageCount, int64(3))
|
||||
@@ -1125,37 +1126,37 @@ func TestNewTeamMembersSince(t *testing.T) {
|
||||
team := th.CreateTeam()
|
||||
|
||||
t.Run("accepts only starter or professional license skus", func(t *testing.T) {
|
||||
_, resp, _ := th.Client.GetNewTeamMembersSince(team.Id, model.TimeRangeToday, 0, 5)
|
||||
_, resp, _ := th.Client.GetNewTeamMembersSince(context.Background(), team.Id, model.TimeRangeToday, 0, 5)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuE10))
|
||||
_, resp, _ = th.Client.GetNewTeamMembersSince(team.Id, model.TimeRangeToday, 0, 5)
|
||||
_, resp, _ = th.Client.GetNewTeamMembersSince(context.Background(), team.Id, model.TimeRangeToday, 0, 5)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuE20))
|
||||
_, resp, _ = th.Client.GetNewTeamMembersSince(team.Id, model.TimeRangeToday, 0, 5)
|
||||
_, resp, _ = th.Client.GetNewTeamMembersSince(context.Background(), team.Id, model.TimeRangeToday, 0, 5)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuProfessional))
|
||||
_, resp, err := th.Client.GetNewTeamMembersSince(team.Id, model.TimeRangeToday, 0, 5)
|
||||
_, resp, err := th.Client.GetNewTeamMembersSince(context.Background(), team.Id, model.TimeRangeToday, 0, 5)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuEnterprise))
|
||||
_, resp, err = th.Client.GetNewTeamMembersSince(team.Id, model.TimeRangeToday, 0, 5)
|
||||
_, resp, err = th.Client.GetNewTeamMembersSince(context.Background(), team.Id, model.TimeRangeToday, 0, 5)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("rejects guests", func(t *testing.T) {
|
||||
_, resp, err := th.Client.GetNewTeamMembersSince(team.Id, model.TimeRangeToday, 0, 5)
|
||||
_, resp, err := th.Client.GetNewTeamMembersSince(context.Background(), team.Id, model.TimeRangeToday, 0, 5)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
|
||||
th.App.DemoteUserToGuest(th.Context, th.BasicUser)
|
||||
defer th.App.PromoteGuestToUser(th.Context, th.BasicUser, "")
|
||||
|
||||
_, resp, _ = th.Client.GetNewTeamMembersSince(team.Id, model.TimeRangeToday, 0, 5)
|
||||
_, resp, _ = th.Client.GetNewTeamMembersSince(context.Background(), team.Id, model.TimeRangeToday, 0, 5)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
})
|
||||
|
||||
@@ -1178,17 +1179,17 @@ func TestNewTeamMembersSince(t *testing.T) {
|
||||
}
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuProfessional))
|
||||
list, resp, err := th.Client.GetNewTeamMembersSince(team.Id, model.TimeRangeToday, 0, 5)
|
||||
list, resp, err := th.Client.GetNewTeamMembersSince(context.Background(), team.Id, model.TimeRangeToday, 0, 5)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
checkUser(list.Items[0], false)
|
||||
|
||||
data, err := testutils.ReadTestFile("test.png")
|
||||
require.NoError(t, err)
|
||||
_, err = th.Client.SetProfileImage(th.BasicUser.Id, data)
|
||||
_, err = th.Client.SetProfileImage(context.Background(), th.BasicUser.Id, data)
|
||||
require.NoError(t, err)
|
||||
|
||||
list, resp, err = th.Client.GetNewTeamMembersSince(team.Id, model.TimeRangeToday, 0, 5)
|
||||
list, resp, err = th.Client.GetNewTeamMembersSince(context.Background(), team.Id, model.TimeRangeToday, 0, 5)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
checkUser(list.Items[0], true)
|
||||
@@ -1196,7 +1197,7 @@ func TestNewTeamMembersSince(t *testing.T) {
|
||||
|
||||
t.Run("implements pagination", func(t *testing.T) {
|
||||
// check the first page of results
|
||||
list, resp, err := th.Client.GetNewTeamMembersSince(team.Id, model.TimeRangeToday, 0, 2)
|
||||
list, resp, err := th.Client.GetNewTeamMembersSince(context.Background(), team.Id, model.TimeRangeToday, 0, 2)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
|
||||
@@ -1205,7 +1206,7 @@ func TestNewTeamMembersSince(t *testing.T) {
|
||||
require.False(t, list.HasNext)
|
||||
|
||||
// check the 2nd page
|
||||
list, resp, err = th.Client.GetNewTeamMembersSince(team.Id, model.TimeRangeToday, 1, 2)
|
||||
list, resp, err = th.Client.GetNewTeamMembersSince(context.Background(), team.Id, model.TimeRangeToday, 1, 2)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
|
||||
@@ -1218,14 +1219,14 @@ func TestNewTeamMembersSince(t *testing.T) {
|
||||
_, appErr = th.App.AddTeamMember(th.Context, team.Id, user.Id)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
list, resp, err = th.Client.GetNewTeamMembersSince(team.Id, model.TimeRangeToday, 0, 2)
|
||||
list, resp, err = th.Client.GetNewTeamMembersSince(context.Background(), team.Id, model.TimeRangeToday, 0, 2)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
require.Equal(t, 3, int(list.TotalCount))
|
||||
require.Len(t, list.Items, 2)
|
||||
require.True(t, list.HasNext)
|
||||
|
||||
list, resp, err = th.Client.GetNewTeamMembersSince(team.Id, model.TimeRangeToday, 1, 2)
|
||||
list, resp, err = th.Client.GetNewTeamMembersSince(context.Background(), team.Id, model.TimeRangeToday, 1, 2)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
require.Equal(t, int(list.TotalCount), 3)
|
||||
@@ -1236,7 +1237,7 @@ func TestNewTeamMembersSince(t *testing.T) {
|
||||
t.Run("get-new-team-members-since invalid license", func(t *testing.T) {
|
||||
th.App.Srv().SetLicense(model.NewTestLicense(""))
|
||||
|
||||
_, resp, err := th.Client.GetNewTeamMembersSince(team.Id, model.TimeRangeToday, 0, 2)
|
||||
_, resp, err := th.Client.GetNewTeamMembersSince(context.Background(), team.Id, model.TimeRangeToday, 0, 2)
|
||||
assert.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
})
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
@@ -128,7 +129,7 @@ func TestPostActionCookies(t *testing.T) {
|
||||
assert.Equal(t, 32, len(th.App.PostActionCookieSecret()))
|
||||
post = model.AddPostActionCookies(post, th.App.PostActionCookieSecret())
|
||||
|
||||
resp, err := client.DoPostActionWithCookie(post.Id, test.Action.Id, "", test.Action.Cookie)
|
||||
resp, err := client.DoPostActionWithCookie(context.Background(), post.Id, test.Action.Id, "", test.Action.Cookie)
|
||||
require.NotNil(t, resp)
|
||||
if test.ExpectedSuccess {
|
||||
assert.NoError(t, err)
|
||||
@@ -174,40 +175,40 @@ func TestOpenDialog(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
_, err := client.OpenInteractiveDialog(request)
|
||||
_, err := client.OpenInteractiveDialog(context.Background(), request)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Should fail on bad trigger ID
|
||||
request.TriggerId = "junk"
|
||||
resp, err := client.OpenInteractiveDialog(request)
|
||||
resp, err := client.OpenInteractiveDialog(context.Background(), request)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
// URL is required
|
||||
request.TriggerId = triggerId
|
||||
request.URL = ""
|
||||
resp, err = client.OpenInteractiveDialog(request)
|
||||
resp, err = client.OpenInteractiveDialog(context.Background(), request)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
// Should pass with markdown formatted introduction text
|
||||
request.URL = "http://localhost:8065"
|
||||
request.Dialog.IntroductionText = "**Some** _introduction text"
|
||||
_, err = client.OpenInteractiveDialog(request)
|
||||
_, err = client.OpenInteractiveDialog(context.Background(), request)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Should pass with empty introduction text
|
||||
request.Dialog.IntroductionText = ""
|
||||
_, err = client.OpenInteractiveDialog(request)
|
||||
_, err = client.OpenInteractiveDialog(context.Background(), request)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Should pass with no elements
|
||||
request.Dialog.Elements = nil
|
||||
_, err = client.OpenInteractiveDialog(request)
|
||||
_, err = client.OpenInteractiveDialog(context.Background(), request)
|
||||
require.NoError(t, err)
|
||||
|
||||
request.Dialog.Elements = []model.DialogElement{}
|
||||
_, err = client.OpenInteractiveDialog(request)
|
||||
_, err = client.OpenInteractiveDialog(context.Background(), request)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -248,19 +249,19 @@ func TestSubmitDialog(t *testing.T) {
|
||||
|
||||
submit.URL = ts.URL
|
||||
|
||||
submitResp, _, err := client.SubmitInteractiveDialog(submit)
|
||||
submitResp, _, err := client.SubmitInteractiveDialog(context.Background(), submit)
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, submitResp)
|
||||
|
||||
submit.URL = ""
|
||||
submitResp, resp, err := client.SubmitInteractiveDialog(submit)
|
||||
submitResp, resp, err := client.SubmitInteractiveDialog(context.Background(), submit)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
assert.Nil(t, submitResp)
|
||||
|
||||
submit.URL = ts.URL
|
||||
submit.ChannelId = model.NewId()
|
||||
submitResp, resp, err = client.SubmitInteractiveDialog(submit)
|
||||
submitResp, resp, err = client.SubmitInteractiveDialog(context.Background(), submit)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
assert.Nil(t, submitResp)
|
||||
@@ -268,7 +269,7 @@ func TestSubmitDialog(t *testing.T) {
|
||||
submit.URL = ts.URL
|
||||
submit.ChannelId = th.BasicChannel.Id
|
||||
submit.TeamId = model.NewId()
|
||||
submitResp, resp, err = client.SubmitInteractiveDialog(submit)
|
||||
submitResp, resp, err = client.SubmitInteractiveDialog(context.Background(), submit)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
assert.Nil(t, submitResp)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -27,19 +28,19 @@ func TestCreateJob(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("valid job as user without permissions", func(t *testing.T) {
|
||||
_, resp, err := th.SystemManagerClient.CreateJob(job)
|
||||
_, resp, err := th.SystemManagerClient.CreateJob(context.Background(), job)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("valid job as user with permissions", func(t *testing.T) {
|
||||
received, _, err := th.SystemAdminClient.CreateJob(job)
|
||||
received, _, err := th.SystemAdminClient.CreateJob(context.Background(), job)
|
||||
require.NoError(t, err)
|
||||
defer th.App.Srv().Store().Job().Delete(received.Id)
|
||||
})
|
||||
|
||||
t.Run("invalid job type as user without permissions", func(t *testing.T) {
|
||||
_, resp, err := th.SystemAdminClient.CreateJob(&model.Job{Type: model.NewId()})
|
||||
_, resp, err := th.SystemAdminClient.CreateJob(context.Background(), &model.Job{Type: model.NewId()})
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
@@ -59,21 +60,21 @@ func TestGetJob(t *testing.T) {
|
||||
|
||||
defer th.App.Srv().Store().Job().Delete(job.Id)
|
||||
|
||||
received, _, err := th.SystemAdminClient.GetJob(job.Id)
|
||||
received, _, err := th.SystemAdminClient.GetJob(context.Background(), job.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, job.Id, received.Id, "incorrect job received")
|
||||
require.Equal(t, job.Status, received.Status, "incorrect job received")
|
||||
|
||||
_, resp, err := th.SystemAdminClient.GetJob("1234")
|
||||
_, resp, err := th.SystemAdminClient.GetJob(context.Background(), "1234")
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
_, resp, err = th.Client.GetJob(job.Id)
|
||||
_, resp, err = th.Client.GetJob(context.Background(), job.Id)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
_, resp, err = th.SystemAdminClient.GetJob(model.NewId())
|
||||
_, resp, err = th.SystemAdminClient.GetJob(context.Background(), model.NewId())
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
}
|
||||
@@ -109,19 +110,19 @@ func TestGetJobs(t *testing.T) {
|
||||
defer th.App.Srv().Store().Job().Delete(job.Id)
|
||||
}
|
||||
|
||||
received, _, err := th.SystemAdminClient.GetJobs(0, 2)
|
||||
received, _, err := th.SystemAdminClient.GetJobs(context.Background(), 0, 2)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, received, 2, "received wrong number of jobs")
|
||||
require.Equal(t, jobs[2].Id, received[0].Id, "should've received newest job first")
|
||||
require.Equal(t, jobs[0].Id, received[1].Id, "should've received second newest job second")
|
||||
|
||||
received, _, err = th.SystemAdminClient.GetJobs(1, 2)
|
||||
received, _, err = th.SystemAdminClient.GetJobs(context.Background(), 1, 2)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, jobs[1].Id, received[0].Id, "should've received oldest job last")
|
||||
|
||||
_, resp, err := th.Client.GetJobs(0, 60)
|
||||
_, resp, err := th.Client.GetJobs(context.Background(), 0, 60)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
}
|
||||
@@ -162,32 +163,32 @@ func TestGetJobsByType(t *testing.T) {
|
||||
defer th.App.Srv().Store().Job().Delete(job.Id)
|
||||
}
|
||||
|
||||
received, _, err := th.SystemAdminClient.GetJobsByType(jobType, 0, 2)
|
||||
received, _, err := th.SystemAdminClient.GetJobsByType(context.Background(), jobType, 0, 2)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, received, 2, "received wrong number of jobs")
|
||||
require.Equal(t, jobs[2].Id, received[0].Id, "should've received newest job first")
|
||||
require.Equal(t, jobs[0].Id, received[1].Id, "should've received second newest job second")
|
||||
|
||||
received, _, err = th.SystemAdminClient.GetJobsByType(jobType, 1, 2)
|
||||
received, _, err = th.SystemAdminClient.GetJobsByType(context.Background(), jobType, 1, 2)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, received, 1, "received wrong number of jobs")
|
||||
require.Equal(t, jobs[1].Id, received[0].Id, "should've received oldest job last")
|
||||
|
||||
_, resp, err := th.SystemAdminClient.GetJobsByType("", 0, 60)
|
||||
_, resp, err := th.SystemAdminClient.GetJobsByType(context.Background(), "", 0, 60)
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
_, resp, err = th.SystemAdminClient.GetJobsByType(strings.Repeat("a", 33), 0, 60)
|
||||
_, resp, err = th.SystemAdminClient.GetJobsByType(context.Background(), strings.Repeat("a", 33), 0, 60)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
_, resp, err = th.Client.GetJobsByType(jobType, 0, 60)
|
||||
_, resp, err = th.Client.GetJobsByType(context.Background(), jobType, 0, 60)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
_, _, err = th.SystemManagerClient.GetJobsByType(model.JobTypeElasticsearchPostIndexing, 0, 60)
|
||||
_, _, err = th.SystemManagerClient.GetJobsByType(context.Background(), model.JobTypeElasticsearchPostIndexing, 0, 60)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -206,7 +207,7 @@ func TestDownloadJob(t *testing.T) {
|
||||
}
|
||||
|
||||
// DownloadExportResults is not set to true so we should get a not implemented error status
|
||||
_, resp, err := th.Client.DownloadJob(job.Id)
|
||||
_, resp, err := th.Client.DownloadJob(context.Background(), job.Id)
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
|
||||
@@ -215,12 +216,12 @@ func TestDownloadJob(t *testing.T) {
|
||||
})
|
||||
|
||||
// Normal user cannot download the results of these job (non-existent job)
|
||||
_, resp, err = th.Client.DownloadJob(job.Id)
|
||||
_, resp, err = th.Client.DownloadJob(context.Background(), job.Id)
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
// System admin trying to download the results of a non-existent job
|
||||
_, resp, err = th.SystemAdminClient.DownloadJob(job.Id)
|
||||
_, resp, err = th.SystemAdminClient.DownloadJob(context.Background(), job.Id)
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
@@ -236,16 +237,16 @@ func TestDownloadJob(t *testing.T) {
|
||||
os.Create(filePath)
|
||||
|
||||
// Normal user cannot download the results of these job (not the right permission)
|
||||
_, resp, err = th.Client.DownloadJob(job.Id)
|
||||
_, resp, err = th.Client.DownloadJob(context.Background(), job.Id)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
th.SystemManagerClient.DownloadJob(job.Id)
|
||||
th.SystemManagerClient.DownloadJob(context.Background(), job.Id)
|
||||
// System manager with default permissions cannot download the results of these job (Doesn't have correct permissions)
|
||||
_, resp, err = th.SystemManagerClient.DownloadJob(job.Id)
|
||||
_, resp, err = th.SystemManagerClient.DownloadJob(context.Background(), job.Id)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
_, resp, err = th.SystemAdminClient.DownloadJob(job.Id)
|
||||
_, resp, err = th.SystemAdminClient.DownloadJob(context.Background(), job.Id)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
@@ -254,7 +255,7 @@ func TestDownloadJob(t *testing.T) {
|
||||
require.True(t, updateStatus)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, resp, err = th.SystemAdminClient.DownloadJob(job.Id)
|
||||
_, resp, err = th.SystemAdminClient.DownloadJob(context.Background(), job.Id)
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
@@ -265,7 +266,7 @@ func TestDownloadJob(t *testing.T) {
|
||||
require.NoError(t, mkdirAllErr)
|
||||
os.Create(filePath)
|
||||
|
||||
_, _, err = th.SystemAdminClient.DownloadJob(job.Id)
|
||||
_, _, err = th.SystemAdminClient.DownloadJob(context.Background(), job.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Here we are creating a new job which doesn't have type of message export
|
||||
@@ -283,7 +284,7 @@ func TestDownloadJob(t *testing.T) {
|
||||
defer th.App.Srv().Store().Job().Delete(job.Id)
|
||||
|
||||
// System admin shouldn't be able to download since the job type is not message export
|
||||
_, resp, err = th.SystemAdminClient.DownloadJob(job.Id)
|
||||
_, resp, err = th.SystemAdminClient.DownloadJob(context.Background(), job.Id)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
}
|
||||
@@ -317,21 +318,21 @@ func TestCancelJob(t *testing.T) {
|
||||
defer th.App.Srv().Store().Job().Delete(job.Id)
|
||||
}
|
||||
|
||||
resp, err := th.Client.CancelJob(jobs[0].Id)
|
||||
resp, err := th.Client.CancelJob(context.Background(), jobs[0].Id)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
_, err = th.SystemAdminClient.CancelJob(jobs[0].Id)
|
||||
_, err = th.SystemAdminClient.CancelJob(context.Background(), jobs[0].Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = th.SystemAdminClient.CancelJob(jobs[1].Id)
|
||||
_, err = th.SystemAdminClient.CancelJob(context.Background(), jobs[1].Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
resp, err = th.SystemAdminClient.CancelJob(jobs[2].Id)
|
||||
resp, err = th.SystemAdminClient.CancelJob(context.Background(), jobs[2].Id)
|
||||
require.Error(t, err)
|
||||
CheckInternalErrorStatus(t, resp)
|
||||
|
||||
resp, err = th.SystemAdminClient.CancelJob(model.NewId())
|
||||
resp, err = th.SystemAdminClient.CancelJob(context.Background(), model.NewId())
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -104,20 +105,20 @@ func TestTestLdap(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
resp, err := client.TestLdap()
|
||||
resp, err := client.TestLdap(context.Background())
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
require.Error(t, err)
|
||||
CheckErrorID(t, err, "api.ldap_groups.license_error")
|
||||
})
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("ldap_groups"))
|
||||
|
||||
resp, err := th.Client.TestLdap()
|
||||
resp, err := th.Client.TestLdap(context.Background())
|
||||
CheckForbiddenStatus(t, resp)
|
||||
require.Error(t, err)
|
||||
CheckErrorID(t, err, "api.context.permissions.app_error")
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
resp, err = client.TestLdap()
|
||||
resp, err = client.TestLdap(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
require.Error(t, err)
|
||||
@@ -130,7 +131,7 @@ func TestSyncLdap(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
resp, err := client.TestLdap()
|
||||
resp, err := client.TestLdap(context.Background())
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
require.Error(t, err)
|
||||
CheckErrorID(t, err, "api.ldap_groups.license_error")
|
||||
@@ -156,18 +157,18 @@ func TestSyncLdap(t *testing.T) {
|
||||
th.App.Channels().Ldap = ldapMock
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
_, err := client.SyncLdap(false)
|
||||
_, err := client.SyncLdap(context.Background(), false)
|
||||
<-ready
|
||||
require.NoError(t, err)
|
||||
require.False(t, includeRemovedMembers)
|
||||
|
||||
_, err = client.SyncLdap(true)
|
||||
_, err = client.SyncLdap(context.Background(), true)
|
||||
<-ready
|
||||
require.NoError(t, err)
|
||||
require.True(t, includeRemovedMembers)
|
||||
})
|
||||
|
||||
resp, err := th.Client.SyncLdap(false)
|
||||
resp, err := th.Client.SyncLdap(context.Background(), false)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
}
|
||||
@@ -176,12 +177,12 @@ func TestGetLdapGroups(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
_, resp, err := th.Client.GetLdapGroups()
|
||||
_, resp, err := th.Client.GetLdapGroups(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
_, resp, err := client.GetLdapGroups()
|
||||
_, resp, err := client.GetLdapGroups(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
})
|
||||
@@ -193,11 +194,11 @@ func TestLinkLdapGroup(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
_, resp, err := th.Client.LinkLdapGroup(entryUUID)
|
||||
_, resp, err := th.Client.LinkLdapGroup(context.Background(), entryUUID)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
_, resp, err = th.SystemAdminClient.LinkLdapGroup(entryUUID)
|
||||
_, resp, err = th.SystemAdminClient.LinkLdapGroup(context.Background(), entryUUID)
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
}
|
||||
@@ -208,11 +209,11 @@ func TestUnlinkLdapGroup(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
_, resp, err := th.Client.UnlinkLdapGroup(entryUUID)
|
||||
_, resp, err := th.Client.UnlinkLdapGroup(context.Background(), entryUUID)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
_, resp, err = th.SystemAdminClient.UnlinkLdapGroup(entryUUID)
|
||||
_, resp, err = th.SystemAdminClient.UnlinkLdapGroup(context.Background(), entryUUID)
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
}
|
||||
@@ -221,16 +222,16 @@ func TestMigrateIdLdap(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
resp, err := th.Client.MigrateIdLdap("objectGUID")
|
||||
resp, err := th.Client.MigrateIdLdap(context.Background(), "objectGUID")
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
resp, err = client.MigrateIdLdap("")
|
||||
resp, err = client.MigrateIdLdap(context.Background(), "")
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
resp, err = client.MigrateIdLdap("objectGUID")
|
||||
resp, err = client.MigrateIdLdap(context.Background(), "objectGUID")
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
})
|
||||
@@ -240,19 +241,19 @@ func TestUploadPublicCertificate(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
_, err := th.Client.UploadLdapPublicCertificate([]byte(spPublicCertificate))
|
||||
_, err := th.Client.UploadLdapPublicCertificate(context.Background(), []byte(spPublicCertificate))
|
||||
require.Error(t, err, "Should have failed. No System Admin privileges")
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
_, err = client.UploadLdapPublicCertificate([]byte(spPrivateKey))
|
||||
_, err = client.UploadLdapPublicCertificate(context.Background(), []byte(spPrivateKey))
|
||||
require.NoErrorf(t, err, "Should have passed. System Admin privileges %v", err)
|
||||
})
|
||||
|
||||
_, err = th.Client.DeleteLdapPublicCertificate()
|
||||
_, err = th.Client.DeleteLdapPublicCertificate(context.Background())
|
||||
require.Error(t, err, "Should have failed. No System Admin privileges")
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
_, err := client.DeleteLdapPublicCertificate()
|
||||
_, err := client.DeleteLdapPublicCertificate(context.Background())
|
||||
require.NoError(t, err, "Should have passed. System Admin privileges")
|
||||
})
|
||||
}
|
||||
@@ -261,19 +262,19 @@ func TestUploadPrivateCertificate(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
_, err := th.Client.UploadLdapPrivateCertificate([]byte(spPrivateKey))
|
||||
_, err := th.Client.UploadLdapPrivateCertificate(context.Background(), []byte(spPrivateKey))
|
||||
require.Error(t, err, "Should have failed. No System Admin privileges")
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
_, err = client.UploadLdapPrivateCertificate([]byte(spPrivateKey))
|
||||
_, err = client.UploadLdapPrivateCertificate(context.Background(), []byte(spPrivateKey))
|
||||
require.NoErrorf(t, err, "Should have passed. System Admin privileges %v", err)
|
||||
})
|
||||
|
||||
_, err = th.Client.DeleteLdapPrivateCertificate()
|
||||
_, err = th.Client.DeleteLdapPrivateCertificate(context.Background())
|
||||
require.Error(t, err, "Should have failed. No System Admin privileges")
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
_, err := client.DeleteLdapPrivateCertificate()
|
||||
_, err := client.DeleteLdapPrivateCertificate(context.Background())
|
||||
require.NoErrorf(t, err, "Should have passed. System Admin privileges %v", err)
|
||||
})
|
||||
}
|
||||
@@ -282,15 +283,15 @@ func TestAddUserToGroupSyncables(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
resp, err := th.Client.AddUserToGroupSyncables(th.BasicUser.Id)
|
||||
resp, err := th.Client.AddUserToGroupSyncables(context.Background(), th.BasicUser.Id)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
resp, err = th.SystemAdminClient.AddUserToGroupSyncables("invalid-user-id")
|
||||
resp, err = th.SystemAdminClient.AddUserToGroupSyncables(context.Background(), "invalid-user-id")
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
resp, err = th.SystemAdminClient.AddUserToGroupSyncables(th.BasicUser.Id)
|
||||
resp, err = th.SystemAdminClient.AddUserToGroupSyncables(context.Background(), th.BasicUser.Id)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
@@ -304,7 +305,7 @@ func TestAddUserToGroupSyncables(t *testing.T) {
|
||||
user, err = th.App.Srv().Store().User().Save(user)
|
||||
require.NoError(t, err)
|
||||
|
||||
resp, err = th.SystemAdminClient.AddUserToGroupSyncables(user.Id)
|
||||
resp, err = th.SystemAdminClient.AddUserToGroupSyncables(context.Background(), user.Id)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@@ -25,27 +26,27 @@ func TestGetOldClientLicense(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
client := th.Client
|
||||
|
||||
license, _, err := client.GetOldClientLicense("")
|
||||
license, _, err := client.GetOldClientLicense(context.Background(), "")
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NotEqual(t, license["IsLicensed"], "", "license not returned correctly")
|
||||
|
||||
client.Logout()
|
||||
client.Logout(context.Background())
|
||||
|
||||
_, _, err = client.GetOldClientLicense("")
|
||||
_, _, err = client.GetOldClientLicense(context.Background(), "")
|
||||
require.NoError(t, err)
|
||||
|
||||
resp, err := client.DoAPIGet("/license/client", "")
|
||||
resp, err := client.DoAPIGet(context.Background(), "/license/client", "")
|
||||
require.Error(t, err, "get /license/client did not return an error")
|
||||
require.Equal(t, http.StatusBadRequest, resp.StatusCode,
|
||||
"expected 400 bad request")
|
||||
|
||||
resp, err = client.DoAPIGet("/license/client?format=junk", "")
|
||||
resp, err = client.DoAPIGet(context.Background(), "/license/client?format=junk", "")
|
||||
require.Error(t, err, "get /license/client?format=junk did not return an error")
|
||||
require.Equal(t, http.StatusBadRequest, resp.StatusCode,
|
||||
"expected 400 Bad Request")
|
||||
|
||||
license, _, err = th.SystemAdminClient.GetOldClientLicense("")
|
||||
license, _, err = th.SystemAdminClient.GetOldClientLicense(context.Background(), "")
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NotEmpty(t, license["IsLicensed"], "license not returned correctly")
|
||||
@@ -58,13 +59,13 @@ func TestUploadLicenseFile(t *testing.T) {
|
||||
LocalClient := th.LocalClient
|
||||
|
||||
t.Run("as system user", func(t *testing.T) {
|
||||
resp, err := client.UploadLicenseFile([]byte{})
|
||||
resp, err := client.UploadLicenseFile(context.Background(), []byte{})
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
|
||||
resp, err := c.UploadLicenseFile([]byte{})
|
||||
resp, err := c.UploadLicenseFile(context.Background(), []byte{})
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
}, "as system admin user")
|
||||
@@ -72,14 +73,14 @@ func TestUploadLicenseFile(t *testing.T) {
|
||||
t.Run("as restricted system admin user", func(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ExperimentalSettings.RestrictSystemAdmin = true })
|
||||
|
||||
resp, err := th.SystemAdminClient.UploadLicenseFile([]byte{})
|
||||
resp, err := th.SystemAdminClient.UploadLicenseFile(context.Background(), []byte{})
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("restricted admin setting not honoured through local client", func(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ExperimentalSettings.RestrictSystemAdmin = true })
|
||||
resp, err := LocalClient.UploadLicenseFile([]byte{})
|
||||
resp, err := LocalClient.UploadLicenseFile(context.Background(), []byte{})
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
@@ -115,7 +116,7 @@ func TestUploadLicenseFile(t *testing.T) {
|
||||
licenseManagerMock.On("CanStartTrial").Return(false, nil).Once()
|
||||
th.App.Srv().Platform().SetLicenseManager(licenseManagerMock)
|
||||
|
||||
resp, err := th.SystemAdminClient.UploadLicenseFile([]byte("sadasdasdasdasdasdsa"))
|
||||
resp, err := th.SystemAdminClient.UploadLicenseFile(context.Background(), []byte("sadasdasdasdasdasdsa"))
|
||||
CheckErrorID(t, err, "api.license.request-trial.can-start-trial.not-allowed")
|
||||
require.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
||||
})
|
||||
@@ -146,7 +147,7 @@ func TestUploadLicenseFile(t *testing.T) {
|
||||
mockLicenseValidator.On("ValidateLicense", mock.Anything).Return(true, string(licenseBytes))
|
||||
utils.LicenseValidator = &mockLicenseValidator
|
||||
|
||||
resp, err := th.SystemAdminClient.UploadLicenseFile([]byte(""))
|
||||
resp, err := th.SystemAdminClient.UploadLicenseFile(context.Background(), []byte(""))
|
||||
CheckErrorID(t, err, "api.license.upgrade_needed.app_error")
|
||||
require.Equal(t, http.StatusInternalServerError, resp.StatusCode)
|
||||
})
|
||||
@@ -184,7 +185,7 @@ func TestUploadLicenseFile(t *testing.T) {
|
||||
licenseManagerMock.On("CanStartTrial").Return(false, nil).Once()
|
||||
th.App.Srv().Platform().SetLicenseManager(licenseManagerMock)
|
||||
|
||||
resp, err := th.SystemAdminClient.UploadLicenseFile([]byte("sadasdasdasdasdasdsa"))
|
||||
resp, err := th.SystemAdminClient.UploadLicenseFile(context.Background(), []byte("sadasdasdasdasdasdsa"))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
})
|
||||
@@ -197,20 +198,20 @@ func TestRemoveLicenseFile(t *testing.T) {
|
||||
LocalClient := th.LocalClient
|
||||
|
||||
t.Run("as system user", func(t *testing.T) {
|
||||
resp, err := client.RemoveLicenseFile()
|
||||
resp, err := client.RemoveLicenseFile(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
|
||||
_, err := c.RemoveLicenseFile()
|
||||
_, err := c.RemoveLicenseFile(context.Background())
|
||||
require.NoError(t, err)
|
||||
}, "as system admin user")
|
||||
|
||||
t.Run("as restricted system admin user", func(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ExperimentalSettings.RestrictSystemAdmin = true })
|
||||
|
||||
resp, err := th.SystemAdminClient.RemoveLicenseFile()
|
||||
resp, err := th.SystemAdminClient.RemoveLicenseFile(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
@@ -218,7 +219,7 @@ func TestRemoveLicenseFile(t *testing.T) {
|
||||
t.Run("restricted admin setting not honoured through local client", func(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ExperimentalSettings.RestrictSystemAdmin = true })
|
||||
|
||||
_, err := LocalClient.RemoveLicenseFile()
|
||||
_, err := LocalClient.RemoveLicenseFile(context.Background())
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
@@ -251,7 +252,7 @@ func TestRequestTrialLicenseWithExtraFields(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("permission denied", func(t *testing.T) {
|
||||
resp, err := th.Client.RequestTrialLicenseWithExtraFields(&model.TrialLicenseRequest{})
|
||||
resp, err := th.Client.RequestTrialLicenseWithExtraFields(context.Background(), &model.TrialLicenseRequest{})
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
@@ -287,7 +288,7 @@ func TestRequestTrialLicenseWithExtraFields(t *testing.T) {
|
||||
|
||||
cloud.On("ValidateBusinessEmail", mock.Anything, mock.Anything).Return(nil)
|
||||
|
||||
resp, err := th.SystemAdminClient.RequestTrialLicenseWithExtraFields(validTrialRequest)
|
||||
resp, err := th.SystemAdminClient.RequestTrialLicenseWithExtraFields(context.Background(), validTrialRequest)
|
||||
CheckErrorID(t, err, "api.license.add_license.unique_users.app_error")
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
@@ -318,7 +319,7 @@ func TestRequestTrialLicenseWithExtraFields(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.CloudSettings.CWSURL = requestTrialURL })
|
||||
}(originalCwsUrl)
|
||||
|
||||
resp, err := th.SystemAdminClient.RequestTrialLicenseWithExtraFields(validTrialRequest)
|
||||
resp, err := th.SystemAdminClient.RequestTrialLicenseWithExtraFields(context.Background(), validTrialRequest)
|
||||
require.Error(t, err)
|
||||
require.Equal(t, resp.StatusCode, 451)
|
||||
})
|
||||
@@ -357,14 +358,14 @@ func TestRequestTrialLicenseWithExtraFields(t *testing.T) {
|
||||
|
||||
cloud.On("ValidateBusinessEmail", mock.Anything, mock.Anything).Return(nil)
|
||||
|
||||
resp, err := th.SystemAdminClient.RequestTrialLicenseWithExtraFields(validTrialRequest)
|
||||
resp, err := th.SystemAdminClient.RequestTrialLicenseWithExtraFields(context.Background(), validTrialRequest)
|
||||
CheckErrorID(t, err, "api.license.request-trial.bad-request")
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
|
||||
th.App.Srv().Platform().SetLicenseManager(nil)
|
||||
t.Run("trial license should fail if LicenseManager is nil", func(t *testing.T) {
|
||||
resp, err := th.SystemAdminClient.RequestTrialLicenseWithExtraFields(validTrialRequest)
|
||||
resp, err := th.SystemAdminClient.RequestTrialLicenseWithExtraFields(context.Background(), validTrialRequest)
|
||||
CheckErrorID(t, err, "api.license.upgrade_needed.app_error")
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
@@ -382,7 +383,7 @@ func TestRequestTrialLicense(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.SiteURL = "http://localhost:8065/" })
|
||||
|
||||
t.Run("permission denied", func(t *testing.T) {
|
||||
resp, err := th.Client.RequestTrialLicense(1000)
|
||||
resp, err := th.Client.RequestTrialLicense(context.Background(), 1000)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
@@ -417,7 +418,7 @@ func TestRequestTrialLicense(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.CloudSettings.CWSURL = requestTrialURL })
|
||||
}(originalCwsUrl)
|
||||
|
||||
resp, err := th.SystemAdminClient.RequestTrialLicense(nUsers)
|
||||
resp, err := th.SystemAdminClient.RequestTrialLicense(context.Background(), nUsers)
|
||||
CheckErrorID(t, err, "api.license.add_license.unique_users.app_error")
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
@@ -448,14 +449,14 @@ func TestRequestTrialLicense(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.CloudSettings.CWSURL = requestTrialURL })
|
||||
}(originalCwsUrl)
|
||||
|
||||
resp, err := th.SystemAdminClient.RequestTrialLicense(nUsers)
|
||||
resp, err := th.SystemAdminClient.RequestTrialLicense(context.Background(), nUsers)
|
||||
require.Error(t, err)
|
||||
require.Equal(t, resp.StatusCode, 451)
|
||||
})
|
||||
|
||||
th.App.Srv().Platform().SetLicenseManager(nil)
|
||||
t.Run("trial license should fail if LicenseManager is nil", func(t *testing.T) {
|
||||
resp, err := th.SystemAdminClient.RequestTrialLicense(1)
|
||||
resp, err := th.SystemAdminClient.RequestTrialLicense(context.Background(), 1)
|
||||
CheckErrorID(t, err, "api.license.upgrade_needed.app_error")
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
@@ -471,7 +472,7 @@ func TestRequestRenewalLink(t *testing.T) {
|
||||
th.App.Srv().Cloud = cloudImpl
|
||||
}()
|
||||
th.App.Srv().Cloud = nil
|
||||
resp, err := th.SystemAdminClient.DoAPIGet("/license/renewal", "")
|
||||
resp, err := th.SystemAdminClient.DoAPIGet(context.Background(), "/license/renewal", "")
|
||||
CheckErrorID(t, err, "app.license.generate_renewal_token.no_license")
|
||||
require.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
||||
})
|
||||
@@ -483,7 +484,7 @@ func TestRequestTrueUpReview(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
th.App.Srv().SetLicense(model.NewTestLicense())
|
||||
|
||||
th.Client.Login(th.SystemAdminUser.Email, th.SystemAdminUser.Password)
|
||||
th.Client.Login(context.Background(), th.SystemAdminUser.Email, th.SystemAdminUser.Password)
|
||||
|
||||
cloud := mocks.CloudInterface{}
|
||||
cloud.Mock.On("SubmitTrueUpReview", mock.Anything, mock.Anything).Return(nil)
|
||||
@@ -495,7 +496,7 @@ func TestRequestTrueUpReview(t *testing.T) {
|
||||
th.App.Srv().Cloud = &cloud
|
||||
|
||||
var reviewProfile map[string]any
|
||||
resp, err := th.Client.SubmitTrueUpReview(reviewProfile)
|
||||
resp, err := th.Client.SubmitTrueUpReview(context.Background(), reviewProfile)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
})
|
||||
@@ -507,7 +508,7 @@ func TestRequestTrueUpReview(t *testing.T) {
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
|
||||
resp, err := th.SystemAdminClient.DoAPIPost("/license/review", "")
|
||||
resp, err := th.SystemAdminClient.DoAPIPost(context.Background(), "/license/review", "")
|
||||
require.Error(t, err)
|
||||
require.Equal(t, http.StatusNotImplemented, resp.StatusCode)
|
||||
|
||||
@@ -519,7 +520,7 @@ func TestRequestTrueUpReview(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
th.App.Srv().SetLicense(model.NewTestLicense())
|
||||
|
||||
resp, err := th.Client.DoAPIPost("/license/review", "")
|
||||
resp, err := th.Client.DoAPIPost(context.Background(), "/license/review", "")
|
||||
require.Error(t, err)
|
||||
require.Equal(t, http.StatusForbidden, resp.StatusCode)
|
||||
})
|
||||
@@ -530,7 +531,7 @@ func TestRequestTrueUpReview(t *testing.T) {
|
||||
|
||||
th.App.Srv().SetLicense(nil)
|
||||
|
||||
resp, err := th.SystemAdminClient.DoAPIPost("/license/review", "")
|
||||
resp, err := th.SystemAdminClient.DoAPIPost(context.Background(), "/license/review", "")
|
||||
require.Error(t, err)
|
||||
require.Equal(t, http.StatusNotImplemented, resp.StatusCode)
|
||||
})
|
||||
@@ -543,7 +544,7 @@ func TestTrueUpReviewStatus(t *testing.T) {
|
||||
th.App.Srv().SetLicense(model.NewTestLicense())
|
||||
|
||||
t.Run("returns 200 when status retrieved", func(t *testing.T) {
|
||||
resp, err := th.SystemAdminClient.DoAPIGet("/license/review/status", "")
|
||||
resp, err := th.SystemAdminClient.DoAPIGet(context.Background(), "/license/review/status", "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
})
|
||||
@@ -551,7 +552,7 @@ func TestTrueUpReviewStatus(t *testing.T) {
|
||||
t.Run("returns 501 when ran by cloud user", func(t *testing.T) {
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
|
||||
resp, err := th.SystemAdminClient.DoAPIGet("/license/review/status", "")
|
||||
resp, err := th.SystemAdminClient.DoAPIGet(context.Background(), "/license/review/status", "")
|
||||
require.Error(t, err)
|
||||
require.Equal(t, http.StatusNotImplemented, resp.StatusCode)
|
||||
|
||||
@@ -559,7 +560,7 @@ func TestTrueUpReviewStatus(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("returns 403 when user does not have permissions", func(t *testing.T) {
|
||||
resp, err := th.Client.DoAPIGet("/license/review/status", "")
|
||||
resp, err := th.Client.DoAPIGet(context.Background(), "/license/review/status", "")
|
||||
require.Error(t, err)
|
||||
require.Equal(t, http.StatusForbidden, resp.StatusCode)
|
||||
})
|
||||
@@ -567,7 +568,7 @@ func TestTrueUpReviewStatus(t *testing.T) {
|
||||
t.Run("returns 400 when license is nil", func(t *testing.T) {
|
||||
th.App.Srv().SetLicense(nil)
|
||||
|
||||
resp, err := th.SystemAdminClient.DoAPIGet("/license/review/status", "")
|
||||
resp, err := th.SystemAdminClient.DoAPIGet(context.Background(), "/license/review/status", "")
|
||||
require.Error(t, err)
|
||||
require.Equal(t, http.StatusNotImplemented, resp.StatusCode)
|
||||
})
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
@@ -16,7 +17,7 @@ func TestNotifyAdmin(t *testing.T) {
|
||||
th := Setup(t).InitBasic().InitLogin()
|
||||
defer th.TearDown()
|
||||
|
||||
statusCode, err := th.Client.NotifyAdmin(&model.NotifyAdminToUpgradeRequest{
|
||||
statusCode, err := th.Client.NotifyAdmin(context.Background(), &model.NotifyAdminToUpgradeRequest{
|
||||
RequiredPlan: "Unknown plan",
|
||||
RequiredFeature: model.PaidFeatureAllProfessionalfeatures,
|
||||
})
|
||||
@@ -31,7 +32,7 @@ func TestNotifyAdmin(t *testing.T) {
|
||||
th := Setup(t).InitBasic().InitLogin()
|
||||
defer th.TearDown()
|
||||
|
||||
statusCode, err := th.Client.NotifyAdmin(&model.NotifyAdminToUpgradeRequest{
|
||||
statusCode, err := th.Client.NotifyAdmin(context.Background(), &model.NotifyAdminToUpgradeRequest{
|
||||
RequiredPlan: "Unknown plan",
|
||||
RequiredFeature: model.PaidFeatureAllProfessionalfeatures,
|
||||
TrialNotification: true,
|
||||
@@ -47,7 +48,7 @@ func TestNotifyAdmin(t *testing.T) {
|
||||
th := Setup(t).InitBasic().InitLogin()
|
||||
defer th.TearDown()
|
||||
|
||||
statusCode, err := th.Client.NotifyAdmin(&model.NotifyAdminToUpgradeRequest{
|
||||
statusCode, err := th.Client.NotifyAdmin(context.Background(), &model.NotifyAdminToUpgradeRequest{
|
||||
RequiredPlan: model.LicenseShortSkuProfessional,
|
||||
RequiredFeature: "Unknown feature",
|
||||
})
|
||||
@@ -61,7 +62,7 @@ func TestNotifyAdmin(t *testing.T) {
|
||||
th := Setup(t).InitBasic().InitLogin()
|
||||
defer th.TearDown()
|
||||
|
||||
statusCode, err := th.Client.NotifyAdmin(&model.NotifyAdminToUpgradeRequest{
|
||||
statusCode, err := th.Client.NotifyAdmin(context.Background(), &model.NotifyAdminToUpgradeRequest{
|
||||
RequiredPlan: model.LicenseShortSkuProfessional,
|
||||
RequiredFeature: "Unknown feature",
|
||||
TrialNotification: true,
|
||||
@@ -76,7 +77,7 @@ func TestNotifyAdmin(t *testing.T) {
|
||||
th := Setup(t).InitBasic().InitLogin()
|
||||
defer th.TearDown()
|
||||
|
||||
statusCode, err := th.Client.NotifyAdmin(&model.NotifyAdminToUpgradeRequest{
|
||||
statusCode, err := th.Client.NotifyAdmin(context.Background(), &model.NotifyAdminToUpgradeRequest{
|
||||
RequiredPlan: model.LicenseShortSkuProfessional,
|
||||
RequiredFeature: model.PaidFeatureAllProfessionalfeatures,
|
||||
})
|
||||
@@ -84,7 +85,7 @@ func TestNotifyAdmin(t *testing.T) {
|
||||
require.Equal(t, http.StatusOK, statusCode)
|
||||
|
||||
// second attempt to notify for all professional features
|
||||
statusCode, err = th.Client.NotifyAdmin(&model.NotifyAdminToUpgradeRequest{
|
||||
statusCode, err = th.Client.NotifyAdmin(context.Background(), &model.NotifyAdminToUpgradeRequest{
|
||||
RequiredPlan: model.LicenseShortSkuProfessional,
|
||||
RequiredFeature: model.PaidFeatureAllProfessionalfeatures,
|
||||
})
|
||||
@@ -98,7 +99,7 @@ func TestNotifyAdmin(t *testing.T) {
|
||||
th := Setup(t).InitBasic().InitLogin()
|
||||
defer th.TearDown()
|
||||
|
||||
statusCode, err := th.Client.NotifyAdmin(&model.NotifyAdminToUpgradeRequest{
|
||||
statusCode, err := th.Client.NotifyAdmin(context.Background(), &model.NotifyAdminToUpgradeRequest{
|
||||
RequiredPlan: model.LicenseShortSkuProfessional,
|
||||
RequiredFeature: model.PaidFeatureAllProfessionalfeatures,
|
||||
})
|
||||
@@ -115,7 +116,7 @@ func TestTriggerNotifyAdmin(t *testing.T) {
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableAPITriggerAdminNotifications = false })
|
||||
|
||||
statusCode, err := th.SystemAdminClient.TriggerNotifyAdmin(&model.NotifyAdminToUpgradeRequest{})
|
||||
statusCode, err := th.SystemAdminClient.TriggerNotifyAdmin(context.Background(), &model.NotifyAdminToUpgradeRequest{})
|
||||
|
||||
require.Error(t, err)
|
||||
require.Equal(t, ": Internal error during cloud api request.", err.Error())
|
||||
@@ -129,7 +130,7 @@ func TestTriggerNotifyAdmin(t *testing.T) {
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableAPITriggerAdminNotifications = true })
|
||||
|
||||
statusCode, err := th.Client.TriggerNotifyAdmin(&model.NotifyAdminToUpgradeRequest{})
|
||||
statusCode, err := th.Client.TriggerNotifyAdmin(context.Background(), &model.NotifyAdminToUpgradeRequest{})
|
||||
|
||||
require.Error(t, err)
|
||||
require.Equal(t, ": You do not have the appropriate permissions.", err.Error())
|
||||
@@ -142,14 +143,14 @@ func TestTriggerNotifyAdmin(t *testing.T) {
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableAPITriggerAdminNotifications = true })
|
||||
|
||||
statusCode, err := th.Client.NotifyAdmin(&model.NotifyAdminToUpgradeRequest{
|
||||
statusCode, err := th.Client.NotifyAdmin(context.Background(), &model.NotifyAdminToUpgradeRequest{
|
||||
RequiredPlan: model.LicenseShortSkuProfessional,
|
||||
RequiredFeature: model.PaidFeatureAllProfessionalfeatures,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, statusCode)
|
||||
|
||||
statusCode, err = th.SystemAdminClient.TriggerNotifyAdmin(&model.NotifyAdminToUpgradeRequest{})
|
||||
statusCode, err = th.SystemAdminClient.TriggerNotifyAdmin(context.Background(), &model.NotifyAdminToUpgradeRequest{})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, statusCode)
|
||||
})
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
@@ -33,7 +34,7 @@ func TestCreateOAuthApp(t *testing.T) {
|
||||
|
||||
oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}, IsTrusted: true}
|
||||
|
||||
rapp, resp, err := adminClient.CreateOAuthApp(oapp)
|
||||
rapp, resp, err := adminClient.CreateOAuthApp(context.Background(), oapp)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
assert.Equal(t, oapp.Name, rapp.Name, "names did not match")
|
||||
@@ -42,35 +43,35 @@ func TestCreateOAuthApp(t *testing.T) {
|
||||
// Revoke permission from regular users.
|
||||
th.RemovePermissionFromRole(model.PermissionManageOAuth.Id, model.SystemUserRoleId)
|
||||
|
||||
_, resp, err = client.CreateOAuthApp(oapp)
|
||||
_, resp, err = client.CreateOAuthApp(context.Background(), oapp)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
// Grant permission to regular users.
|
||||
th.AddPermissionToRole(model.PermissionManageOAuth.Id, model.SystemUserRoleId)
|
||||
|
||||
rapp, resp, err = client.CreateOAuthApp(oapp)
|
||||
rapp, resp, err = client.CreateOAuthApp(context.Background(), oapp)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
|
||||
assert.False(t, rapp.IsTrusted, "trusted should be false - created by non admin")
|
||||
|
||||
oapp.Name = ""
|
||||
_, resp, err = adminClient.CreateOAuthApp(oapp)
|
||||
_, resp, err = adminClient.CreateOAuthApp(context.Background(), oapp)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
r, err := client.DoAPIPost("/oauth/apps", "garbage")
|
||||
r, err := client.DoAPIPost(context.Background(), "/oauth/apps", "garbage")
|
||||
require.Error(t, err, "expected error from garbage post")
|
||||
assert.Equal(t, http.StatusBadRequest, r.StatusCode)
|
||||
|
||||
client.Logout()
|
||||
_, resp, err = client.CreateOAuthApp(oapp)
|
||||
client.Logout(context.Background())
|
||||
_, resp, err = client.CreateOAuthApp(context.Background(), oapp)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = false })
|
||||
oapp.Name = GenerateTestAppName()
|
||||
_, resp, err = adminClient.CreateOAuthApp(oapp)
|
||||
_, resp, err = adminClient.CreateOAuthApp(context.Background(), oapp)
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
}
|
||||
@@ -101,7 +102,7 @@ func TestUpdateOAuthApp(t *testing.T) {
|
||||
CallbackUrls: []string{"https://callback.com"},
|
||||
}
|
||||
|
||||
oapp, _, _ = adminClient.CreateOAuthApp(oapp)
|
||||
oapp, _, _ = adminClient.CreateOAuthApp(context.Background(), oapp)
|
||||
|
||||
oapp.Name = "oapp_update"
|
||||
oapp.IsTrusted = true
|
||||
@@ -110,7 +111,7 @@ func TestUpdateOAuthApp(t *testing.T) {
|
||||
oapp.Description = "test_update"
|
||||
oapp.CallbackUrls = []string{"https://callback_update.com", "https://another_callback.com"}
|
||||
|
||||
updatedApp, _, err := adminClient.UpdateOAuthApp(oapp)
|
||||
updatedApp, _, err := adminClient.UpdateOAuthApp(context.Background(), oapp)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, oapp.Id, updatedApp.Id, "Id should have not updated")
|
||||
assert.Equal(t, oapp.CreatorId, updatedApp.CreatorId, "CreatorId should have not updated")
|
||||
@@ -131,7 +132,7 @@ func TestUpdateOAuthApp(t *testing.T) {
|
||||
|
||||
th.LoginBasic2()
|
||||
updatedApp.CreatorId = th.BasicUser2.Id
|
||||
_, resp, err := client.UpdateOAuthApp(oapp)
|
||||
_, resp, err := client.UpdateOAuthApp(context.Background(), oapp)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
@@ -140,28 +141,28 @@ func TestUpdateOAuthApp(t *testing.T) {
|
||||
// Revoke permission from regular users.
|
||||
th.RemovePermissionFromRole(model.PermissionManageOAuth.Id, model.SystemUserRoleId)
|
||||
|
||||
_, resp, err = client.UpdateOAuthApp(oapp)
|
||||
_, resp, err = client.UpdateOAuthApp(context.Background(), oapp)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
oapp.Id = "zhk9d1ggatrqz236c7h87im7bc"
|
||||
_, resp, err = adminClient.UpdateOAuthApp(oapp)
|
||||
_, resp, err = adminClient.UpdateOAuthApp(context.Background(), oapp)
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = false })
|
||||
|
||||
_, resp, err = adminClient.UpdateOAuthApp(oapp)
|
||||
_, resp, err = adminClient.UpdateOAuthApp(context.Background(), oapp)
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
|
||||
client.Logout()
|
||||
_, resp, err = client.UpdateOAuthApp(oapp)
|
||||
client.Logout(context.Background())
|
||||
_, resp, err = client.UpdateOAuthApp(context.Background(), oapp)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
|
||||
oapp.Id = "junk"
|
||||
_, resp, err = adminClient.UpdateOAuthApp(oapp)
|
||||
_, resp, err = adminClient.UpdateOAuthApp(context.Background(), oapp)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
@@ -178,21 +179,21 @@ func TestUpdateOAuthApp(t *testing.T) {
|
||||
CallbackUrls: []string{"https://callback.com"},
|
||||
}
|
||||
|
||||
userOapp, _, err = client.CreateOAuthApp(userOapp)
|
||||
userOapp, _, err = client.CreateOAuthApp(context.Background(), userOapp)
|
||||
require.NoError(t, err)
|
||||
|
||||
userOapp.IsTrusted = true
|
||||
userOapp, _, err = client.UpdateOAuthApp(userOapp)
|
||||
userOapp, _, err = client.UpdateOAuthApp(context.Background(), userOapp)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, userOapp.IsTrusted)
|
||||
|
||||
userOapp.IsTrusted = true
|
||||
userOapp, _, err = adminClient.UpdateOAuthApp(userOapp)
|
||||
userOapp, _, err = adminClient.UpdateOAuthApp(context.Background(), userOapp)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, userOapp.IsTrusted)
|
||||
|
||||
userOapp.IsTrusted = false
|
||||
userOapp, _, err = client.UpdateOAuthApp(userOapp)
|
||||
userOapp, _, err = client.UpdateOAuthApp(context.Background(), userOapp)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, userOapp.IsTrusted)
|
||||
}
|
||||
@@ -216,14 +217,14 @@ func TestGetOAuthApps(t *testing.T) {
|
||||
|
||||
oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}
|
||||
|
||||
rapp, _, err := adminClient.CreateOAuthApp(oapp)
|
||||
rapp, _, err := adminClient.CreateOAuthApp(context.Background(), oapp)
|
||||
require.NoError(t, err)
|
||||
|
||||
oapp.Name = GenerateTestAppName()
|
||||
rapp2, _, err := client.CreateOAuthApp(oapp)
|
||||
rapp2, _, err := client.CreateOAuthApp(context.Background(), oapp)
|
||||
require.NoError(t, err)
|
||||
|
||||
apps, _, err := adminClient.GetOAuthApps(0, 1000)
|
||||
apps, _, err := adminClient.GetOAuthApps(context.Background(), 0, 1000)
|
||||
require.NoError(t, err)
|
||||
|
||||
found1 := false
|
||||
@@ -239,29 +240,29 @@ func TestGetOAuthApps(t *testing.T) {
|
||||
assert.Truef(t, found1, "missing oauth app %v", rapp.Id)
|
||||
assert.Truef(t, found2, "missing oauth app %v", rapp2.Id)
|
||||
|
||||
apps, _, err = adminClient.GetOAuthApps(1, 1)
|
||||
apps, _, err = adminClient.GetOAuthApps(context.Background(), 1, 1)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, len(apps), "paging failed")
|
||||
|
||||
apps, _, err = client.GetOAuthApps(0, 1000)
|
||||
apps, _, err = client.GetOAuthApps(context.Background(), 0, 1000)
|
||||
require.NoError(t, err)
|
||||
require.True(t, len(apps) == 1 || apps[0].Id == rapp2.Id, "wrong apps returned")
|
||||
|
||||
// Revoke permission from regular users.
|
||||
th.RemovePermissionFromRole(model.PermissionManageOAuth.Id, model.SystemUserRoleId)
|
||||
|
||||
_, resp, err := client.GetOAuthApps(0, 1000)
|
||||
_, resp, err := client.GetOAuthApps(context.Background(), 0, 1000)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
client.Logout()
|
||||
client.Logout(context.Background())
|
||||
|
||||
_, resp, err = client.GetOAuthApps(0, 1000)
|
||||
_, resp, err = client.GetOAuthApps(context.Background(), 0, 1000)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = false })
|
||||
_, resp, err = adminClient.GetOAuthApps(0, 1000)
|
||||
_, resp, err = adminClient.GetOAuthApps(context.Background(), 0, 1000)
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
}
|
||||
@@ -285,53 +286,53 @@ func TestGetOAuthApp(t *testing.T) {
|
||||
|
||||
oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}
|
||||
|
||||
rapp, _, err := adminClient.CreateOAuthApp(oapp)
|
||||
rapp, _, err := adminClient.CreateOAuthApp(context.Background(), oapp)
|
||||
require.NoError(t, err)
|
||||
|
||||
oapp.Name = GenerateTestAppName()
|
||||
rapp2, _, err := client.CreateOAuthApp(oapp)
|
||||
rapp2, _, err := client.CreateOAuthApp(context.Background(), oapp)
|
||||
require.NoError(t, err)
|
||||
|
||||
rrapp, _, err := adminClient.GetOAuthApp(rapp.Id)
|
||||
rrapp, _, err := adminClient.GetOAuthApp(context.Background(), rapp.Id)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, rapp.Id, rrapp.Id, "wrong app")
|
||||
assert.NotEqual(t, "", rrapp.ClientSecret, "should not be sanitized")
|
||||
|
||||
rrapp2, _, err := adminClient.GetOAuthApp(rapp2.Id)
|
||||
rrapp2, _, err := adminClient.GetOAuthApp(context.Background(), rapp2.Id)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, rapp2.Id, rrapp2.Id, "wrong app")
|
||||
assert.NotEqual(t, "", rrapp2.ClientSecret, "should not be sanitized")
|
||||
|
||||
_, _, err = client.GetOAuthApp(rapp2.Id)
|
||||
_, _, err = client.GetOAuthApp(context.Background(), rapp2.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, resp, err := client.GetOAuthApp(rapp.Id)
|
||||
_, resp, err := client.GetOAuthApp(context.Background(), rapp.Id)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
// Revoke permission from regular users.
|
||||
th.RemovePermissionFromRole(model.PermissionManageOAuth.Id, model.SystemUserRoleId)
|
||||
|
||||
_, resp, err = client.GetOAuthApp(rapp2.Id)
|
||||
_, resp, err = client.GetOAuthApp(context.Background(), rapp2.Id)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
client.Logout()
|
||||
client.Logout(context.Background())
|
||||
|
||||
_, resp, err = client.GetOAuthApp(rapp2.Id)
|
||||
_, resp, err = client.GetOAuthApp(context.Background(), rapp2.Id)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
|
||||
_, resp, err = adminClient.GetOAuthApp("junk")
|
||||
_, resp, err = adminClient.GetOAuthApp(context.Background(), "junk")
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
_, resp, err = adminClient.GetOAuthApp(model.NewId())
|
||||
_, resp, err = adminClient.GetOAuthApp(context.Background(), model.NewId())
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = false })
|
||||
_, resp, err = adminClient.GetOAuthApp(rapp.Id)
|
||||
_, resp, err = adminClient.GetOAuthApp(context.Background(), rapp.Id)
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
}
|
||||
@@ -355,51 +356,51 @@ func TestGetOAuthAppInfo(t *testing.T) {
|
||||
|
||||
oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}
|
||||
|
||||
rapp, _, err := adminClient.CreateOAuthApp(oapp)
|
||||
rapp, _, err := adminClient.CreateOAuthApp(context.Background(), oapp)
|
||||
require.NoError(t, err)
|
||||
|
||||
oapp.Name = GenerateTestAppName()
|
||||
rapp2, _, err := client.CreateOAuthApp(oapp)
|
||||
rapp2, _, err := client.CreateOAuthApp(context.Background(), oapp)
|
||||
require.NoError(t, err)
|
||||
|
||||
rrapp, _, err := adminClient.GetOAuthAppInfo(rapp.Id)
|
||||
rrapp, _, err := adminClient.GetOAuthAppInfo(context.Background(), rapp.Id)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, rapp.Id, rrapp.Id, "wrong app")
|
||||
assert.Equal(t, "", rrapp.ClientSecret, "should be sanitized")
|
||||
|
||||
rrapp2, _, err := adminClient.GetOAuthAppInfo(rapp2.Id)
|
||||
rrapp2, _, err := adminClient.GetOAuthAppInfo(context.Background(), rapp2.Id)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, rapp2.Id, rrapp2.Id, "wrong app")
|
||||
assert.Equal(t, "", rrapp2.ClientSecret, "should be sanitized")
|
||||
|
||||
_, _, err = client.GetOAuthAppInfo(rapp2.Id)
|
||||
_, _, err = client.GetOAuthAppInfo(context.Background(), rapp2.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, err = client.GetOAuthAppInfo(rapp.Id)
|
||||
_, _, err = client.GetOAuthAppInfo(context.Background(), rapp.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Revoke permission from regular users.
|
||||
th.RemovePermissionFromRole(model.PermissionManageOAuth.Id, model.SystemUserRoleId)
|
||||
|
||||
_, _, err = client.GetOAuthAppInfo(rapp2.Id)
|
||||
_, _, err = client.GetOAuthAppInfo(context.Background(), rapp2.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
client.Logout()
|
||||
client.Logout(context.Background())
|
||||
|
||||
_, resp, err := client.GetOAuthAppInfo(rapp2.Id)
|
||||
_, resp, err := client.GetOAuthAppInfo(context.Background(), rapp2.Id)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
|
||||
_, resp, err = adminClient.GetOAuthAppInfo("junk")
|
||||
_, resp, err = adminClient.GetOAuthAppInfo(context.Background(), "junk")
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
_, resp, err = adminClient.GetOAuthAppInfo(model.NewId())
|
||||
_, resp, err = adminClient.GetOAuthAppInfo(context.Background(), model.NewId())
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = false })
|
||||
_, resp, err = adminClient.GetOAuthAppInfo(rapp.Id)
|
||||
_, resp, err = adminClient.GetOAuthAppInfo(context.Background(), rapp.Id)
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
}
|
||||
@@ -423,55 +424,55 @@ func TestDeleteOAuthApp(t *testing.T) {
|
||||
|
||||
oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}
|
||||
|
||||
rapp, _, err := adminClient.CreateOAuthApp(oapp)
|
||||
rapp, _, err := adminClient.CreateOAuthApp(context.Background(), oapp)
|
||||
require.NoError(t, err)
|
||||
|
||||
oapp.Name = GenerateTestAppName()
|
||||
rapp2, _, err := client.CreateOAuthApp(oapp)
|
||||
rapp2, _, err := client.CreateOAuthApp(context.Background(), oapp)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = adminClient.DeleteOAuthApp(rapp.Id)
|
||||
_, err = adminClient.DeleteOAuthApp(context.Background(), rapp.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = adminClient.DeleteOAuthApp(rapp2.Id)
|
||||
_, err = adminClient.DeleteOAuthApp(context.Background(), rapp2.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
rapp, _, err = adminClient.CreateOAuthApp(oapp)
|
||||
rapp, _, err = adminClient.CreateOAuthApp(context.Background(), oapp)
|
||||
require.NoError(t, err)
|
||||
|
||||
oapp.Name = GenerateTestAppName()
|
||||
rapp2, _, err = client.CreateOAuthApp(oapp)
|
||||
rapp2, _, err = client.CreateOAuthApp(context.Background(), oapp)
|
||||
require.NoError(t, err)
|
||||
|
||||
resp, err := client.DeleteOAuthApp(rapp.Id)
|
||||
resp, err := client.DeleteOAuthApp(context.Background(), rapp.Id)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
_, err = client.DeleteOAuthApp(rapp2.Id)
|
||||
_, err = client.DeleteOAuthApp(context.Background(), rapp2.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Revoke permission from regular users.
|
||||
th.RemovePermissionFromRole(model.PermissionManageOAuth.Id, model.SystemUserRoleId)
|
||||
|
||||
resp, err = client.DeleteOAuthApp(rapp.Id)
|
||||
resp, err = client.DeleteOAuthApp(context.Background(), rapp.Id)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
client.Logout()
|
||||
resp, err = client.DeleteOAuthApp(rapp.Id)
|
||||
client.Logout(context.Background())
|
||||
resp, err = client.DeleteOAuthApp(context.Background(), rapp.Id)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
|
||||
resp, err = adminClient.DeleteOAuthApp("junk")
|
||||
resp, err = adminClient.DeleteOAuthApp(context.Background(), "junk")
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
resp, err = adminClient.DeleteOAuthApp(model.NewId())
|
||||
resp, err = adminClient.DeleteOAuthApp(context.Background(), model.NewId())
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = false })
|
||||
resp, err = adminClient.DeleteOAuthApp(rapp.Id)
|
||||
resp, err = adminClient.DeleteOAuthApp(context.Background(), rapp.Id)
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
}
|
||||
@@ -495,57 +496,57 @@ func TestRegenerateOAuthAppSecret(t *testing.T) {
|
||||
|
||||
oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}
|
||||
|
||||
rapp, _, err := adminClient.CreateOAuthApp(oapp)
|
||||
rapp, _, err := adminClient.CreateOAuthApp(context.Background(), oapp)
|
||||
require.NoError(t, err)
|
||||
|
||||
oapp.Name = GenerateTestAppName()
|
||||
rapp2, _, err := client.CreateOAuthApp(oapp)
|
||||
rapp2, _, err := client.CreateOAuthApp(context.Background(), oapp)
|
||||
require.NoError(t, err)
|
||||
|
||||
rrapp, _, err := adminClient.RegenerateOAuthAppSecret(rapp.Id)
|
||||
rrapp, _, err := adminClient.RegenerateOAuthAppSecret(context.Background(), rapp.Id)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, rrapp.Id, rapp.Id, "wrong app")
|
||||
assert.NotEqual(t, rapp.ClientSecret, rrapp.ClientSecret, "secret didn't change")
|
||||
|
||||
_, _, err = adminClient.RegenerateOAuthAppSecret(rapp2.Id)
|
||||
_, _, err = adminClient.RegenerateOAuthAppSecret(context.Background(), rapp2.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
rapp, _, err = adminClient.CreateOAuthApp(oapp)
|
||||
rapp, _, err = adminClient.CreateOAuthApp(context.Background(), oapp)
|
||||
require.NoError(t, err)
|
||||
|
||||
oapp.Name = GenerateTestAppName()
|
||||
rapp2, _, err = client.CreateOAuthApp(oapp)
|
||||
rapp2, _, err = client.CreateOAuthApp(context.Background(), oapp)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, resp, err := client.RegenerateOAuthAppSecret(rapp.Id)
|
||||
_, resp, err := client.RegenerateOAuthAppSecret(context.Background(), rapp.Id)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
_, _, err = client.RegenerateOAuthAppSecret(rapp2.Id)
|
||||
_, _, err = client.RegenerateOAuthAppSecret(context.Background(), rapp2.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Revoke permission from regular users.
|
||||
th.RemovePermissionFromRole(model.PermissionManageOAuth.Id, model.SystemUserRoleId)
|
||||
|
||||
_, resp, err = client.RegenerateOAuthAppSecret(rapp.Id)
|
||||
_, resp, err = client.RegenerateOAuthAppSecret(context.Background(), rapp.Id)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
client.Logout()
|
||||
_, resp, err = client.RegenerateOAuthAppSecret(rapp.Id)
|
||||
client.Logout(context.Background())
|
||||
_, resp, err = client.RegenerateOAuthAppSecret(context.Background(), rapp.Id)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
|
||||
_, resp, err = adminClient.RegenerateOAuthAppSecret("junk")
|
||||
_, resp, err = adminClient.RegenerateOAuthAppSecret(context.Background(), "junk")
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
_, resp, err = adminClient.RegenerateOAuthAppSecret(model.NewId())
|
||||
_, resp, err = adminClient.RegenerateOAuthAppSecret(context.Background(), model.NewId())
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = false })
|
||||
_, resp, err = adminClient.RegenerateOAuthAppSecret(rapp.Id)
|
||||
_, resp, err = adminClient.RegenerateOAuthAppSecret(context.Background(), rapp.Id)
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
}
|
||||
@@ -564,7 +565,7 @@ func TestGetAuthorizedOAuthAppsForUser(t *testing.T) {
|
||||
|
||||
oapp := &model.OAuthApp{Name: GenerateTestAppName(), Homepage: "https://nowhere.com", Description: "test", CallbackUrls: []string{"https://nowhere.com"}}
|
||||
|
||||
rapp, _, err := adminClient.CreateOAuthApp(oapp)
|
||||
rapp, _, err := adminClient.CreateOAuthApp(context.Background(), oapp)
|
||||
require.NoError(t, err)
|
||||
|
||||
authRequest := &model.AuthorizeRequest{
|
||||
@@ -575,10 +576,10 @@ func TestGetAuthorizedOAuthAppsForUser(t *testing.T) {
|
||||
State: "123",
|
||||
}
|
||||
|
||||
_, _, err = client.AuthorizeOAuthApp(authRequest)
|
||||
_, _, err = client.AuthorizeOAuthApp(context.Background(), authRequest)
|
||||
require.NoError(t, err)
|
||||
|
||||
apps, _, err := client.GetAuthorizedOAuthAppsForUser(th.BasicUser.Id, 0, 1000)
|
||||
apps, _, err := client.GetAuthorizedOAuthAppsForUser(context.Background(), th.BasicUser.Id, 0, 1000)
|
||||
require.NoError(t, err)
|
||||
|
||||
found := false
|
||||
@@ -590,20 +591,20 @@ func TestGetAuthorizedOAuthAppsForUser(t *testing.T) {
|
||||
}
|
||||
require.True(t, found, "missing app")
|
||||
|
||||
_, resp, err := client.GetAuthorizedOAuthAppsForUser(th.BasicUser2.Id, 0, 1000)
|
||||
_, resp, err := client.GetAuthorizedOAuthAppsForUser(context.Background(), th.BasicUser2.Id, 0, 1000)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
_, resp, err = client.GetAuthorizedOAuthAppsForUser("junk", 0, 1000)
|
||||
_, resp, err = client.GetAuthorizedOAuthAppsForUser(context.Background(), "junk", 0, 1000)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
client.Logout()
|
||||
_, resp, err = client.GetAuthorizedOAuthAppsForUser(th.BasicUser.Id, 0, 1000)
|
||||
client.Logout(context.Background())
|
||||
_, resp, err = client.GetAuthorizedOAuthAppsForUser(context.Background(), th.BasicUser.Id, 0, 1000)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
|
||||
_, _, err = adminClient.GetAuthorizedOAuthAppsForUser(th.BasicUser.Id, 0, 1000)
|
||||
_, _, err = adminClient.GetAuthorizedOAuthAppsForUser(context.Background(), th.BasicUser.Id, 0, 1000)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -612,7 +613,7 @@ func TestNilAuthorizeOAuthApp(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
client := th.Client
|
||||
|
||||
_, _, err := client.AuthorizeOAuthApp(nil)
|
||||
_, _, err := client.AuthorizeOAuthApp(context.Background(), nil)
|
||||
require.Error(t, err)
|
||||
CheckErrorID(t, err, "api.context.invalid_body_param.app_error")
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@@ -59,7 +60,7 @@ func TestGetOpenGraphMetadata(t *testing.T) {
|
||||
{"path": "/no-og-data/", "title": "", "cacheMissCount": 2},
|
||||
} {
|
||||
|
||||
openGraph, _, err := client.OpenGraph(ts.URL + data["path"].(string))
|
||||
openGraph, _, err := client.OpenGraph(context.Background(), ts.URL+data["path"].(string))
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equalf(t, openGraph["title"], data["title"].(string),
|
||||
@@ -70,7 +71,7 @@ func TestGetOpenGraphMetadata(t *testing.T) {
|
||||
}
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableLinkPreviews = false })
|
||||
_, resp, err := client.OpenGraph(ts.URL + "/og-data/")
|
||||
_, resp, err := client.OpenGraph(context.Background(), ts.URL+"/og-data/")
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -21,7 +22,7 @@ func TestGetAncillaryPermissions(t *testing.T) {
|
||||
t.Run("Valid Case, Passing in SubSection Permissions", func(t *testing.T) {
|
||||
subsectionPermissions = []string{model.PermissionSysconsoleReadReportingSiteStatistics.Id}
|
||||
expectedAncillaryPermissions = []string{model.PermissionGetAnalytics.Id}
|
||||
actualAncillaryPermissions, _, err := th.Client.GetAncillaryPermissions(subsectionPermissions)
|
||||
actualAncillaryPermissions, _, err := th.Client.GetAncillaryPermissions(context.Background(), subsectionPermissions)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, append(subsectionPermissions, expectedAncillaryPermissions...), actualAncillaryPermissions)
|
||||
})
|
||||
@@ -29,7 +30,7 @@ func TestGetAncillaryPermissions(t *testing.T) {
|
||||
t.Run("Invalid Case, Passing in SubSection Permissions That Don't Exist", func(t *testing.T) {
|
||||
subsectionPermissions = []string{"All", "The", "Things", "She", "Said", "Running", "Through", "My", "Head"}
|
||||
expectedAncillaryPermissions = []string{}
|
||||
actualAncillaryPermissions, _, err := th.Client.GetAncillaryPermissions(subsectionPermissions)
|
||||
actualAncillaryPermissions, _, err := th.Client.GetAncillaryPermissions(context.Background(), subsectionPermissions)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, append(subsectionPermissions, expectedAncillaryPermissions...), actualAncillaryPermissions)
|
||||
})
|
||||
@@ -37,7 +38,7 @@ func TestGetAncillaryPermissions(t *testing.T) {
|
||||
t.Run("Invalid Case, Passing in nothing", func(t *testing.T) {
|
||||
subsectionPermissions = []string{}
|
||||
expectedAncillaryPermissions = []string{}
|
||||
_, resp, err := th.Client.GetAncillaryPermissions(subsectionPermissions)
|
||||
_, resp, err := th.Client.GetAncillaryPermissions(context.Background(), subsectionPermissions)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
|
||||
@@ -5,6 +5,7 @@ package api4
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@@ -56,15 +57,15 @@ func TestPlugin(t *testing.T) {
|
||||
|
||||
url := testServer.URL
|
||||
|
||||
manifest, _, err := client.InstallPluginFromURL(url, false)
|
||||
manifest, _, err := client.InstallPluginFromURL(context.Background(), url, false)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "testplugin", manifest.Id)
|
||||
|
||||
_, resp, err := client.InstallPluginFromURL(url, false)
|
||||
_, resp, err := client.InstallPluginFromURL(context.Background(), url, false)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
manifest, _, err = client.InstallPluginFromURL(url, true)
|
||||
manifest, _, err = client.InstallPluginFromURL(context.Background(), url, true)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "testplugin", manifest.Id)
|
||||
|
||||
@@ -73,41 +74,41 @@ func TestPlugin(t *testing.T) {
|
||||
assert.Nil(t, appErr)
|
||||
assert.True(t, pluginStored)
|
||||
|
||||
_, err = client.RemovePlugin(manifest.Id)
|
||||
_, err = client.RemovePlugin(context.Background(), manifest.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
th.App.Channels().RemovePlugin(manifest.Id)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PluginSettings.Enable = false })
|
||||
|
||||
_, resp, err = client.InstallPluginFromURL(url, false)
|
||||
_, resp, err = client.InstallPluginFromURL(context.Background(), url, false)
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PluginSettings.Enable = true })
|
||||
|
||||
_, resp, err = th.Client.InstallPluginFromURL(url, false)
|
||||
_, resp, err = th.Client.InstallPluginFromURL(context.Background(), url, false)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
_, resp, err = client.InstallPluginFromURL("http://nodata", false)
|
||||
_, resp, err = client.InstallPluginFromURL(context.Background(), "http://nodata", false)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PluginSettings.AllowInsecureDownloadURL = false })
|
||||
|
||||
_, resp, err = client.InstallPluginFromURL(url, false)
|
||||
_, resp, err = client.InstallPluginFromURL(context.Background(), url, false)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
// Successful upload
|
||||
manifest, _, err = client.UploadPlugin(bytes.NewReader(tarData))
|
||||
manifest, _, err = client.UploadPlugin(context.Background(), bytes.NewReader(tarData))
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "testplugin", manifest.Id)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PluginSettings.EnableUploads = true })
|
||||
|
||||
manifest, _, err = client.UploadPluginForced(bytes.NewReader(tarData))
|
||||
manifest, _, err = client.UploadPluginForced(context.Background(), bytes.NewReader(tarData))
|
||||
defer os.RemoveAll("plugins/testplugin")
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -119,12 +120,12 @@ func TestPlugin(t *testing.T) {
|
||||
assert.True(t, pluginStored)
|
||||
|
||||
// Upload error cases
|
||||
_, resp, err = client.UploadPlugin(bytes.NewReader([]byte("badfile")))
|
||||
_, resp, err = client.UploadPlugin(context.Background(), bytes.NewReader([]byte("badfile")))
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PluginSettings.Enable = false })
|
||||
_, resp, err = client.UploadPlugin(bytes.NewReader(tarData))
|
||||
_, resp, err = client.UploadPlugin(context.Background(), bytes.NewReader(tarData))
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
|
||||
@@ -132,21 +133,21 @@ func TestPlugin(t *testing.T) {
|
||||
*cfg.PluginSettings.Enable = true
|
||||
*cfg.PluginSettings.EnableUploads = false
|
||||
})
|
||||
_, resp, err = client.UploadPlugin(bytes.NewReader(tarData))
|
||||
_, resp, err = client.UploadPlugin(context.Background(), bytes.NewReader(tarData))
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
|
||||
_, resp, err = client.InstallPluginFromURL(url, false)
|
||||
_, resp, err = client.InstallPluginFromURL(context.Background(), url, false)
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PluginSettings.EnableUploads = true })
|
||||
_, resp, err = th.Client.UploadPlugin(bytes.NewReader(tarData))
|
||||
_, resp, err = th.Client.UploadPlugin(context.Background(), bytes.NewReader(tarData))
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
// Successful gets
|
||||
pluginsResp, _, err := client.GetPlugins()
|
||||
pluginsResp, _, err := client.GetPlugins(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
found := false
|
||||
@@ -168,10 +169,10 @@ func TestPlugin(t *testing.T) {
|
||||
assert.False(t, found)
|
||||
|
||||
// Successful activate
|
||||
_, err = client.EnablePlugin(manifest.Id)
|
||||
_, err = client.EnablePlugin(context.Background(), manifest.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
pluginsResp, _, err = client.GetPlugins()
|
||||
pluginsResp, _, err = client.GetPlugins(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
found = false
|
||||
@@ -184,19 +185,19 @@ func TestPlugin(t *testing.T) {
|
||||
assert.True(t, found)
|
||||
|
||||
// Activate error case
|
||||
resp, err = client.EnablePlugin("junk")
|
||||
resp, err = client.EnablePlugin(context.Background(), "junk")
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
resp, err = client.EnablePlugin("JUNK")
|
||||
resp, err = client.EnablePlugin(context.Background(), "JUNK")
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
// Successful deactivate
|
||||
_, err = client.DisablePlugin(manifest.Id)
|
||||
_, err = client.DisablePlugin(context.Background(), manifest.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
pluginsResp, _, err = client.GetPlugins()
|
||||
pluginsResp, _, err = client.GetPlugins(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
found = false
|
||||
@@ -209,26 +210,26 @@ func TestPlugin(t *testing.T) {
|
||||
assert.True(t, found)
|
||||
|
||||
// Deactivate error case
|
||||
resp, err = client.DisablePlugin("junk")
|
||||
resp, err = client.DisablePlugin(context.Background(), "junk")
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
// Get error cases
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PluginSettings.Enable = false })
|
||||
_, resp, err = client.GetPlugins()
|
||||
_, resp, err = client.GetPlugins(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PluginSettings.Enable = true })
|
||||
_, resp, err = th.Client.GetPlugins()
|
||||
_, resp, err = th.Client.GetPlugins(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
// Successful webapp get
|
||||
_, err = client.EnablePlugin(manifest.Id)
|
||||
_, err = client.EnablePlugin(context.Background(), manifest.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
manifests, _, err := th.Client.GetWebappPlugins()
|
||||
manifests, _, err := th.Client.GetWebappPlugins(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
found = false
|
||||
@@ -241,25 +242,25 @@ func TestPlugin(t *testing.T) {
|
||||
assert.True(t, found)
|
||||
|
||||
// Successful remove
|
||||
_, err = client.RemovePlugin(manifest.Id)
|
||||
_, err = client.RemovePlugin(context.Background(), manifest.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Remove error cases
|
||||
resp, err = client.RemovePlugin(manifest.Id)
|
||||
resp, err = client.RemovePlugin(context.Background(), manifest.Id)
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PluginSettings.Enable = false })
|
||||
resp, err = client.RemovePlugin(manifest.Id)
|
||||
resp, err = client.RemovePlugin(context.Background(), manifest.Id)
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.PluginSettings.Enable = true })
|
||||
resp, err = th.Client.RemovePlugin(manifest.Id)
|
||||
resp, err = th.Client.RemovePlugin(context.Background(), manifest.Id)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
resp, err = client.RemovePlugin("bad.id")
|
||||
resp, err = client.RemovePlugin(context.Background(), "bad.id")
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
})
|
||||
@@ -284,7 +285,7 @@ func TestNotifyClusterPluginEvent(t *testing.T) {
|
||||
testCluster.ClearMessages()
|
||||
|
||||
// Successful upload
|
||||
manifest, _, err := th.SystemAdminClient.UploadPlugin(bytes.NewReader(tarData))
|
||||
manifest, _, err := th.SystemAdminClient.UploadPlugin(context.Background(), bytes.NewReader(tarData))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "testplugin", manifest.Id)
|
||||
|
||||
@@ -311,7 +312,7 @@ func TestNotifyClusterPluginEvent(t *testing.T) {
|
||||
|
||||
// Upgrade
|
||||
testCluster.ClearMessages()
|
||||
manifest, _, err = th.SystemAdminClient.UploadPluginForced(bytes.NewReader(tarData))
|
||||
manifest, _, err = th.SystemAdminClient.UploadPluginForced(context.Background(), bytes.NewReader(tarData))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "testplugin", manifest.Id)
|
||||
|
||||
@@ -337,7 +338,7 @@ func TestNotifyClusterPluginEvent(t *testing.T) {
|
||||
}()
|
||||
|
||||
testCluster.ClearMessages()
|
||||
_, err = th.SystemAdminClient.RemovePlugin(manifest.Id)
|
||||
_, err = th.SystemAdminClient.RemovePlugin(context.Background(), manifest.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
result := <-done
|
||||
@@ -390,12 +391,12 @@ func TestDisableOnRemove(t *testing.T) {
|
||||
})
|
||||
|
||||
// Upload
|
||||
manifest, _, err := client.UploadPlugin(bytes.NewReader(tarData))
|
||||
manifest, _, err := client.UploadPlugin(context.Background(), bytes.NewReader(tarData))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "testplugin", manifest.Id)
|
||||
|
||||
// Check initial status
|
||||
pluginsResp, _, err := client.GetPlugins()
|
||||
pluginsResp, _, err := client.GetPlugins(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, pluginsResp.Active)
|
||||
require.Equal(t, pluginsResp.Inactive, []*model.PluginInfo{{
|
||||
@@ -403,11 +404,11 @@ func TestDisableOnRemove(t *testing.T) {
|
||||
}})
|
||||
|
||||
// Enable plugin
|
||||
_, err = client.EnablePlugin(manifest.Id)
|
||||
_, err = client.EnablePlugin(context.Background(), manifest.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Confirm enabled status
|
||||
pluginsResp, _, err = client.GetPlugins()
|
||||
pluginsResp, _, err = client.GetPlugins(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, pluginsResp.Inactive)
|
||||
require.Equal(t, pluginsResp.Active, []*model.PluginInfo{{
|
||||
@@ -416,12 +417,12 @@ func TestDisableOnRemove(t *testing.T) {
|
||||
|
||||
if tc.Upgrade {
|
||||
// Upgrade
|
||||
manifest, _, err = client.UploadPluginForced(bytes.NewReader(tarData))
|
||||
manifest, _, err = client.UploadPluginForced(context.Background(), bytes.NewReader(tarData))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "testplugin", manifest.Id)
|
||||
|
||||
// Plugin should remain active
|
||||
pluginsResp, _, err = client.GetPlugins()
|
||||
pluginsResp, _, err = client.GetPlugins(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, pluginsResp.Inactive)
|
||||
require.Equal(t, pluginsResp.Active, []*model.PluginInfo{{
|
||||
@@ -430,22 +431,22 @@ func TestDisableOnRemove(t *testing.T) {
|
||||
}
|
||||
|
||||
// Remove plugin
|
||||
_, err = client.RemovePlugin(manifest.Id)
|
||||
_, err = client.RemovePlugin(context.Background(), manifest.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Plugin should have no status
|
||||
pluginsResp, _, err = client.GetPlugins()
|
||||
pluginsResp, _, err = client.GetPlugins(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, pluginsResp.Inactive)
|
||||
require.Empty(t, pluginsResp.Active)
|
||||
|
||||
// Upload same plugin
|
||||
manifest, _, err = client.UploadPlugin(bytes.NewReader(tarData))
|
||||
manifest, _, err = client.UploadPlugin(context.Background(), bytes.NewReader(tarData))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "testplugin", manifest.Id)
|
||||
|
||||
// Plugin should be inactive
|
||||
pluginsResp, _, err = client.GetPlugins()
|
||||
pluginsResp, _, err = client.GetPlugins(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, pluginsResp.Active)
|
||||
require.Equal(t, pluginsResp.Inactive, []*model.PluginInfo{{
|
||||
@@ -453,7 +454,7 @@ func TestDisableOnRemove(t *testing.T) {
|
||||
}})
|
||||
|
||||
// Clean up
|
||||
_, err = client.RemovePlugin(manifest.Id)
|
||||
_, err = client.RemovePlugin(context.Background(), manifest.Id)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
})
|
||||
@@ -476,7 +477,7 @@ func TestGetMarketplacePlugins(t *testing.T) {
|
||||
*cfg.PluginSettings.MarketplaceURL = "invalid.com"
|
||||
})
|
||||
|
||||
plugins, resp, err := client.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||
plugins, resp, err := client.GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{})
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
require.Nil(t, plugins)
|
||||
@@ -488,7 +489,7 @@ func TestGetMarketplacePlugins(t *testing.T) {
|
||||
*cfg.PluginSettings.MarketplaceURL = "invalid.com"
|
||||
})
|
||||
|
||||
plugins, resp, err := client.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||
plugins, resp, err := client.GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{})
|
||||
require.Error(t, err)
|
||||
CheckInternalErrorStatus(t, resp)
|
||||
require.Nil(t, plugins)
|
||||
@@ -500,7 +501,7 @@ func TestGetMarketplacePlugins(t *testing.T) {
|
||||
*cfg.PluginSettings.MarketplaceURL = "invalid.com"
|
||||
})
|
||||
|
||||
plugins, resp, err := th.Client.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||
plugins, resp, err := th.Client.GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{})
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
require.Nil(t, plugins)
|
||||
@@ -520,7 +521,7 @@ func TestGetMarketplacePlugins(t *testing.T) {
|
||||
*cfg.PluginSettings.MarketplaceURL = testServer.URL
|
||||
})
|
||||
|
||||
plugins, _, err := client.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||
plugins, _, err := client.GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{})
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, plugins)
|
||||
}, "empty response from server")
|
||||
@@ -545,7 +546,7 @@ func TestGetMarketplacePlugins(t *testing.T) {
|
||||
*cfg.PluginSettings.MarketplaceURL = testServer.URL
|
||||
})
|
||||
|
||||
plugins, _, err := client.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||
plugins, _, err := client.GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{})
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, plugins)
|
||||
}, "verify server version is passed through")
|
||||
@@ -569,7 +570,7 @@ func TestGetMarketplacePlugins(t *testing.T) {
|
||||
*cfg.PluginSettings.MarketplaceURL = testServer.URL
|
||||
})
|
||||
|
||||
plugins, _, err := client.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||
plugins, _, err := client.GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{})
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, plugins)
|
||||
}, "verify EnterprisePlugins is false for TE")
|
||||
@@ -598,7 +599,7 @@ func TestGetMarketplacePlugins(t *testing.T) {
|
||||
*l.Features.EnterprisePlugins = false
|
||||
th.App.Srv().SetLicense(l)
|
||||
|
||||
plugins, _, err := client.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||
plugins, _, err := client.GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{})
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, plugins)
|
||||
}, "verify EnterprisePlugins is false for E10")
|
||||
@@ -624,7 +625,7 @@ func TestGetMarketplacePlugins(t *testing.T) {
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("enterprise_plugins"))
|
||||
|
||||
plugins, _, err := client.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||
plugins, _, err := client.GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{})
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, plugins)
|
||||
}, "verify EnterprisePlugins is true for E20")
|
||||
@@ -648,7 +649,7 @@ func TestGetMarketplacePlugins(t *testing.T) {
|
||||
*cfg.PluginSettings.MarketplaceURL = testServer.URL
|
||||
})
|
||||
|
||||
plugins, _, err := client.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||
plugins, _, err := client.GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{})
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, plugins)
|
||||
}, "verify EnterprisePlugins is false if there is no license")
|
||||
@@ -674,7 +675,7 @@ func TestGetMarketplacePlugins(t *testing.T) {
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
|
||||
plugins, _, err := client.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||
plugins, _, err := client.GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{})
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, plugins)
|
||||
}, "verify Cloud is true for cloud license")
|
||||
@@ -728,11 +729,11 @@ func TestGetInstalledMarketplacePlugins(t *testing.T) {
|
||||
*cfg.PluginSettings.MarketplaceURL = testServer.URL
|
||||
})
|
||||
|
||||
plugins, _, err := th.SystemAdminClient.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||
plugins, _, err := th.SystemAdminClient.GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, samplePlugins, plugins)
|
||||
|
||||
manifest, _, err := th.SystemAdminClient.UploadPlugin(bytes.NewReader(tarData))
|
||||
manifest, _, err := th.SystemAdminClient.UploadPlugin(context.Background(), bytes.NewReader(tarData))
|
||||
require.NoError(t, err)
|
||||
|
||||
testIcon, err := os.ReadFile(filepath.Join(path, "test.svg"))
|
||||
@@ -758,14 +759,14 @@ func TestGetInstalledMarketplacePlugins(t *testing.T) {
|
||||
return strings.ToLower(expectedPlugins[i].Manifest.Name) < strings.ToLower(expectedPlugins[j].Manifest.Name)
|
||||
})
|
||||
|
||||
plugins, _, err = th.SystemAdminClient.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||
plugins, _, err = th.SystemAdminClient.GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expectedPlugins, plugins)
|
||||
|
||||
_, err = th.SystemAdminClient.RemovePlugin(manifest.Id)
|
||||
_, err = th.SystemAdminClient.RemovePlugin(context.Background(), manifest.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
plugins, _, err = th.SystemAdminClient.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||
plugins, _, err = th.SystemAdminClient.GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, samplePlugins, plugins)
|
||||
})
|
||||
@@ -780,7 +781,7 @@ func TestGetInstalledMarketplacePlugins(t *testing.T) {
|
||||
*cfg.PluginSettings.EnableMarketplace = true
|
||||
})
|
||||
|
||||
manifest, _, err := th.SystemAdminClient.UploadPlugin(bytes.NewReader(tarData))
|
||||
manifest, _, err := th.SystemAdminClient.UploadPlugin(context.Background(), bytes.NewReader(tarData))
|
||||
require.NoError(t, err)
|
||||
|
||||
newPlugin := &model.MarketplacePlugin{
|
||||
@@ -809,14 +810,14 @@ func TestGetInstalledMarketplacePlugins(t *testing.T) {
|
||||
*cfg.PluginSettings.MarketplaceURL = testServer.URL
|
||||
})
|
||||
|
||||
plugins, _, err := th.SystemAdminClient.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||
plugins, _, err := th.SystemAdminClient.GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expectedPlugins, plugins)
|
||||
|
||||
_, err = th.SystemAdminClient.RemovePlugin(manifest.Id)
|
||||
_, err = th.SystemAdminClient.RemovePlugin(context.Background(), manifest.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
plugins, _, err = th.SystemAdminClient.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||
plugins, _, err = th.SystemAdminClient.GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{})
|
||||
require.NoError(t, err)
|
||||
newPlugin.InstalledVersion = ""
|
||||
require.Equal(t, expectedPlugins, plugins)
|
||||
@@ -873,11 +874,11 @@ func TestSearchGetMarketplacePlugins(t *testing.T) {
|
||||
*cfg.PluginSettings.MarketplaceURL = testServer.URL
|
||||
})
|
||||
|
||||
plugins, _, err := th.SystemAdminClient.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||
plugins, _, err := th.SystemAdminClient.GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, samplePlugins, plugins)
|
||||
|
||||
manifest, _, err := th.SystemAdminClient.UploadPlugin(bytes.NewReader(tarData))
|
||||
manifest, _, err := th.SystemAdminClient.UploadPlugin(context.Background(), bytes.NewReader(tarData))
|
||||
require.NoError(t, err)
|
||||
|
||||
plugin1 := &model.MarketplacePlugin{
|
||||
@@ -896,7 +897,7 @@ func TestSearchGetMarketplacePlugins(t *testing.T) {
|
||||
}
|
||||
expectedPlugins := append(samplePlugins, plugin1)
|
||||
|
||||
manifest, _, err = th.SystemAdminClient.UploadPlugin(bytes.NewReader(tarDataV2))
|
||||
manifest, _, err = th.SystemAdminClient.UploadPlugin(context.Background(), bytes.NewReader(tarDataV2))
|
||||
require.NoError(t, err)
|
||||
|
||||
plugin2 := &model.MarketplacePlugin{
|
||||
@@ -918,32 +919,32 @@ func TestSearchGetMarketplacePlugins(t *testing.T) {
|
||||
return strings.ToLower(expectedPlugins[i].Manifest.Name) < strings.ToLower(expectedPlugins[j].Manifest.Name)
|
||||
})
|
||||
|
||||
plugins, _, err = th.SystemAdminClient.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||
plugins, _, err = th.SystemAdminClient.GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expectedPlugins, plugins)
|
||||
|
||||
// Search for plugins from the server
|
||||
plugins, _, err = th.SystemAdminClient.GetMarketplacePlugins(&model.MarketplacePluginFilter{Filter: "testplugin2"})
|
||||
plugins, _, err = th.SystemAdminClient.GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{Filter: "testplugin2"})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []*model.MarketplacePlugin{plugin2}, plugins)
|
||||
|
||||
plugins, _, err = th.SystemAdminClient.GetMarketplacePlugins(&model.MarketplacePluginFilter{Filter: "a second plugin"})
|
||||
plugins, _, err = th.SystemAdminClient.GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{Filter: "a second plugin"})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []*model.MarketplacePlugin{plugin2}, plugins)
|
||||
|
||||
plugins, _, err = th.SystemAdminClient.GetMarketplacePlugins(&model.MarketplacePluginFilter{Filter: "User Satisfaction Surveys"})
|
||||
plugins, _, err = th.SystemAdminClient.GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{Filter: "User Satisfaction Surveys"})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, samplePlugins, plugins)
|
||||
|
||||
plugins, _, err = th.SystemAdminClient.GetMarketplacePlugins(&model.MarketplacePluginFilter{Filter: "NOFILTER"})
|
||||
plugins, _, err = th.SystemAdminClient.GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{Filter: "NOFILTER"})
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, plugins)
|
||||
|
||||
// cleanup
|
||||
_, err = th.SystemAdminClient.RemovePlugin(plugin1.Manifest.Id)
|
||||
_, err = th.SystemAdminClient.RemovePlugin(context.Background(), plugin1.Manifest.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = th.SystemAdminClient.RemovePlugin(plugin2.Manifest.Id)
|
||||
_, err = th.SystemAdminClient.RemovePlugin(context.Background(), plugin2.Manifest.Id)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
@@ -989,7 +990,7 @@ func TestGetLocalPluginInMarketplace(t *testing.T) {
|
||||
*cfg.PluginSettings.EnableRemoteMarketplace = true
|
||||
})
|
||||
|
||||
plugins, _, err := th.SystemAdminClient.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||
plugins, _, err := th.SystemAdminClient.GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{})
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, plugins, len(samplePlugins))
|
||||
@@ -1007,15 +1008,15 @@ func TestGetLocalPluginInMarketplace(t *testing.T) {
|
||||
tarData, err := os.ReadFile(filepath.Join(path, "testplugin.tar.gz"))
|
||||
require.NoError(t, err)
|
||||
|
||||
manifest, _, err := th.SystemAdminClient.UploadPlugin(bytes.NewReader(tarData))
|
||||
manifest, _, err := th.SystemAdminClient.UploadPlugin(context.Background(), bytes.NewReader(tarData))
|
||||
require.NoError(t, err)
|
||||
|
||||
plugins, _, err := th.SystemAdminClient.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||
plugins, _, err := th.SystemAdminClient.GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{})
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, plugins, 2)
|
||||
|
||||
_, err = th.SystemAdminClient.RemovePlugin(manifest.Id)
|
||||
_, err = th.SystemAdminClient.RemovePlugin(context.Background(), manifest.Id)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
@@ -1026,7 +1027,7 @@ func TestGetLocalPluginInMarketplace(t *testing.T) {
|
||||
})
|
||||
|
||||
// No marketplace plugins returned
|
||||
plugins, _, err := th.SystemAdminClient.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||
plugins, _, err := th.SystemAdminClient.GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{})
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, plugins, 0)
|
||||
@@ -1036,7 +1037,7 @@ func TestGetLocalPluginInMarketplace(t *testing.T) {
|
||||
tarData, err := os.ReadFile(filepath.Join(path, "testplugin.tar.gz"))
|
||||
require.NoError(t, err)
|
||||
|
||||
manifest, _, err := th.SystemAdminClient.UploadPlugin(bytes.NewReader(tarData))
|
||||
manifest, _, err := th.SystemAdminClient.UploadPlugin(context.Background(), bytes.NewReader(tarData))
|
||||
require.NoError(t, err)
|
||||
|
||||
testIcon, err := os.ReadFile(filepath.Join(path, "test.svg"))
|
||||
@@ -1054,14 +1055,14 @@ func TestGetLocalPluginInMarketplace(t *testing.T) {
|
||||
InstalledVersion: manifest.Version,
|
||||
}
|
||||
|
||||
plugins, _, err = th.SystemAdminClient.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||
plugins, _, err = th.SystemAdminClient.GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Only get the local plugins
|
||||
require.Len(t, plugins, 1)
|
||||
require.Equal(t, newPlugin, plugins[0])
|
||||
|
||||
_, err = th.SystemAdminClient.RemovePlugin(manifest.Id)
|
||||
_, err = th.SystemAdminClient.RemovePlugin(context.Background(), manifest.Id)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
@@ -1076,7 +1077,7 @@ func TestGetLocalPluginInMarketplace(t *testing.T) {
|
||||
tarData, err := os.ReadFile(filepath.Join(path, "testplugin.tar.gz"))
|
||||
require.NoError(t, err)
|
||||
|
||||
manifest, _, err := th.SystemAdminClient.UploadPlugin(bytes.NewReader(tarData))
|
||||
manifest, _, err := th.SystemAdminClient.UploadPlugin(context.Background(), bytes.NewReader(tarData))
|
||||
require.NoError(t, err)
|
||||
|
||||
testIcon, err := os.ReadFile(filepath.Join(path, "test.svg"))
|
||||
@@ -1098,13 +1099,13 @@ func TestGetLocalPluginInMarketplace(t *testing.T) {
|
||||
InstalledVersion: manifest.Version,
|
||||
}
|
||||
|
||||
plugins, _, err := th.SystemAdminClient.GetMarketplacePlugins(&model.MarketplacePluginFilter{LocalOnly: true})
|
||||
plugins, _, err := th.SystemAdminClient.GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{LocalOnly: true})
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, plugins, 1)
|
||||
require.Equal(t, newPlugin, plugins[0])
|
||||
|
||||
_, err = th.SystemAdminClient.RemovePlugin(manifest.Id)
|
||||
_, err = th.SystemAdminClient.RemovePlugin(context.Background(), manifest.Id)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
@@ -1152,16 +1153,16 @@ func TestGetRemotePluginInMarketplace(t *testing.T) {
|
||||
tarData, err := os.ReadFile(filepath.Join(path, "testplugin.tar.gz"))
|
||||
require.NoError(t, err)
|
||||
|
||||
manifest, _, err := th.SystemAdminClient.UploadPlugin(bytes.NewReader(tarData))
|
||||
manifest, _, err := th.SystemAdminClient.UploadPlugin(context.Background(), bytes.NewReader(tarData))
|
||||
require.NoError(t, err)
|
||||
|
||||
plugins, _, err := th.SystemAdminClient.GetMarketplacePlugins(&model.MarketplacePluginFilter{RemoteOnly: true})
|
||||
plugins, _, err := th.SystemAdminClient.GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{RemoteOnly: true})
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, plugins, 1)
|
||||
require.Equal(t, samplePlugins[0], plugins[0])
|
||||
|
||||
_, err = th.SystemAdminClient.RemovePlugin(manifest.Id)
|
||||
_, err = th.SystemAdminClient.RemovePlugin(context.Background(), manifest.Id)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -1217,7 +1218,7 @@ func TestGetPrepackagedPluginInMarketplace(t *testing.T) {
|
||||
*cfg.PluginSettings.EnableUploads = true
|
||||
})
|
||||
|
||||
plugins, _, err := th.SystemAdminClient.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||
plugins, _, err := th.SystemAdminClient.GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{})
|
||||
require.NoError(t, err)
|
||||
|
||||
expectedPlugins := marketplacePlugins
|
||||
@@ -1238,7 +1239,7 @@ func TestGetPrepackagedPluginInMarketplace(t *testing.T) {
|
||||
})
|
||||
|
||||
// No marketplace plugins returned
|
||||
plugins, _, err := th.SystemAdminClient.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||
plugins, _, err := th.SystemAdminClient.GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Only returns the prepackaged plugins
|
||||
@@ -1264,7 +1265,7 @@ func TestGetPrepackagedPluginInMarketplace(t *testing.T) {
|
||||
env := th.App.GetPluginsEnvironment()
|
||||
env.SetPrepackagedPlugins([]*plugin.PrepackagedPlugin{newerPrepackagePlugin})
|
||||
|
||||
plugins, _, err := th.SystemAdminClient.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||
plugins, _, err := th.SystemAdminClient.GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{})
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, plugins, 1)
|
||||
@@ -1279,7 +1280,7 @@ func TestGetPrepackagedPluginInMarketplace(t *testing.T) {
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
|
||||
plugins, _, err := th.SystemAdminClient.GetMarketplacePlugins(&model.MarketplacePluginFilter{})
|
||||
plugins, _, err := th.SystemAdminClient.GetMarketplacePlugins(context.Background(), &model.MarketplacePluginFilter{})
|
||||
require.NoError(t, err)
|
||||
|
||||
require.ElementsMatch(t, marketplacePlugins, plugins)
|
||||
@@ -1354,7 +1355,7 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
||||
*cfg.PluginSettings.EnableMarketplace = false
|
||||
*cfg.PluginSettings.MarketplaceURL = "invalid.com"
|
||||
})
|
||||
plugin, resp, err := client.InstallMarketplacePlugin(request)
|
||||
plugin, resp, err := client.InstallMarketplacePlugin(context.Background(), request)
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
require.Nil(t, plugin)
|
||||
@@ -1365,12 +1366,12 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
||||
*cfg.PluginSettings.Enable = true
|
||||
*cfg.PluginSettings.RequirePluginSignature = true
|
||||
})
|
||||
manifest, resp, err := client.UploadPlugin(bytes.NewReader(tarData))
|
||||
manifest, resp, err := client.UploadPlugin(context.Background(), bytes.NewReader(tarData))
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
require.Nil(t, manifest)
|
||||
|
||||
manifest, resp, err = client.InstallPluginFromURL("some_url", true)
|
||||
manifest, resp, err = client.InstallPluginFromURL(context.Background(), "some_url", true)
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
require.Nil(t, manifest)
|
||||
@@ -1382,7 +1383,7 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
||||
*cfg.PluginSettings.MarketplaceURL = "invalid.com"
|
||||
})
|
||||
|
||||
plugin, resp, err := client.InstallMarketplacePlugin(request)
|
||||
plugin, resp, err := client.InstallMarketplacePlugin(context.Background(), request)
|
||||
require.Error(t, err)
|
||||
CheckInternalErrorStatus(t, resp)
|
||||
require.Nil(t, plugin)
|
||||
@@ -1394,7 +1395,7 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
||||
*cfg.PluginSettings.MarketplaceURL = "invalid.com"
|
||||
})
|
||||
|
||||
plugin, resp, err := th.Client.InstallMarketplacePlugin(request)
|
||||
plugin, resp, err := th.Client.InstallMarketplacePlugin(context.Background(), request)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
require.Nil(t, plugin)
|
||||
@@ -1414,7 +1415,7 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
||||
*cfg.PluginSettings.MarketplaceURL = testServer.URL
|
||||
})
|
||||
pRequest := &model.InstallMarketplacePluginRequest{Id: "some_plugin_id"}
|
||||
plugin, resp, err := client.InstallMarketplacePlugin(pRequest)
|
||||
plugin, resp, err := client.InstallMarketplacePlugin(context.Background(), pRequest)
|
||||
require.Error(t, err)
|
||||
CheckInternalErrorStatus(t, resp)
|
||||
require.Nil(t, plugin)
|
||||
@@ -1435,7 +1436,7 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
||||
*cfg.PluginSettings.AllowInsecureDownloadURL = true
|
||||
})
|
||||
pRequest := &model.InstallMarketplacePluginRequest{Id: "testplugin2"}
|
||||
plugin, resp, err := client.InstallMarketplacePlugin(pRequest)
|
||||
plugin, resp, err := client.InstallMarketplacePlugin(context.Background(), pRequest)
|
||||
require.Error(t, err)
|
||||
CheckInternalErrorStatus(t, resp)
|
||||
require.Nil(t, plugin)
|
||||
@@ -1465,7 +1466,7 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
||||
require.Nil(t, appErr)
|
||||
|
||||
pRequest := &model.InstallMarketplacePluginRequest{Id: "testplugin2"}
|
||||
manifest, _, err := client.InstallMarketplacePlugin(pRequest)
|
||||
manifest, _, err := client.InstallMarketplacePlugin(context.Background(), pRequest)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, manifest)
|
||||
require.Equal(t, "testplugin2", manifest.Id)
|
||||
@@ -1476,7 +1477,7 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
||||
require.Nil(t, appErr)
|
||||
require.EqualValues(t, sigFile, savedSigFile)
|
||||
|
||||
_, err = client.RemovePlugin(manifest.Id)
|
||||
_, err = client.RemovePlugin(context.Background(), manifest.Id)
|
||||
require.NoError(t, err)
|
||||
exists, appErr := th.App.FileExists(filePath)
|
||||
require.Nil(t, appErr)
|
||||
@@ -1510,7 +1511,7 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
||||
require.Nil(t, appErr)
|
||||
|
||||
pRequest := &model.InstallMarketplacePluginRequest{Id: "testplugin2", Version: "9.9.9"}
|
||||
manifest, _, err := client.InstallMarketplacePlugin(pRequest)
|
||||
manifest, _, err := client.InstallMarketplacePlugin(context.Background(), pRequest)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, manifest)
|
||||
require.Equal(t, "testplugin2", manifest.Id)
|
||||
@@ -1521,7 +1522,7 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
||||
require.Nil(t, appErr)
|
||||
require.EqualValues(t, sigFile, savedSigFile)
|
||||
|
||||
_, err = client.RemovePlugin(manifest.Id)
|
||||
_, err = client.RemovePlugin(context.Background(), manifest.Id)
|
||||
require.NoError(t, err)
|
||||
exists, appErr := th.App.FileExists(filePath)
|
||||
require.Nil(t, appErr)
|
||||
@@ -1557,7 +1558,7 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
||||
})
|
||||
|
||||
pRequest := &model.InstallMarketplacePluginRequest{Id: "testplugin"}
|
||||
manifest, resp, err := client.InstallMarketplacePlugin(pRequest)
|
||||
manifest, resp, err := client.InstallMarketplacePlugin(context.Background(), pRequest)
|
||||
require.Error(t, err)
|
||||
CheckInternalErrorStatus(t, resp)
|
||||
require.Nil(t, manifest)
|
||||
@@ -1595,7 +1596,7 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
||||
th.App.Srv().SetLicense(l)
|
||||
|
||||
pRequest := &model.InstallMarketplacePluginRequest{Id: "testplugin"}
|
||||
manifest, resp, err := client.InstallMarketplacePlugin(pRequest)
|
||||
manifest, resp, err := client.InstallMarketplacePlugin(context.Background(), pRequest)
|
||||
require.Error(t, err)
|
||||
CheckInternalErrorStatus(t, resp)
|
||||
require.Nil(t, manifest)
|
||||
@@ -1629,7 +1630,7 @@ func TestInstallMarketplacePlugin(t *testing.T) {
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("enterprise_plugins"))
|
||||
|
||||
pRequest := &model.InstallMarketplacePluginRequest{Id: "testplugin"}
|
||||
manifest, resp, err := client.InstallMarketplacePlugin(pRequest)
|
||||
manifest, resp, err := client.InstallMarketplacePlugin(context.Background(), pRequest)
|
||||
require.Error(t, err)
|
||||
CheckInternalErrorStatus(t, resp)
|
||||
require.Nil(t, manifest)
|
||||
@@ -1755,14 +1756,14 @@ func TestInstallMarketplacePluginPrepackagedDisabled(t *testing.T) {
|
||||
|
||||
env := th.App.GetPluginsEnvironment()
|
||||
|
||||
pluginsResp, _, err := client.GetPlugins()
|
||||
pluginsResp, _, err := client.GetPlugins(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Len(t, pluginsResp.Active, 0)
|
||||
require.Len(t, pluginsResp.Inactive, 0)
|
||||
|
||||
t.Run("Should fail to install unknown prepackaged plugin", func(t *testing.T) {
|
||||
pRequest := &model.InstallMarketplacePluginRequest{Id: "testpluginXX"}
|
||||
manifest, resp, err := client.InstallMarketplacePlugin(pRequest)
|
||||
manifest, resp, err := client.InstallMarketplacePlugin(context.Background(), pRequest)
|
||||
require.Error(t, err)
|
||||
CheckInternalErrorStatus(t, resp)
|
||||
require.Nil(t, manifest)
|
||||
@@ -1772,7 +1773,7 @@ func TestInstallMarketplacePluginPrepackagedDisabled(t *testing.T) {
|
||||
require.Equal(t, "testplugin", plugins[0].Manifest.Id)
|
||||
require.Equal(t, pluginSignatureData, plugins[0].Signature)
|
||||
|
||||
pluginsResp, _, err = client.GetPlugins()
|
||||
pluginsResp, _, err = client.GetPlugins(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Len(t, pluginsResp.Active, 0)
|
||||
require.Len(t, pluginsResp.Inactive, 0)
|
||||
@@ -1780,18 +1781,18 @@ func TestInstallMarketplacePluginPrepackagedDisabled(t *testing.T) {
|
||||
|
||||
t.Run("Install prepackaged plugin with Marketplace disabled", func(t *testing.T) {
|
||||
pRequest := &model.InstallMarketplacePluginRequest{Id: "testplugin"}
|
||||
manifest, _, err := client.InstallMarketplacePlugin(pRequest)
|
||||
manifest, _, err := client.InstallMarketplacePlugin(context.Background(), pRequest)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, manifest)
|
||||
require.Equal(t, "testplugin", manifest.Id)
|
||||
require.Equal(t, "0.0.1", manifest.Version)
|
||||
|
||||
t.Cleanup(func() {
|
||||
_, err = client.RemovePlugin(manifest.Id)
|
||||
_, err = client.RemovePlugin(context.Background(), manifest.Id)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
pluginsResp, _, err = client.GetPlugins()
|
||||
pluginsResp, _, err = client.GetPlugins(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Len(t, pluginsResp.Active, 0)
|
||||
require.Equal(t, pluginsResp.Inactive, []*model.PluginInfo{{
|
||||
@@ -1801,7 +1802,7 @@ func TestInstallMarketplacePluginPrepackagedDisabled(t *testing.T) {
|
||||
|
||||
t.Run("Try to install remote marketplace plugin while Marketplace is disabled", func(t *testing.T) {
|
||||
pRequest := &model.InstallMarketplacePluginRequest{Id: "testplugin2"}
|
||||
manifest, resp, err := client.InstallMarketplacePlugin(pRequest)
|
||||
manifest, resp, err := client.InstallMarketplacePlugin(context.Background(), pRequest)
|
||||
require.Error(t, err)
|
||||
CheckInternalErrorStatus(t, resp)
|
||||
require.Nil(t, manifest)
|
||||
@@ -1817,11 +1818,11 @@ func TestInstallMarketplacePluginPrepackagedDisabled(t *testing.T) {
|
||||
|
||||
t.Run("Install prepackaged, not listed plugin with Marketplace enabled", func(t *testing.T) {
|
||||
pRequest := &model.InstallMarketplacePluginRequest{Id: "testplugin"}
|
||||
manifest, _, err := client.InstallMarketplacePlugin(pRequest)
|
||||
manifest, _, err := client.InstallMarketplacePlugin(context.Background(), pRequest)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Cleanup(func() {
|
||||
_, err = client.RemovePlugin(manifest.Id)
|
||||
_, err = client.RemovePlugin(context.Background(), manifest.Id)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
@@ -1832,30 +1833,30 @@ func TestInstallMarketplacePluginPrepackagedDisabled(t *testing.T) {
|
||||
|
||||
t.Run("Install both a prepacked and a Marketplace plugin", func(t *testing.T) {
|
||||
pRequest := &model.InstallMarketplacePluginRequest{Id: "testplugin"}
|
||||
manifest1, _, err := client.InstallMarketplacePlugin(pRequest)
|
||||
manifest1, _, err := client.InstallMarketplacePlugin(context.Background(), pRequest)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, manifest1)
|
||||
assert.Equal(t, "testplugin", manifest1.Id)
|
||||
assert.Equal(t, "0.0.1", manifest1.Version)
|
||||
|
||||
t.Cleanup(func() {
|
||||
_, err = client.RemovePlugin(manifest1.Id)
|
||||
_, err = client.RemovePlugin(context.Background(), manifest1.Id)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
pRequest = &model.InstallMarketplacePluginRequest{Id: "testplugin2"}
|
||||
manifest2, _, err := client.InstallMarketplacePlugin(pRequest)
|
||||
manifest2, _, err := client.InstallMarketplacePlugin(context.Background(), pRequest)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, manifest2)
|
||||
require.Equal(t, "testplugin2", manifest2.Id)
|
||||
require.Equal(t, "1.2.3", manifest2.Version)
|
||||
|
||||
t.Cleanup(func() {
|
||||
_, err = client.RemovePlugin(manifest2.Id)
|
||||
_, err = client.RemovePlugin(context.Background(), manifest2.Id)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
pluginsResp, _, err = client.GetPlugins()
|
||||
pluginsResp, _, err = client.GetPlugins(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Len(t, pluginsResp.Active, 0)
|
||||
require.ElementsMatch(t, pluginsResp.Inactive, []*model.PluginInfo{
|
||||
@@ -1927,29 +1928,29 @@ func TestInstallMarketplacePluginPrepackagedDisabled(t *testing.T) {
|
||||
require.Equal(t, "testplugin", plugins[0].Manifest.Id)
|
||||
require.Empty(t, plugins[0].Signature)
|
||||
|
||||
pluginsResp, _, err := client.GetPlugins()
|
||||
pluginsResp, _, err := client.GetPlugins(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Len(t, pluginsResp.Active, 0)
|
||||
require.Len(t, pluginsResp.Inactive, 0)
|
||||
|
||||
pRequest := &model.InstallMarketplacePluginRequest{Id: "testplugin"}
|
||||
manifest, resp, err := client.InstallMarketplacePlugin(pRequest)
|
||||
manifest, resp, err := client.InstallMarketplacePlugin(context.Background(), pRequest)
|
||||
require.Error(t, err)
|
||||
CheckInternalErrorStatus(t, resp)
|
||||
require.Nil(t, manifest)
|
||||
|
||||
pluginsResp, _, err = client.GetPlugins()
|
||||
pluginsResp, _, err = client.GetPlugins(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Len(t, pluginsResp.Active, 0)
|
||||
require.Len(t, pluginsResp.Inactive, 0)
|
||||
|
||||
pRequest = &model.InstallMarketplacePluginRequest{Id: "testplugin2"}
|
||||
manifest, resp, err = client.InstallMarketplacePlugin(pRequest)
|
||||
manifest, resp, err = client.InstallMarketplacePlugin(context.Background(), pRequest)
|
||||
require.Error(t, err)
|
||||
CheckInternalErrorStatus(t, resp)
|
||||
require.Nil(t, manifest)
|
||||
|
||||
pluginsResp, _, err = client.GetPlugins()
|
||||
pluginsResp, _, err = client.GetPlugins(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Len(t, pluginsResp.Active, 0)
|
||||
require.Len(t, pluginsResp.Inactive, 0)
|
||||
|
||||
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -44,9 +45,9 @@ func TestGetPreferences(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
client.UpdatePreferences(user1.Id, preferences1)
|
||||
client.UpdatePreferences(context.Background(), user1.Id, preferences1)
|
||||
|
||||
prefs, _, err := client.GetPreferences(user1.Id)
|
||||
prefs, _, err := client.GetPreferences(context.Background(), user1.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
// 6 because we have 3 initial preferences insights, tutorial_step and recommended_next_steps added when creating a new user
|
||||
@@ -60,17 +61,17 @@ func TestGetPreferences(t *testing.T) {
|
||||
th.BasicUser2 = th.CreateUser()
|
||||
th.LoginBasic2()
|
||||
|
||||
prefs, _, err = client.GetPreferences(th.BasicUser2.Id)
|
||||
prefs, _, err = client.GetPreferences(context.Background(), th.BasicUser2.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Greater(t, len(prefs), 0, "received the wrong number of preferences")
|
||||
|
||||
_, resp, err := client.GetPreferences(th.BasicUser.Id)
|
||||
_, resp, err := client.GetPreferences(context.Background(), th.BasicUser.Id)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
client.Logout()
|
||||
_, resp, err = client.GetPreferences(th.BasicUser2.Id)
|
||||
client.Logout(context.Background())
|
||||
_, resp, err = client.GetPreferences(context.Background(), th.BasicUser2.Id)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
}
|
||||
@@ -102,35 +103,35 @@ func TestGetPreferencesByCategory(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
client.UpdatePreferences(user1.Id, preferences1)
|
||||
client.UpdatePreferences(context.Background(), user1.Id, preferences1)
|
||||
|
||||
prefs, _, err := client.GetPreferencesByCategory(user1.Id, category)
|
||||
prefs, _, err := client.GetPreferencesByCategory(context.Background(), user1.Id, category)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, len(prefs), 2, "received the wrong number of preferences")
|
||||
|
||||
_, resp, err := client.GetPreferencesByCategory(user1.Id, "junk")
|
||||
_, resp, err := client.GetPreferencesByCategory(context.Background(), user1.Id, "junk")
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
th.LoginBasic2()
|
||||
|
||||
_, resp, err = client.GetPreferencesByCategory(th.BasicUser2.Id, category)
|
||||
_, resp, err = client.GetPreferencesByCategory(context.Background(), th.BasicUser2.Id, category)
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
_, resp, err = client.GetPreferencesByCategory(user1.Id, category)
|
||||
_, resp, err = client.GetPreferencesByCategory(context.Background(), user1.Id, category)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
prefs, resp, err = client.GetPreferencesByCategory(th.BasicUser2.Id, "junk")
|
||||
prefs, resp, err = client.GetPreferencesByCategory(context.Background(), th.BasicUser2.Id, "junk")
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
require.Equal(t, len(prefs), 0, "received the wrong number of preferences")
|
||||
|
||||
client.Logout()
|
||||
_, resp, err = client.GetPreferencesByCategory(th.BasicUser2.Id, category)
|
||||
client.Logout(context.Background())
|
||||
_, resp, err = client.GetPreferencesByCategory(context.Background(), th.BasicUser2.Id, category)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
}
|
||||
@@ -160,9 +161,9 @@ func TestGetPreferenceByCategoryAndName(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
client.UpdatePreferences(user.Id, preferences)
|
||||
client.UpdatePreferences(context.Background(), user.Id, preferences)
|
||||
|
||||
pref, _, err := client.GetPreferenceByCategoryAndName(user.Id, model.PreferenceCategoryDirectChannelShow, name)
|
||||
pref, _, err := client.GetPreferenceByCategoryAndName(context.Background(), user.Id, model.PreferenceCategoryDirectChannelShow, name)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, preferences[0].UserId, pref.UserId, "UserId preference not saved")
|
||||
@@ -170,25 +171,25 @@ func TestGetPreferenceByCategoryAndName(t *testing.T) {
|
||||
require.Equal(t, preferences[0].Name, pref.Name, "Name preference not saved")
|
||||
|
||||
preferences[0].Value = model.NewId()
|
||||
client.UpdatePreferences(user.Id, preferences)
|
||||
client.UpdatePreferences(context.Background(), user.Id, preferences)
|
||||
|
||||
_, resp, err := client.GetPreferenceByCategoryAndName(user.Id, "junk", preferences[0].Name)
|
||||
_, resp, err := client.GetPreferenceByCategoryAndName(context.Background(), user.Id, "junk", preferences[0].Name)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
_, resp, err = client.GetPreferenceByCategoryAndName(user.Id, preferences[0].Category, "junk")
|
||||
_, resp, err = client.GetPreferenceByCategoryAndName(context.Background(), user.Id, preferences[0].Category, "junk")
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
_, resp, err = client.GetPreferenceByCategoryAndName(th.BasicUser2.Id, preferences[0].Category, "junk")
|
||||
_, resp, err = client.GetPreferenceByCategoryAndName(context.Background(), th.BasicUser2.Id, preferences[0].Category, "junk")
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
_, _, err = client.GetPreferenceByCategoryAndName(user.Id, preferences[0].Category, preferences[0].Name)
|
||||
_, _, err = client.GetPreferenceByCategoryAndName(context.Background(), user.Id, preferences[0].Category, preferences[0].Name)
|
||||
require.NoError(t, err)
|
||||
|
||||
client.Logout()
|
||||
_, resp, err = client.GetPreferenceByCategoryAndName(user.Id, preferences[0].Category, preferences[0].Name)
|
||||
client.Logout(context.Background())
|
||||
_, resp, err = client.GetPreferenceByCategoryAndName(context.Background(), user.Id, preferences[0].Category, preferences[0].Name)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
|
||||
@@ -221,7 +222,7 @@ func TestUpdatePreferences(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
_, err := client.UpdatePreferences(user1.Id, preferences1)
|
||||
_, err := client.UpdatePreferences(context.Background(), user1.Id, preferences1)
|
||||
require.NoError(t, err)
|
||||
|
||||
preferences := model.Preferences{
|
||||
@@ -232,7 +233,7 @@ func TestUpdatePreferences(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
resp, err := client.UpdatePreferences(user1.Id, preferences)
|
||||
resp, err := client.UpdatePreferences(context.Background(), user1.Id, preferences)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
@@ -243,16 +244,16 @@ func TestUpdatePreferences(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
resp, err = client.UpdatePreferences(user1.Id, preferences)
|
||||
resp, err = client.UpdatePreferences(context.Background(), user1.Id, preferences)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
resp, err = client.UpdatePreferences(th.BasicUser2.Id, preferences)
|
||||
resp, err = client.UpdatePreferences(context.Background(), th.BasicUser2.Id, preferences)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
client.Logout()
|
||||
resp, err = client.UpdatePreferences(user1.Id, preferences1)
|
||||
client.Logout(context.Background())
|
||||
resp, err = client.UpdatePreferences(context.Background(), user1.Id, preferences1)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
}
|
||||
@@ -283,7 +284,7 @@ func TestUpdatePreferencesWebsocket(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
_, err = th.Client.UpdatePreferences(userId, preferences)
|
||||
_, err = th.Client.UpdatePreferences(context.Background(), userId, preferences)
|
||||
require.NoError(t, err)
|
||||
|
||||
timeout := time.After(300 * time.Millisecond)
|
||||
@@ -324,14 +325,14 @@ func TestUpdateSidebarPreferences(t *testing.T) {
|
||||
team1 := th.CreateTeam()
|
||||
th.LinkUserToTeam(user, team1)
|
||||
|
||||
_, _, err := th.Client.GetSidebarCategoriesForTeamForUser(user.Id, team1.Id, "")
|
||||
_, _, err := th.Client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, team1.Id, "")
|
||||
require.NoError(t, err)
|
||||
|
||||
channel := th.CreateChannelWithClientAndTeam(th.Client, model.ChannelTypeOpen, team1.Id)
|
||||
th.AddUserToChannel(user, channel)
|
||||
|
||||
// Confirm that the sidebar is populated correctly to begin with
|
||||
categories, _, err := th.Client.GetSidebarCategoriesForTeamForUser(user.Id, team1.Id, "")
|
||||
categories, _, err := th.Client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, team1.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, model.SidebarCategoryFavorites, categories.Categories[0].Type)
|
||||
require.NotContains(t, categories.Categories[0].Channels, channel.Id)
|
||||
@@ -339,7 +340,7 @@ func TestUpdateSidebarPreferences(t *testing.T) {
|
||||
require.Contains(t, categories.Categories[1].Channels, channel.Id)
|
||||
|
||||
// Favorite the channel
|
||||
_, err = th.Client.UpdatePreferences(user.Id, model.Preferences{
|
||||
_, err = th.Client.UpdatePreferences(context.Background(), user.Id, model.Preferences{
|
||||
{
|
||||
UserId: user.Id,
|
||||
Category: model.PreferenceCategoryFavoriteChannel,
|
||||
@@ -350,7 +351,7 @@ func TestUpdateSidebarPreferences(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Confirm that the channel was added to the Favorites
|
||||
categories, _, err = th.Client.GetSidebarCategoriesForTeamForUser(user.Id, team1.Id, "")
|
||||
categories, _, err = th.Client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, team1.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, model.SidebarCategoryFavorites, categories.Categories[0].Type)
|
||||
assert.Contains(t, categories.Categories[0].Channels, channel.Id)
|
||||
@@ -358,7 +359,7 @@ func TestUpdateSidebarPreferences(t *testing.T) {
|
||||
assert.NotContains(t, categories.Categories[1].Channels, channel.Id)
|
||||
|
||||
// And unfavorite the channel
|
||||
_, err = th.Client.UpdatePreferences(user.Id, model.Preferences{
|
||||
_, err = th.Client.UpdatePreferences(context.Background(), user.Id, model.Preferences{
|
||||
{
|
||||
UserId: user.Id,
|
||||
Category: model.PreferenceCategoryFavoriteChannel,
|
||||
@@ -369,7 +370,7 @@ func TestUpdateSidebarPreferences(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// The channel should've been removed from the Favorites
|
||||
categories, _, err = th.Client.GetSidebarCategoriesForTeamForUser(user.Id, team1.Id, "")
|
||||
categories, _, err = th.Client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, team1.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, model.SidebarCategoryFavorites, categories.Categories[0].Type)
|
||||
require.NotContains(t, categories.Categories[0].Channels, channel.Id)
|
||||
@@ -392,7 +393,7 @@ func TestUpdateSidebarPreferences(t *testing.T) {
|
||||
dmChannel := th.CreateDmChannel(user2)
|
||||
|
||||
// Favorite the channel
|
||||
_, err := th.Client.UpdatePreferences(user.Id, model.Preferences{
|
||||
_, err := th.Client.UpdatePreferences(context.Background(), user.Id, model.Preferences{
|
||||
{
|
||||
UserId: user.Id,
|
||||
Category: model.PreferenceCategoryFavoriteChannel,
|
||||
@@ -403,14 +404,14 @@ func TestUpdateSidebarPreferences(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Confirm that the channel was added to the Favorites on all teams
|
||||
categories, _, err := th.Client.GetSidebarCategoriesForTeamForUser(user.Id, team1.Id, "")
|
||||
categories, _, err := th.Client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, team1.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, model.SidebarCategoryFavorites, categories.Categories[0].Type)
|
||||
assert.Contains(t, categories.Categories[0].Channels, dmChannel.Id)
|
||||
require.Equal(t, model.SidebarCategoryDirectMessages, categories.Categories[2].Type)
|
||||
assert.NotContains(t, categories.Categories[2].Channels, dmChannel.Id)
|
||||
|
||||
categories, _, err = th.Client.GetSidebarCategoriesForTeamForUser(user.Id, team2.Id, "")
|
||||
categories, _, err = th.Client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, team2.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, model.SidebarCategoryFavorites, categories.Categories[0].Type)
|
||||
assert.Contains(t, categories.Categories[0].Channels, dmChannel.Id)
|
||||
@@ -418,7 +419,7 @@ func TestUpdateSidebarPreferences(t *testing.T) {
|
||||
assert.NotContains(t, categories.Categories[2].Channels, dmChannel.Id)
|
||||
|
||||
// And unfavorite the channel
|
||||
_, err = th.Client.UpdatePreferences(user.Id, model.Preferences{
|
||||
_, err = th.Client.UpdatePreferences(context.Background(), user.Id, model.Preferences{
|
||||
{
|
||||
UserId: user.Id,
|
||||
Category: model.PreferenceCategoryFavoriteChannel,
|
||||
@@ -429,14 +430,14 @@ func TestUpdateSidebarPreferences(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// The channel should've been removed from the Favorites on all teams
|
||||
categories, _, err = th.Client.GetSidebarCategoriesForTeamForUser(user.Id, team1.Id, "")
|
||||
categories, _, err = th.Client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, team1.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, model.SidebarCategoryFavorites, categories.Categories[0].Type)
|
||||
require.NotContains(t, categories.Categories[0].Channels, dmChannel.Id)
|
||||
require.Equal(t, model.SidebarCategoryDirectMessages, categories.Categories[2].Type)
|
||||
assert.Contains(t, categories.Categories[2].Channels, dmChannel.Id)
|
||||
|
||||
categories, _, err = th.Client.GetSidebarCategoriesForTeamForUser(user.Id, team2.Id, "")
|
||||
categories, _, err = th.Client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, team2.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, model.SidebarCategoryFavorites, categories.Categories[0].Type)
|
||||
require.NotContains(t, categories.Categories[0].Channels, dmChannel.Id)
|
||||
@@ -458,9 +459,9 @@ func TestUpdateSidebarPreferences(t *testing.T) {
|
||||
th.LinkUserToTeam(user, team1)
|
||||
th.LinkUserToTeam(user2, team1)
|
||||
|
||||
_, _, err := th.Client.GetSidebarCategoriesForTeamForUser(user.Id, team1.Id, "")
|
||||
_, _, err := th.Client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, team1.Id, "")
|
||||
require.NoError(t, err)
|
||||
_, _, err = client2.GetSidebarCategoriesForTeamForUser(user2.Id, team1.Id, "")
|
||||
_, _, err = client2.GetSidebarCategoriesForTeamForUser(context.Background(), user2.Id, team1.Id, "")
|
||||
require.NoError(t, err)
|
||||
|
||||
channel := th.CreateChannelWithClientAndTeam(th.Client, model.ChannelTypeOpen, team1.Id)
|
||||
@@ -468,14 +469,14 @@ func TestUpdateSidebarPreferences(t *testing.T) {
|
||||
th.AddUserToChannel(user2, channel)
|
||||
|
||||
// Confirm that the sidebar is populated correctly to begin with
|
||||
categories, _, err := th.Client.GetSidebarCategoriesForTeamForUser(user.Id, team1.Id, "")
|
||||
categories, _, err := th.Client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, team1.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, model.SidebarCategoryFavorites, categories.Categories[0].Type)
|
||||
require.NotContains(t, categories.Categories[0].Channels, channel.Id)
|
||||
require.Equal(t, model.SidebarCategoryChannels, categories.Categories[1].Type)
|
||||
require.Contains(t, categories.Categories[1].Channels, channel.Id)
|
||||
|
||||
categories, _, err = client2.GetSidebarCategoriesForTeamForUser(user2.Id, team1.Id, "")
|
||||
categories, _, err = client2.GetSidebarCategoriesForTeamForUser(context.Background(), user2.Id, team1.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, model.SidebarCategoryFavorites, categories.Categories[0].Type)
|
||||
require.NotContains(t, categories.Categories[0].Channels, channel.Id)
|
||||
@@ -483,7 +484,7 @@ func TestUpdateSidebarPreferences(t *testing.T) {
|
||||
require.Contains(t, categories.Categories[1].Channels, channel.Id)
|
||||
|
||||
// Favorite the channel
|
||||
_, err = th.Client.UpdatePreferences(user.Id, model.Preferences{
|
||||
_, err = th.Client.UpdatePreferences(context.Background(), user.Id, model.Preferences{
|
||||
{
|
||||
UserId: user.Id,
|
||||
Category: model.PreferenceCategoryFavoriteChannel,
|
||||
@@ -494,7 +495,7 @@ func TestUpdateSidebarPreferences(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Confirm that the channel was not added to Favorites for the second user
|
||||
categories, _, err = client2.GetSidebarCategoriesForTeamForUser(user2.Id, team1.Id, "")
|
||||
categories, _, err = client2.GetSidebarCategoriesForTeamForUser(context.Background(), user2.Id, team1.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, model.SidebarCategoryFavorites, categories.Categories[0].Type)
|
||||
assert.NotContains(t, categories.Categories[0].Channels, channel.Id)
|
||||
@@ -502,7 +503,7 @@ func TestUpdateSidebarPreferences(t *testing.T) {
|
||||
assert.Contains(t, categories.Categories[1].Channels, channel.Id)
|
||||
|
||||
// Favorite the channel for the second user
|
||||
_, err = client2.UpdatePreferences(user2.Id, model.Preferences{
|
||||
_, err = client2.UpdatePreferences(context.Background(), user2.Id, model.Preferences{
|
||||
{
|
||||
UserId: user2.Id,
|
||||
Category: model.PreferenceCategoryFavoriteChannel,
|
||||
@@ -513,7 +514,7 @@ func TestUpdateSidebarPreferences(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Confirm that the channel is now in the Favorites for the second user
|
||||
categories, _, err = client2.GetSidebarCategoriesForTeamForUser(user2.Id, team1.Id, "")
|
||||
categories, _, err = client2.GetSidebarCategoriesForTeamForUser(context.Background(), user2.Id, team1.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, model.SidebarCategoryFavorites, categories.Categories[0].Type)
|
||||
assert.Contains(t, categories.Categories[0].Channels, channel.Id)
|
||||
@@ -521,7 +522,7 @@ func TestUpdateSidebarPreferences(t *testing.T) {
|
||||
assert.NotContains(t, categories.Categories[1].Channels, channel.Id)
|
||||
|
||||
// And unfavorite the channel
|
||||
_, err = th.Client.UpdatePreferences(user.Id, model.Preferences{
|
||||
_, err = th.Client.UpdatePreferences(context.Background(), user.Id, model.Preferences{
|
||||
{
|
||||
UserId: user.Id,
|
||||
Category: model.PreferenceCategoryFavoriteChannel,
|
||||
@@ -532,7 +533,7 @@ func TestUpdateSidebarPreferences(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// The channel should still be in the second user's favorites
|
||||
categories, _, err = client2.GetSidebarCategoriesForTeamForUser(user2.Id, team1.Id, "")
|
||||
categories, _, err = client2.GetSidebarCategoriesForTeamForUser(context.Background(), user2.Id, team1.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, model.SidebarCategoryFavorites, categories.Categories[0].Type)
|
||||
assert.Contains(t, categories.Categories[0].Channels, channel.Id)
|
||||
@@ -548,7 +549,7 @@ func TestDeletePreferences(t *testing.T) {
|
||||
|
||||
th.LoginBasic()
|
||||
|
||||
prefs, _, _ := client.GetPreferences(th.BasicUser.Id)
|
||||
prefs, _, _ := client.GetPreferences(context.Background(), th.BasicUser.Id)
|
||||
originalCount := len(prefs)
|
||||
|
||||
// save 10 preferences
|
||||
@@ -562,29 +563,29 @@ func TestDeletePreferences(t *testing.T) {
|
||||
preferences = append(preferences, preference)
|
||||
}
|
||||
|
||||
client.UpdatePreferences(th.BasicUser.Id, preferences)
|
||||
client.UpdatePreferences(context.Background(), th.BasicUser.Id, preferences)
|
||||
|
||||
// delete 10 preferences
|
||||
th.LoginBasic2()
|
||||
|
||||
resp, err := client.DeletePreferences(th.BasicUser2.Id, preferences)
|
||||
resp, err := client.DeletePreferences(context.Background(), th.BasicUser2.Id, preferences)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
th.LoginBasic()
|
||||
|
||||
_, err = client.DeletePreferences(th.BasicUser.Id, preferences)
|
||||
_, err = client.DeletePreferences(context.Background(), th.BasicUser.Id, preferences)
|
||||
require.NoError(t, err)
|
||||
|
||||
resp, err = client.DeletePreferences(th.BasicUser2.Id, preferences)
|
||||
resp, err = client.DeletePreferences(context.Background(), th.BasicUser2.Id, preferences)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
prefs, _, _ = client.GetPreferences(th.BasicUser.Id)
|
||||
prefs, _, _ = client.GetPreferences(context.Background(), th.BasicUser.Id)
|
||||
require.Len(t, prefs, originalCount, "should've deleted preferences")
|
||||
|
||||
client.Logout()
|
||||
resp, err = client.DeletePreferences(th.BasicUser.Id, preferences)
|
||||
client.Logout(context.Background())
|
||||
resp, err = client.DeletePreferences(context.Background(), th.BasicUser.Id, preferences)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
}
|
||||
@@ -606,7 +607,7 @@ func TestDeletePreferencesWebsocket(t *testing.T) {
|
||||
Name: model.NewId(),
|
||||
},
|
||||
}
|
||||
_, err := th.Client.UpdatePreferences(userId, preferences)
|
||||
_, err := th.Client.UpdatePreferences(context.Background(), userId, preferences)
|
||||
require.NoError(t, err)
|
||||
|
||||
WebSocketClient, err := th.CreateWebSocketClient()
|
||||
@@ -616,7 +617,7 @@ func TestDeletePreferencesWebsocket(t *testing.T) {
|
||||
wsResp := <-WebSocketClient.ResponseChannel
|
||||
require.Equal(t, model.StatusOk, wsResp.Status, "should have responded OK to authentication challenge")
|
||||
|
||||
_, err = th.Client.DeletePreferences(userId, preferences)
|
||||
_, err = th.Client.DeletePreferences(context.Background(), userId, preferences)
|
||||
require.NoError(t, err)
|
||||
|
||||
timeout := time.After(30000 * time.Millisecond)
|
||||
@@ -657,14 +658,14 @@ func TestDeleteSidebarPreferences(t *testing.T) {
|
||||
team1 := th.CreateTeam()
|
||||
th.LinkUserToTeam(user, team1)
|
||||
|
||||
_, _, err := th.Client.GetSidebarCategoriesForTeamForUser(user.Id, team1.Id, "")
|
||||
_, _, err := th.Client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, team1.Id, "")
|
||||
require.NoError(t, err)
|
||||
|
||||
channel := th.CreateChannelWithClientAndTeam(th.Client, model.ChannelTypeOpen, team1.Id)
|
||||
th.AddUserToChannel(user, channel)
|
||||
|
||||
// Confirm that the sidebar is populated correctly to begin with
|
||||
categories, _, err := th.Client.GetSidebarCategoriesForTeamForUser(user.Id, team1.Id, "")
|
||||
categories, _, err := th.Client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, team1.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, model.SidebarCategoryFavorites, categories.Categories[0].Type)
|
||||
require.NotContains(t, categories.Categories[0].Channels, channel.Id)
|
||||
@@ -672,7 +673,7 @@ func TestDeleteSidebarPreferences(t *testing.T) {
|
||||
require.Contains(t, categories.Categories[1].Channels, channel.Id)
|
||||
|
||||
// Favorite the channel
|
||||
_, err = th.Client.UpdatePreferences(user.Id, model.Preferences{
|
||||
_, err = th.Client.UpdatePreferences(context.Background(), user.Id, model.Preferences{
|
||||
{
|
||||
UserId: user.Id,
|
||||
Category: model.PreferenceCategoryFavoriteChannel,
|
||||
@@ -682,7 +683,7 @@ func TestDeleteSidebarPreferences(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
// Confirm that the channel was added to the Favorites
|
||||
categories, _, err = th.Client.GetSidebarCategoriesForTeamForUser(user.Id, team1.Id, "")
|
||||
categories, _, err = th.Client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, team1.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, model.SidebarCategoryFavorites, categories.Categories[0].Type)
|
||||
assert.Contains(t, categories.Categories[0].Channels, channel.Id)
|
||||
@@ -690,7 +691,7 @@ func TestDeleteSidebarPreferences(t *testing.T) {
|
||||
assert.NotContains(t, categories.Categories[1].Channels, channel.Id)
|
||||
|
||||
// And unfavorite the channel by deleting the preference
|
||||
_, err = th.Client.DeletePreferences(user.Id, model.Preferences{
|
||||
_, err = th.Client.DeletePreferences(context.Background(), user.Id, model.Preferences{
|
||||
{
|
||||
UserId: user.Id,
|
||||
Category: model.PreferenceCategoryFavoriteChannel,
|
||||
@@ -700,7 +701,7 @@ func TestDeleteSidebarPreferences(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// The channel should've been removed from the Favorites
|
||||
categories, _, err = th.Client.GetSidebarCategoriesForTeamForUser(user.Id, team1.Id, "")
|
||||
categories, _, err = th.Client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, team1.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, model.SidebarCategoryFavorites, categories.Categories[0].Type)
|
||||
require.NotContains(t, categories.Categories[0].Channels, channel.Id)
|
||||
@@ -723,7 +724,7 @@ func TestDeleteSidebarPreferences(t *testing.T) {
|
||||
dmChannel := th.CreateDmChannel(user2)
|
||||
|
||||
// Favorite the channel
|
||||
_, err := th.Client.UpdatePreferences(user.Id, model.Preferences{
|
||||
_, err := th.Client.UpdatePreferences(context.Background(), user.Id, model.Preferences{
|
||||
{
|
||||
UserId: user.Id,
|
||||
Category: model.PreferenceCategoryFavoriteChannel,
|
||||
@@ -734,14 +735,14 @@ func TestDeleteSidebarPreferences(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Confirm that the channel was added to the Favorites on all teams
|
||||
categories, _, err := th.Client.GetSidebarCategoriesForTeamForUser(user.Id, team1.Id, "")
|
||||
categories, _, err := th.Client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, team1.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, model.SidebarCategoryFavorites, categories.Categories[0].Type)
|
||||
assert.Contains(t, categories.Categories[0].Channels, dmChannel.Id)
|
||||
require.Equal(t, model.SidebarCategoryDirectMessages, categories.Categories[2].Type)
|
||||
assert.NotContains(t, categories.Categories[2].Channels, dmChannel.Id)
|
||||
|
||||
categories, _, err = th.Client.GetSidebarCategoriesForTeamForUser(user.Id, team2.Id, "")
|
||||
categories, _, err = th.Client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, team2.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, model.SidebarCategoryFavorites, categories.Categories[0].Type)
|
||||
assert.Contains(t, categories.Categories[0].Channels, dmChannel.Id)
|
||||
@@ -749,7 +750,7 @@ func TestDeleteSidebarPreferences(t *testing.T) {
|
||||
assert.NotContains(t, categories.Categories[2].Channels, dmChannel.Id)
|
||||
|
||||
// And unfavorite the channel by deleting the preference
|
||||
_, err = th.Client.DeletePreferences(user.Id, model.Preferences{
|
||||
_, err = th.Client.DeletePreferences(context.Background(), user.Id, model.Preferences{
|
||||
{
|
||||
UserId: user.Id,
|
||||
Category: model.PreferenceCategoryFavoriteChannel,
|
||||
@@ -759,14 +760,14 @@ func TestDeleteSidebarPreferences(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// The channel should've been removed from the Favorites on all teams
|
||||
categories, _, err = th.Client.GetSidebarCategoriesForTeamForUser(user.Id, team1.Id, "")
|
||||
categories, _, err = th.Client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, team1.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, model.SidebarCategoryFavorites, categories.Categories[0].Type)
|
||||
require.NotContains(t, categories.Categories[0].Channels, dmChannel.Id)
|
||||
require.Equal(t, model.SidebarCategoryDirectMessages, categories.Categories[2].Type)
|
||||
assert.Contains(t, categories.Categories[2].Channels, dmChannel.Id)
|
||||
|
||||
categories, _, err = th.Client.GetSidebarCategoriesForTeamForUser(user.Id, team2.Id, "")
|
||||
categories, _, err = th.Client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, team2.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, model.SidebarCategoryFavorites, categories.Categories[0].Type)
|
||||
require.NotContains(t, categories.Categories[0].Channels, dmChannel.Id)
|
||||
@@ -788,9 +789,9 @@ func TestDeleteSidebarPreferences(t *testing.T) {
|
||||
th.LinkUserToTeam(user, team1)
|
||||
th.LinkUserToTeam(user2, team1)
|
||||
|
||||
_, _, err := th.Client.GetSidebarCategoriesForTeamForUser(user.Id, team1.Id, "")
|
||||
_, _, err := th.Client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, team1.Id, "")
|
||||
require.NoError(t, err)
|
||||
_, _, err = client2.GetSidebarCategoriesForTeamForUser(user2.Id, team1.Id, "")
|
||||
_, _, err = client2.GetSidebarCategoriesForTeamForUser(context.Background(), user2.Id, team1.Id, "")
|
||||
require.NoError(t, err)
|
||||
|
||||
channel := th.CreateChannelWithClientAndTeam(th.Client, model.ChannelTypeOpen, team1.Id)
|
||||
@@ -798,14 +799,14 @@ func TestDeleteSidebarPreferences(t *testing.T) {
|
||||
th.AddUserToChannel(user2, channel)
|
||||
|
||||
// Confirm that the sidebar is populated correctly to begin with
|
||||
categories, _, err := th.Client.GetSidebarCategoriesForTeamForUser(user.Id, team1.Id, "")
|
||||
categories, _, err := th.Client.GetSidebarCategoriesForTeamForUser(context.Background(), user.Id, team1.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, model.SidebarCategoryFavorites, categories.Categories[0].Type)
|
||||
require.NotContains(t, categories.Categories[0].Channels, channel.Id)
|
||||
require.Equal(t, model.SidebarCategoryChannels, categories.Categories[1].Type)
|
||||
require.Contains(t, categories.Categories[1].Channels, channel.Id)
|
||||
|
||||
categories, _, err = client2.GetSidebarCategoriesForTeamForUser(user2.Id, team1.Id, "")
|
||||
categories, _, err = client2.GetSidebarCategoriesForTeamForUser(context.Background(), user2.Id, team1.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, model.SidebarCategoryFavorites, categories.Categories[0].Type)
|
||||
require.NotContains(t, categories.Categories[0].Channels, channel.Id)
|
||||
@@ -813,7 +814,7 @@ func TestDeleteSidebarPreferences(t *testing.T) {
|
||||
require.Contains(t, categories.Categories[1].Channels, channel.Id)
|
||||
|
||||
// Favorite the channel for both users
|
||||
_, err = th.Client.UpdatePreferences(user.Id, model.Preferences{
|
||||
_, err = th.Client.UpdatePreferences(context.Background(), user.Id, model.Preferences{
|
||||
{
|
||||
UserId: user.Id,
|
||||
Category: model.PreferenceCategoryFavoriteChannel,
|
||||
@@ -823,7 +824,7 @@ func TestDeleteSidebarPreferences(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = client2.UpdatePreferences(user2.Id, model.Preferences{
|
||||
_, err = client2.UpdatePreferences(context.Background(), user2.Id, model.Preferences{
|
||||
{
|
||||
UserId: user2.Id,
|
||||
Category: model.PreferenceCategoryFavoriteChannel,
|
||||
@@ -834,7 +835,7 @@ func TestDeleteSidebarPreferences(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Confirm that the channel is in the Favorites for the second user
|
||||
categories, _, err = client2.GetSidebarCategoriesForTeamForUser(user2.Id, team1.Id, "")
|
||||
categories, _, err = client2.GetSidebarCategoriesForTeamForUser(context.Background(), user2.Id, team1.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, model.SidebarCategoryFavorites, categories.Categories[0].Type)
|
||||
assert.Contains(t, categories.Categories[0].Channels, channel.Id)
|
||||
@@ -842,7 +843,7 @@ func TestDeleteSidebarPreferences(t *testing.T) {
|
||||
assert.NotContains(t, categories.Categories[1].Channels, channel.Id)
|
||||
|
||||
// And unfavorite the channel for the first user by deleting the preference
|
||||
_, err = th.Client.UpdatePreferences(user.Id, model.Preferences{
|
||||
_, err = th.Client.UpdatePreferences(context.Background(), user.Id, model.Preferences{
|
||||
{
|
||||
UserId: user.Id,
|
||||
Category: model.PreferenceCategoryFavoriteChannel,
|
||||
@@ -853,7 +854,7 @@ func TestDeleteSidebarPreferences(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// The channel should still be in the second user's favorites
|
||||
categories, _, err = client2.GetSidebarCategoriesForTeamForUser(user2.Id, team1.Id, "")
|
||||
categories, _, err = client2.GetSidebarCategoriesForTeamForUser(context.Background(), user2.Id, team1.Id, "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, model.SidebarCategoryFavorites, categories.Categories[0].Type)
|
||||
assert.Contains(t, categories.Categories[0].Channels, channel.Id)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -33,7 +34,7 @@ func TestSaveReaction(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("successful-reaction", func(t *testing.T) {
|
||||
rr, _, err := client.SaveReaction(reaction)
|
||||
rr, _, err := client.SaveReaction(context.Background(), reaction)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, reaction.UserId, rr.UserId, "UserId did not match")
|
||||
require.Equal(t, reaction.PostId, rr.PostId, "PostId did not match")
|
||||
@@ -46,7 +47,7 @@ func TestSaveReaction(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("duplicated-reaction", func(t *testing.T) {
|
||||
_, _, err := client.SaveReaction(reaction)
|
||||
_, _, err := client.SaveReaction(context.Background(), reaction)
|
||||
require.NoError(t, err)
|
||||
reactions, appErr := th.App.GetReactionsForPost(postId)
|
||||
require.Nil(t, appErr)
|
||||
@@ -56,7 +57,7 @@ func TestSaveReaction(t *testing.T) {
|
||||
t.Run("save-second-reaction", func(t *testing.T) {
|
||||
reaction.EmojiName = "sad"
|
||||
|
||||
rr, _, err := client.SaveReaction(reaction)
|
||||
rr, _, err := client.SaveReaction(context.Background(), reaction)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, rr.EmojiName, reaction.EmojiName, "EmojiName did not match")
|
||||
|
||||
@@ -68,7 +69,7 @@ func TestSaveReaction(t *testing.T) {
|
||||
t.Run("saving-special-case", func(t *testing.T) {
|
||||
reaction.EmojiName = "+1"
|
||||
|
||||
rr, _, err := client.SaveReaction(reaction)
|
||||
rr, _, err := client.SaveReaction(context.Background(), reaction)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, reaction.EmojiName, rr.EmojiName, "EmojiName did not match")
|
||||
|
||||
@@ -80,7 +81,7 @@ func TestSaveReaction(t *testing.T) {
|
||||
t.Run("react-to-not-existing-post-id", func(t *testing.T) {
|
||||
reaction.PostId = GenerateTestId()
|
||||
|
||||
_, resp, err := client.SaveReaction(reaction)
|
||||
_, resp, err := client.SaveReaction(context.Background(), reaction)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
@@ -88,7 +89,7 @@ func TestSaveReaction(t *testing.T) {
|
||||
t.Run("react-to-not-valid-post-id", func(t *testing.T) {
|
||||
reaction.PostId = "junk"
|
||||
|
||||
_, resp, err := client.SaveReaction(reaction)
|
||||
_, resp, err := client.SaveReaction(context.Background(), reaction)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
@@ -97,7 +98,7 @@ func TestSaveReaction(t *testing.T) {
|
||||
reaction.PostId = postId
|
||||
reaction.UserId = GenerateTestId()
|
||||
|
||||
_, resp, err := client.SaveReaction(reaction)
|
||||
_, resp, err := client.SaveReaction(context.Background(), reaction)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
@@ -105,7 +106,7 @@ func TestSaveReaction(t *testing.T) {
|
||||
t.Run("react-as-not-valid-user-id", func(t *testing.T) {
|
||||
reaction.UserId = "junk"
|
||||
|
||||
_, resp, err := client.SaveReaction(reaction)
|
||||
_, resp, err := client.SaveReaction(context.Background(), reaction)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
@@ -114,7 +115,7 @@ func TestSaveReaction(t *testing.T) {
|
||||
reaction.UserId = userId
|
||||
reaction.EmojiName = ""
|
||||
|
||||
_, resp, err := client.SaveReaction(reaction)
|
||||
_, resp, err := client.SaveReaction(context.Background(), reaction)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
@@ -122,7 +123,7 @@ func TestSaveReaction(t *testing.T) {
|
||||
t.Run("react-as-not-valid-emoji-name", func(t *testing.T) {
|
||||
reaction.EmojiName = strings.Repeat("a", 65)
|
||||
|
||||
_, resp, err := client.SaveReaction(reaction)
|
||||
_, resp, err := client.SaveReaction(context.Background(), reaction)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
@@ -130,23 +131,23 @@ func TestSaveReaction(t *testing.T) {
|
||||
t.Run("react-as-other-user", func(t *testing.T) {
|
||||
reaction.EmojiName = "smile"
|
||||
otherUser := th.CreateUser()
|
||||
client.Logout()
|
||||
client.Login(otherUser.Email, otherUser.Password)
|
||||
client.Logout(context.Background())
|
||||
client.Login(context.Background(), otherUser.Email, otherUser.Password)
|
||||
|
||||
_, resp, err := client.SaveReaction(reaction)
|
||||
_, resp, err := client.SaveReaction(context.Background(), reaction)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("react-being-not-logged-in", func(t *testing.T) {
|
||||
client.Logout()
|
||||
_, resp, err := client.SaveReaction(reaction)
|
||||
client.Logout(context.Background())
|
||||
_, resp, err := client.SaveReaction(context.Background(), reaction)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("react-as-other-user-being-system-admin", func(t *testing.T) {
|
||||
_, resp, err := th.SystemAdminClient.SaveReaction(reaction)
|
||||
_, resp, err := th.SystemAdminClient.SaveReaction(context.Background(), reaction)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
@@ -155,7 +156,7 @@ func TestSaveReaction(t *testing.T) {
|
||||
th.LoginBasic()
|
||||
|
||||
th.RemovePermissionFromRole(model.PermissionAddReaction.Id, model.ChannelUserRoleId)
|
||||
_, resp, err := client.SaveReaction(reaction)
|
||||
_, resp, err := client.SaveReaction(context.Background(), reaction)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
@@ -180,7 +181,7 @@ func TestSaveReaction(t *testing.T) {
|
||||
appErr := th.App.DeleteChannel(th.Context, channel, userId)
|
||||
assert.Nil(t, appErr)
|
||||
|
||||
_, resp, err := client.SaveReaction(reaction)
|
||||
_, resp, err := client.SaveReaction(context.Background(), reaction)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
@@ -235,7 +236,7 @@ func TestGetReactions(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("get-reactions", func(t *testing.T) {
|
||||
rr, _, err := client.GetReactions(postId)
|
||||
rr, _, err := client.GetReactions(context.Background(), postId)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Len(t, rr, 5)
|
||||
@@ -245,7 +246,7 @@ func TestGetReactions(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("get-reactions-of-invalid-post-id", func(t *testing.T) {
|
||||
rr, resp, err := client.GetReactions("junk")
|
||||
rr, resp, err := client.GetReactions(context.Background(), "junk")
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
@@ -253,21 +254,21 @@ func TestGetReactions(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("get-reactions-of-not-existing-post-id", func(t *testing.T) {
|
||||
_, resp, err := client.GetReactions(GenerateTestId())
|
||||
_, resp, err := client.GetReactions(context.Background(), GenerateTestId())
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("get-reactions-as-anonymous-user", func(t *testing.T) {
|
||||
client.Logout()
|
||||
client.Logout(context.Background())
|
||||
|
||||
_, resp, err := client.GetReactions(postId)
|
||||
_, resp, err := client.GetReactions(context.Background(), postId)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("get-reactions-as-system-admin", func(t *testing.T) {
|
||||
_, _, err := th.SystemAdminClient.GetReactions(postId)
|
||||
_, _, err := th.SystemAdminClient.GetReactions(context.Background(), postId)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
@@ -316,7 +317,7 @@ func TestDeleteReaction(t *testing.T) {
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, 1, len(reactions), "didn't save reaction correctly")
|
||||
|
||||
_, err := client.DeleteReaction(r1)
|
||||
_, err := client.DeleteReaction(context.Background(), r1)
|
||||
require.NoError(t, err)
|
||||
|
||||
reactions, appErr = th.App.GetReactionsForPost(postId)
|
||||
@@ -331,7 +332,7 @@ func TestDeleteReaction(t *testing.T) {
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, len(reactions), 2, "didn't save reactions correctly")
|
||||
|
||||
_, err := client.DeleteReaction(r2)
|
||||
_, err := client.DeleteReaction(context.Background(), r2)
|
||||
require.NoError(t, err)
|
||||
|
||||
reactions, appErr = th.App.GetReactionsForPost(postId)
|
||||
@@ -346,7 +347,7 @@ func TestDeleteReaction(t *testing.T) {
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, 2, len(reactions), "didn't save reactions correctly")
|
||||
|
||||
_, err := client.DeleteReaction(r3)
|
||||
_, err := client.DeleteReaction(context.Background(), r3)
|
||||
require.NoError(t, err)
|
||||
|
||||
reactions, appErr = th.App.GetReactionsForPost(postId)
|
||||
@@ -364,7 +365,7 @@ func TestDeleteReaction(t *testing.T) {
|
||||
|
||||
th.LoginBasic()
|
||||
|
||||
resp, err := client.DeleteReaction(r4)
|
||||
resp, err := client.DeleteReaction(context.Background(), r4)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
@@ -375,7 +376,7 @@ func TestDeleteReaction(t *testing.T) {
|
||||
|
||||
t.Run("delete-reaction-from-not-existing-post-id", func(t *testing.T) {
|
||||
r1.PostId = GenerateTestId()
|
||||
resp, err := client.DeleteReaction(r1)
|
||||
resp, err := client.DeleteReaction(context.Background(), r1)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
@@ -383,7 +384,7 @@ func TestDeleteReaction(t *testing.T) {
|
||||
t.Run("delete-reaction-from-not-valid-post-id", func(t *testing.T) {
|
||||
r1.PostId = "junk"
|
||||
|
||||
resp, err := client.DeleteReaction(r1)
|
||||
resp, err := client.DeleteReaction(context.Background(), r1)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
@@ -392,7 +393,7 @@ func TestDeleteReaction(t *testing.T) {
|
||||
r1.PostId = postId
|
||||
r1.UserId = GenerateTestId()
|
||||
|
||||
resp, err := client.DeleteReaction(r1)
|
||||
resp, err := client.DeleteReaction(context.Background(), r1)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
@@ -400,7 +401,7 @@ func TestDeleteReaction(t *testing.T) {
|
||||
t.Run("delete-reaction-from-not-valid-user-id", func(t *testing.T) {
|
||||
r1.UserId = "junk"
|
||||
|
||||
resp, err := client.DeleteReaction(r1)
|
||||
resp, err := client.DeleteReaction(context.Background(), r1)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
@@ -409,7 +410,7 @@ func TestDeleteReaction(t *testing.T) {
|
||||
r1.UserId = userId
|
||||
r1.EmojiName = ""
|
||||
|
||||
resp, err := client.DeleteReaction(r1)
|
||||
resp, err := client.DeleteReaction(context.Background(), r1)
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
})
|
||||
@@ -417,25 +418,25 @@ func TestDeleteReaction(t *testing.T) {
|
||||
t.Run("delete-reaction-with-not-existing-name", func(t *testing.T) {
|
||||
r1.EmojiName = strings.Repeat("a", 65)
|
||||
|
||||
resp, err := client.DeleteReaction(r1)
|
||||
resp, err := client.DeleteReaction(context.Background(), r1)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("delete-reaction-as-anonymous-user", func(t *testing.T) {
|
||||
client.Logout()
|
||||
client.Logout(context.Background())
|
||||
r1.EmojiName = "smile"
|
||||
|
||||
resp, err := client.DeleteReaction(r1)
|
||||
resp, err := client.DeleteReaction(context.Background(), r1)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("delete-reaction-as-system-admin", func(t *testing.T) {
|
||||
_, err := th.SystemAdminClient.DeleteReaction(r1)
|
||||
_, err := th.SystemAdminClient.DeleteReaction(context.Background(), r1)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = th.SystemAdminClient.DeleteReaction(r4)
|
||||
_, err = th.SystemAdminClient.DeleteReaction(context.Background(), r4)
|
||||
require.NoError(t, err)
|
||||
|
||||
reactions, appErr := th.App.GetReactionsForPost(postId)
|
||||
@@ -449,7 +450,7 @@ func TestDeleteReaction(t *testing.T) {
|
||||
th.RemovePermissionFromRole(model.PermissionRemoveReaction.Id, model.ChannelUserRoleId)
|
||||
th.App.SaveReactionForPost(th.Context, r1)
|
||||
|
||||
resp, err := client.DeleteReaction(r1)
|
||||
resp, err := client.DeleteReaction(context.Background(), r1)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
@@ -463,7 +464,7 @@ func TestDeleteReaction(t *testing.T) {
|
||||
th.RemovePermissionFromRole(model.PermissionRemoveOthersReactions.Id, model.SystemAdminRoleId)
|
||||
th.App.SaveReactionForPost(th.Context, r1)
|
||||
|
||||
resp, err := th.SystemAdminClient.DeleteReaction(r1)
|
||||
resp, err := th.SystemAdminClient.DeleteReaction(context.Background(), r1)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
@@ -485,7 +486,7 @@ func TestDeleteReaction(t *testing.T) {
|
||||
EmojiName: "smile",
|
||||
}
|
||||
|
||||
r1, _, err := client.SaveReaction(reaction)
|
||||
r1, _, err := client.SaveReaction(context.Background(), reaction)
|
||||
require.NoError(t, err)
|
||||
|
||||
reactions, appErr := th.App.GetReactionsForPost(postId)
|
||||
@@ -495,7 +496,7 @@ func TestDeleteReaction(t *testing.T) {
|
||||
appErr = th.App.DeleteChannel(th.Context, channel, userId)
|
||||
assert.Nil(t, appErr)
|
||||
|
||||
_, resp, err := client.SaveReaction(r1)
|
||||
_, resp, err := client.SaveReaction(context.Background(), r1)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
@@ -518,11 +519,11 @@ func TestGetBulkReactions(t *testing.T) {
|
||||
post4 := &model.Post{UserId: user2Id, ChannelId: th.BasicChannel.Id, Message: "zz" + model.NewId() + "a"}
|
||||
post5 := &model.Post{UserId: user2Id, ChannelId: th.BasicChannel.Id, Message: "zz" + model.NewId() + "a"}
|
||||
|
||||
post1, _, _ = client.CreatePost(post1)
|
||||
post2, _, _ = client.CreatePost(post2)
|
||||
post3, _, _ = client.CreatePost(post3)
|
||||
post4, _, _ = client.CreatePost(post4)
|
||||
post5, _, _ = client.CreatePost(post5)
|
||||
post1, _, _ = client.CreatePost(context.Background(), post1)
|
||||
post2, _, _ = client.CreatePost(context.Background(), post2)
|
||||
post3, _, _ = client.CreatePost(context.Background(), post3)
|
||||
post4, _, _ = client.CreatePost(context.Background(), post4)
|
||||
post5, _, _ = client.CreatePost(context.Background(), post5)
|
||||
|
||||
expectedPostIdsReactionsMap := make(map[string][]*model.Reaction)
|
||||
expectedPostIdsReactionsMap[post1.Id] = []*model.Reaction{}
|
||||
@@ -564,7 +565,7 @@ func TestGetBulkReactions(t *testing.T) {
|
||||
postIds := []string{post1.Id, post2.Id, post3.Id, post4.Id, post5.Id}
|
||||
|
||||
t.Run("get-reactions", func(t *testing.T) {
|
||||
postIdsReactionsMap, _, err := client.GetBulkReactions(postIds)
|
||||
postIdsReactionsMap, _, err := client.GetBulkReactions(context.Background(), postIds)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.ElementsMatch(t, expectedPostIdsReactionsMap[post1.Id], postIdsReactionsMap[post1.Id])
|
||||
@@ -577,9 +578,9 @@ func TestGetBulkReactions(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("get-reactions-as-anonymous-user", func(t *testing.T) {
|
||||
client.Logout()
|
||||
client.Logout(context.Background())
|
||||
|
||||
_, resp, err := client.GetBulkReactions(postIds)
|
||||
_, resp, err := client.GetBulkReactions(context.Background(), postIds)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
})
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"testing"
|
||||
@@ -314,7 +315,7 @@ func TestGraphQLChannels(t *testing.T) {
|
||||
require.Len(t, resp.Errors, 0) // no errors for no channels found
|
||||
|
||||
th.BasicChannel.Purpose = "newpurpose"
|
||||
_, _, err = th.Client.UpdateChannel(th.BasicChannel)
|
||||
_, _, err = th.Client.UpdateChannel(context.Background(), th.BasicChannel)
|
||||
require.NoError(t, err)
|
||||
|
||||
input = graphQLInput{
|
||||
@@ -332,10 +333,10 @@ func TestGraphQLChannels(t *testing.T) {
|
||||
require.NoError(t, json.Unmarshal(resp.Data, &q))
|
||||
assert.Len(t, q.Channels, 1)
|
||||
|
||||
_, err = th.Client.DeleteChannel(ch1.Id)
|
||||
_, err = th.Client.DeleteChannel(context.Background(), ch1.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = th.Client.DeleteChannel(ch2.Id)
|
||||
_, err = th.Client.DeleteChannel(context.Background(), ch2.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
input = graphQLInput{
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"sort"
|
||||
@@ -57,7 +58,7 @@ func TestGraphQLSidebarCategories(t *testing.T) {
|
||||
require.NoError(t, json.Unmarshal(resp.Data, &q))
|
||||
assert.Len(t, q.SidebarCategories, 3)
|
||||
|
||||
categories, _, err := th.Client.GetSidebarCategoriesForTeamForUser(th.BasicUser.Id, th.BasicTeam.Id, "")
|
||||
categories, _, err := th.Client.GetSidebarCategoriesForTeamForUser(context.Background(), th.BasicUser.Id, th.BasicTeam.Id, "")
|
||||
require.NoError(t, err)
|
||||
|
||||
sort.Slice(q.SidebarCategories, func(i, j int) bool {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"sort"
|
||||
@@ -307,7 +308,7 @@ func TestGraphQLTeamMembersAsGuest(t *testing.T) {
|
||||
}
|
||||
|
||||
var err error
|
||||
team, _, err = th.Client.CreateTeam(team)
|
||||
team, _, err = th.Client.CreateTeam(context.Background(), team)
|
||||
require.NoError(t, err)
|
||||
th.BasicTeam = team
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"testing"
|
||||
@@ -35,7 +36,7 @@ func TestGraphQLConfig(t *testing.T) {
|
||||
`,
|
||||
}
|
||||
|
||||
cfg, _, err := th.Client.GetOldClientConfig("")
|
||||
cfg, _, err := th.Client.GetOldClientConfig(context.Background(), "")
|
||||
require.NoError(t, err)
|
||||
|
||||
resp, err := th.MakeGraphQLRequest(&input)
|
||||
@@ -66,7 +67,7 @@ func TestGraphQLLicense(t *testing.T) {
|
||||
`,
|
||||
}
|
||||
|
||||
cfg, _, err := th.Client.GetOldClientLicense("")
|
||||
cfg, _, err := th.Client.GetOldClientLicense(context.Background(), "")
|
||||
require.NoError(t, err)
|
||||
|
||||
resp, err := th.MakeGraphQLRequest(&input)
|
||||
@@ -105,7 +106,7 @@ func TestGraphQLChannelsLeft(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Left", func(t *testing.T) {
|
||||
_, err := th.Client.RemoveUserFromChannel(th.BasicChannel.Id, th.BasicUser.Id)
|
||||
_, err := th.Client.RemoveUserFromChannel(context.Background(), th.BasicChannel.Id, th.BasicUser.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
input := graphQLInput{
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"sort"
|
||||
@@ -134,7 +135,7 @@ func TestGraphQLUser(t *testing.T) {
|
||||
assert.Equal(t, th.BasicUser.Props, q.User.Props)
|
||||
assert.Equal(t, th.BasicUser.NotifyProps, q.User.NotifyProps)
|
||||
|
||||
roles, _, err := th.Client.GetRolesByNames(th.BasicUser.GetRoles())
|
||||
roles, _, err := th.Client.GetRolesByNames(context.Background(), th.BasicUser.GetRoles())
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Len(t, q.User.Roles, 1)
|
||||
@@ -145,7 +146,7 @@ func TestGraphQLUser(t *testing.T) {
|
||||
assert.Equal(t, float64(roles[0].UpdateAt), q.User.Roles[0].UpdateAt)
|
||||
assert.Equal(t, float64(roles[0].DeleteAt), q.User.Roles[0].DeleteAt)
|
||||
|
||||
prefs, _, err := th.Client.GetPreferences(th.BasicUser.Id)
|
||||
prefs, _, err := th.Client.GetPreferences(context.Background(), th.BasicUser.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
sort.Slice(prefs, func(i, j int) bool {
|
||||
|
||||
@@ -23,7 +23,7 @@ func TestGetAllRoles(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
received, resp, err := client.GetAllRoles()
|
||||
received, resp, err := client.GetAllRoles(context.Background())
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
|
||||
@@ -31,7 +31,7 @@ func TestGetAllRoles(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("NormalClient", func(t *testing.T) {
|
||||
_, resp, err := th.Client.GetAllRoles()
|
||||
_, resp, err := th.Client.GetAllRoles(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
@@ -54,7 +54,7 @@ func TestGetRole(t *testing.T) {
|
||||
defer th.App.Srv().Store().Job().Delete(role.Id)
|
||||
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
received, _, err := client.GetRole(role.Id)
|
||||
received, _, err := client.GetRole(context.Background(), role.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, received.Id, role.Id)
|
||||
@@ -66,11 +66,11 @@ func TestGetRole(t *testing.T) {
|
||||
})
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
_, resp, err := client.GetRole("1234")
|
||||
_, resp, err := client.GetRole(context.Background(), "1234")
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
_, resp, err = client.GetRole(model.NewId())
|
||||
_, resp, err = client.GetRole(context.Background(), model.NewId())
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
})
|
||||
@@ -93,7 +93,7 @@ func TestGetRoleByName(t *testing.T) {
|
||||
defer th.App.Srv().Store().Job().Delete(role.Id)
|
||||
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
received, _, err := client.GetRoleByName(role.Name)
|
||||
received, _, err := client.GetRoleByName(context.Background(), role.Name)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, received.Id, role.Id)
|
||||
@@ -105,11 +105,11 @@ func TestGetRoleByName(t *testing.T) {
|
||||
})
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
_, resp, err := client.GetRoleByName(strings.Repeat("abcdefghij", 10))
|
||||
_, resp, err := client.GetRoleByName(context.Background(), strings.Repeat("abcdefghij", 10))
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
_, resp, err = client.GetRoleByName(model.NewId())
|
||||
_, resp, err = client.GetRoleByName(context.Background(), model.NewId())
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
})
|
||||
@@ -155,7 +155,7 @@ func TestGetRolesByNames(t *testing.T) {
|
||||
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
// Check all three roles can be found.
|
||||
received, _, err := client.GetRolesByNames([]string{role1.Name, role2.Name, role3.Name})
|
||||
received, _, err := client.GetRolesByNames(context.Background(), []string{role1.Name, role2.Name, role3.Name})
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Contains(t, received, role1)
|
||||
@@ -163,25 +163,25 @@ func TestGetRolesByNames(t *testing.T) {
|
||||
assert.Contains(t, received, role3)
|
||||
|
||||
// Check a list of non-existent roles.
|
||||
_, _, err = client.GetRolesByNames([]string{model.NewId(), model.NewId()})
|
||||
_, _, err = client.GetRolesByNames(context.Background(), []string{model.NewId(), model.NewId()})
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
// Empty list should error.
|
||||
_, resp, err := client.GetRolesByNames([]string{})
|
||||
_, resp, err := client.GetRolesByNames(context.Background(), []string{})
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
// Invalid role name should error.
|
||||
_, resp, err := client.GetRolesByNames([]string{model.NewId(), model.NewId(), "!!!!!!"})
|
||||
_, resp, err := client.GetRolesByNames(context.Background(), []string{model.NewId(), model.NewId(), "!!!!!!"})
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
// Empty/whitespace rolenames should be ignored.
|
||||
_, _, err = client.GetRolesByNames([]string{model.NewId(), model.NewId(), "", " "})
|
||||
_, _, err = client.GetRolesByNames(context.Background(), []string{model.NewId(), model.NewId(), "", " "})
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
@@ -214,7 +214,7 @@ func TestPatchRole(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
defer th.App.Srv().Store().Job().Delete(adminRole.Id)
|
||||
|
||||
_, resp, err := client.PatchRole(adminRole.Id, patch)
|
||||
_, resp, err := client.PatchRole(context.Background(), adminRole.Id, patch)
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
|
||||
@@ -227,7 +227,7 @@ func TestPatchRole(t *testing.T) {
|
||||
Permissions: &[]string{model.PermissionSysconsoleWriteUserManagementSystemRoles.Id},
|
||||
}
|
||||
|
||||
_, resp, err = client.PatchRole(systemManager.Id, patchWriteSystemRoles)
|
||||
_, resp, err = client.PatchRole(context.Background(), systemManager.Id, patchWriteSystemRoles)
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
|
||||
@@ -235,7 +235,7 @@ func TestPatchRole(t *testing.T) {
|
||||
Permissions: &[]string{model.PermissionSysconsoleReadUserManagementSystemRoles.Id},
|
||||
}
|
||||
|
||||
_, resp, err = client.PatchRole(systemManager.Id, patchReadSystemRoles)
|
||||
_, resp, err = client.PatchRole(context.Background(), systemManager.Id, patchReadSystemRoles)
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
|
||||
@@ -243,13 +243,13 @@ func TestPatchRole(t *testing.T) {
|
||||
Permissions: &[]string{model.PermissionManageRoles.Id},
|
||||
}
|
||||
|
||||
_, resp, err = client.PatchRole(systemManager.Id, patchManageRoles)
|
||||
_, resp, err = client.PatchRole(context.Background(), systemManager.Id, patchManageRoles)
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
})
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
received, _, err := client.PatchRole(role.Id, patch)
|
||||
received, _, err := client.PatchRole(context.Background(), role.Id, patch)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, received.Id, role.Id)
|
||||
@@ -262,19 +262,19 @@ func TestPatchRole(t *testing.T) {
|
||||
assert.Equal(t, received.SchemeManaged, role.SchemeManaged)
|
||||
|
||||
// Check a no-op patch succeeds.
|
||||
_, _, err = client.PatchRole(role.Id, patch)
|
||||
_, _, err = client.PatchRole(context.Background(), role.Id, patch)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, resp, err := client.PatchRole("junk", patch)
|
||||
_, resp, err := client.PatchRole(context.Background(), "junk", patch)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
|
||||
_, resp, err := th.Client.PatchRole(model.NewId(), patch)
|
||||
_, resp, err := th.Client.PatchRole(context.Background(), model.NewId(), patch)
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
_, resp, err = th.Client.PatchRole(role.Id, patch)
|
||||
_, resp, err = th.Client.PatchRole(context.Background(), role.Id, patch)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
@@ -283,7 +283,7 @@ func TestPatchRole(t *testing.T) {
|
||||
}
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) {
|
||||
received, _, err := client.PatchRole(role.Id, patch)
|
||||
received, _, err := client.PatchRole(context.Background(), role.Id, patch)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, received.Id, role.Id)
|
||||
@@ -302,7 +302,7 @@ func TestPatchRole(t *testing.T) {
|
||||
|
||||
guestRole, err := th.App.Srv().Store().Role().GetByName(context.Background(), "system_guest")
|
||||
require.NoError(t, err)
|
||||
received, resp, err = client.PatchRole(guestRole.Id, patch)
|
||||
received, resp, err = client.PatchRole(context.Background(), guestRole.Id, patch)
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
})
|
||||
@@ -313,7 +313,7 @@ func TestPatchRole(t *testing.T) {
|
||||
th.App.Srv().SetLicense(license)
|
||||
guestRole, err := th.App.Srv().Store().Role().GetByName(context.Background(), "system_guest")
|
||||
require.NoError(t, err)
|
||||
_, _, err = client.PatchRole(guestRole.Id, patch)
|
||||
_, _, err = client.PatchRole(context.Background(), guestRole.Id, patch)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
@@ -18,7 +19,7 @@ func TestGetSamlMetadata(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
client := th.Client
|
||||
|
||||
_, resp, err := client.GetSamlMetadata()
|
||||
_, resp, err := client.GetSamlMetadata(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, resp)
|
||||
|
||||
@@ -65,11 +66,11 @@ func TestSamlResetId(t *testing.T) {
|
||||
})
|
||||
require.Nil(t, appErr)
|
||||
|
||||
_, resp, err := th.Client.ResetSamlAuthDataToEmail(false, false, nil)
|
||||
_, resp, err := th.Client.ResetSamlAuthDataToEmail(context.Background(), false, false, nil)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
numAffected, resp, err := th.SystemAdminClient.ResetSamlAuthDataToEmail(false, false, nil)
|
||||
numAffected, resp, err := th.SystemAdminClient.ResetSamlAuthDataToEmail(context.Background(), false, false, nil)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
require.Equal(t, int64(1), numAffected)
|
||||
|
||||
@@ -30,7 +30,7 @@ func TestCreateScheme(t *testing.T) {
|
||||
Scope: model.SchemeScopeTeam,
|
||||
}
|
||||
|
||||
s1, _, err := th.SystemAdminClient.CreateScheme(scheme1)
|
||||
s1, _, err := th.SystemAdminClient.CreateScheme(context.Background(), scheme1)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, s1.DisplayName, scheme1.DisplayName)
|
||||
@@ -48,20 +48,20 @@ func TestCreateScheme(t *testing.T) {
|
||||
assert.NotZero(t, len(s1.DefaultChannelGuestRole))
|
||||
|
||||
// Check the default roles have been created.
|
||||
_, _, err = th.SystemAdminClient.GetRoleByName(s1.DefaultTeamAdminRole)
|
||||
_, _, err = th.SystemAdminClient.GetRoleByName(context.Background(), s1.DefaultTeamAdminRole)
|
||||
require.NoError(t, err)
|
||||
_, _, err = th.SystemAdminClient.GetRoleByName(s1.DefaultTeamUserRole)
|
||||
_, _, err = th.SystemAdminClient.GetRoleByName(context.Background(), s1.DefaultTeamUserRole)
|
||||
require.NoError(t, err)
|
||||
_, _, err = th.SystemAdminClient.GetRoleByName(s1.DefaultChannelAdminRole)
|
||||
_, _, err = th.SystemAdminClient.GetRoleByName(context.Background(), s1.DefaultChannelAdminRole)
|
||||
require.NoError(t, err)
|
||||
_, _, err = th.SystemAdminClient.GetRoleByName(s1.DefaultChannelUserRole)
|
||||
_, _, err = th.SystemAdminClient.GetRoleByName(context.Background(), s1.DefaultChannelUserRole)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, err = th.SystemAdminClient.GetRoleByName(s1.DefaultTeamGuestRole)
|
||||
_, _, err = th.SystemAdminClient.GetRoleByName(context.Background(), s1.DefaultTeamGuestRole)
|
||||
require.NoError(t, err)
|
||||
_, _, err = th.SystemAdminClient.GetRoleByName(s1.DefaultTeamGuestRole)
|
||||
_, _, err = th.SystemAdminClient.GetRoleByName(context.Background(), s1.DefaultTeamGuestRole)
|
||||
require.NoError(t, err)
|
||||
_, _, err = th.SystemAdminClient.GetRoleByName(s1.DefaultChannelGuestRole)
|
||||
_, _, err = th.SystemAdminClient.GetRoleByName(context.Background(), s1.DefaultChannelGuestRole)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Basic Test of a Channel scheme.
|
||||
@@ -72,7 +72,7 @@ func TestCreateScheme(t *testing.T) {
|
||||
Scope: model.SchemeScopeChannel,
|
||||
}
|
||||
|
||||
s2, _, err := th.SystemAdminClient.CreateScheme(scheme2)
|
||||
s2, _, err := th.SystemAdminClient.CreateScheme(context.Background(), scheme2)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, s2.DisplayName, scheme2.DisplayName)
|
||||
@@ -90,11 +90,11 @@ func TestCreateScheme(t *testing.T) {
|
||||
assert.NotZero(t, len(s2.DefaultChannelGuestRole))
|
||||
|
||||
// Check the default roles have been created.
|
||||
_, _, err = th.SystemAdminClient.GetRoleByName(s2.DefaultChannelAdminRole)
|
||||
_, _, err = th.SystemAdminClient.GetRoleByName(context.Background(), s2.DefaultChannelAdminRole)
|
||||
require.NoError(t, err)
|
||||
_, _, err = th.SystemAdminClient.GetRoleByName(s2.DefaultChannelUserRole)
|
||||
_, _, err = th.SystemAdminClient.GetRoleByName(context.Background(), s2.DefaultChannelUserRole)
|
||||
require.NoError(t, err)
|
||||
_, _, err = th.SystemAdminClient.GetRoleByName(s2.DefaultChannelGuestRole)
|
||||
_, _, err = th.SystemAdminClient.GetRoleByName(context.Background(), s2.DefaultChannelGuestRole)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Try and create a scheme with an invalid scope.
|
||||
@@ -105,7 +105,7 @@ func TestCreateScheme(t *testing.T) {
|
||||
Scope: model.NewId(),
|
||||
}
|
||||
|
||||
_, r3, _ := th.SystemAdminClient.CreateScheme(scheme3)
|
||||
_, r3, _ := th.SystemAdminClient.CreateScheme(context.Background(), scheme3)
|
||||
CheckBadRequestStatus(t, r3)
|
||||
|
||||
// Try and create a scheme with an invalid display name.
|
||||
@@ -115,7 +115,7 @@ func TestCreateScheme(t *testing.T) {
|
||||
Description: model.NewId(),
|
||||
Scope: model.NewId(),
|
||||
}
|
||||
_, r4, _ := th.SystemAdminClient.CreateScheme(scheme4)
|
||||
_, r4, _ := th.SystemAdminClient.CreateScheme(context.Background(), scheme4)
|
||||
CheckBadRequestStatus(t, r4)
|
||||
|
||||
// Try and create a scheme with an invalid name.
|
||||
@@ -125,7 +125,7 @@ func TestCreateScheme(t *testing.T) {
|
||||
Description: model.NewId(),
|
||||
Scope: model.NewId(),
|
||||
}
|
||||
_, r8, _ := th.SystemAdminClient.CreateScheme(scheme8)
|
||||
_, r8, _ := th.SystemAdminClient.CreateScheme(context.Background(), scheme8)
|
||||
CheckBadRequestStatus(t, r8)
|
||||
|
||||
// Try and create a scheme without the appropriate permissions.
|
||||
@@ -135,7 +135,7 @@ func TestCreateScheme(t *testing.T) {
|
||||
Description: model.NewId(),
|
||||
Scope: model.SchemeScopeTeam,
|
||||
}
|
||||
_, r5, err := th.Client.CreateScheme(scheme5)
|
||||
_, r5, err := th.Client.CreateScheme(context.Background(), scheme5)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, r5)
|
||||
|
||||
@@ -147,7 +147,7 @@ func TestCreateScheme(t *testing.T) {
|
||||
Description: model.NewId(),
|
||||
Scope: model.SchemeScopeTeam,
|
||||
}
|
||||
_, r6, _ := th.SystemAdminClient.CreateScheme(scheme6)
|
||||
_, r6, _ := th.SystemAdminClient.CreateScheme(context.Background(), scheme6)
|
||||
CheckNotImplementedStatus(t, r6)
|
||||
|
||||
// Create scheme with a Professional SKU license but no explicit 'custom_permissions_schemes' license feature.
|
||||
@@ -171,7 +171,7 @@ func TestCreateScheme(t *testing.T) {
|
||||
Description: model.NewId(),
|
||||
Scope: model.SchemeScopeTeam,
|
||||
}
|
||||
_, resp, err := th.SystemAdminClient.CreateScheme(scheme6b)
|
||||
_, resp, err := th.SystemAdminClient.CreateScheme(context.Background(), scheme6b)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
|
||||
@@ -186,7 +186,7 @@ func TestCreateScheme(t *testing.T) {
|
||||
Description: model.NewId(),
|
||||
Scope: model.SchemeScopeTeam,
|
||||
}
|
||||
_, r7, _ := th.SystemAdminClient.CreateScheme(scheme7)
|
||||
_, r7, _ := th.SystemAdminClient.CreateScheme(context.Background(), scheme7)
|
||||
CheckNotImplementedStatus(t, r7)
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ func TestGetScheme(t *testing.T) {
|
||||
|
||||
th.App.SetPhase2PermissionsMigrationStatus(true)
|
||||
|
||||
s1, _, err := th.SystemAdminClient.CreateScheme(scheme1)
|
||||
s1, _, err := th.SystemAdminClient.CreateScheme(context.Background(), scheme1)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, s1.DisplayName, scheme1.DisplayName)
|
||||
@@ -223,33 +223,33 @@ func TestGetScheme(t *testing.T) {
|
||||
assert.NotZero(t, len(s1.DefaultChannelUserRole))
|
||||
assert.NotZero(t, len(s1.DefaultChannelGuestRole))
|
||||
|
||||
s2, _, err := th.SystemAdminClient.GetScheme(s1.Id)
|
||||
s2, _, err := th.SystemAdminClient.GetScheme(context.Background(), s1.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, s1, s2)
|
||||
|
||||
_, r3, _ := th.SystemAdminClient.GetScheme(model.NewId())
|
||||
_, r3, _ := th.SystemAdminClient.GetScheme(context.Background(), model.NewId())
|
||||
CheckNotFoundStatus(t, r3)
|
||||
|
||||
_, r4, _ := th.SystemAdminClient.GetScheme("12345")
|
||||
_, r4, _ := th.SystemAdminClient.GetScheme(context.Background(), "12345")
|
||||
CheckBadRequestStatus(t, r4)
|
||||
|
||||
th.SystemAdminClient.Logout()
|
||||
_, r5, _ := th.SystemAdminClient.GetScheme(s1.Id)
|
||||
th.SystemAdminClient.Logout(context.Background())
|
||||
_, r5, _ := th.SystemAdminClient.GetScheme(context.Background(), s1.Id)
|
||||
CheckUnauthorizedStatus(t, r5)
|
||||
|
||||
th.SystemAdminClient.Login(th.SystemAdminUser.Username, th.SystemAdminUser.Password)
|
||||
th.SystemAdminClient.Login(context.Background(), th.SystemAdminUser.Username, th.SystemAdminUser.Password)
|
||||
th.App.Srv().SetLicense(nil)
|
||||
_, _, err = th.SystemAdminClient.GetScheme(s1.Id)
|
||||
_, _, err = th.SystemAdminClient.GetScheme(context.Background(), s1.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, r7, err := th.Client.GetScheme(s1.Id)
|
||||
_, r7, err := th.Client.GetScheme(context.Background(), s1.Id)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, r7)
|
||||
|
||||
th.App.SetPhase2PermissionsMigrationStatus(false)
|
||||
|
||||
_, r8, _ := th.SystemAdminClient.GetScheme(s1.Id)
|
||||
_, r8, _ := th.SystemAdminClient.GetScheme(context.Background(), s1.Id)
|
||||
CheckNotImplementedStatus(t, r8)
|
||||
}
|
||||
|
||||
@@ -275,45 +275,45 @@ func TestGetSchemes(t *testing.T) {
|
||||
|
||||
th.App.SetPhase2PermissionsMigrationStatus(true)
|
||||
|
||||
_, _, err := th.SystemAdminClient.CreateScheme(scheme1)
|
||||
_, _, err := th.SystemAdminClient.CreateScheme(context.Background(), scheme1)
|
||||
require.NoError(t, err)
|
||||
_, _, err = th.SystemAdminClient.CreateScheme(scheme2)
|
||||
_, _, err = th.SystemAdminClient.CreateScheme(context.Background(), scheme2)
|
||||
require.NoError(t, err)
|
||||
|
||||
l3, _, err := th.SystemAdminClient.GetSchemes("", 0, 100)
|
||||
l3, _, err := th.SystemAdminClient.GetSchemes(context.Background(), "", 0, 100)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.NotZero(t, len(l3))
|
||||
|
||||
l4, _, err := th.SystemAdminClient.GetSchemes("team", 0, 100)
|
||||
l4, _, err := th.SystemAdminClient.GetSchemes(context.Background(), "team", 0, 100)
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, s := range l4 {
|
||||
assert.Equal(t, "team", s.Scope)
|
||||
}
|
||||
|
||||
l5, _, err := th.SystemAdminClient.GetSchemes("channel", 0, 100)
|
||||
l5, _, err := th.SystemAdminClient.GetSchemes(context.Background(), "channel", 0, 100)
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, s := range l5 {
|
||||
assert.Equal(t, "channel", s.Scope)
|
||||
}
|
||||
|
||||
_, r6, _ := th.SystemAdminClient.GetSchemes("asdf", 0, 100)
|
||||
_, r6, _ := th.SystemAdminClient.GetSchemes(context.Background(), "asdf", 0, 100)
|
||||
CheckBadRequestStatus(t, r6)
|
||||
|
||||
th.Client.Logout()
|
||||
_, r7, _ := th.Client.GetSchemes("", 0, 100)
|
||||
th.Client.Logout(context.Background())
|
||||
_, r7, _ := th.Client.GetSchemes(context.Background(), "", 0, 100)
|
||||
CheckUnauthorizedStatus(t, r7)
|
||||
|
||||
th.Client.Login(th.BasicUser.Username, th.BasicUser.Password)
|
||||
_, r8, err := th.Client.GetSchemes("", 0, 100)
|
||||
th.Client.Login(context.Background(), th.BasicUser.Username, th.BasicUser.Password)
|
||||
_, r8, err := th.Client.GetSchemes(context.Background(), "", 0, 100)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, r8)
|
||||
|
||||
th.App.SetPhase2PermissionsMigrationStatus(false)
|
||||
|
||||
_, r9, _ := th.SystemAdminClient.GetSchemes("", 0, 100)
|
||||
_, r9, _ := th.SystemAdminClient.GetSchemes(context.Background(), "", 0, 100)
|
||||
CheckNotImplementedStatus(t, r9)
|
||||
}
|
||||
|
||||
@@ -331,7 +331,7 @@ func TestGetTeamsForScheme(t *testing.T) {
|
||||
Description: model.NewId(),
|
||||
Scope: model.SchemeScopeTeam,
|
||||
}
|
||||
scheme1, _, err := th.SystemAdminClient.CreateScheme(scheme1)
|
||||
scheme1, _, err := th.SystemAdminClient.CreateScheme(context.Background(), scheme1)
|
||||
require.NoError(t, err)
|
||||
|
||||
team1 := &model.Team{
|
||||
@@ -343,7 +343,7 @@ func TestGetTeamsForScheme(t *testing.T) {
|
||||
team1, err = th.App.Srv().Store().Team().Save(team1)
|
||||
require.NoError(t, err)
|
||||
|
||||
l2, _, err := th.SystemAdminClient.GetTeamsForScheme(scheme1.Id, 0, 100)
|
||||
l2, _, err := th.SystemAdminClient.GetTeamsForScheme(context.Background(), scheme1.Id, 0, 100)
|
||||
require.NoError(t, err)
|
||||
assert.Zero(t, len(l2))
|
||||
|
||||
@@ -351,7 +351,7 @@ func TestGetTeamsForScheme(t *testing.T) {
|
||||
team1, err = th.App.Srv().Store().Team().Update(team1)
|
||||
assert.NoError(t, err)
|
||||
|
||||
l3, _, err := th.SystemAdminClient.GetTeamsForScheme(scheme1.Id, 0, 100)
|
||||
l3, _, err := th.SystemAdminClient.GetTeamsForScheme(context.Background(), scheme1.Id, 0, 100)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, l3, 1)
|
||||
assert.Equal(t, team1.Id, l3[0].Id)
|
||||
@@ -365,30 +365,30 @@ func TestGetTeamsForScheme(t *testing.T) {
|
||||
team2, err = th.App.Srv().Store().Team().Save(team2)
|
||||
require.NoError(t, err)
|
||||
|
||||
l4, _, err := th.SystemAdminClient.GetTeamsForScheme(scheme1.Id, 0, 100)
|
||||
l4, _, err := th.SystemAdminClient.GetTeamsForScheme(context.Background(), scheme1.Id, 0, 100)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, l4, 2)
|
||||
assert.Equal(t, team1.Id, l4[0].Id)
|
||||
assert.Equal(t, team2.Id, l4[1].Id)
|
||||
|
||||
l5, _, err := th.SystemAdminClient.GetTeamsForScheme(scheme1.Id, 1, 1)
|
||||
l5, _, err := th.SystemAdminClient.GetTeamsForScheme(context.Background(), scheme1.Id, 1, 1)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, l5, 1)
|
||||
assert.Equal(t, team2.Id, l5[0].Id)
|
||||
|
||||
// Check various error cases.
|
||||
_, ri1, _ := th.SystemAdminClient.GetTeamsForScheme(model.NewId(), 0, 100)
|
||||
_, ri1, _ := th.SystemAdminClient.GetTeamsForScheme(context.Background(), model.NewId(), 0, 100)
|
||||
CheckNotFoundStatus(t, ri1)
|
||||
|
||||
_, ri2, _ := th.SystemAdminClient.GetTeamsForScheme("", 0, 100)
|
||||
_, ri2, _ := th.SystemAdminClient.GetTeamsForScheme(context.Background(), "", 0, 100)
|
||||
CheckBadRequestStatus(t, ri2)
|
||||
|
||||
th.Client.Logout()
|
||||
_, ri3, _ := th.Client.GetTeamsForScheme(model.NewId(), 0, 100)
|
||||
th.Client.Logout(context.Background())
|
||||
_, ri3, _ := th.Client.GetTeamsForScheme(context.Background(), model.NewId(), 0, 100)
|
||||
CheckUnauthorizedStatus(t, ri3)
|
||||
|
||||
th.Client.Login(th.BasicUser.Username, th.BasicUser.Password)
|
||||
_, ri4, err := th.Client.GetTeamsForScheme(model.NewId(), 0, 100)
|
||||
th.Client.Login(context.Background(), th.BasicUser.Username, th.BasicUser.Password)
|
||||
_, ri4, err := th.Client.GetTeamsForScheme(context.Background(), model.NewId(), 0, 100)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, ri4)
|
||||
|
||||
@@ -398,15 +398,15 @@ func TestGetTeamsForScheme(t *testing.T) {
|
||||
Description: model.NewId(),
|
||||
Scope: model.SchemeScopeChannel,
|
||||
}
|
||||
scheme2, _, err = th.SystemAdminClient.CreateScheme(scheme2)
|
||||
scheme2, _, err = th.SystemAdminClient.CreateScheme(context.Background(), scheme2)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, ri5, _ := th.SystemAdminClient.GetTeamsForScheme(scheme2.Id, 0, 100)
|
||||
_, ri5, _ := th.SystemAdminClient.GetTeamsForScheme(context.Background(), scheme2.Id, 0, 100)
|
||||
CheckBadRequestStatus(t, ri5)
|
||||
|
||||
th.App.SetPhase2PermissionsMigrationStatus(false)
|
||||
|
||||
_, ri6, _ := th.SystemAdminClient.GetTeamsForScheme(scheme1.Id, 0, 100)
|
||||
_, ri6, _ := th.SystemAdminClient.GetTeamsForScheme(context.Background(), scheme1.Id, 0, 100)
|
||||
CheckNotImplementedStatus(t, ri6)
|
||||
}
|
||||
|
||||
@@ -424,7 +424,7 @@ func TestGetChannelsForScheme(t *testing.T) {
|
||||
Description: model.NewId(),
|
||||
Scope: model.SchemeScopeChannel,
|
||||
}
|
||||
scheme1, _, err := th.SystemAdminClient.CreateScheme(scheme1)
|
||||
scheme1, _, err := th.SystemAdminClient.CreateScheme(context.Background(), scheme1)
|
||||
require.NoError(t, err)
|
||||
|
||||
channel1 := &model.Channel{
|
||||
@@ -437,7 +437,7 @@ func TestGetChannelsForScheme(t *testing.T) {
|
||||
channel1, errCh := th.App.Srv().Store().Channel().Save(channel1, 1000000)
|
||||
assert.NoError(t, errCh)
|
||||
|
||||
l2, _, err := th.SystemAdminClient.GetChannelsForScheme(scheme1.Id, 0, 100)
|
||||
l2, _, err := th.SystemAdminClient.GetChannelsForScheme(context.Background(), scheme1.Id, 0, 100)
|
||||
require.NoError(t, err)
|
||||
assert.Zero(t, len(l2))
|
||||
|
||||
@@ -445,7 +445,7 @@ func TestGetChannelsForScheme(t *testing.T) {
|
||||
channel1, err = th.App.Srv().Store().Channel().Update(channel1)
|
||||
assert.NoError(t, err)
|
||||
|
||||
l3, _, err := th.SystemAdminClient.GetChannelsForScheme(scheme1.Id, 0, 100)
|
||||
l3, _, err := th.SystemAdminClient.GetChannelsForScheme(context.Background(), scheme1.Id, 0, 100)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, l3, 1)
|
||||
assert.Equal(t, channel1.Id, l3[0].Id)
|
||||
@@ -460,30 +460,30 @@ func TestGetChannelsForScheme(t *testing.T) {
|
||||
channel2, err = th.App.Srv().Store().Channel().Save(channel2, 1000000)
|
||||
assert.NoError(t, err)
|
||||
|
||||
l4, _, err := th.SystemAdminClient.GetChannelsForScheme(scheme1.Id, 0, 100)
|
||||
l4, _, err := th.SystemAdminClient.GetChannelsForScheme(context.Background(), scheme1.Id, 0, 100)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, l4, 2)
|
||||
assert.Equal(t, channel1.Id, l4[0].Id)
|
||||
assert.Equal(t, channel2.Id, l4[1].Id)
|
||||
|
||||
l5, _, err := th.SystemAdminClient.GetChannelsForScheme(scheme1.Id, 1, 1)
|
||||
l5, _, err := th.SystemAdminClient.GetChannelsForScheme(context.Background(), scheme1.Id, 1, 1)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, l5, 1)
|
||||
assert.Equal(t, channel2.Id, l5[0].Id)
|
||||
|
||||
// Check various error cases.
|
||||
_, ri1, _ := th.SystemAdminClient.GetChannelsForScheme(model.NewId(), 0, 100)
|
||||
_, ri1, _ := th.SystemAdminClient.GetChannelsForScheme(context.Background(), model.NewId(), 0, 100)
|
||||
CheckNotFoundStatus(t, ri1)
|
||||
|
||||
_, ri2, _ := th.SystemAdminClient.GetChannelsForScheme("", 0, 100)
|
||||
_, ri2, _ := th.SystemAdminClient.GetChannelsForScheme(context.Background(), "", 0, 100)
|
||||
CheckBadRequestStatus(t, ri2)
|
||||
|
||||
th.Client.Logout()
|
||||
_, ri3, _ := th.Client.GetChannelsForScheme(model.NewId(), 0, 100)
|
||||
th.Client.Logout(context.Background())
|
||||
_, ri3, _ := th.Client.GetChannelsForScheme(context.Background(), model.NewId(), 0, 100)
|
||||
CheckUnauthorizedStatus(t, ri3)
|
||||
|
||||
th.Client.Login(th.BasicUser.Username, th.BasicUser.Password)
|
||||
_, ri4, err := th.Client.GetChannelsForScheme(model.NewId(), 0, 100)
|
||||
th.Client.Login(context.Background(), th.BasicUser.Username, th.BasicUser.Password)
|
||||
_, ri4, err := th.Client.GetChannelsForScheme(context.Background(), model.NewId(), 0, 100)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, ri4)
|
||||
|
||||
@@ -493,15 +493,15 @@ func TestGetChannelsForScheme(t *testing.T) {
|
||||
Description: model.NewId(),
|
||||
Scope: model.SchemeScopeTeam,
|
||||
}
|
||||
scheme2, _, err = th.SystemAdminClient.CreateScheme(scheme2)
|
||||
scheme2, _, err = th.SystemAdminClient.CreateScheme(context.Background(), scheme2)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, ri5, _ := th.SystemAdminClient.GetChannelsForScheme(scheme2.Id, 0, 100)
|
||||
_, ri5, _ := th.SystemAdminClient.GetChannelsForScheme(context.Background(), scheme2.Id, 0, 100)
|
||||
CheckBadRequestStatus(t, ri5)
|
||||
|
||||
th.App.SetPhase2PermissionsMigrationStatus(false)
|
||||
|
||||
_, ri6, _ := th.SystemAdminClient.GetChannelsForScheme(scheme1.Id, 0, 100)
|
||||
_, ri6, _ := th.SystemAdminClient.GetChannelsForScheme(context.Background(), scheme1.Id, 0, 100)
|
||||
CheckNotImplementedStatus(t, ri6)
|
||||
}
|
||||
|
||||
@@ -521,7 +521,7 @@ func TestPatchScheme(t *testing.T) {
|
||||
Scope: model.SchemeScopeTeam,
|
||||
}
|
||||
|
||||
s1, _, err := th.SystemAdminClient.CreateScheme(scheme1)
|
||||
s1, _, err := th.SystemAdminClient.CreateScheme(context.Background(), scheme1)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, s1.DisplayName, scheme1.DisplayName)
|
||||
@@ -538,7 +538,7 @@ func TestPatchScheme(t *testing.T) {
|
||||
assert.NotZero(t, len(s1.DefaultChannelUserRole))
|
||||
assert.NotZero(t, len(s1.DefaultChannelGuestRole))
|
||||
|
||||
s2, _, err := th.SystemAdminClient.GetScheme(s1.Id)
|
||||
s2, _, err := th.SystemAdminClient.GetScheme(context.Background(), s1.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, s1, s2)
|
||||
@@ -553,14 +553,14 @@ func TestPatchScheme(t *testing.T) {
|
||||
*schemePatch.Name = model.NewId()
|
||||
*schemePatch.Description = model.NewId()
|
||||
|
||||
s3, _, err := th.SystemAdminClient.PatchScheme(s2.Id, schemePatch)
|
||||
s3, _, err := th.SystemAdminClient.PatchScheme(context.Background(), s2.Id, schemePatch)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, s3.Id, s2.Id)
|
||||
assert.Equal(t, s3.DisplayName, *schemePatch.DisplayName)
|
||||
assert.Equal(t, s3.Name, *schemePatch.Name)
|
||||
assert.Equal(t, s3.Description, *schemePatch.Description)
|
||||
|
||||
s4, _, err := th.SystemAdminClient.GetScheme(s3.Id)
|
||||
s4, _, err := th.SystemAdminClient.GetScheme(context.Background(), s3.Id)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, s3, s4)
|
||||
|
||||
@@ -569,39 +569,39 @@ func TestPatchScheme(t *testing.T) {
|
||||
*schemePatch.DisplayName = model.NewId()
|
||||
schemePatch.Description = nil
|
||||
|
||||
s5, _, err := th.SystemAdminClient.PatchScheme(s4.Id, schemePatch)
|
||||
s5, _, err := th.SystemAdminClient.PatchScheme(context.Background(), s4.Id, schemePatch)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, s5.Id, s4.Id)
|
||||
assert.Equal(t, s5.DisplayName, *schemePatch.DisplayName)
|
||||
assert.Equal(t, s5.Name, *schemePatch.Name)
|
||||
assert.Equal(t, s5.Description, s4.Description)
|
||||
|
||||
s6, _, err := th.SystemAdminClient.GetScheme(s5.Id)
|
||||
s6, _, err := th.SystemAdminClient.GetScheme(context.Background(), s5.Id)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, s5, s6)
|
||||
|
||||
// Test with invalid patch.
|
||||
*schemePatch.Name = strings.Repeat(model.NewId(), 20)
|
||||
_, r7, _ := th.SystemAdminClient.PatchScheme(s6.Id, schemePatch)
|
||||
_, r7, _ := th.SystemAdminClient.PatchScheme(context.Background(), s6.Id, schemePatch)
|
||||
CheckBadRequestStatus(t, r7)
|
||||
|
||||
// Test with unknown ID.
|
||||
*schemePatch.Name = model.NewId()
|
||||
_, r8, _ := th.SystemAdminClient.PatchScheme(model.NewId(), schemePatch)
|
||||
_, r8, _ := th.SystemAdminClient.PatchScheme(context.Background(), model.NewId(), schemePatch)
|
||||
CheckNotFoundStatus(t, r8)
|
||||
|
||||
// Test with invalid ID.
|
||||
_, r9, _ := th.SystemAdminClient.PatchScheme("12345", schemePatch)
|
||||
_, r9, _ := th.SystemAdminClient.PatchScheme(context.Background(), "12345", schemePatch)
|
||||
CheckBadRequestStatus(t, r9)
|
||||
|
||||
// Test without required permissions.
|
||||
_, r10, err := th.Client.PatchScheme(s6.Id, schemePatch)
|
||||
_, r10, err := th.Client.PatchScheme(context.Background(), s6.Id, schemePatch)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, r10)
|
||||
|
||||
// Test without license.
|
||||
th.App.Srv().SetLicense(nil)
|
||||
_, r11, _ := th.SystemAdminClient.PatchScheme(s6.Id, schemePatch)
|
||||
_, r11, _ := th.SystemAdminClient.PatchScheme(context.Background(), s6.Id, schemePatch)
|
||||
CheckNotImplementedStatus(t, r11)
|
||||
|
||||
// Patch scheme with a Professional SKU license but no explicit 'custom_permissions_schemes' license feature.
|
||||
@@ -619,7 +619,7 @@ func TestPatchScheme(t *testing.T) {
|
||||
ExpiresAt: model.GetMillis() + 100000,
|
||||
}
|
||||
th.App.Srv().SetLicense(lic)
|
||||
_, _, err = th.SystemAdminClient.PatchScheme(s6.Id, schemePatch)
|
||||
_, _, err = th.SystemAdminClient.PatchScheme(context.Background(), s6.Id, schemePatch)
|
||||
require.NoError(t, err)
|
||||
|
||||
th.App.SetPhase2PermissionsMigrationStatus(false)
|
||||
@@ -627,7 +627,7 @@ func TestPatchScheme(t *testing.T) {
|
||||
th.LoginSystemAdmin()
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("custom_permissions_schemes"))
|
||||
|
||||
_, r12, _ := th.SystemAdminClient.PatchScheme(s6.Id, schemePatch)
|
||||
_, r12, _ := th.SystemAdminClient.PatchScheme(context.Background(), s6.Id, schemePatch)
|
||||
CheckNotImplementedStatus(t, r12)
|
||||
}
|
||||
|
||||
@@ -648,21 +648,21 @@ func TestDeleteScheme(t *testing.T) {
|
||||
Scope: model.SchemeScopeTeam,
|
||||
}
|
||||
|
||||
s1, _, err := th.SystemAdminClient.CreateScheme(scheme1)
|
||||
s1, _, err := th.SystemAdminClient.CreateScheme(context.Background(), scheme1)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Retrieve the roles and check they are not deleted.
|
||||
role1, _, err := th.SystemAdminClient.GetRoleByName(s1.DefaultTeamAdminRole)
|
||||
role1, _, err := th.SystemAdminClient.GetRoleByName(context.Background(), s1.DefaultTeamAdminRole)
|
||||
require.NoError(t, err)
|
||||
role2, _, err := th.SystemAdminClient.GetRoleByName(s1.DefaultTeamUserRole)
|
||||
role2, _, err := th.SystemAdminClient.GetRoleByName(context.Background(), s1.DefaultTeamUserRole)
|
||||
require.NoError(t, err)
|
||||
role3, _, err := th.SystemAdminClient.GetRoleByName(s1.DefaultChannelAdminRole)
|
||||
role3, _, err := th.SystemAdminClient.GetRoleByName(context.Background(), s1.DefaultChannelAdminRole)
|
||||
require.NoError(t, err)
|
||||
role4, _, err := th.SystemAdminClient.GetRoleByName(s1.DefaultChannelUserRole)
|
||||
role4, _, err := th.SystemAdminClient.GetRoleByName(context.Background(), s1.DefaultChannelUserRole)
|
||||
require.NoError(t, err)
|
||||
role5, _, err := th.SystemAdminClient.GetRoleByName(s1.DefaultTeamGuestRole)
|
||||
role5, _, err := th.SystemAdminClient.GetRoleByName(context.Background(), s1.DefaultTeamGuestRole)
|
||||
require.NoError(t, err)
|
||||
role6, _, err := th.SystemAdminClient.GetRoleByName(s1.DefaultChannelGuestRole)
|
||||
role6, _, err := th.SystemAdminClient.GetRoleByName(context.Background(), s1.DefaultChannelGuestRole)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Zero(t, role1.DeleteAt)
|
||||
@@ -683,21 +683,21 @@ func TestDeleteScheme(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Delete the Scheme.
|
||||
_, err = th.SystemAdminClient.DeleteScheme(s1.Id)
|
||||
_, err = th.SystemAdminClient.DeleteScheme(context.Background(), s1.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Check the roles were deleted.
|
||||
role1, _, err = th.SystemAdminClient.GetRoleByName(s1.DefaultTeamAdminRole)
|
||||
role1, _, err = th.SystemAdminClient.GetRoleByName(context.Background(), s1.DefaultTeamAdminRole)
|
||||
require.NoError(t, err)
|
||||
role2, _, err = th.SystemAdminClient.GetRoleByName(s1.DefaultTeamUserRole)
|
||||
role2, _, err = th.SystemAdminClient.GetRoleByName(context.Background(), s1.DefaultTeamUserRole)
|
||||
require.NoError(t, err)
|
||||
role3, _, err = th.SystemAdminClient.GetRoleByName(s1.DefaultChannelAdminRole)
|
||||
role3, _, err = th.SystemAdminClient.GetRoleByName(context.Background(), s1.DefaultChannelAdminRole)
|
||||
require.NoError(t, err)
|
||||
role4, _, err = th.SystemAdminClient.GetRoleByName(s1.DefaultChannelUserRole)
|
||||
role4, _, err = th.SystemAdminClient.GetRoleByName(context.Background(), s1.DefaultChannelUserRole)
|
||||
require.NoError(t, err)
|
||||
role5, _, err = th.SystemAdminClient.GetRoleByName(s1.DefaultTeamGuestRole)
|
||||
role5, _, err = th.SystemAdminClient.GetRoleByName(context.Background(), s1.DefaultTeamGuestRole)
|
||||
require.NoError(t, err)
|
||||
role6, _, err = th.SystemAdminClient.GetRoleByName(s1.DefaultChannelGuestRole)
|
||||
role6, _, err = th.SystemAdminClient.GetRoleByName(context.Background(), s1.DefaultChannelGuestRole)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.NotZero(t, role1.DeleteAt)
|
||||
@@ -708,7 +708,7 @@ func TestDeleteScheme(t *testing.T) {
|
||||
assert.NotZero(t, role6.DeleteAt)
|
||||
|
||||
// Check the team now uses the default scheme
|
||||
c2, _, err := th.SystemAdminClient.GetTeam(team.Id, "")
|
||||
c2, _, err := th.SystemAdminClient.GetTeam(context.Background(), team.Id, "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "", *c2.SchemeId)
|
||||
})
|
||||
@@ -726,15 +726,15 @@ func TestDeleteScheme(t *testing.T) {
|
||||
Scope: model.SchemeScopeChannel,
|
||||
}
|
||||
|
||||
s1, _, err := th.SystemAdminClient.CreateScheme(scheme1)
|
||||
s1, _, err := th.SystemAdminClient.CreateScheme(context.Background(), scheme1)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Retrieve the roles and check they are not deleted.
|
||||
role3, _, err := th.SystemAdminClient.GetRoleByName(s1.DefaultChannelAdminRole)
|
||||
role3, _, err := th.SystemAdminClient.GetRoleByName(context.Background(), s1.DefaultChannelAdminRole)
|
||||
require.NoError(t, err)
|
||||
role4, _, err := th.SystemAdminClient.GetRoleByName(s1.DefaultChannelUserRole)
|
||||
role4, _, err := th.SystemAdminClient.GetRoleByName(context.Background(), s1.DefaultChannelUserRole)
|
||||
require.NoError(t, err)
|
||||
role6, _, err := th.SystemAdminClient.GetRoleByName(s1.DefaultChannelGuestRole)
|
||||
role6, _, err := th.SystemAdminClient.GetRoleByName(context.Background(), s1.DefaultChannelGuestRole)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Zero(t, role3.DeleteAt)
|
||||
@@ -752,15 +752,15 @@ func TestDeleteScheme(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
|
||||
// Delete the Scheme.
|
||||
_, err = th.SystemAdminClient.DeleteScheme(s1.Id)
|
||||
_, err = th.SystemAdminClient.DeleteScheme(context.Background(), s1.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Check the roles were deleted.
|
||||
role3, _, err = th.SystemAdminClient.GetRoleByName(s1.DefaultChannelAdminRole)
|
||||
role3, _, err = th.SystemAdminClient.GetRoleByName(context.Background(), s1.DefaultChannelAdminRole)
|
||||
require.NoError(t, err)
|
||||
role4, _, err = th.SystemAdminClient.GetRoleByName(s1.DefaultChannelUserRole)
|
||||
role4, _, err = th.SystemAdminClient.GetRoleByName(context.Background(), s1.DefaultChannelUserRole)
|
||||
require.NoError(t, err)
|
||||
role6, _, err = th.SystemAdminClient.GetRoleByName(s1.DefaultChannelGuestRole)
|
||||
role6, _, err = th.SystemAdminClient.GetRoleByName(context.Background(), s1.DefaultChannelGuestRole)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.NotZero(t, role3.DeleteAt)
|
||||
@@ -768,7 +768,7 @@ func TestDeleteScheme(t *testing.T) {
|
||||
assert.NotZero(t, role6.DeleteAt)
|
||||
|
||||
// Check the channel now uses the default scheme
|
||||
c2, _, err := th.SystemAdminClient.GetChannelByName(channel.Name, channel.TeamId, "")
|
||||
c2, _, err := th.SystemAdminClient.GetChannelByName(context.Background(), channel.Name, channel.TeamId, "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "", *c2.SchemeId)
|
||||
})
|
||||
@@ -785,7 +785,7 @@ func TestDeleteScheme(t *testing.T) {
|
||||
Scope: model.SchemeScopeChannel,
|
||||
}
|
||||
|
||||
s1, _, err := th.SystemAdminClient.CreateScheme(scheme1)
|
||||
s1, _, err := th.SystemAdminClient.CreateScheme(context.Background(), scheme1)
|
||||
require.NoError(t, err)
|
||||
|
||||
scheme2 := &model.Scheme{
|
||||
@@ -794,27 +794,27 @@ func TestDeleteScheme(t *testing.T) {
|
||||
Description: model.NewId(),
|
||||
Scope: model.SchemeScopeChannel,
|
||||
}
|
||||
s2, _, err := th.SystemAdminClient.CreateScheme(scheme2)
|
||||
s2, _, err := th.SystemAdminClient.CreateScheme(context.Background(), scheme2)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Test with unknown ID.
|
||||
r2, err := th.SystemAdminClient.DeleteScheme(model.NewId())
|
||||
r2, err := th.SystemAdminClient.DeleteScheme(context.Background(), model.NewId())
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, r2)
|
||||
|
||||
// Test with invalid ID.
|
||||
r3, err := th.SystemAdminClient.DeleteScheme("12345")
|
||||
r3, err := th.SystemAdminClient.DeleteScheme(context.Background(), "12345")
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, r3)
|
||||
|
||||
// Test without required permissions.
|
||||
r4, err := th.Client.DeleteScheme(s1.Id)
|
||||
r4, err := th.Client.DeleteScheme(context.Background(), s1.Id)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, r4)
|
||||
|
||||
// Test without license.
|
||||
th.App.Srv().SetLicense(nil)
|
||||
r5, err := th.SystemAdminClient.DeleteScheme(s1.Id)
|
||||
r5, err := th.SystemAdminClient.DeleteScheme(context.Background(), s1.Id)
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, r5)
|
||||
|
||||
@@ -833,14 +833,14 @@ func TestDeleteScheme(t *testing.T) {
|
||||
ExpiresAt: model.GetMillis() + 100000,
|
||||
}
|
||||
th.App.Srv().SetLicense(lic)
|
||||
_, err = th.SystemAdminClient.DeleteScheme(s2.Id)
|
||||
_, err = th.SystemAdminClient.DeleteScheme(context.Background(), s2.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
th.App.SetPhase2PermissionsMigrationStatus(false)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("custom_permissions_schemes"))
|
||||
|
||||
r6, err := th.SystemAdminClient.DeleteScheme(s1.Id)
|
||||
r6, err := th.SystemAdminClient.DeleteScheme(context.Background(), s1.Id)
|
||||
require.Error(t, err)
|
||||
CheckNotImplementedStatus(t, r6)
|
||||
})
|
||||
@@ -867,14 +867,14 @@ func TestUpdateTeamSchemeWithTeamMembers(t *testing.T) {
|
||||
|
||||
th.LoginBasic()
|
||||
|
||||
_, _, err := th.Client.CreateChannel(&model.Channel{DisplayName: "Test API Name", Name: GenerateTestChannelName(), Type: model.ChannelTypeOpen, TeamId: team.Id})
|
||||
_, _, err := th.Client.CreateChannel(context.Background(), &model.Channel{DisplayName: "Test API Name", Name: GenerateTestChannelName(), Type: model.ChannelTypeOpen, TeamId: team.Id})
|
||||
require.NoError(t, err)
|
||||
|
||||
team.SchemeId = &teamScheme.Id
|
||||
team, appErr = th.App.UpdateTeamScheme(team)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
_, _, err = th.Client.CreateChannel(&model.Channel{DisplayName: "Test API Name", Name: GenerateTestChannelName(), Type: model.ChannelTypeOpen, TeamId: team.Id})
|
||||
_, _, err = th.Client.CreateChannel(context.Background(), &model.Channel{DisplayName: "Test API Name", Name: GenerateTestChannelName(), Type: model.ChannelTypeOpen, TeamId: team.Id})
|
||||
require.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"sort"
|
||||
@@ -53,7 +54,7 @@ func TestGetAllSharedChannels(t *testing.T) {
|
||||
t.Run("get shared channels paginated", func(t *testing.T) {
|
||||
channelIds := make([]string, 0, 21)
|
||||
for i := 0; i < pages; i++ {
|
||||
channels, _, err := th.Client.GetAllSharedChannels(th.BasicTeam.Id, i, pageSize)
|
||||
channels, _, err := th.Client.GetAllSharedChannels(context.Background(), th.BasicTeam.Id, i, pageSize)
|
||||
require.NoError(t, err)
|
||||
channelIds = append(channelIds, getIds(channels)...)
|
||||
}
|
||||
@@ -64,7 +65,7 @@ func TestGetAllSharedChannels(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("get shared channels for invalid team", func(t *testing.T) {
|
||||
_, _, err := th.Client.GetAllSharedChannels(model.NewId(), 0, 100)
|
||||
_, _, err := th.Client.GetAllSharedChannels(context.Background(), model.NewId(), 0, 100)
|
||||
require.Error(t, err)
|
||||
})
|
||||
|
||||
@@ -74,10 +75,10 @@ func TestGetAllSharedChannels(t *testing.T) {
|
||||
Name: GenerateTestTeamName(),
|
||||
Type: model.TeamOpen,
|
||||
}
|
||||
team, _, err := th.SystemAdminClient.CreateTeam(team)
|
||||
team, _, err := th.SystemAdminClient.CreateTeam(context.Background(), team)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, err = th.Client.GetAllSharedChannels(team.Id, 0, 100)
|
||||
_, _, err = th.Client.GetAllSharedChannels(context.Background(), team.Id, 0, 100)
|
||||
require.Error(t, err)
|
||||
})
|
||||
}
|
||||
@@ -140,13 +141,13 @@ func TestGetRemoteClusterById(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Run("valid remote, user is member", func(t *testing.T) {
|
||||
rcInfo, _, err := th.Client.GetRemoteClusterInfo(rc.RemoteId)
|
||||
rcInfo, _, err := th.Client.GetRemoteClusterInfo(context.Background(), rc.RemoteId)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, rc.Name, rcInfo.Name)
|
||||
})
|
||||
|
||||
t.Run("invalid remote", func(t *testing.T) {
|
||||
_, resp, err := th.Client.GetRemoteClusterInfo(model.NewId())
|
||||
_, resp, err := th.Client.GetRemoteClusterInfo(context.Background(), model.NewId())
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
})
|
||||
@@ -158,7 +159,7 @@ func TestCreateDirectChannelWithRemoteUser(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
client := th.Client
|
||||
defer client.Logout()
|
||||
defer client.Logout(context.Background())
|
||||
|
||||
localUser := th.BasicUser
|
||||
remoteUser := th.CreateUser()
|
||||
@@ -166,7 +167,7 @@ func TestCreateDirectChannelWithRemoteUser(t *testing.T) {
|
||||
remoteUser, appErr := th.App.UpdateUser(th.Context, remoteUser, false)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
dm, _, err := client.CreateDirectChannel(localUser.Id, remoteUser.Id)
|
||||
dm, _, err := client.CreateDirectChannel(context.Background(), localUser.Id, remoteUser.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
channelName := model.GetDMNameFromIds(localUser.Id, remoteUser.Id)
|
||||
@@ -178,7 +179,7 @@ func TestCreateDirectChannelWithRemoteUser(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
client := th.Client
|
||||
defer client.Logout()
|
||||
defer client.Logout(context.Background())
|
||||
|
||||
mockService := app.NewMockSharedChannelService(nil, app.MockOptionSharedChannelServiceWithActive(true))
|
||||
th.App.Srv().SetSharedChannelSyncService(mockService)
|
||||
@@ -197,7 +198,7 @@ func TestCreateDirectChannelWithRemoteUser(t *testing.T) {
|
||||
remoteUser, appErr = th.App.UpdateUser(th.Context, remoteUser, false)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
dm, _, err := client.CreateDirectChannel(localUser.Id, remoteUser.Id)
|
||||
dm, _, err := client.CreateDirectChannel(context.Background(), localUser.Id, remoteUser.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
channelName := model.GetDMNameFromIds(localUser.Id, remoteUser.Id)
|
||||
@@ -211,7 +212,7 @@ func TestCreateDirectChannelWithRemoteUser(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
client := th.Client
|
||||
defer client.Logout()
|
||||
defer client.Logout(context.Background())
|
||||
|
||||
mockService := app.NewMockSharedChannelService(nil, app.MockOptionSharedChannelServiceWithActive(true))
|
||||
th.App.Srv().SetSharedChannelSyncService(mockService)
|
||||
@@ -230,7 +231,7 @@ func TestCreateDirectChannelWithRemoteUser(t *testing.T) {
|
||||
remoteUser, appErr = th.App.UpdateUser(th.Context, remoteUser, false)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
dm, _, err := client.CreateDirectChannel(remoteUser.Id, localUser.Id)
|
||||
dm, _, err := client.CreateDirectChannel(context.Background(), remoteUser.Id, localUser.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
channelName := model.GetDMNameFromIds(localUser.Id, remoteUser.Id)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -19,35 +20,35 @@ func TestGetUserStatus(t *testing.T) {
|
||||
client := th.Client
|
||||
|
||||
t.Run("offline status", func(t *testing.T) {
|
||||
userStatus, _, err := client.GetUserStatus(th.BasicUser.Id, "")
|
||||
userStatus, _, err := client.GetUserStatus(context.Background(), th.BasicUser.Id, "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "offline", userStatus.Status)
|
||||
})
|
||||
|
||||
t.Run("online status", func(t *testing.T) {
|
||||
th.App.SetStatusOnline(th.BasicUser.Id, true)
|
||||
userStatus, _, err := client.GetUserStatus(th.BasicUser.Id, "")
|
||||
userStatus, _, err := client.GetUserStatus(context.Background(), th.BasicUser.Id, "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "online", userStatus.Status)
|
||||
})
|
||||
|
||||
t.Run("away status", func(t *testing.T) {
|
||||
th.App.SetStatusAwayIfNeeded(th.BasicUser.Id, true)
|
||||
userStatus, _, err := client.GetUserStatus(th.BasicUser.Id, "")
|
||||
userStatus, _, err := client.GetUserStatus(context.Background(), th.BasicUser.Id, "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "away", userStatus.Status)
|
||||
})
|
||||
|
||||
t.Run("dnd status", func(t *testing.T) {
|
||||
th.App.SetStatusDoNotDisturb(th.BasicUser.Id)
|
||||
userStatus, _, err := client.GetUserStatus(th.BasicUser.Id, "")
|
||||
userStatus, _, err := client.GetUserStatus(context.Background(), th.BasicUser.Id, "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "dnd", userStatus.Status)
|
||||
})
|
||||
|
||||
t.Run("dnd status timed", func(t *testing.T) {
|
||||
th.App.SetStatusDoNotDisturbTimed(th.BasicUser.Id, time.Now().Add(10*time.Minute).Unix())
|
||||
userStatus, _, err := client.GetUserStatus(th.BasicUser.Id, "")
|
||||
userStatus, _, err := client.GetUserStatus(context.Background(), th.BasicUser.Id, "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "dnd", userStatus.Status)
|
||||
})
|
||||
@@ -56,43 +57,43 @@ func TestGetUserStatus(t *testing.T) {
|
||||
task := model.CreateRecurringTaskFromNextIntervalTime("Unset DND Statuses From Test", th.App.UpdateDNDStatusOfUsers, 1*time.Second)
|
||||
defer task.Cancel()
|
||||
th.App.SetStatusOnline(th.BasicUser.Id, true)
|
||||
userStatus, _, err := client.GetUserStatus(th.BasicUser.Id, "")
|
||||
userStatus, _, err := client.GetUserStatus(context.Background(), th.BasicUser.Id, "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "online", userStatus.Status)
|
||||
th.App.SetStatusDoNotDisturbTimed(th.BasicUser.Id, time.Now().Add(2*time.Second).Unix())
|
||||
userStatus, _, err = client.GetUserStatus(th.BasicUser.Id, "")
|
||||
userStatus, _, err = client.GetUserStatus(context.Background(), th.BasicUser.Id, "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "dnd", userStatus.Status)
|
||||
time.Sleep(3 * time.Second)
|
||||
userStatus, _, err = client.GetUserStatus(th.BasicUser.Id, "")
|
||||
userStatus, _, err = client.GetUserStatus(context.Background(), th.BasicUser.Id, "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "online", userStatus.Status)
|
||||
})
|
||||
|
||||
t.Run("back to offline status", func(t *testing.T) {
|
||||
th.App.SetStatusOffline(th.BasicUser.Id, true)
|
||||
userStatus, _, err := client.GetUserStatus(th.BasicUser.Id, "")
|
||||
userStatus, _, err := client.GetUserStatus(context.Background(), th.BasicUser.Id, "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "offline", userStatus.Status)
|
||||
})
|
||||
|
||||
t.Run("get other user status", func(t *testing.T) {
|
||||
//Get user2 status logged as user1
|
||||
userStatus, _, err := client.GetUserStatus(th.BasicUser2.Id, "")
|
||||
userStatus, _, err := client.GetUserStatus(context.Background(), th.BasicUser2.Id, "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "offline", userStatus.Status)
|
||||
})
|
||||
|
||||
t.Run("get status from logged out user", func(t *testing.T) {
|
||||
client.Logout()
|
||||
_, resp, err := client.GetUserStatus(th.BasicUser2.Id, "")
|
||||
client.Logout(context.Background())
|
||||
_, resp, err := client.GetUserStatus(context.Background(), th.BasicUser2.Id, "")
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("get status from other user", func(t *testing.T) {
|
||||
th.LoginBasic2()
|
||||
userStatus, _, err := client.GetUserStatus(th.BasicUser2.Id, "")
|
||||
userStatus, _, err := client.GetUserStatus(context.Background(), th.BasicUser2.Id, "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "offline", userStatus.Status)
|
||||
})
|
||||
@@ -106,25 +107,25 @@ func TestGetUsersStatusesByIds(t *testing.T) {
|
||||
usersIds := []string{th.BasicUser.Id, th.BasicUser2.Id}
|
||||
|
||||
t.Run("empty userIds list", func(t *testing.T) {
|
||||
_, resp, err := client.GetUsersStatusesByIds([]string{})
|
||||
_, resp, err := client.GetUsersStatusesByIds(context.Background(), []string{})
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("completely invalid userIds list", func(t *testing.T) {
|
||||
_, resp, err := client.GetUsersStatusesByIds([]string{"invalid_user_id", "invalid_user_id"})
|
||||
_, resp, err := client.GetUsersStatusesByIds(context.Background(), []string{"invalid_user_id", "invalid_user_id"})
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("partly invalid userIds list", func(t *testing.T) {
|
||||
_, resp, err := client.GetUsersStatusesByIds([]string{th.BasicUser.Id, "invalid_user_id"})
|
||||
_, resp, err := client.GetUsersStatusesByIds(context.Background(), []string{th.BasicUser.Id, "invalid_user_id"})
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("offline status", func(t *testing.T) {
|
||||
usersStatuses, _, err := client.GetUsersStatusesByIds(usersIds)
|
||||
usersStatuses, _, err := client.GetUsersStatusesByIds(context.Background(), usersIds)
|
||||
require.NoError(t, err)
|
||||
for _, userStatus := range usersStatuses {
|
||||
assert.Equal(t, "offline", userStatus.Status)
|
||||
@@ -134,7 +135,7 @@ func TestGetUsersStatusesByIds(t *testing.T) {
|
||||
t.Run("online status", func(t *testing.T) {
|
||||
th.App.SetStatusOnline(th.BasicUser.Id, true)
|
||||
th.App.SetStatusOnline(th.BasicUser2.Id, true)
|
||||
usersStatuses, _, err := client.GetUsersStatusesByIds(usersIds)
|
||||
usersStatuses, _, err := client.GetUsersStatusesByIds(context.Background(), usersIds)
|
||||
require.NoError(t, err)
|
||||
for _, userStatus := range usersStatuses {
|
||||
assert.Equal(t, "online", userStatus.Status)
|
||||
@@ -144,7 +145,7 @@ func TestGetUsersStatusesByIds(t *testing.T) {
|
||||
t.Run("away status", func(t *testing.T) {
|
||||
th.App.SetStatusAwayIfNeeded(th.BasicUser.Id, true)
|
||||
th.App.SetStatusAwayIfNeeded(th.BasicUser2.Id, true)
|
||||
usersStatuses, _, err := client.GetUsersStatusesByIds(usersIds)
|
||||
usersStatuses, _, err := client.GetUsersStatusesByIds(context.Background(), usersIds)
|
||||
require.NoError(t, err)
|
||||
for _, userStatus := range usersStatuses {
|
||||
assert.Equal(t, "away", userStatus.Status)
|
||||
@@ -154,7 +155,7 @@ func TestGetUsersStatusesByIds(t *testing.T) {
|
||||
t.Run("dnd status", func(t *testing.T) {
|
||||
th.App.SetStatusDoNotDisturb(th.BasicUser.Id)
|
||||
th.App.SetStatusDoNotDisturb(th.BasicUser2.Id)
|
||||
usersStatuses, _, err := client.GetUsersStatusesByIds(usersIds)
|
||||
usersStatuses, _, err := client.GetUsersStatusesByIds(context.Background(), usersIds)
|
||||
require.NoError(t, err)
|
||||
for _, userStatus := range usersStatuses {
|
||||
assert.Equal(t, "dnd", userStatus.Status)
|
||||
@@ -164,7 +165,7 @@ func TestGetUsersStatusesByIds(t *testing.T) {
|
||||
t.Run("dnd status", func(t *testing.T) {
|
||||
th.App.SetStatusDoNotDisturbTimed(th.BasicUser.Id, time.Now().Add(10*time.Minute).Unix())
|
||||
th.App.SetStatusDoNotDisturbTimed(th.BasicUser2.Id, time.Now().Add(15*time.Minute).Unix())
|
||||
usersStatuses, _, err := client.GetUsersStatusesByIds(usersIds)
|
||||
usersStatuses, _, err := client.GetUsersStatusesByIds(context.Background(), usersIds)
|
||||
require.NoError(t, err)
|
||||
for _, userStatus := range usersStatuses {
|
||||
assert.Equal(t, "dnd", userStatus.Status)
|
||||
@@ -172,9 +173,9 @@ func TestGetUsersStatusesByIds(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("get statuses from logged out user", func(t *testing.T) {
|
||||
client.Logout()
|
||||
client.Logout(context.Background())
|
||||
|
||||
_, resp, err := client.GetUsersStatusesByIds(usersIds)
|
||||
_, resp, err := client.GetUsersStatusesByIds(context.Background(), usersIds)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
})
|
||||
@@ -187,57 +188,57 @@ func TestUpdateUserStatus(t *testing.T) {
|
||||
|
||||
t.Run("set online status", func(t *testing.T) {
|
||||
toUpdateUserStatus := &model.Status{Status: "online", UserId: th.BasicUser.Id}
|
||||
updateUserStatus, _, err := client.UpdateUserStatus(th.BasicUser.Id, toUpdateUserStatus)
|
||||
updateUserStatus, _, err := client.UpdateUserStatus(context.Background(), th.BasicUser.Id, toUpdateUserStatus)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "online", updateUserStatus.Status)
|
||||
})
|
||||
|
||||
t.Run("set away status", func(t *testing.T) {
|
||||
toUpdateUserStatus := &model.Status{Status: "away", UserId: th.BasicUser.Id}
|
||||
updateUserStatus, _, err := client.UpdateUserStatus(th.BasicUser.Id, toUpdateUserStatus)
|
||||
updateUserStatus, _, err := client.UpdateUserStatus(context.Background(), th.BasicUser.Id, toUpdateUserStatus)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "away", updateUserStatus.Status)
|
||||
})
|
||||
|
||||
t.Run("set dnd status timed", func(t *testing.T) {
|
||||
toUpdateUserStatus := &model.Status{Status: "dnd", UserId: th.BasicUser.Id, DNDEndTime: time.Now().Add(10 * time.Minute).Unix()}
|
||||
updateUserStatus, _, err := client.UpdateUserStatus(th.BasicUser.Id, toUpdateUserStatus)
|
||||
updateUserStatus, _, err := client.UpdateUserStatus(context.Background(), th.BasicUser.Id, toUpdateUserStatus)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "dnd", updateUserStatus.Status)
|
||||
})
|
||||
|
||||
t.Run("set offline status", func(t *testing.T) {
|
||||
toUpdateUserStatus := &model.Status{Status: "offline", UserId: th.BasicUser.Id}
|
||||
updateUserStatus, _, err := client.UpdateUserStatus(th.BasicUser.Id, toUpdateUserStatus)
|
||||
updateUserStatus, _, err := client.UpdateUserStatus(context.Background(), th.BasicUser.Id, toUpdateUserStatus)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "offline", updateUserStatus.Status)
|
||||
})
|
||||
|
||||
t.Run("set status for other user as regular user", func(t *testing.T) {
|
||||
toUpdateUserStatus := &model.Status{Status: "online", UserId: th.BasicUser2.Id}
|
||||
_, resp, err := client.UpdateUserStatus(th.BasicUser2.Id, toUpdateUserStatus)
|
||||
_, resp, err := client.UpdateUserStatus(context.Background(), th.BasicUser2.Id, toUpdateUserStatus)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("set status for other user as admin user", func(t *testing.T) {
|
||||
toUpdateUserStatus := &model.Status{Status: "online", UserId: th.BasicUser2.Id}
|
||||
updateUserStatus, _, _ := th.SystemAdminClient.UpdateUserStatus(th.BasicUser2.Id, toUpdateUserStatus)
|
||||
updateUserStatus, _, _ := th.SystemAdminClient.UpdateUserStatus(context.Background(), th.BasicUser2.Id, toUpdateUserStatus)
|
||||
assert.Equal(t, "online", updateUserStatus.Status)
|
||||
})
|
||||
|
||||
t.Run("not matching status user id and the user id passed in the function", func(t *testing.T) {
|
||||
toUpdateUserStatus := &model.Status{Status: "online", UserId: th.BasicUser2.Id}
|
||||
_, resp, err := client.UpdateUserStatus(th.BasicUser.Id, toUpdateUserStatus)
|
||||
_, resp, err := client.UpdateUserStatus(context.Background(), th.BasicUser.Id, toUpdateUserStatus)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("get statuses from logged out user", func(t *testing.T) {
|
||||
toUpdateUserStatus := &model.Status{Status: "online", UserId: th.BasicUser2.Id}
|
||||
client.Logout()
|
||||
client.Logout(context.Background())
|
||||
|
||||
_, resp, err := client.UpdateUserStatus(th.BasicUser2.Id, toUpdateUserStatus)
|
||||
_, resp, err := client.UpdateUserStatus(context.Background(), th.BasicUser2.Id, toUpdateUserStatus)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
})
|
||||
|
||||
@@ -5,6 +5,7 @@ package api4
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@@ -32,7 +33,7 @@ func TestGetPing(t *testing.T) {
|
||||
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
t.Run("healthy", func(t *testing.T) {
|
||||
status, _, err := client.GetPing()
|
||||
status, _, err := client.GetPing(context.Background())
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, model.StatusOk, status)
|
||||
})
|
||||
@@ -44,7 +45,7 @@ func TestGetPing(t *testing.T) {
|
||||
}()
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.GoroutineHealthThreshold = 10 })
|
||||
status, resp, err := client.GetPing()
|
||||
status, resp, err := client.GetPing(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckInternalErrorStatus(t, resp)
|
||||
assert.Equal(t, model.StatusUnhealthy, status)
|
||||
@@ -53,7 +54,7 @@ func TestGetPing(t *testing.T) {
|
||||
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
t.Run("healthy", func(t *testing.T) {
|
||||
status, _, err := client.GetPingWithServerStatus()
|
||||
status, _, err := client.GetPingWithServerStatus(context.Background())
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, model.StatusOk, status)
|
||||
})
|
||||
@@ -61,7 +62,7 @@ func TestGetPing(t *testing.T) {
|
||||
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
th.App.ReloadConfig()
|
||||
resp, err := client.DoAPIGet("/system/ping", "")
|
||||
resp, err := client.DoAPIGet(context.Background(), "/system/ping", "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
respBytes, err := io.ReadAll(resp.Body)
|
||||
@@ -74,7 +75,7 @@ func TestGetPing(t *testing.T) {
|
||||
defer os.Unsetenv("MM_FEATUREFLAGS_TESTFEATURE")
|
||||
th.App.ReloadConfig()
|
||||
|
||||
resp, err = client.DoAPIGet("/system/ping", "")
|
||||
resp, err = client.DoAPIGet(context.Background(), "/system/ping", "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
respBytes, err = io.ReadAll(resp.Body)
|
||||
@@ -85,7 +86,7 @@ func TestGetPing(t *testing.T) {
|
||||
|
||||
th.TestForAllClients(t, func(t *testing.T, client *model.Client4) {
|
||||
th.App.ReloadConfig()
|
||||
resp, err := client.DoAPIGet("/system/ping?device_id=platform:id", "")
|
||||
resp, err := client.DoAPIGet(context.Background(), "/system/ping?device_id=platform:id", "")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
var respMap map[string]string
|
||||
@@ -100,27 +101,27 @@ func TestGetAudits(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
client := th.Client
|
||||
|
||||
audits, _, err := th.SystemAdminClient.GetAudits(0, 100, "")
|
||||
audits, _, err := th.SystemAdminClient.GetAudits(context.Background(), 0, 100, "")
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, audits, "should not be empty")
|
||||
|
||||
audits, _, err = th.SystemAdminClient.GetAudits(0, 1, "")
|
||||
audits, _, err = th.SystemAdminClient.GetAudits(context.Background(), 0, 1, "")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, audits, 1, "should only be 1")
|
||||
|
||||
audits, _, err = th.SystemAdminClient.GetAudits(1, 1, "")
|
||||
audits, _, err = th.SystemAdminClient.GetAudits(context.Background(), 1, 1, "")
|
||||
require.NoError(t, err)
|
||||
require.Len(t, audits, 1, "should only be 1")
|
||||
|
||||
_, _, err = th.SystemAdminClient.GetAudits(-1, -1, "")
|
||||
_, _, err = th.SystemAdminClient.GetAudits(context.Background(), -1, -1, "")
|
||||
require.NoError(t, err)
|
||||
|
||||
_, resp, err := client.GetAudits(0, 100, "")
|
||||
_, resp, err := client.GetAudits(context.Background(), 0, 100, "")
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
client.Logout()
|
||||
_, resp, err = client.GetAudits(0, 100, "")
|
||||
client.Logout(context.Background())
|
||||
_, resp, err = client.GetAudits(context.Background(), 0, 100, "")
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
}
|
||||
@@ -162,13 +163,13 @@ func TestEmailTest(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("as system user", func(t *testing.T) {
|
||||
resp, err := client.TestEmail(&config)
|
||||
resp, err := client.TestEmail(context.Background(), &config)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("as system admin", func(t *testing.T) {
|
||||
resp, err := th.SystemAdminClient.TestEmail(&config)
|
||||
resp, err := th.SystemAdminClient.TestEmail(context.Background(), &config)
|
||||
CheckErrorID(t, err, "api.admin.test_email.missing_server")
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
@@ -184,7 +185,7 @@ func TestEmailTest(t *testing.T) {
|
||||
|
||||
*config.EmailSettings.SMTPServer = inbucket_host
|
||||
*config.EmailSettings.SMTPPort = inbucket_port
|
||||
resp, err = th.SystemAdminClient.TestEmail(&config)
|
||||
resp, err = th.SystemAdminClient.TestEmail(context.Background(), &config)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
})
|
||||
@@ -192,14 +193,14 @@ func TestEmailTest(t *testing.T) {
|
||||
t.Run("as restricted system admin", func(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ExperimentalSettings.RestrictSystemAdmin = true })
|
||||
|
||||
resp, err := th.SystemAdminClient.TestEmail(&config)
|
||||
resp, err := th.SystemAdminClient.TestEmail(context.Background(), &config)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("empty email settings", func(t *testing.T) {
|
||||
config.EmailSettings = model.EmailSettings{}
|
||||
resp, err := th.SystemAdminClient.TestEmail(&config)
|
||||
resp, err := th.SystemAdminClient.TestEmail(context.Background(), &config)
|
||||
require.Error(t, err)
|
||||
CheckErrorID(t, err, "api.file.test_connection_email_settings_nil.app_error")
|
||||
CheckBadRequestStatus(t, resp)
|
||||
@@ -215,7 +216,7 @@ func TestGenerateSupportPacket(t *testing.T) {
|
||||
l := model.NewTestLicense()
|
||||
th.App.Srv().SetLicense(l)
|
||||
|
||||
file, _, err := th.SystemAdminClient.GenerateSupportPacket()
|
||||
file, _, err := th.SystemAdminClient.GenerateSupportPacket(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.NotZero(t, len(file))
|
||||
})
|
||||
@@ -229,28 +230,28 @@ func TestGenerateSupportPacket(t *testing.T) {
|
||||
})
|
||||
}()
|
||||
|
||||
_, resp, err := th.SystemAdminClient.GenerateSupportPacket()
|
||||
_, resp, err := th.SystemAdminClient.GenerateSupportPacket(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("As a system role, not system admin", func(t *testing.T) {
|
||||
_, resp, err := th.SystemManagerClient.GenerateSupportPacket()
|
||||
_, resp, err := th.SystemManagerClient.GenerateSupportPacket(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("As a Regular User", func(t *testing.T) {
|
||||
_, resp, err := th.Client.GenerateSupportPacket()
|
||||
_, resp, err := th.Client.GenerateSupportPacket(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("Server with no License", func(t *testing.T) {
|
||||
_, err := th.SystemAdminClient.RemoveLicenseFile()
|
||||
_, err := th.SystemAdminClient.RemoveLicenseFile(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
_, resp, err := th.SystemAdminClient.GenerateSupportPacket()
|
||||
_, resp, err := th.SystemAdminClient.GenerateSupportPacket(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
@@ -274,21 +275,21 @@ func TestSiteURLTest(t *testing.T) {
|
||||
invalidSiteURL := ts.URL + "/invalid"
|
||||
|
||||
t.Run("as system admin", func(t *testing.T) {
|
||||
resp, err := th.SystemAdminClient.TestSiteURL("")
|
||||
resp, err := th.SystemAdminClient.TestSiteURL(context.Background(), "")
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
resp, err = th.SystemAdminClient.TestSiteURL(invalidSiteURL)
|
||||
resp, err = th.SystemAdminClient.TestSiteURL(context.Background(), invalidSiteURL)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
resp, err = th.SystemAdminClient.TestSiteURL(validSiteURL)
|
||||
resp, err = th.SystemAdminClient.TestSiteURL(context.Background(), validSiteURL)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("as system user", func(t *testing.T) {
|
||||
resp, err := client.TestSiteURL(validSiteURL)
|
||||
resp, err := client.TestSiteURL(context.Background(), validSiteURL)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
@@ -296,7 +297,7 @@ func TestSiteURLTest(t *testing.T) {
|
||||
t.Run("as restricted system admin", func(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ExperimentalSettings.RestrictSystemAdmin = true })
|
||||
|
||||
resp, err := client.TestSiteURL(validSiteURL)
|
||||
resp, err := client.TestSiteURL(context.Background(), validSiteURL)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
@@ -308,20 +309,20 @@ func TestDatabaseRecycle(t *testing.T) {
|
||||
client := th.Client
|
||||
|
||||
t.Run("as system user", func(t *testing.T) {
|
||||
resp, err := client.DatabaseRecycle()
|
||||
resp, err := client.DatabaseRecycle(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("as system admin", func(t *testing.T) {
|
||||
_, err := th.SystemAdminClient.DatabaseRecycle()
|
||||
_, err := th.SystemAdminClient.DatabaseRecycle(context.Background())
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("as restricted system admin", func(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ExperimentalSettings.RestrictSystemAdmin = true })
|
||||
|
||||
resp, err := th.SystemAdminClient.DatabaseRecycle()
|
||||
resp, err := th.SystemAdminClient.DatabaseRecycle(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
@@ -333,20 +334,20 @@ func TestInvalidateCaches(t *testing.T) {
|
||||
client := th.Client
|
||||
|
||||
t.Run("as system user", func(t *testing.T) {
|
||||
resp, err := client.InvalidateCaches()
|
||||
resp, err := client.InvalidateCaches(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("as system admin", func(t *testing.T) {
|
||||
_, err := th.SystemAdminClient.InvalidateCaches()
|
||||
_, err := th.SystemAdminClient.InvalidateCaches(context.Background())
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("as restricted system admin", func(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ExperimentalSettings.RestrictSystemAdmin = true })
|
||||
|
||||
resp, err := th.SystemAdminClient.InvalidateCaches()
|
||||
resp, err := th.SystemAdminClient.InvalidateCaches(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
@@ -364,7 +365,7 @@ func TestGetLogs(t *testing.T) {
|
||||
require.NoError(t, err, "failed to flush log")
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
|
||||
logs, _, err2 := c.GetLogs(0, 10)
|
||||
logs, _, err2 := c.GetLogs(context.Background(), 0, 10)
|
||||
require.NoError(t, err2)
|
||||
require.Len(t, logs, 10)
|
||||
|
||||
@@ -372,28 +373,28 @@ func TestGetLogs(t *testing.T) {
|
||||
assert.Containsf(t, logs[i-10], fmt.Sprintf(`"msg":"%d"`, i), "Log line doesn't contain correct message")
|
||||
}
|
||||
|
||||
logs, _, err = c.GetLogs(1, 10)
|
||||
logs, _, err = c.GetLogs(context.Background(), 1, 10)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, logs, 10)
|
||||
|
||||
logs, _, err = c.GetLogs(-1, -1)
|
||||
logs, _, err = c.GetLogs(context.Background(), -1, -1)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, logs, "should not be empty")
|
||||
})
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ExperimentalSettings.RestrictSystemAdmin = true })
|
||||
_, resp, err2 := th.Client.GetLogs(0, 10)
|
||||
_, resp, err2 := th.Client.GetLogs(context.Background(), 0, 10)
|
||||
require.Error(t, err2)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
_, resp, err := th.Client.GetLogs(0, 10)
|
||||
_, resp, err := th.Client.GetLogs(context.Background(), 0, 10)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
th.Client.Logout()
|
||||
_, resp, err = th.Client.GetLogs(0, 10)
|
||||
th.Client.Logout(context.Background())
|
||||
_, resp, err = th.Client.GetLogs(context.Background(), 0, 10)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
}
|
||||
@@ -413,28 +414,28 @@ func TestPostLog(t *testing.T) {
|
||||
message["level"] = "ERROR"
|
||||
message["message"] = "this is a test"
|
||||
|
||||
_, _, err := client.PostLog(message)
|
||||
_, _, err := client.PostLog(context.Background(), message)
|
||||
require.NoError(t, err)
|
||||
|
||||
*th.App.Config().ServiceSettings.EnableDeveloper = false
|
||||
|
||||
_, _, err = client.PostLog(message)
|
||||
_, _, err = client.PostLog(context.Background(), message)
|
||||
require.NoError(t, err)
|
||||
|
||||
*th.App.Config().ServiceSettings.EnableDeveloper = true
|
||||
|
||||
client.Logout()
|
||||
client.Logout(context.Background())
|
||||
|
||||
_, _, err = client.PostLog(message)
|
||||
_, _, err = client.PostLog(context.Background(), message)
|
||||
require.NoError(t, err)
|
||||
|
||||
*th.App.Config().ServiceSettings.EnableDeveloper = false
|
||||
|
||||
_, resp, err := client.PostLog(message)
|
||||
_, resp, err := client.PostLog(context.Background(), message)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
logMessage, _, err := th.SystemAdminClient.PostLog(message)
|
||||
logMessage, _, err := th.SystemAdminClient.PostLog(context.Background(), message)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, logMessage, "should return the log message")
|
||||
|
||||
@@ -445,11 +446,11 @@ func TestGetAnalyticsOld(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
client := th.Client
|
||||
|
||||
rows, resp, err := client.GetAnalyticsOld("", "")
|
||||
rows, resp, err := client.GetAnalyticsOld(context.Background(), "", "")
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
require.Nil(t, rows, "should be nil")
|
||||
rows, _, err = th.SystemAdminClient.GetAnalyticsOld("", "")
|
||||
rows, _, err = th.SystemAdminClient.GetAnalyticsOld(context.Background(), "", "")
|
||||
require.NoError(t, err)
|
||||
|
||||
found := false
|
||||
@@ -466,16 +467,16 @@ func TestGetAnalyticsOld(t *testing.T) {
|
||||
assert.True(t, found, "should return unique user count")
|
||||
assert.True(t, found2, "should return inactive user count")
|
||||
|
||||
_, _, err = th.SystemAdminClient.GetAnalyticsOld("post_counts_day", "")
|
||||
_, _, err = th.SystemAdminClient.GetAnalyticsOld(context.Background(), "post_counts_day", "")
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, err = th.SystemAdminClient.GetAnalyticsOld("user_counts_with_posts_day", "")
|
||||
_, _, err = th.SystemAdminClient.GetAnalyticsOld(context.Background(), "user_counts_with_posts_day", "")
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, err = th.SystemAdminClient.GetAnalyticsOld("extra_counts", "")
|
||||
_, _, err = th.SystemAdminClient.GetAnalyticsOld(context.Background(), "extra_counts", "")
|
||||
require.NoError(t, err)
|
||||
|
||||
rows, _, err = th.SystemAdminClient.GetAnalyticsOld("", th.BasicTeam.Id)
|
||||
rows, _, err = th.SystemAdminClient.GetAnalyticsOld(context.Background(), "", th.BasicTeam.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, row := range rows {
|
||||
@@ -484,7 +485,7 @@ func TestGetAnalyticsOld(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
rows2, _, err := th.SystemAdminClient.GetAnalyticsOld("standard", "")
|
||||
rows2, _, err := th.SystemAdminClient.GetAnalyticsOld(context.Background(), "standard", "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "total_websocket_connections", rows2[5].Name)
|
||||
assert.Equal(t, float64(0), rows2[5].Value)
|
||||
@@ -492,20 +493,20 @@ func TestGetAnalyticsOld(t *testing.T) {
|
||||
WebSocketClient, err := th.CreateWebSocketClient()
|
||||
require.NoError(t, err)
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
rows2, _, err = th.SystemAdminClient.GetAnalyticsOld("standard", "")
|
||||
rows2, _, err = th.SystemAdminClient.GetAnalyticsOld(context.Background(), "standard", "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "total_websocket_connections", rows2[5].Name)
|
||||
assert.Equal(t, float64(1), rows2[5].Value)
|
||||
|
||||
WebSocketClient.Close()
|
||||
|
||||
rows2, _, err = th.SystemAdminClient.GetAnalyticsOld("standard", "")
|
||||
rows2, _, err = th.SystemAdminClient.GetAnalyticsOld(context.Background(), "standard", "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "total_websocket_connections", rows2[5].Name)
|
||||
assert.Equal(t, float64(0), rows2[5].Value)
|
||||
|
||||
client.Logout()
|
||||
_, resp, err = client.GetAnalyticsOld("", th.BasicTeam.Id)
|
||||
client.Logout(context.Background())
|
||||
_, resp, err = client.GetAnalyticsOld(context.Background(), "", th.BasicTeam.Id)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
}
|
||||
@@ -544,13 +545,13 @@ func TestS3TestConnection(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("as system user", func(t *testing.T) {
|
||||
resp, err := client.TestS3Connection(&config)
|
||||
resp, err := client.TestS3Connection(context.Background(), &config)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("as system admin", func(t *testing.T) {
|
||||
resp, err := th.SystemAdminClient.TestS3Connection(&config)
|
||||
resp, err := th.SystemAdminClient.TestS3Connection(context.Background(), &config)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
CheckErrorMessage(t, err, "S3 Bucket is required")
|
||||
// If this fails, check the test configuration to ensure minio is setup with the
|
||||
@@ -558,22 +559,22 @@ func TestS3TestConnection(t *testing.T) {
|
||||
*config.FileSettings.AmazonS3Bucket = model.MinioBucket
|
||||
config.FileSettings.AmazonS3PathPrefix = model.NewString("")
|
||||
*config.FileSettings.AmazonS3Region = "us-east-1"
|
||||
resp, err = th.SystemAdminClient.TestS3Connection(&config)
|
||||
resp, err = th.SystemAdminClient.TestS3Connection(context.Background(), &config)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
|
||||
config.FileSettings.AmazonS3Region = model.NewString("")
|
||||
resp, err = th.SystemAdminClient.TestS3Connection(&config)
|
||||
resp, err = th.SystemAdminClient.TestS3Connection(context.Background(), &config)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
|
||||
config.FileSettings.AmazonS3Bucket = model.NewString("Wrong_bucket")
|
||||
resp, err = th.SystemAdminClient.TestS3Connection(&config)
|
||||
resp, err = th.SystemAdminClient.TestS3Connection(context.Background(), &config)
|
||||
CheckInternalErrorStatus(t, resp)
|
||||
CheckErrorID(t, err, "api.file.test_connection_s3_bucket_does_not_exist.app_error")
|
||||
|
||||
*config.FileSettings.AmazonS3Bucket = "shouldnotcreatenewbucket"
|
||||
resp, err = th.SystemAdminClient.TestS3Connection(&config)
|
||||
resp, err = th.SystemAdminClient.TestS3Connection(context.Background(), &config)
|
||||
CheckInternalErrorStatus(t, resp)
|
||||
CheckErrorID(t, err, "api.file.test_connection_s3_bucket_does_not_exist.app_error")
|
||||
})
|
||||
@@ -581,7 +582,7 @@ func TestS3TestConnection(t *testing.T) {
|
||||
t.Run("with incorrect credentials", func(t *testing.T) {
|
||||
configCopy := config
|
||||
*configCopy.FileSettings.AmazonS3AccessKeyId = "invalidaccesskey"
|
||||
resp, err := th.SystemAdminClient.TestS3Connection(&configCopy)
|
||||
resp, err := th.SystemAdminClient.TestS3Connection(context.Background(), &configCopy)
|
||||
CheckInternalErrorStatus(t, resp)
|
||||
CheckErrorID(t, err, "api.file.test_connection_s3_auth.app_error")
|
||||
})
|
||||
@@ -590,14 +591,14 @@ func TestS3TestConnection(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ExperimentalSettings.RestrictSystemAdmin = true })
|
||||
defer th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ExperimentalSettings.RestrictSystemAdmin = false })
|
||||
|
||||
resp, err := th.SystemAdminClient.TestS3Connection(&config)
|
||||
resp, err := th.SystemAdminClient.TestS3Connection(context.Background(), &config)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("empty file settings", func(t *testing.T) {
|
||||
config.FileSettings = model.FileSettings{}
|
||||
resp, err := th.SystemAdminClient.TestS3Connection(&config)
|
||||
resp, err := th.SystemAdminClient.TestS3Connection(context.Background(), &config)
|
||||
require.Error(t, err)
|
||||
CheckErrorID(t, err, "api.file.test_connection_s3_settings_nil.app_error")
|
||||
CheckBadRequestStatus(t, resp)
|
||||
@@ -610,7 +611,7 @@ func TestSupportedTimezones(t *testing.T) {
|
||||
client := th.Client
|
||||
|
||||
supportedTimezonesFromConfig := th.App.Timezones().GetSupported()
|
||||
supportedTimezones, _, err := client.GetSupportedTimezone()
|
||||
supportedTimezones, _, err := client.GetSupportedTimezone(context.Background())
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, supportedTimezonesFromConfig, supportedTimezones)
|
||||
@@ -639,37 +640,37 @@ func TestRedirectLocation(t *testing.T) {
|
||||
*th.App.Config().ServiceSettings.EnableLinkPreviews = true
|
||||
*th.App.Config().ServiceSettings.AllowedUntrustedInternalConnections = "127.0.0.1"
|
||||
|
||||
_, _, err := th.SystemAdminClient.GetRedirectLocation("https://mattermost.com/", "")
|
||||
_, _, err := th.SystemAdminClient.GetRedirectLocation(context.Background(), "https://mattermost.com/", "")
|
||||
require.NoError(t, err)
|
||||
|
||||
_, resp, err := th.SystemAdminClient.GetRedirectLocation("", "")
|
||||
_, resp, err := th.SystemAdminClient.GetRedirectLocation(context.Background(), "", "")
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
actual, _, err := th.SystemAdminClient.GetRedirectLocation(mockBitlyLink, "")
|
||||
actual, _, err := th.SystemAdminClient.GetRedirectLocation(context.Background(), mockBitlyLink, "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, expected, actual)
|
||||
|
||||
// Check cached value
|
||||
actual, _, err = th.SystemAdminClient.GetRedirectLocation(mockBitlyLink, "")
|
||||
actual, _, err = th.SystemAdminClient.GetRedirectLocation(context.Background(), mockBitlyLink, "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, expected, actual)
|
||||
|
||||
*th.App.Config().ServiceSettings.EnableLinkPreviews = false
|
||||
actual, _, err = th.SystemAdminClient.GetRedirectLocation("https://mattermost.com/", "")
|
||||
actual, _, err = th.SystemAdminClient.GetRedirectLocation(context.Background(), "https://mattermost.com/", "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, actual, "")
|
||||
|
||||
actual, _, err = th.SystemAdminClient.GetRedirectLocation("", "")
|
||||
actual, _, err = th.SystemAdminClient.GetRedirectLocation(context.Background(), "", "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, actual, "")
|
||||
|
||||
actual, _, err = th.SystemAdminClient.GetRedirectLocation(mockBitlyLink, "")
|
||||
actual, _, err = th.SystemAdminClient.GetRedirectLocation(context.Background(), mockBitlyLink, "")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, actual, "")
|
||||
|
||||
client.Logout()
|
||||
_, resp, err = client.GetRedirectLocation("", "")
|
||||
client.Logout(context.Background())
|
||||
_, resp, err = client.GetRedirectLocation(context.Background(), "", "")
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
}
|
||||
@@ -681,14 +682,14 @@ func TestSetServerBusy(t *testing.T) {
|
||||
const secs = 30
|
||||
|
||||
t.Run("as system user", func(t *testing.T) {
|
||||
resp, err := th.Client.SetServerBusy(secs)
|
||||
resp, err := th.Client.SetServerBusy(context.Background(), secs)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
require.False(t, th.App.Srv().Platform().Busy.IsBusy(), "server should not be marked busy")
|
||||
})
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
|
||||
_, err := c.SetServerBusy(secs)
|
||||
_, err := c.SetServerBusy(context.Background(), secs)
|
||||
require.NoError(t, err)
|
||||
require.True(t, th.App.Srv().Platform().Busy.IsBusy(), "server should be marked busy")
|
||||
}, "as system admin")
|
||||
@@ -701,7 +702,7 @@ func TestSetServerBusyInvalidParam(t *testing.T) {
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
|
||||
params := []int{-1, 0, MaxServerBusySeconds + 1}
|
||||
for _, p := range params {
|
||||
resp, err := c.SetServerBusy(p)
|
||||
resp, err := c.SetServerBusy(context.Background(), p)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
require.False(t, th.App.Srv().Platform().Busy.IsBusy(), "server should not be marked busy due to invalid param ", p)
|
||||
@@ -715,7 +716,7 @@ func TestClearServerBusy(t *testing.T) {
|
||||
|
||||
th.App.Srv().Platform().Busy.Set(time.Second * 30)
|
||||
t.Run("as system user", func(t *testing.T) {
|
||||
resp, err := th.Client.ClearServerBusy()
|
||||
resp, err := th.Client.ClearServerBusy(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
require.True(t, th.App.Srv().Platform().Busy.IsBusy(), "server should be marked busy")
|
||||
@@ -723,7 +724,7 @@ func TestClearServerBusy(t *testing.T) {
|
||||
|
||||
th.App.Srv().Platform().Busy.Set(time.Second * 30)
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
|
||||
_, err := c.ClearServerBusy()
|
||||
_, err := c.ClearServerBusy(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.False(t, th.App.Srv().Platform().Busy.IsBusy(), "server should not be marked busy")
|
||||
}, "as system admin")
|
||||
@@ -736,13 +737,13 @@ func TestGetServerBusy(t *testing.T) {
|
||||
th.App.Srv().Platform().Busy.Set(time.Second * 30)
|
||||
|
||||
t.Run("as system user", func(t *testing.T) {
|
||||
_, resp, err := th.Client.GetServerBusy()
|
||||
_, resp, err := th.Client.GetServerBusy(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
|
||||
sbs, _, err := c.GetServerBusy()
|
||||
sbs, _, err := c.GetServerBusy(context.Background())
|
||||
expires := time.Unix(sbs.Expires, 0)
|
||||
require.NoError(t, err)
|
||||
require.Greater(t, expires.Unix(), time.Now().Unix())
|
||||
@@ -757,28 +758,28 @@ func TestServerBusy503(t *testing.T) {
|
||||
|
||||
t.Run("search users while busy", func(t *testing.T) {
|
||||
us := &model.UserSearch{Term: "test"}
|
||||
_, resp, err := th.SystemAdminClient.SearchUsers(us)
|
||||
_, resp, err := th.SystemAdminClient.SearchUsers(context.Background(), us)
|
||||
require.Error(t, err)
|
||||
CheckServiceUnavailableStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("search teams while busy", func(t *testing.T) {
|
||||
ts := &model.TeamSearch{}
|
||||
_, resp, err := th.SystemAdminClient.SearchTeams(ts)
|
||||
_, resp, err := th.SystemAdminClient.SearchTeams(context.Background(), ts)
|
||||
require.Error(t, err)
|
||||
CheckServiceUnavailableStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("search channels while busy", func(t *testing.T) {
|
||||
cs := &model.ChannelSearch{}
|
||||
_, resp, err := th.SystemAdminClient.SearchChannels("foo", cs)
|
||||
_, resp, err := th.SystemAdminClient.SearchChannels(context.Background(), "foo", cs)
|
||||
require.Error(t, err)
|
||||
CheckServiceUnavailableStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("search archived channels while busy", func(t *testing.T) {
|
||||
cs := &model.ChannelSearch{}
|
||||
_, resp, err := th.SystemAdminClient.SearchArchivedChannels("foo", cs)
|
||||
_, resp, err := th.SystemAdminClient.SearchArchivedChannels(context.Background(), "foo", cs)
|
||||
require.Error(t, err)
|
||||
CheckServiceUnavailableStatus(t, resp)
|
||||
})
|
||||
@@ -787,7 +788,7 @@ func TestServerBusy503(t *testing.T) {
|
||||
|
||||
t.Run("search users while not busy", func(t *testing.T) {
|
||||
us := &model.UserSearch{Term: "test"}
|
||||
_, _, err := th.SystemAdminClient.SearchUsers(us)
|
||||
_, _, err := th.SystemAdminClient.SearchUsers(context.Background(), us)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
}
|
||||
@@ -896,18 +897,18 @@ func TestCompleteOnboarding(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("as a regular user", func(t *testing.T) {
|
||||
resp, err := th.Client.CompleteOnboarding(req)
|
||||
resp, err := th.Client.CompleteOnboarding(context.Background(), req)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("as a system admin", func(t *testing.T) {
|
||||
resp, err := th.SystemAdminClient.CompleteOnboarding(req)
|
||||
resp, err := th.SystemAdminClient.CompleteOnboarding(context.Background(), req)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
|
||||
t.Cleanup(func() {
|
||||
resp, err = th.SystemAdminClient.RemovePlugin("testplugin2")
|
||||
resp, err = th.SystemAdminClient.RemovePlugin(context.Background(), "testplugin2")
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
})
|
||||
@@ -916,7 +917,7 @@ func TestCompleteOnboarding(t *testing.T) {
|
||||
|
||||
go func() {
|
||||
for {
|
||||
installedPlugins, resp, err := th.SystemAdminClient.GetPlugins()
|
||||
installedPlugins, resp, err := th.SystemAdminClient.GetPlugins(context.Background())
|
||||
if err != nil || resp.StatusCode != http.StatusOK {
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
continue
|
||||
@@ -952,7 +953,7 @@ func TestCompleteOnboarding(t *testing.T) {
|
||||
})
|
||||
})
|
||||
|
||||
resp, err := th.SystemAdminClient.CompleteOnboarding(req)
|
||||
resp, err := th.SystemAdminClient.CompleteOnboarding(context.Background(), req)
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
})
|
||||
@@ -963,7 +964,7 @@ func TestGetAppliedSchemaMigrations(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
t.Run("as a regular user", func(t *testing.T) {
|
||||
_, resp, err := th.Client.GetAppliedSchemaMigrations()
|
||||
_, resp, err := th.Client.GetAppliedSchemaMigrations(context.Background())
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
@@ -973,13 +974,13 @@ func TestGetAppliedSchemaMigrations(t *testing.T) {
|
||||
require.Nil(t, appErr)
|
||||
th.LoginBasic2()
|
||||
|
||||
_, resp, err := th.Client.GetAppliedSchemaMigrations()
|
||||
_, resp, err := th.Client.GetAppliedSchemaMigrations(context.Background())
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
})
|
||||
|
||||
th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) {
|
||||
_, resp, err := c.GetAppliedSchemaMigrations()
|
||||
_, resp, err := c.GetAppliedSchemaMigrations(context.Background())
|
||||
require.NoError(t, err)
|
||||
CheckOKStatus(t, resp)
|
||||
})
|
||||
|
||||
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -20,7 +21,7 @@ func TestGetTermsOfService(t *testing.T) {
|
||||
_, appErr := th.App.CreateTermsOfService("abc", th.BasicUser.Id)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
termsOfService, _, err := client.GetTermsOfService("")
|
||||
termsOfService, _, err := client.GetTermsOfService(context.Background(), "")
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.NotNil(t, termsOfService)
|
||||
@@ -34,7 +35,7 @@ func TestCreateTermsOfService(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
client := th.Client
|
||||
|
||||
_, _, err := client.CreateTermsOfService("terms of service new", th.BasicUser.Id)
|
||||
_, _, err := client.CreateTermsOfService(context.Background(), "terms of service new", th.BasicUser.Id)
|
||||
CheckErrorID(t, err, "api.context.permissions.app_error")
|
||||
}
|
||||
|
||||
@@ -43,13 +44,13 @@ func TestCreateTermsOfServiceAdminUser(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
client := th.SystemAdminClient
|
||||
|
||||
termsOfService, _, err := client.CreateTermsOfService("terms of service new", th.SystemAdminUser.Id)
|
||||
termsOfService, _, err := client.CreateTermsOfService(context.Background(), "terms of service new", th.SystemAdminUser.Id)
|
||||
CheckErrorID(t, err, "api.create_terms_of_service.custom_terms_of_service_disabled.app_error")
|
||||
assert.Nil(t, termsOfService)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("EnableCustomTermsOfService"))
|
||||
|
||||
termsOfService, _, err = client.CreateTermsOfService("terms of service new_2", th.SystemAdminUser.Id)
|
||||
termsOfService, _, err = client.CreateTermsOfService(context.Background(), "terms of service new_2", th.SystemAdminUser.Id)
|
||||
require.NoError(t, err)
|
||||
assert.NotEmpty(t, termsOfService.Id)
|
||||
assert.NotEmpty(t, termsOfService.CreateAt)
|
||||
|
||||
@@ -5,6 +5,7 @@ package api4
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
@@ -31,7 +32,7 @@ func TestCreateUpload(t *testing.T) {
|
||||
t.Run("file attachments disabled", func(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.EnableFileAttachments = false })
|
||||
defer th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.EnableFileAttachments = true })
|
||||
u, resp, err := th.Client.CreateUpload(us)
|
||||
u, resp, err := th.Client.CreateUpload(context.Background(), us)
|
||||
require.Nil(t, u)
|
||||
CheckErrorID(t, err, "api.file.attachments.disabled.app_error")
|
||||
require.Equal(t, http.StatusNotImplemented, resp.StatusCode)
|
||||
@@ -39,7 +40,7 @@ func TestCreateUpload(t *testing.T) {
|
||||
|
||||
t.Run("no permissions", func(t *testing.T) {
|
||||
us.ChannelId = th.BasicPrivateChannel2.Id
|
||||
u, resp, err := th.Client.CreateUpload(us)
|
||||
u, resp, err := th.Client.CreateUpload(context.Background(), us)
|
||||
require.Nil(t, u)
|
||||
CheckErrorID(t, err, "api.context.permissions.app_error")
|
||||
require.Equal(t, http.StatusForbidden, resp.StatusCode)
|
||||
@@ -50,7 +51,7 @@ func TestCreateUpload(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.MaxFileSize = us.FileSize - 1 })
|
||||
defer th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.MaxFileSize = maxFileSize })
|
||||
us.ChannelId = th.BasicChannel.Id
|
||||
u, resp, err := th.Client.CreateUpload(us)
|
||||
u, resp, err := th.Client.CreateUpload(context.Background(), us)
|
||||
require.Nil(t, u)
|
||||
CheckErrorID(t, err, "api.upload.create.upload_too_large.app_error")
|
||||
require.Equal(t, http.StatusRequestEntityTooLarge, resp.StatusCode)
|
||||
@@ -60,7 +61,7 @@ func TestCreateUpload(t *testing.T) {
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
defer th.App.Srv().RemoveLicense()
|
||||
|
||||
u, resp, err := th.SystemAdminClient.CreateUpload(&model.UploadSession{
|
||||
u, resp, err := th.SystemAdminClient.CreateUpload(context.Background(), &model.UploadSession{
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Filename: "upload",
|
||||
FileSize: 8 * 1024 * 1024,
|
||||
@@ -73,7 +74,7 @@ func TestCreateUpload(t *testing.T) {
|
||||
|
||||
t.Run("valid", func(t *testing.T) {
|
||||
us.ChannelId = th.BasicChannel.Id
|
||||
u, resp, err := th.Client.CreateUpload(us)
|
||||
u, resp, err := th.Client.CreateUpload(context.Background(), us)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, u)
|
||||
require.Equal(t, http.StatusCreated, resp.StatusCode)
|
||||
@@ -95,7 +96,7 @@ func TestCreateUpload(t *testing.T) {
|
||||
FileSize: info.Size(),
|
||||
Type: model.UploadTypeImport,
|
||||
}
|
||||
u, resp, err := th.Client.CreateUpload(us)
|
||||
u, resp, err := th.Client.CreateUpload(context.Background(), us)
|
||||
require.Nil(t, u)
|
||||
CheckErrorID(t, err, "api.context.permissions.app_error")
|
||||
require.Equal(t, http.StatusForbidden, resp.StatusCode)
|
||||
@@ -107,7 +108,7 @@ func TestCreateUpload(t *testing.T) {
|
||||
FileSize: info.Size(),
|
||||
Type: model.UploadTypeImport,
|
||||
}
|
||||
u, _, err := th.SystemAdminClient.CreateUpload(us)
|
||||
u, _, err := th.SystemAdminClient.CreateUpload(context.Background(), us)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, u)
|
||||
})
|
||||
@@ -133,25 +134,25 @@ func TestGetUpload(t *testing.T) {
|
||||
require.NotEmpty(t, us)
|
||||
|
||||
t.Run("upload not found", func(t *testing.T) {
|
||||
u, resp, err := th.Client.GetUpload(model.NewId())
|
||||
u, resp, err := th.Client.GetUpload(context.Background(), model.NewId())
|
||||
require.Nil(t, u)
|
||||
CheckErrorID(t, err, "app.upload.get.app_error")
|
||||
require.Equal(t, http.StatusNotFound, resp.StatusCode)
|
||||
})
|
||||
|
||||
t.Run("no permissions", func(t *testing.T) {
|
||||
u, _, err := th.Client.GetUpload(us.Id)
|
||||
u, _, err := th.Client.GetUpload(context.Background(), us.Id)
|
||||
require.Nil(t, u)
|
||||
CheckErrorID(t, err, "api.upload.get_upload.forbidden.app_error")
|
||||
})
|
||||
|
||||
t.Run("success", func(t *testing.T) {
|
||||
expected, resp, err := th.Client.CreateUpload(us)
|
||||
expected, resp, err := th.Client.CreateUpload(context.Background(), us)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, expected)
|
||||
require.Equal(t, http.StatusCreated, resp.StatusCode)
|
||||
|
||||
u, _, err := th.Client.GetUpload(expected.Id)
|
||||
u, _, err := th.Client.GetUpload(context.Background(), expected.Id)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, u)
|
||||
require.Equal(t, expected, u)
|
||||
@@ -163,14 +164,14 @@ func TestGetUploadsForUser(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
t.Run("no permissions", func(t *testing.T) {
|
||||
uss, _, err := th.Client.GetUploadsForUser(th.BasicUser2.Id)
|
||||
uss, _, err := th.Client.GetUploadsForUser(context.Background(), th.BasicUser2.Id)
|
||||
require.Error(t, err)
|
||||
CheckErrorID(t, err, "api.user.get_uploads_for_user.forbidden.app_error")
|
||||
require.Nil(t, uss)
|
||||
})
|
||||
|
||||
t.Run("empty", func(t *testing.T) {
|
||||
uss, _, err := th.Client.GetUploadsForUser(th.BasicUser.Id)
|
||||
uss, _, err := th.Client.GetUploadsForUser(context.Background(), th.BasicUser.Id)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, uss)
|
||||
})
|
||||
@@ -195,7 +196,7 @@ func TestGetUploadsForUser(t *testing.T) {
|
||||
uploads[i] = us
|
||||
}
|
||||
|
||||
uss, _, err := th.Client.GetUploadsForUser(th.BasicUser.Id)
|
||||
uss, _, err := th.Client.GetUploadsForUser(context.Background(), th.BasicUser.Id)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, uss)
|
||||
require.Len(t, uss, len(uploads))
|
||||
@@ -231,20 +232,20 @@ func TestUploadData(t *testing.T) {
|
||||
t.Run("file attachments disabled", func(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.EnableFileAttachments = false })
|
||||
defer th.App.UpdateConfig(func(cfg *model.Config) { *cfg.FileSettings.EnableFileAttachments = true })
|
||||
info, _, err := th.Client.UploadData(model.NewId(), bytes.NewReader(data))
|
||||
info, _, err := th.Client.UploadData(context.Background(), model.NewId(), bytes.NewReader(data))
|
||||
require.Nil(t, info)
|
||||
CheckErrorID(t, err, "api.file.attachments.disabled.app_error")
|
||||
})
|
||||
|
||||
t.Run("upload not found", func(t *testing.T) {
|
||||
info, resp, err := th.Client.UploadData(model.NewId(), bytes.NewReader(data))
|
||||
info, resp, err := th.Client.UploadData(context.Background(), model.NewId(), bytes.NewReader(data))
|
||||
require.Nil(t, info)
|
||||
CheckErrorID(t, err, "app.upload.get.app_error")
|
||||
require.Equal(t, http.StatusNotFound, resp.StatusCode)
|
||||
})
|
||||
|
||||
t.Run("no permissions", func(t *testing.T) {
|
||||
info, _, err := th.Client.UploadData(us.Id, bytes.NewReader(data))
|
||||
info, _, err := th.Client.UploadData(context.Background(), us.Id, bytes.NewReader(data))
|
||||
require.Nil(t, info)
|
||||
CheckErrorID(t, err, "api.context.permissions.app_error")
|
||||
})
|
||||
@@ -265,30 +266,30 @@ func TestUploadData(t *testing.T) {
|
||||
_, appErr := th.App.CreateUploadSession(th.Context, us2)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
info, resp, err := th.SystemAdminClient.UploadData(us2.Id, bytes.NewReader(data))
|
||||
info, resp, err := th.SystemAdminClient.UploadData(context.Background(), us2.Id, bytes.NewReader(data))
|
||||
require.Nil(t, info)
|
||||
CheckErrorID(t, err, "api.file.cloud_upload.app_error")
|
||||
require.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
||||
})
|
||||
|
||||
t.Run("bad content-length", func(t *testing.T) {
|
||||
u, resp, err := th.Client.CreateUpload(us)
|
||||
u, resp, err := th.Client.CreateUpload(context.Background(), us)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, u)
|
||||
require.Equal(t, http.StatusCreated, resp.StatusCode)
|
||||
|
||||
info, _, err := th.Client.UploadData(u.Id, bytes.NewReader(append(data, 0x00)))
|
||||
info, _, err := th.Client.UploadData(context.Background(), u.Id, bytes.NewReader(append(data, 0x00)))
|
||||
require.Nil(t, info)
|
||||
CheckErrorID(t, err, "api.upload.upload_data.invalid_content_length")
|
||||
})
|
||||
|
||||
t.Run("success", func(t *testing.T) {
|
||||
u, resp, err := th.Client.CreateUpload(us)
|
||||
u, resp, err := th.Client.CreateUpload(context.Background(), us)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, u)
|
||||
require.Equal(t, http.StatusCreated, resp.StatusCode)
|
||||
|
||||
info, _, err := th.Client.UploadData(u.Id, bytes.NewReader(data))
|
||||
info, _, err := th.Client.UploadData(context.Background(), u.Id, bytes.NewReader(data))
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, info)
|
||||
require.Equal(t, u.Filename, info.Name)
|
||||
@@ -296,13 +297,13 @@ func TestUploadData(t *testing.T) {
|
||||
require.Equal(t, "zip", info.Extension)
|
||||
require.Equal(t, "application/zip", info.MimeType)
|
||||
|
||||
file, _, err := th.Client.GetFile(info.Id)
|
||||
file, _, err := th.Client.GetFile(context.Background(), info.Id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, file, data)
|
||||
})
|
||||
|
||||
t.Run("resume success", func(t *testing.T) {
|
||||
u, resp, err := th.Client.CreateUpload(us)
|
||||
u, resp, err := th.Client.CreateUpload(context.Background(), us)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, u)
|
||||
require.Equal(t, http.StatusCreated, resp.StatusCode)
|
||||
@@ -311,17 +312,17 @@ func TestUploadData(t *testing.T) {
|
||||
R: bytes.NewReader(data),
|
||||
N: 5 * 1024 * 1024,
|
||||
}
|
||||
info, resp, err := th.Client.UploadData(u.Id, rd)
|
||||
info, resp, err := th.Client.UploadData(context.Background(), u.Id, rd)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, info)
|
||||
require.Equal(t, http.StatusNoContent, resp.StatusCode)
|
||||
|
||||
info, _, err = th.Client.UploadData(u.Id, bytes.NewReader(data[5*1024*1024:]))
|
||||
info, _, err = th.Client.UploadData(context.Background(), u.Id, bytes.NewReader(data[5*1024*1024:]))
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, info)
|
||||
require.Equal(t, u.Filename, info.Name)
|
||||
|
||||
file, _, err := th.Client.GetFile(info.Id)
|
||||
file, _, err := th.Client.GetFile(context.Background(), info.Id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, file, data)
|
||||
})
|
||||
@@ -343,7 +344,7 @@ func TestUploadDataMultipart(t *testing.T) {
|
||||
Filename: "upload",
|
||||
FileSize: 8 * 1024 * 1024,
|
||||
}
|
||||
us, _, err := th.Client.CreateUpload(us)
|
||||
us, _, err := th.Client.CreateUpload(context.Background(), us)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, us)
|
||||
require.NotEmpty(t, us)
|
||||
@@ -364,7 +365,7 @@ func TestUploadDataMultipart(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("bad content-type", func(t *testing.T) {
|
||||
info, _, err := th.Client.DoUploadFile("/uploads/"+us.Id, data, "multipart/form-data;")
|
||||
info, _, err := th.Client.DoUploadFile(context.Background(), "/uploads/"+us.Id, data, "multipart/form-data;")
|
||||
require.Nil(t, info)
|
||||
CheckErrorID(t, err, "api.upload.upload_data.invalid_content_type")
|
||||
})
|
||||
@@ -385,7 +386,7 @@ func TestUploadDataMultipart(t *testing.T) {
|
||||
require.NotEmpty(t, info)
|
||||
require.Equal(t, us.Filename, info.Name)
|
||||
|
||||
file, _, err := th.Client.GetFile(info.Id)
|
||||
file, _, err := th.Client.GetFile(context.Background(), info.Id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, file, data)
|
||||
})
|
||||
@@ -393,7 +394,7 @@ func TestUploadDataMultipart(t *testing.T) {
|
||||
t.Run("resume success", func(t *testing.T) {
|
||||
mpData, contentType := genMultipartData(t, data[:5*1024*1024])
|
||||
|
||||
u, _, err := th.Client.CreateUpload(us)
|
||||
u, _, err := th.Client.CreateUpload(context.Background(), us)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, u)
|
||||
require.NotEmpty(t, u)
|
||||
@@ -422,7 +423,7 @@ func TestUploadDataMultipart(t *testing.T) {
|
||||
require.NotEmpty(t, info)
|
||||
require.Equal(t, u.Filename, info.Name)
|
||||
|
||||
file, _, err := th.Client.GetFile(info.Id)
|
||||
file, _, err := th.Client.GetFile(context.Background(), info.Id)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, file, data)
|
||||
})
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
@@ -18,9 +19,9 @@ func TestGetPostsUsage(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
th.Client.Logout()
|
||||
th.Client.Logout(context.Background())
|
||||
|
||||
usage, r, err := th.Client.GetPostsUsage()
|
||||
usage, r, err := th.Client.GetPostsUsage(context.Background())
|
||||
assert.Error(t, err)
|
||||
assert.Nil(t, usage)
|
||||
assert.Equal(t, http.StatusUnauthorized, r.StatusCode)
|
||||
@@ -43,7 +44,7 @@ func TestGetPostsUsage(t *testing.T) {
|
||||
require.LessOrEqual(t, usersOnly, int64(20))
|
||||
require.GreaterOrEqual(t, total, usersOnly)
|
||||
|
||||
usage, r, err := th.Client.GetPostsUsage()
|
||||
usage, r, err := th.Client.GetPostsUsage(context.Background())
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, http.StatusOK, r.StatusCode)
|
||||
assert.NotNil(t, usage)
|
||||
@@ -56,9 +57,9 @@ func TestGetStorageUsage(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
th.Client.Logout()
|
||||
th.Client.Logout(context.Background())
|
||||
|
||||
usage, r, err := th.Client.GetStorageUsage()
|
||||
usage, r, err := th.Client.GetStorageUsage(context.Background())
|
||||
assert.Error(t, err)
|
||||
assert.Nil(t, usage)
|
||||
assert.Equal(t, http.StatusUnauthorized, r.StatusCode)
|
||||
@@ -70,9 +71,9 @@ func TestGetTeamsUsage(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
|
||||
th.Client.Logout()
|
||||
th.Client.Logout(context.Background())
|
||||
|
||||
usage, r, err := th.Client.GetTeamsUsage()
|
||||
usage, r, err := th.Client.GetTeamsUsage(context.Background())
|
||||
assert.Error(t, err)
|
||||
assert.Nil(t, usage)
|
||||
assert.Equal(t, http.StatusUnauthorized, r.StatusCode)
|
||||
@@ -85,7 +86,7 @@ func TestGetTeamsUsage(t *testing.T) {
|
||||
th.CreateTeam()
|
||||
th.CreateTeam()
|
||||
|
||||
usage, r, err := th.Client.GetTeamsUsage()
|
||||
usage, r, err := th.Client.GetTeamsUsage(context.Background())
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, http.StatusOK, r.StatusCode)
|
||||
assert.NotNil(t, usage)
|
||||
|
||||
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -60,7 +61,7 @@ func TestAPIRestrictedViewMembers(t *testing.T) {
|
||||
th.App.SetStatusOnline(user4.Id, true)
|
||||
th.App.SetStatusOnline(user5.Id, true)
|
||||
|
||||
_, _, err := th.Client.Login(user1.Username, "test-password-1")
|
||||
_, _, err := th.Client.Login(context.Background(), user1.Username, "test-password-1")
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Run("getUser", func(t *testing.T) {
|
||||
@@ -134,7 +135,7 @@ func TestAPIRestrictedViewMembers(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionViewMembers.Id, model.SystemUserRoleId)
|
||||
}
|
||||
|
||||
_, _, err := th.Client.GetUser(tc.UserId, "")
|
||||
_, _, err := th.Client.GetUser(context.Background(), tc.UserId, "")
|
||||
if tc.ExpectedError != "" {
|
||||
CheckErrorID(t, err, tc.ExpectedError)
|
||||
} else {
|
||||
@@ -215,7 +216,7 @@ func TestAPIRestrictedViewMembers(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionViewMembers.Id, model.SystemUserRoleId)
|
||||
}
|
||||
|
||||
_, _, err := th.Client.GetUserByUsername(tc.Username, "")
|
||||
_, _, err := th.Client.GetUserByUsername(context.Background(), tc.Username, "")
|
||||
if tc.ExpectedError != "" {
|
||||
CheckErrorID(t, err, tc.ExpectedError)
|
||||
} else {
|
||||
@@ -296,7 +297,7 @@ func TestAPIRestrictedViewMembers(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionViewMembers.Id, model.SystemUserRoleId)
|
||||
}
|
||||
|
||||
_, _, err := th.Client.GetUserByEmail(tc.Email, "")
|
||||
_, _, err := th.Client.GetUserByEmail(context.Background(), tc.Email, "")
|
||||
if tc.ExpectedError != "" {
|
||||
CheckErrorID(t, err, tc.ExpectedError)
|
||||
} else {
|
||||
@@ -377,7 +378,7 @@ func TestAPIRestrictedViewMembers(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionViewMembers.Id, model.SystemUserRoleId)
|
||||
}
|
||||
|
||||
_, _, err := th.Client.GetDefaultProfileImage(tc.UserId)
|
||||
_, _, err := th.Client.GetDefaultProfileImage(context.Background(), tc.UserId)
|
||||
if tc.ExpectedError != "" {
|
||||
CheckErrorID(t, err, tc.ExpectedError)
|
||||
} else {
|
||||
@@ -458,7 +459,7 @@ func TestAPIRestrictedViewMembers(t *testing.T) {
|
||||
th.AddPermissionToRole(model.PermissionViewMembers.Id, model.SystemUserRoleId)
|
||||
}
|
||||
|
||||
_, _, err := th.Client.GetProfileImage(tc.UserId, "")
|
||||
_, _, err := th.Client.GetProfileImage(context.Background(), tc.UserId, "")
|
||||
if tc.ExpectedError != "" {
|
||||
CheckErrorID(t, err, tc.ExpectedError)
|
||||
} else {
|
||||
|
||||
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
@@ -141,7 +142,7 @@ func TestCreateDirectChannelWithSocket(t *testing.T) {
|
||||
|
||||
for _, user := range users {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
_, _, err := client.CreateDirectChannel(th.BasicUser.Id, user.Id)
|
||||
_, _, err := client.CreateDirectChannel(context.Background(), th.BasicUser.Id, user.Id)
|
||||
require.NoError(t, err, "failed to create DM channel")
|
||||
}
|
||||
|
||||
@@ -291,23 +292,23 @@ func TestWebSocketStatuses(t *testing.T) {
|
||||
require.Equal(t, resp.Status, model.StatusOk, "should have responded OK to authentication challenge")
|
||||
|
||||
team := model.Team{DisplayName: "Name", Name: "z-z-" + model.NewRandomTeamName() + "a", Email: "test@nowhere.com", Type: model.TeamOpen}
|
||||
rteam, _, _ := client.CreateTeam(&team)
|
||||
rteam, _, _ := client.CreateTeam(context.Background(), &team)
|
||||
|
||||
user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
ruser, _, err := client.CreateUser(&user)
|
||||
ruser, _, err := client.CreateUser(context.Background(), &user)
|
||||
require.NoError(t, err)
|
||||
th.LinkUserToTeam(ruser, rteam)
|
||||
_, err = th.App.Srv().Store().User().VerifyEmail(ruser.Id, ruser.Email)
|
||||
require.NoError(t, err)
|
||||
|
||||
user2 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
ruser2, _, err := client.CreateUser(&user2)
|
||||
ruser2, _, err := client.CreateUser(context.Background(), &user2)
|
||||
require.NoError(t, err)
|
||||
th.LinkUserToTeam(ruser2, rteam)
|
||||
_, err = th.App.Srv().Store().User().VerifyEmail(ruser2.Id, ruser2.Email)
|
||||
require.NoError(t, err)
|
||||
|
||||
client.Login(user.Email, user.Password)
|
||||
client.Login(context.Background(), user.Email, user.Password)
|
||||
|
||||
th.LoginBasic2()
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package slashcommands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
@@ -37,7 +38,7 @@ func CreateTestEnvironmentWithTeams(a *app.App, c request.CTX, client *model.Cli
|
||||
if err != nil {
|
||||
return TestEnvironment{}, err
|
||||
}
|
||||
client.LoginById(randomUser.Id, UserPassword)
|
||||
client.LoginById(context.Background(), randomUser.Id, UserPassword)
|
||||
teamEnvironment, err := CreateTestEnvironmentInTeam(a, c, client, team, rangeChannels, rangeUsers, rangePosts, fuzzy)
|
||||
if err != nil {
|
||||
return TestEnvironment{}, err
|
||||
@@ -77,12 +78,12 @@ func CreateTestEnvironmentInTeam(a *app.App, c request.CTX, client *model.Client
|
||||
// Have every user join every channel
|
||||
for _, user := range users {
|
||||
for _, channel := range channels {
|
||||
_, _, err := client.LoginById(user.Id, UserPassword)
|
||||
_, _, err := client.LoginById(context.Background(), user.Id, UserPassword)
|
||||
if err != nil {
|
||||
return TeamEnvironment{}, err
|
||||
}
|
||||
|
||||
_, _, err = client.AddChannelMember(channel.Id, user.Id)
|
||||
_, _, err = client.AddChannelMember(context.Background(), channel.Id, user.Id)
|
||||
if err != nil {
|
||||
return TeamEnvironment{}, err
|
||||
}
|
||||
@@ -93,7 +94,7 @@ func CreateTestEnvironmentInTeam(a *app.App, c request.CTX, client *model.Client
|
||||
numImages := utils.RandIntFromRange(rangePosts) / 4
|
||||
for j := 0; j < numPosts; j++ {
|
||||
user := users[utils.RandIntFromRange(utils.Range{Begin: 0, End: len(users) - 1})]
|
||||
_, _, err := client.LoginById(user.Id, UserPassword)
|
||||
_, _, err := client.LoginById(context.Background(), user.Id, UserPassword)
|
||||
if err != nil {
|
||||
return TeamEnvironment{}, err
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
package slashcommands
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/mattermost/mattermost-server/server/public/model"
|
||||
"github.com/mattermost/mattermost-server/server/v8/channels/utils"
|
||||
)
|
||||
@@ -57,7 +59,7 @@ func (cfg *AutoTeamCreator) createRandomTeam() (*model.Team, error) {
|
||||
Type: model.TeamOpen,
|
||||
}
|
||||
|
||||
createdTeam, _, err := cfg.client.CreateTeam(team)
|
||||
createdTeam, _, err := cfg.client.CreateTeam(context.Background(), team)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package slashcommands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
@@ -42,18 +43,18 @@ func NewAutoUserCreator(a *app.App, client *model.Client4, team *model.Team) *Au
|
||||
|
||||
// Basic test team and user so you always know one
|
||||
func CreateBasicUser(a *app.App, client *model.Client4) error {
|
||||
found, _, _ := client.TeamExists(BTestTeamName, "")
|
||||
found, _, _ := client.TeamExists(context.Background(), BTestTeamName, "")
|
||||
if found {
|
||||
return nil
|
||||
}
|
||||
|
||||
newteam := &model.Team{DisplayName: BTestTeamDisplayName, Name: BTestTeamName, Email: BTestTeamEmail, Type: BTestTeamType}
|
||||
basicteam, _, err := client.CreateTeam(newteam)
|
||||
basicteam, _, err := client.CreateTeam(context.Background(), newteam)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
newuser := &model.User{Email: BTestUserEmail, Nickname: BTestUserName, Password: BTestUserPassword}
|
||||
ruser, _, err := client.CreateUser(newuser)
|
||||
ruser, _, err := client.CreateUser(context.Background(), newuser)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package slashcommands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
@@ -248,7 +249,7 @@ func (*LoadTestProvider) SetupCommand(a *app.App, c request.CTX, args *model.Com
|
||||
if err := CreateBasicUser(a, client); err != nil {
|
||||
return &model.CommandResponse{Text: "Failed to create testing environment", ResponseType: model.CommandResponseTypeEphemeral}, err
|
||||
}
|
||||
_, _, err := client.Login(BTestUserEmail, BTestUserPassword)
|
||||
_, _, err := client.Login(context.Background(), BTestUserEmail, BTestUserPassword)
|
||||
if err != nil {
|
||||
return &model.CommandResponse{Text: "Failed to create testing environment", ResponseType: model.CommandResponseTypeEphemeral}, err
|
||||
}
|
||||
@@ -604,7 +605,7 @@ func (*LoadTestProvider) PostCommand(a *app.App, c request.CTX, args *model.Comm
|
||||
}
|
||||
|
||||
client := model.NewAPIv4Client(args.SiteURL)
|
||||
_, _, nErr := client.LoginById(user.Id, passwd)
|
||||
_, _, nErr := client.LoginById(context.Background(), user.Id, passwd)
|
||||
if nErr != nil {
|
||||
return &model.CommandResponse{Text: "Failed to login a user", ResponseType: model.CommandResponseTypeEphemeral}, nErr
|
||||
}
|
||||
@@ -613,7 +614,7 @@ func (*LoadTestProvider) PostCommand(a *app.App, c request.CTX, args *model.Comm
|
||||
ChannelId: channel.Id,
|
||||
Message: textMessage,
|
||||
}
|
||||
_, _, nErr = client.CreatePost(post)
|
||||
_, _, nErr = client.CreatePost(context.Background(), post)
|
||||
if nErr != nil {
|
||||
return &model.CommandResponse{Text: "Failed to create a post", ResponseType: model.CommandResponseTypeEphemeral}, nErr
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package manualtesting
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"hash/fnv"
|
||||
"math/rand"
|
||||
@@ -107,7 +108,7 @@ func manualTest(c *web.Context, w http.ResponseWriter, r *http.Request) {
|
||||
Nickname: username[0],
|
||||
Password: slashcommands.UserPassword}
|
||||
|
||||
user, _, err = client.CreateUser(user)
|
||||
user, _, err = client.CreateUser(context.Background(), user)
|
||||
if err != nil {
|
||||
var appErr *model.AppError
|
||||
ok = errors.As(err, &appErr)
|
||||
@@ -126,7 +127,7 @@ func manualTest(c *web.Context, w http.ResponseWriter, r *http.Request) {
|
||||
userID = user.Id
|
||||
|
||||
// Login as user to generate auth token
|
||||
_, _, err = client.LoginById(user.Id, slashcommands.UserPassword)
|
||||
_, _, err = client.LoginById(context.Background(), user.Id, slashcommands.UserPassword)
|
||||
if err != nil {
|
||||
var appErr *model.AppError
|
||||
ok = errors.As(err, &appErr)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package manualtesting
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
@@ -32,7 +33,7 @@ func testAutoLink(env TestEnvironment) *model.AppError {
|
||||
post := &model.Post{
|
||||
ChannelId: channelID,
|
||||
Message: linkPostText}
|
||||
_, _, err := env.Client.CreatePost(post)
|
||||
_, _, err := env.Client.CreatePost(context.Background(), post)
|
||||
|
||||
var appErr *model.AppError
|
||||
if ok = errors.As(err, &appErr); !ok {
|
||||
|
||||
@@ -80,7 +80,7 @@ func TestAuthorizeOAuthApp(t *testing.T) {
|
||||
}
|
||||
|
||||
// Test auth code flow
|
||||
ruri, _, err := apiClient.AuthorizeOAuthApp(authRequest)
|
||||
ruri, _, err := apiClient.AuthorizeOAuthApp(context.Background(), authRequest)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NotEmpty(t, ruri, "redirect url should be set")
|
||||
@@ -92,7 +92,7 @@ func TestAuthorizeOAuthApp(t *testing.T) {
|
||||
|
||||
// Test implicit flow
|
||||
authRequest.ResponseType = model.ImplicitResponseType
|
||||
ruri, _, err = apiClient.AuthorizeOAuthApp(authRequest)
|
||||
ruri, _, err = apiClient.AuthorizeOAuthApp(context.Background(), authRequest)
|
||||
require.NoError(t, err)
|
||||
require.False(t, ruri == "", "redirect url should be set")
|
||||
|
||||
@@ -105,36 +105,36 @@ func TestAuthorizeOAuthApp(t *testing.T) {
|
||||
|
||||
oldToken := apiClient.AuthToken
|
||||
apiClient.AuthToken = values.Get("access_token")
|
||||
_, resp, err := apiClient.AuthorizeOAuthApp(authRequest)
|
||||
_, resp, err := apiClient.AuthorizeOAuthApp(context.Background(), authRequest)
|
||||
require.Error(t, err)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
apiClient.AuthToken = oldToken
|
||||
|
||||
authRequest.RedirectURI = ""
|
||||
_, resp, err = apiClient.AuthorizeOAuthApp(authRequest)
|
||||
_, resp, err = apiClient.AuthorizeOAuthApp(context.Background(), authRequest)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
authRequest.RedirectURI = "http://somewhereelse.com"
|
||||
_, resp, err = apiClient.AuthorizeOAuthApp(authRequest)
|
||||
_, resp, err = apiClient.AuthorizeOAuthApp(context.Background(), authRequest)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
authRequest.RedirectURI = rapp.CallbackUrls[0]
|
||||
authRequest.ResponseType = ""
|
||||
_, resp, err = apiClient.AuthorizeOAuthApp(authRequest)
|
||||
_, resp, err = apiClient.AuthorizeOAuthApp(context.Background(), authRequest)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
authRequest.ResponseType = model.AuthCodeResponseType
|
||||
authRequest.ClientId = ""
|
||||
_, resp, err = apiClient.AuthorizeOAuthApp(authRequest)
|
||||
_, resp, err = apiClient.AuthorizeOAuthApp(context.Background(), authRequest)
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
authRequest.ClientId = model.NewId()
|
||||
_, resp, err = apiClient.AuthorizeOAuthApp(authRequest)
|
||||
_, resp, err = apiClient.AuthorizeOAuthApp(context.Background(), authRequest)
|
||||
require.Error(t, err)
|
||||
CheckNotFoundStatus(t, resp)
|
||||
|
||||
@@ -157,7 +157,7 @@ func TestAuthorizeOAuthApp(t *testing.T) {
|
||||
Scope: "",
|
||||
State: "123",
|
||||
}
|
||||
uriResponse, _, err := apiClient.AuthorizeOAuthApp(authRequest)
|
||||
uriResponse, _, err := apiClient.AuthorizeOAuthApp(context.Background(), authRequest)
|
||||
require.NoError(t, err)
|
||||
ru, _ = url.Parse(uriResponse)
|
||||
require.NotEmpty(t, uriResponse, "redirect url should be set")
|
||||
@@ -198,21 +198,21 @@ func TestDeauthorizeOAuthApp(t *testing.T) {
|
||||
State: "123",
|
||||
}
|
||||
|
||||
_, _, err := apiClient.AuthorizeOAuthApp(authRequest)
|
||||
_, _, err := apiClient.AuthorizeOAuthApp(context.Background(), authRequest)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = apiClient.DeauthorizeOAuthApp(rapp.Id)
|
||||
_, err = apiClient.DeauthorizeOAuthApp(context.Background(), rapp.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
resp, err := apiClient.DeauthorizeOAuthApp("junk")
|
||||
resp, err := apiClient.DeauthorizeOAuthApp(context.Background(), "junk")
|
||||
require.Error(t, err)
|
||||
CheckBadRequestStatus(t, resp)
|
||||
|
||||
_, err = apiClient.DeauthorizeOAuthApp(model.NewId())
|
||||
_, err = apiClient.DeauthorizeOAuthApp(context.Background(), model.NewId())
|
||||
require.NoError(t, err)
|
||||
|
||||
th.Logout(apiClient)
|
||||
resp, err = apiClient.DeauthorizeOAuthApp(rapp.Id)
|
||||
resp, err = apiClient.DeauthorizeOAuthApp(context.Background(), rapp.Id)
|
||||
require.Error(t, err)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
}
|
||||
@@ -252,7 +252,7 @@ func TestOAuthAccessToken(t *testing.T) {
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = false })
|
||||
data := url.Values{"grant_type": []string{"junk"}, "client_id": []string{"12345678901234567890123456"}, "client_secret": []string{"12345678901234567890123456"}, "code": []string{"junk"}, "redirect_uri": []string{oauthApp.CallbackUrls[0]}}
|
||||
|
||||
_, _, err := apiClient.GetOAuthAccessToken(data)
|
||||
_, _, err := apiClient.GetOAuthAccessToken(context.Background(), data)
|
||||
require.Error(t, err, "should have failed - oauth providing turned off")
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOAuthServiceProvider = true })
|
||||
|
||||
@@ -264,47 +264,47 @@ func TestOAuthAccessToken(t *testing.T) {
|
||||
State: "123",
|
||||
}
|
||||
|
||||
redirect, _, err := apiClient.AuthorizeOAuthApp(authRequest)
|
||||
redirect, _, err := apiClient.AuthorizeOAuthApp(context.Background(), authRequest)
|
||||
require.NoError(t, err)
|
||||
rurl, _ := url.Parse(redirect)
|
||||
|
||||
apiClient.Logout()
|
||||
apiClient.Logout(context.Background())
|
||||
|
||||
data = url.Values{"grant_type": []string{"junk"}, "client_id": []string{oauthApp.Id}, "client_secret": []string{oauthApp.ClientSecret}, "code": []string{rurl.Query().Get("code")}, "redirect_uri": []string{oauthApp.CallbackUrls[0]}}
|
||||
|
||||
_, _, err = apiClient.GetOAuthAccessToken(data)
|
||||
_, _, err = apiClient.GetOAuthAccessToken(context.Background(), data)
|
||||
require.Error(t, err, "should have failed - bad grant type")
|
||||
|
||||
data.Set("grant_type", model.AccessTokenGrantType)
|
||||
data.Set("client_id", "")
|
||||
_, _, err = apiClient.GetOAuthAccessToken(data)
|
||||
_, _, err = apiClient.GetOAuthAccessToken(context.Background(), data)
|
||||
require.Error(t, err, "should have failed - missing client id")
|
||||
|
||||
data.Set("client_id", "junk")
|
||||
_, _, err = apiClient.GetOAuthAccessToken(data)
|
||||
_, _, err = apiClient.GetOAuthAccessToken(context.Background(), data)
|
||||
require.Error(t, err, "should have failed - bad client id")
|
||||
|
||||
data.Set("client_id", oauthApp.Id)
|
||||
data.Set("client_secret", "")
|
||||
_, _, err = apiClient.GetOAuthAccessToken(data)
|
||||
_, _, err = apiClient.GetOAuthAccessToken(context.Background(), data)
|
||||
require.Error(t, err, "should have failed - missing client secret")
|
||||
|
||||
data.Set("client_secret", "junk")
|
||||
_, _, err = apiClient.GetOAuthAccessToken(data)
|
||||
_, _, err = apiClient.GetOAuthAccessToken(context.Background(), data)
|
||||
require.Error(t, err, "should have failed - bad client secret")
|
||||
|
||||
data.Set("client_secret", oauthApp.ClientSecret)
|
||||
data.Set("code", "")
|
||||
_, _, err = apiClient.GetOAuthAccessToken(data)
|
||||
_, _, err = apiClient.GetOAuthAccessToken(context.Background(), data)
|
||||
require.Error(t, err, "should have failed - missing code")
|
||||
|
||||
data.Set("code", "junk")
|
||||
_, _, err = apiClient.GetOAuthAccessToken(data)
|
||||
_, _, err = apiClient.GetOAuthAccessToken(context.Background(), data)
|
||||
require.Error(t, err, "should have failed - bad code")
|
||||
|
||||
data.Set("code", rurl.Query().Get("code"))
|
||||
data.Set("redirect_uri", "junk")
|
||||
_, _, err = apiClient.GetOAuthAccessToken(data)
|
||||
_, _, err = apiClient.GetOAuthAccessToken(context.Background(), data)
|
||||
require.Error(t, err, "should have failed - non-matching redirect uri")
|
||||
|
||||
// reset data for successful request
|
||||
@@ -316,29 +316,29 @@ func TestOAuthAccessToken(t *testing.T) {
|
||||
|
||||
token := ""
|
||||
refreshToken := ""
|
||||
rsp, _, err := apiClient.GetOAuthAccessToken(data)
|
||||
rsp, _, err := apiClient.GetOAuthAccessToken(context.Background(), data)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, rsp.AccessToken, "access token not returned")
|
||||
require.NotEmpty(t, rsp.RefreshToken, "refresh token not returned")
|
||||
token, refreshToken = rsp.AccessToken, rsp.RefreshToken
|
||||
require.Equal(t, rsp.TokenType, model.AccessTokenType, "access token type incorrect")
|
||||
|
||||
_, err = apiClient.DoAPIGet("/oauth_test", "")
|
||||
_, err = apiClient.DoAPIGet(context.Background(), "/oauth_test", "")
|
||||
require.NoError(t, err)
|
||||
|
||||
apiClient.SetOAuthToken("")
|
||||
_, err = apiClient.DoAPIGet("/oauth_test", "")
|
||||
_, err = apiClient.DoAPIGet(context.Background(), "/oauth_test", "")
|
||||
require.Error(t, err, "should have failed - no access token provided")
|
||||
|
||||
apiClient.SetOAuthToken("badtoken")
|
||||
_, err = apiClient.DoAPIGet("/oauth_test", "")
|
||||
_, err = apiClient.DoAPIGet(context.Background(), "/oauth_test", "")
|
||||
require.Error(t, err, "should have failed - bad token provided")
|
||||
|
||||
apiClient.SetOAuthToken(token)
|
||||
_, err = apiClient.DoAPIGet("/oauth_test", "")
|
||||
_, err = apiClient.DoAPIGet(context.Background(), "/oauth_test", "")
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, err = apiClient.GetOAuthAccessToken(data)
|
||||
_, _, err = apiClient.GetOAuthAccessToken(context.Background(), data)
|
||||
require.Error(t, err, "should have failed - tried to reuse auth code")
|
||||
|
||||
data.Set("grant_type", model.RefreshTokenGrantType)
|
||||
@@ -347,11 +347,11 @@ func TestOAuthAccessToken(t *testing.T) {
|
||||
data.Set("refresh_token", "")
|
||||
data.Set("redirect_uri", oauthApp.CallbackUrls[0])
|
||||
data.Del("code")
|
||||
_, _, err = apiClient.GetOAuthAccessToken(data)
|
||||
_, _, err = apiClient.GetOAuthAccessToken(context.Background(), data)
|
||||
require.Error(t, err, "Should have failed - refresh token empty")
|
||||
|
||||
data.Set("refresh_token", refreshToken)
|
||||
rsp, _, err = apiClient.GetOAuthAccessToken(data)
|
||||
rsp, _, err = apiClient.GetOAuthAccessToken(context.Background(), data)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, rsp.AccessToken, "access token not returned")
|
||||
require.NotEmpty(t, rsp.RefreshToken, "refresh token not returned")
|
||||
@@ -359,11 +359,11 @@ func TestOAuthAccessToken(t *testing.T) {
|
||||
require.Equal(t, rsp.TokenType, model.AccessTokenType, "access token type incorrect")
|
||||
|
||||
apiClient.SetOAuthToken(rsp.AccessToken)
|
||||
_, err = apiClient.DoAPIGet("/oauth_test", "")
|
||||
_, err = apiClient.DoAPIGet(context.Background(), "/oauth_test", "")
|
||||
require.NoError(t, err)
|
||||
|
||||
data.Set("refresh_token", rsp.RefreshToken)
|
||||
rsp, _, err = apiClient.GetOAuthAccessToken(data)
|
||||
rsp, _, err = apiClient.GetOAuthAccessToken(context.Background(), data)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, rsp.AccessToken, "access token not returned")
|
||||
require.NotEmpty(t, rsp.RefreshToken, "refresh token not returned")
|
||||
@@ -371,7 +371,7 @@ func TestOAuthAccessToken(t *testing.T) {
|
||||
require.Equal(t, rsp.TokenType, model.AccessTokenType, "access token type incorrect")
|
||||
|
||||
apiClient.SetOAuthToken(rsp.AccessToken)
|
||||
_, err = apiClient.DoAPIGet("/oauth_test", "")
|
||||
_, err = apiClient.DoAPIGet(context.Background(), "/oauth_test", "")
|
||||
require.NoError(t, err)
|
||||
|
||||
authData := &model.AuthData{ClientId: oauthApp.Id, RedirectUri: oauthApp.CallbackUrls[0], UserId: th.BasicUser.Id, Code: model.NewId(), ExpiresIn: -1}
|
||||
@@ -384,7 +384,7 @@ func TestOAuthAccessToken(t *testing.T) {
|
||||
data.Set("redirect_uri", oauthApp.CallbackUrls[0])
|
||||
data.Set("code", authData.Code)
|
||||
data.Del("refresh_token")
|
||||
_, _, err = apiClient.GetOAuthAccessToken(data)
|
||||
_, _, err = apiClient.GetOAuthAccessToken(context.Background(), data)
|
||||
require.Error(t, err, "Should have failed - code is expired")
|
||||
|
||||
apiClient.ClearOAuthToken()
|
||||
@@ -529,7 +529,7 @@ func TestOAuthComplete(t *testing.T) {
|
||||
State: "123",
|
||||
}
|
||||
|
||||
redirect, _, err := apiClient.AuthorizeOAuthApp(authRequest)
|
||||
redirect, _, err := apiClient.AuthorizeOAuthApp(context.Background(), authRequest)
|
||||
require.NoError(t, err)
|
||||
rurl, _ := url.Parse(redirect)
|
||||
|
||||
@@ -547,7 +547,7 @@ func TestOAuthComplete(t *testing.T) {
|
||||
|
||||
einterfaces.RegisterOAuthProvider(model.ServiceGitlab, provider)
|
||||
|
||||
redirect, _, err = apiClient.AuthorizeOAuthApp(authRequest)
|
||||
redirect, _, err = apiClient.AuthorizeOAuthApp(context.Background(), authRequest)
|
||||
require.NoError(t, err)
|
||||
rurl, _ = url.Parse(redirect)
|
||||
|
||||
@@ -561,7 +561,7 @@ func TestOAuthComplete(t *testing.T) {
|
||||
th.BasicUser.Id, model.ServiceGitlab, &th.BasicUser.Email, th.BasicUser.Email, true)
|
||||
require.NoError(t, nErr)
|
||||
|
||||
redirect, _, err = apiClient.AuthorizeOAuthApp(authRequest)
|
||||
redirect, _, err = apiClient.AuthorizeOAuthApp(context.Background(), authRequest)
|
||||
require.NoError(t, err)
|
||||
rurl, _ = url.Parse(redirect)
|
||||
|
||||
@@ -572,7 +572,7 @@ func TestOAuthComplete(t *testing.T) {
|
||||
closeBody(r)
|
||||
}
|
||||
|
||||
redirect, _, err = apiClient.AuthorizeOAuthApp(authRequest)
|
||||
redirect, _, err = apiClient.AuthorizeOAuthApp(context.Background(), authRequest)
|
||||
require.NoError(t, err)
|
||||
rurl, _ = url.Parse(redirect)
|
||||
|
||||
@@ -583,7 +583,7 @@ func TestOAuthComplete(t *testing.T) {
|
||||
closeBody(r)
|
||||
}
|
||||
|
||||
redirect, _, err = apiClient.AuthorizeOAuthApp(authRequest)
|
||||
redirect, _, err = apiClient.AuthorizeOAuthApp(context.Background(), authRequest)
|
||||
require.NoError(t, err)
|
||||
rurl, _ = url.Parse(redirect)
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user