diff --git a/server/.golangci.yml b/server/.golangci.yml index d2c9179776..2536d8a68f 100644 --- a/server/.golangci.yml +++ b/server/.golangci.yml @@ -86,7 +86,6 @@ linters: - errcheck path: "\ channels/api4/apitestlib.go|\ - channels/api4/channel_test.go|\ channels/app/helper_test.go|\ channels/app/platform/helper_test.go|\ channels/store/localcachelayer/channel_layer.go|\ diff --git a/server/channels/api4/channel_test.go b/server/channels/api4/channel_test.go index fce6792ac4..bf1ead14be 100644 --- a/server/channels/api4/channel_test.go +++ b/server/channels/api4/channel_test.go @@ -7,7 +7,6 @@ import ( "context" "encoding/json" "fmt" - "io" "net/http" "sort" "strings" @@ -60,13 +59,15 @@ func TestCreateChannel(t *testing.T) { CheckErrorID(t, err, "api.channel.create_channel.direct_channel.app_error") CheckBadRequestStatus(t, resp) - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) _, resp, err = client.CreateChannel(context.Background(), channel) require.Error(t, err) CheckUnauthorizedStatus(t, resp) userNotOnTeam := th.CreateUser() - client.Login(context.Background(), userNotOnTeam.Email, userNotOnTeam.Password) + _, _, err = client.Login(context.Background(), userNotOnTeam.Email, userNotOnTeam.Password) + require.NoError(t, err) _, resp, err = client.CreateChannel(context.Background(), channel) require.Error(t, err) @@ -213,8 +214,10 @@ func TestUpdateChannel(t *testing.T) { channel := &model.Channel{DisplayName: "Test API Name", Name: GenerateTestChannelName(), Type: model.ChannelTypeOpen, TeamId: team.Id} private := &model.Channel{DisplayName: "Test API Name", Name: GenerateTestChannelName(), Type: model.ChannelTypePrivate, TeamId: team.Id} - channel, _, _ = client.CreateChannel(context.Background(), channel) - private, _, _ = client.CreateChannel(context.Background(), private) + channel, _, err := client.CreateChannel(context.Background(), channel) + require.NoError(t, err) + private, _, err = client.CreateChannel(context.Background(), private) + require.NoError(t, err) // Update a open channel channel.DisplayName = "My new display name" @@ -249,7 +252,8 @@ func TestUpdateChannel(t *testing.T) { require.Equal(t, private.Purpose, newPrivateChannel.Purpose, "Update failed for Purpose in private channel") // Test updating default channel's name and returns error - defaultChannel, _ := th.App.GetChannelByName(th.Context, model.DefaultChannelName, team.Id, false) + defaultChannel, appErr := th.App.GetChannelByName(th.Context, model.DefaultChannelName, team.Id, false) + require.Nil(t, appErr) defaultChannel.Name = "testing" _, resp, err = client.UpdateChannel(context.Background(), defaultChannel) require.Error(t, err) @@ -274,14 +278,16 @@ func TestUpdateChannel(t *testing.T) { CheckNotFoundStatus(t, resp) // Try to update with not logged user - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) _, resp, err = client.UpdateChannel(context.Background(), channel) require.Error(t, err) CheckUnauthorizedStatus(t, resp) // Try to update using another user user := th.CreateUser() - client.Login(context.Background(), user.Email, user.Password) + _, _, err = client.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) channel.DisplayName = "Should not update" _, resp, err = client.UpdateChannel(context.Background(), channel) @@ -297,22 +303,28 @@ func TestUpdateChannel(t *testing.T) { require.NoError(t, err) groupChannel.Header = "lolololol" - client.Logout(context.Background()) - client.Login(context.Background(), user3.Email, user3.Password) + _, err = client.Logout(context.Background()) + require.NoError(t, err) + _, _, err = client.Login(context.Background(), user3.Email, user3.Password) + require.NoError(t, err) _, resp, err = client.UpdateChannel(context.Background(), groupChannel) require.Error(t, err) CheckForbiddenStatus(t, resp) // Test updating the header of someone else's GM channel. - client.Logout(context.Background()) - client.Login(context.Background(), user.Email, user.Password) + _, err = client.Logout(context.Background()) + require.NoError(t, err) + _, _, err = client.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) directChannel, _, err := client.CreateDirectChannel(context.Background(), user.Id, user1.Id) require.NoError(t, err) directChannel.Header = "lolololol" - client.Logout(context.Background()) - client.Login(context.Background(), user3.Email, user3.Password) + _, err = client.Logout(context.Background()) + require.NoError(t, err) + _, _, err = client.Login(context.Background(), user3.Email, user3.Password) + require.NoError(t, err) _, resp, err = client.UpdateChannel(context.Background(), directChannel) require.Error(t, err) CheckForbiddenStatus(t, resp) @@ -330,8 +342,10 @@ func TestUpdateChannel(t *testing.T) { user2 := th.CreateUser() user3 := th.CreateUser() - client.Logout(context.Background()) - client.Login(context.Background(), user1.Email, user1.Password) + _, err := client.Logout(context.Background()) + require.NoError(t, err) + _, _, err = client.Login(context.Background(), user1.Email, user1.Password) + require.NoError(t, err) groupChannel, _, err := client.CreateGroupChannel(context.Background(), []string{user1.Id, user2.Id, user3.Id}) require.NoError(t, err) @@ -356,8 +370,10 @@ func TestUpdateChannel(t *testing.T) { user1 := th.CreateUser() user2 := th.CreateUser() - client.Logout(context.Background()) - client.Login(context.Background(), user1.Email, user1.Password) + _, err := client.Logout(context.Background()) + require.NoError(t, err) + _, _, err = client.Login(context.Background(), user1.Email, user1.Password) + require.NoError(t, err) directChannel, _, err := client.CreateDirectChannel(context.Background(), user1.Id, user2.Id) require.NoError(t, err) @@ -440,7 +456,8 @@ func TestPatchChannel(t *testing.T) { t.Run("Test updating default channel's name and returns error", func(t *testing.T) { // Test updating default channel's name and returns error - defaultChannel, _ := th.App.GetChannelByName(th.Context, model.DefaultChannelName, team.Id, false) + defaultChannel, appErr := th.App.GetChannelByName(th.Context, model.DefaultChannelName, team.Id, false) + require.Nil(t, appErr) defaultChannelPatch := &model.ChannelPatch{ Name: new(string), } @@ -470,7 +487,8 @@ func TestPatchChannel(t *testing.T) { CheckNotFoundStatus(t, resp) user := th.CreateUser() - client.Login(context.Background(), user.Email, user.Password) + _, _, err = client.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) _, resp, err = client.PatchChannel(context.Background(), th.BasicChannel.Id, patch) require.Error(t, err) CheckForbiddenStatus(t, resp) @@ -485,11 +503,13 @@ func TestPatchChannel(t *testing.T) { }) t.Run("Test GroupConstrained flag set to true and non group members are removed", func(t *testing.T) { - client.Logout(context.Background()) + _, err := client.Logout(context.Background()) + require.NoError(t, err) th.LoginBasic() th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuEnterprise)) defer func() { - th.App.Srv().RemoveLicense() + appErr := th.App.Srv().RemoveLicense() + require.Nil(t, appErr) }() // Create a test group @@ -550,11 +570,13 @@ func TestPatchChannel(t *testing.T) { }) t.Run("Test GroupConstrained flag changed from true to false and non group members are not removed", func(t *testing.T) { - client.Logout(context.Background()) + _, err := client.Logout(context.Background()) + require.NoError(t, err) th.LoginBasic() th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuEnterprise)) defer func() { - th.App.Srv().RemoveLicense() + appErr := th.App.Srv().RemoveLicense() + require.Nil(t, appErr) }() // Create a test group @@ -656,8 +678,10 @@ func TestPatchChannel(t *testing.T) { groupChannel, _, err := client.CreateGroupChannel(context.Background(), []string{user1.Id, user2.Id}) require.NoError(t, err) - client.Logout(context.Background()) - client.Login(context.Background(), user3.Email, user3.Password) + _, err = client.Logout(context.Background()) + require.NoError(t, err) + _, _, err = client.Login(context.Background(), user3.Email, user3.Password) + require.NoError(t, err) channelPatch := &model.ChannelPatch{} channelPatch.Header = new(string) @@ -667,14 +691,18 @@ func TestPatchChannel(t *testing.T) { require.Error(t, err) CheckForbiddenStatus(t, resp) - client.Logout(context.Background()) - client.Login(context.Background(), user.Email, user.Password) + _, err = client.Logout(context.Background()) + require.NoError(t, err) + _, _, err = client.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) directChannel, _, err := client.CreateDirectChannel(context.Background(), user.Id, user1.Id) require.NoError(t, err) - client.Logout(context.Background()) - client.Login(context.Background(), user3.Email, user3.Password) + _, err = client.Logout(context.Background()) + require.NoError(t, err) + _, _, err = client.Login(context.Background(), user3.Email, user3.Password) + require.NoError(t, err) _, resp, err = client.PatchChannel(context.Background(), directChannel.Id, channelPatch) require.Error(t, err) CheckForbiddenStatus(t, resp) @@ -685,8 +713,10 @@ func TestPatchChannel(t *testing.T) { user2 := th.CreateUser() user3 := th.CreateUser() - client.Logout(context.Background()) - client.Login(context.Background(), user1.Email, user1.Password) + _, err := client.Logout(context.Background()) + require.NoError(t, err) + _, _, err = client.Login(context.Background(), user1.Email, user1.Password) + require.NoError(t, err) groupChannel, _, err := client.CreateGroupChannel(context.Background(), []string{user1.Id, user2.Id, user3.Id}) require.NoError(t, err) @@ -720,8 +750,10 @@ func TestPatchChannel(t *testing.T) { user1 := th.CreateUser() user2 := th.CreateUser() - client.Logout(context.Background()) - client.Login(context.Background(), user1.Email, user1.Password) + _, err := client.Logout(context.Background()) + require.NoError(t, err) + _, _, err = client.Login(context.Background(), user1.Email, user1.Password) + require.NoError(t, err) directChannel, _, err := client.CreateDirectChannel(context.Background(), user1.Id, user2.Id) require.NoError(t, err) @@ -752,9 +784,11 @@ func TestPatchChannel(t *testing.T) { }) t.Run("Should not be able to configure channel banner without a license", func(t *testing.T) { - client.Logout(context.Background()) + _, err := client.Logout(context.Background()) + require.NoError(t, err) th.LoginBasic() - th.App.Srv().RemoveLicense() + appErr := th.App.Srv().RemoveLicense() + require.Nil(t, appErr) channel := &model.Channel{ DisplayName: GenerateTestChannelName(), @@ -762,7 +796,6 @@ func TestPatchChannel(t *testing.T) { Type: model.ChannelTypeOpen, TeamId: team.Id, } - var err error channel, _, err = client.CreateChannel(context.Background(), channel) require.NoError(t, err) @@ -781,11 +814,13 @@ func TestPatchChannel(t *testing.T) { }) t.Run("Should not be able to configure channel banner with a professional license", func(t *testing.T) { - client.Logout(context.Background()) + _, err := client.Logout(context.Background()) + require.NoError(t, err) th.LoginBasic() th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuProfessional)) defer func() { - th.App.Srv().RemoveLicense() + appErr := th.App.Srv().RemoveLicense() + require.Nil(t, appErr) }() channel := &model.Channel{ @@ -794,7 +829,6 @@ func TestPatchChannel(t *testing.T) { Type: model.ChannelTypeOpen, TeamId: team.Id, } - var err error channel, _, err = client.CreateChannel(context.Background(), channel) require.NoError(t, err) @@ -817,11 +851,13 @@ func TestPatchChannel(t *testing.T) { t.Skip("Channel banner tests are not supported on MySQL") } - client.Logout(context.Background()) + _, err := client.Logout(context.Background()) + require.NoError(t, err) th.LoginBasic() th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuEnterpriseAdvanced)) defer func() { - th.App.Srv().RemoveLicense() + appErr := th.App.Srv().RemoveLicense() + require.Nil(t, appErr) }() channel := &model.Channel{ @@ -830,7 +866,6 @@ func TestPatchChannel(t *testing.T) { Type: model.ChannelTypeOpen, TeamId: team.Id, } - var err error channel, _, err = client.CreateChannel(context.Background(), channel) require.NoError(t, err) @@ -852,11 +887,13 @@ func TestPatchChannel(t *testing.T) { }) t.Run("Should not be able to configure channel banner on a channel as a non-admin channel member", func(t *testing.T) { - client.Logout(context.Background()) + _, err := client.Logout(context.Background()) + require.NoError(t, err) th.LoginBasic() th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuEnterpriseAdvanced)) defer func() { - th.App.Srv().RemoveLicense() + appErr := th.App.Srv().RemoveLicense() + require.Nil(t, appErr) }() patch := &model.ChannelPatch{ @@ -877,11 +914,13 @@ func TestPatchChannel(t *testing.T) { t.Skip("Channel banner tests are not supported on MySQL") } - client.Logout(context.Background()) + _, err := client.Logout(context.Background()) + require.NoError(t, err) th.LoginTeamAdmin() th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuEnterpriseAdvanced)) defer func() { - th.App.Srv().RemoveLicense() + appErr := th.App.Srv().RemoveLicense() + require.Nil(t, appErr) }() patch := &model.ChannelPatch{ @@ -906,11 +945,13 @@ func TestPatchChannel(t *testing.T) { t.Skip("Channel banner tests are not supported on MySQL") } - client.Logout(context.Background()) + _, err := client.Logout(context.Background()) + require.NoError(t, err) th.LoginBasic() th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuEnterpriseAdvanced)) defer func() { - th.App.Srv().RemoveLicense() + appErr := th.App.Srv().RemoveLicense() + require.Nil(t, appErr) }() channel := &model.Channel{ @@ -919,7 +960,6 @@ func TestPatchChannel(t *testing.T) { Type: model.ChannelTypeOpen, TeamId: team.Id, } - var err error channel, _, err = client.CreateChannel(context.Background(), channel) require.NoError(t, err) @@ -966,11 +1006,13 @@ func TestPatchChannel(t *testing.T) { }) t.Run("Cannot configure channel banner on a DM channel", func(t *testing.T) { - client.Logout(context.Background()) + _, err := client.Logout(context.Background()) + require.NoError(t, err) th.LoginBasic() th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuEnterpriseAdvanced)) defer func() { - th.App.Srv().RemoveLicense() + appErr := th.App.Srv().RemoveLicense() + require.Nil(t, appErr) }() dmChannel, resp, err := client.CreateDirectChannel(context.Background(), th.BasicUser.Id, th.BasicUser2.Id) @@ -993,11 +1035,13 @@ func TestPatchChannel(t *testing.T) { }) t.Run("Cannot configure channel banner on a GM channel", func(t *testing.T) { - client.Logout(context.Background()) + _, err := client.Logout(context.Background()) + require.NoError(t, err) th.LoginBasic() th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuEnterpriseAdvanced)) defer func() { - th.App.Srv().RemoveLicense() + appErr := th.App.Srv().RemoveLicense() + require.Nil(t, appErr) }() user3 := th.CreateUser() @@ -1196,7 +1240,8 @@ func TestChannelUnicodeNames(t *testing.T) { Type: model.ChannelTypeOpen, TeamId: team.Id, } - channel, _, _ = client.CreateChannel(context.Background(), channel) + channel, _, err := client.CreateChannel(context.Background(), channel) + require.NoError(t, err) channel.Name = "\u206ahistorychannel" channel.DisplayName = "UFO's and \ufff9stuff\ufffb." @@ -1283,7 +1328,8 @@ func TestCreateDirectChannel(t *testing.T) { _, _, err = th.Client.CreateDirectChannel(context.Background(), user1.Id, user4.Id) require.NoError(t, err) - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) _, resp, err = client.CreateDirectChannel(context.Background(), model.NewId(), user2.Id) require.Error(t, err) CheckUnauthorizedStatus(t, resp) @@ -1299,7 +1345,8 @@ func TestCreateDirectChannelAsGuest(t *testing.T) { enableGuestAccounts := *th.App.Config().GuestAccountsSettings.Enable defer func() { th.App.UpdateConfig(func(cfg *model.Config) { *cfg.GuestAccountsSettings.Enable = enableGuestAccounts }) - th.App.Srv().RemoveLicense() + appErr := th.App.Srv().RemoveLicense() + require.Nil(t, appErr) }() th.App.UpdateConfig(func(cfg *model.Config) { *cfg.GuestAccountsSettings.Enable = true }) th.App.Srv().SetLicense(model.NewTestLicense()) @@ -1373,7 +1420,8 @@ func TestCreateGroupChannel(t *testing.T) { require.NotNil(t, rgc, "should have created a group channel") require.Equal(t, model.ChannelTypeGroup, rgc.Type, "should have created a channel of group type") - m, _ := th.App.GetChannelMembersPage(th.Context, rgc.Id, 0, 10) + m, appErr := th.App.GetChannelMembersPage(th.Context, rgc.Id, 0, 10) + require.Nil(t, appErr) require.Len(t, m, 3, "should have 3 channel members") // saving duplicate group channel @@ -1381,7 +1429,8 @@ func TestCreateGroupChannel(t *testing.T) { require.NoError(t, err) require.Equal(t, rgc.Id, rgc2.Id, "should have returned existing channel") - m2, _ := th.App.GetChannelMembersPage(th.Context, rgc2.Id, 0, 10) + m2, appErr := th.App.GetChannelMembersPage(th.Context, rgc2.Id, 0, 10) + require.Nil(t, appErr) require.ElementsMatch(t, m, m2) _, resp, err = client.CreateGroupChannel(context.Background(), []string{user2.Id}) @@ -1408,7 +1457,8 @@ func TestCreateGroupChannel(t *testing.T) { require.Error(t, err) CheckBadRequestStatus(t, resp) - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) _, resp, err = client.CreateGroupChannel(context.Background(), userIds) require.Error(t, err) @@ -1436,7 +1486,8 @@ func TestCreateGroupChannelAsGuest(t *testing.T) { enableGuestAccounts := *th.App.Config().GuestAccountsSettings.Enable defer func() { th.App.UpdateConfig(func(cfg *model.Config) { *cfg.GuestAccountsSettings.Enable = enableGuestAccounts }) - th.App.Srv().RemoveLicense() + appErr := th.App.Srv().RemoveLicense() + require.Nil(t, appErr) }() th.App.UpdateConfig(func(cfg *model.Config) { *cfg.GuestAccountsSettings.Enable = true }) th.App.Srv().SetLicense(model.NewTestLicense()) @@ -1516,7 +1567,8 @@ func TestGetChannel(t *testing.T) { require.NoError(t, err) require.Equal(t, th.BasicChannel.Id, channel.Id, "ids did not match") - client.RemoveUserFromChannel(context.Background(), th.BasicChannel.Id, th.BasicUser.Id) + _, err = client.RemoveUserFromChannel(context.Background(), th.BasicChannel.Id, th.BasicUser.Id) + require.NoError(t, err) _, _, err = client.GetChannel(context.Background(), th.BasicChannel.Id, "") require.NoError(t, err) @@ -1524,7 +1576,8 @@ func TestGetChannel(t *testing.T) { require.NoError(t, err) require.Equal(t, th.BasicPrivateChannel.Id, channel.Id, "ids did not match") - client.RemoveUserFromChannel(context.Background(), th.BasicPrivateChannel.Id, th.BasicUser.Id) + _, err = client.RemoveUserFromChannel(context.Background(), th.BasicPrivateChannel.Id, th.BasicUser.Id) + require.NoError(t, err) _, resp, err := client.GetChannel(context.Background(), th.BasicPrivateChannel.Id, "") require.Error(t, err) CheckForbiddenStatus(t, resp) @@ -1533,13 +1586,15 @@ func TestGetChannel(t *testing.T) { require.Error(t, err) CheckNotFoundStatus(t, resp) - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) _, resp, err = client.GetChannel(context.Background(), th.BasicChannel.Id, "") require.Error(t, err) CheckUnauthorizedStatus(t, resp) user := th.CreateUser() - client.Login(context.Background(), user.Email, user.Password) + _, _, err = client.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) _, resp, err = client.GetChannel(context.Background(), th.BasicChannel.Id, "") require.Error(t, err) CheckForbiddenStatus(t, resp) @@ -1573,7 +1628,8 @@ func TestGetDeletedChannelsForTeam(t *testing.T) { // create and delete public channel publicChannel1 := th.CreatePublicChannel() - client.DeleteChannel(context.Background(), publicChannel1.Id) + _, err = client.DeleteChannel(context.Background(), publicChannel1.Id) + require.NoError(t, err) th.TestForAllClients(t, func(t *testing.T, client *model.Client4) { channels, _, err = client.GetDeletedChannelsForTeam(context.Background(), team.Id, 0, 100, "") @@ -1582,7 +1638,8 @@ func TestGetDeletedChannelsForTeam(t *testing.T) { }) publicChannel2 := th.CreatePublicChannel() - client.DeleteChannel(context.Background(), publicChannel2.Id) + _, err = client.DeleteChannel(context.Background(), publicChannel2.Id) + require.NoError(t, err) th.TestForAllClients(t, func(t *testing.T, client *model.Client4) { channels, _, err = client.GetDeletedChannelsForTeam(context.Background(), team.Id, 0, 100, "") @@ -1593,7 +1650,8 @@ func TestGetDeletedChannelsForTeam(t *testing.T) { th.LoginBasic() privateChannel1 := th.CreatePrivateChannel() - client.DeleteChannel(context.Background(), privateChannel1.Id) + _, err = client.DeleteChannel(context.Background(), privateChannel1.Id) + require.NoError(t, err) channels, _, err = client.GetDeletedChannelsForTeam(context.Background(), team.Id, 0, 100, "") require.NoError(t, err) @@ -1602,7 +1660,8 @@ func TestGetDeletedChannelsForTeam(t *testing.T) { // Login as different user and create private channel th.LoginBasic2() privateChannel2 := th.CreatePrivateChannel() - client.DeleteChannel(context.Background(), privateChannel2.Id) + _, err = client.DeleteChannel(context.Background(), privateChannel2.Id) + require.NoError(t, err) // Log back in as first user th.LoginBasic() @@ -1627,7 +1686,8 @@ func TestGetDeletedChannelsForTeam(t *testing.T) { require.Len(t, channels, 1, "should be one channel per page") // test non team member - th.SystemAdminClient.RemoveTeamMember(context.Background(), team.Id, th.BasicUser.Id) + _, err = th.SystemAdminClient.RemoveTeamMember(context.Background(), team.Id, th.BasicUser.Id) + require.NoError(t, err) _, resp, err := client.GetDeletedChannelsForTeam(context.Background(), team.Id, 0, 100, "") require.Error(t, err) CheckForbiddenStatus(t, resp) @@ -1732,13 +1792,15 @@ func TestGetPublicChannelsForTeam(t *testing.T) { require.Error(t, err) CheckForbiddenStatus(t, resp) - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) _, resp, err = client.GetPublicChannelsForTeam(context.Background(), team.Id, 0, 100, "") require.Error(t, err) CheckUnauthorizedStatus(t, resp) user := th.CreateUser() - client.Login(context.Background(), user.Email, user.Password) + _, _, err = client.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) _, resp, err = client.GetPublicChannelsForTeam(context.Background(), team.Id, 0, 100, "") require.Error(t, err) CheckForbiddenStatus(t, resp) @@ -1797,7 +1859,8 @@ func TestGetPublicChannelsByIdsForTeam(t *testing.T) { require.Error(t, err) CheckNotFoundStatus(t, resp) - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) _, resp, err = client.GetPublicChannelsByIdsForTeam(context.Background(), teamId, input) require.Error(t, err) @@ -1834,7 +1897,9 @@ func TestGetChannelsForTeamForUser(t *testing.T) { require.True(t, f, "missing a channel") } - channels, resp, _ = client.GetChannelsForTeamForUser(context.Background(), th.BasicTeam.Id, th.BasicUser.Id, false, resp.Etag) + channels, resp, err = client.GetChannelsForTeamForUser(context.Background(), th.BasicTeam.Id, th.BasicUser.Id, false, resp.Etag) + // an error is expected as the server didn't return any data and the client still tries to unmarshal the response + require.Error(t, err) CheckEtag(t, channels, resp) _, resp, err = client.GetChannelsForTeamForUser(context.Background(), th.BasicTeam.Id, "junk", false, "") @@ -1865,12 +1930,18 @@ func TestGetChannelsForTeamForUser(t *testing.T) { TeamId: th.BasicTeam.Id, CreatorId: th.BasicUser.Id, } - th.App.CreateChannel(th.Context, testChannel, true) - defer th.App.PermanentDeleteChannel(th.Context, testChannel) + testChannel, appErr := th.App.CreateChannel(th.Context, testChannel, true) + require.Nil(t, appErr) + defer func() { + appErr = th.App.PermanentDeleteChannel(th.Context, testChannel) + require.Nil(t, appErr) + }() + channels, _, err := client.GetChannelsForTeamForUser(context.Background(), th.BasicTeam.Id, th.BasicUser.Id, false, "") require.NoError(t, err) assert.Equal(t, 6, len(channels)) - th.App.DeleteChannel(th.Context, testChannel, th.BasicUser.Id) + appErr = th.App.DeleteChannel(th.Context, testChannel, th.BasicUser.Id) + require.Nil(t, appErr) channels, _, err = client.GetChannelsForTeamForUser(context.Background(), th.BasicTeam.Id, th.BasicUser.Id, false, "") require.NoError(t, err) assert.Equal(t, 5, len(channels)) @@ -1882,8 +1953,9 @@ func TestGetChannelsForTeamForUser(t *testing.T) { // Should stil return all channels including basicDeleted. now := time.Now().Add(-time.Minute).Unix() * 1000 - client.GetChannelsForTeamAndUserWithLastDeleteAt(context.Background(), th.BasicTeam.Id, th.BasicUser.Id, + channels, _, err = client.GetChannelsForTeamAndUserWithLastDeleteAt(context.Background(), th.BasicTeam.Id, th.BasicUser.Id, true, int(now), "") + require.NoError(t, err) assert.Equal(t, 7, len(channels)) }) } @@ -1900,8 +1972,10 @@ func TestGetChannelsForUser(t *testing.T) { ch1 := th.CreateChannelWithClientAndTeam(client, model.ChannelTypeOpen, myTeam.Id) ch2 := th.CreateChannelWithClientAndTeam(client, model.ChannelTypePrivate, myTeam.Id) th.LinkUserToTeam(th.BasicUser, myTeam) - th.App.AddUserToChannel(th.Context, th.BasicUser, ch1, false) - th.App.AddUserToChannel(th.Context, th.BasicUser, ch2, false) + _, appErr := th.App.AddUserToChannel(th.Context, th.BasicUser, ch1, false) + require.Nil(t, appErr) + _, appErr = th.App.AddUserToChannel(th.Context, th.BasicUser, ch2, false) + require.Nil(t, appErr) channels, _, err := client.GetChannelsForUserWithLastDeleteAt(context.Background(), th.BasicUser.Id, 0) require.NoError(t, err) @@ -1933,7 +2007,8 @@ func TestGetChannelsForUser(t *testing.T) { // Creating some more channels to be exactly 100 to test page size boundaries. for i := 0; i < 91; i++ { ch1 = th.CreateChannelWithClientAndTeam(client, model.ChannelTypeOpen, myTeam.Id) - th.App.AddUserToChannel(th.Context, th.BasicUser, ch1, false) + _, appErr := th.App.AddUserToChannel(th.Context, th.BasicUser, ch1, false) + require.Nil(t, appErr) } channels, _, err = client.GetChannelsForUserWithLastDeleteAt(context.Background(), th.BasicUser.Id, 0) @@ -2216,7 +2291,8 @@ func TestSearchChannels(t *testing.T) { }) t.Run("Remove the user from BasicChannel and search again, should not be returned", func(t *testing.T) { - th.App.RemoveUserFromChannel(th.Context, th.BasicUser.Id, th.BasicUser.Id, th.BasicChannel) + appErr := th.App.RemoveUserFromChannel(th.Context, th.BasicUser.Id, th.BasicUser.Id, th.BasicChannel) + require.Nil(t, appErr) search.Term = th.BasicChannel.Name channelList, _, err := client.SearchChannels(context.Background(), th.BasicTeam.Id, search) @@ -2278,7 +2354,8 @@ func TestSearchArchivedChannels(t *testing.T) { search := &model.ChannelSearch{Term: th.BasicChannel.Name} - client.DeleteChannel(context.Background(), th.BasicChannel.Id) + _, err := client.DeleteChannel(context.Background(), th.BasicChannel.Id) + require.NoError(t, err) channels, _, err := client.SearchArchivedChannels(context.Background(), th.BasicTeam.Id, search) require.NoError(t, err) @@ -2295,7 +2372,8 @@ func TestSearchArchivedChannels(t *testing.T) { require.True(t, found) search.Term = th.BasicPrivateChannel.Name - client.DeleteChannel(context.Background(), th.BasicPrivateChannel.Id) + _, err = client.DeleteChannel(context.Background(), th.BasicPrivateChannel.Id) + require.NoError(t, err) channels, _, err = client.SearchArchivedChannels(context.Background(), th.BasicTeam.Id, search) require.NoError(t, err) @@ -2347,7 +2425,8 @@ func TestSearchArchivedChannels(t *testing.T) { }) t.Run("Remove the user from BasicDeletedChannel and search again, should still return", func(t *testing.T) { - th.App.RemoveUserFromChannel(th.Context, th.BasicUser.Id, th.BasicUser.Id, th.BasicDeletedChannel) + appErr := th.App.RemoveUserFromChannel(th.Context, th.BasicUser.Id, th.BasicUser.Id, th.BasicDeletedChannel) + require.Nil(t, appErr) search.Term = th.BasicDeletedChannel.Name channelList, _, err := client.SearchArchivedChannels(context.Background(), th.BasicTeam.Id, search) @@ -2683,11 +2762,9 @@ func TestSearchGroupChannels(t *testing.T) { // Create a group channel in which base user belongs but not sysadmin gc1, _, err := th.Client.CreateGroupChannel(context.Background(), []string{th.BasicUser.Id, th.BasicUser2.Id, u1.Id}) require.NoError(t, err) - defer th.Client.DeleteChannel(context.Background(), gc1.Id) gc2, _, err := th.Client.CreateGroupChannel(context.Background(), []string{th.BasicUser.Id, th.BasicUser2.Id, th.SystemAdminUser.Id}) require.NoError(t, err) - defer th.Client.DeleteChannel(context.Background(), gc2.Id) search := &model.ChannelSearch{Term: th.BasicUser2.Username} @@ -2699,7 +2776,8 @@ func TestSearchGroupChannels(t *testing.T) { assert.Equal(t, channels[0].Id, gc2.Id) // basic user should find both - client.Login(context.Background(), th.BasicUser.Username, th.BasicUser.Password) + _, _, err = client.Login(context.Background(), th.BasicUser.Username, th.BasicUser.Password) + require.NoError(t, err) channels, _, err = client.SearchGroupChannels(context.Background(), search) require.NoError(t, err) @@ -2726,14 +2804,16 @@ func TestSearchGroupChannels(t *testing.T) { assert.Empty(t, channels) // search unprivileged, forbidden - th.Client.Logout(context.Background()) + _, err = th.Client.Logout(context.Background()) + require.NoError(t, err) _, resp, err := client.SearchAllChannels(context.Background(), search) require.Error(t, err) CheckUnauthorizedStatus(t, resp) t.Run("search with null value", func(t *testing.T) { var search *model.ChannelSearch - client.Login(context.Background(), th.BasicUser.Username, th.BasicUser.Password) + _, _, err := client.Login(context.Background(), th.BasicUser.Username, th.BasicUser.Password) + require.NoError(t, err) _, resp, err := client.SearchGroupChannels(context.Background(), search) require.Error(t, err) @@ -2757,11 +2837,12 @@ func TestDeleteChannel(t *testing.T) { require.NoError(t, err) ch, appErr := th.App.GetChannel(th.Context, publicChannel1.Id) - require.Nilf(t, appErr, "Expected nil, Got %v", appErr) + require.Nil(t, appErr) require.True(t, ch.DeleteAt != 0, "should have returned one with a populated DeleteAt.") post1 := &model.Post{ChannelId: publicChannel1.Id, Message: "a" + GenerateTestID() + "a"} - _, resp, _ := client.CreatePost(context.Background(), post1) + _, resp, err := client.CreatePost(context.Background(), post1) + require.Error(t, err) require.NotNil(t, resp, "expected response to not be nil") // successful delete of private channel @@ -2771,13 +2852,16 @@ func TestDeleteChannel(t *testing.T) { // successful delete of channel with multiple members publicChannel3 := th.CreatePublicChannel() - th.App.AddUserToChannel(th.Context, user, publicChannel3, false) - th.App.AddUserToChannel(th.Context, user2, publicChannel3, false) + _, appErr = th.App.AddUserToChannel(th.Context, user, publicChannel3, false) + require.Nil(t, appErr) + _, appErr = th.App.AddUserToChannel(th.Context, user2, publicChannel3, false) + require.Nil(t, appErr) _, err = client.DeleteChannel(context.Background(), publicChannel3.Id) require.NoError(t, err) // default channel cannot be deleted. - defaultChannel, _ := th.App.GetChannelByName(th.Context, model.DefaultChannelName, team.Id, false) + defaultChannel, appErr := th.App.GetChannelByName(th.Context, model.DefaultChannelName, team.Id, false) + require.Nil(t, appErr) resp, err = client.DeleteChannel(context.Background(), defaultChannel.Id) require.Error(t, err) CheckBadRequestStatus(t, resp) @@ -2806,28 +2890,37 @@ func TestDeleteChannel(t *testing.T) { _, err = client.DeleteChannel(context.Background(), sdPrivateChannel.Id) require.NoError(t, err) }) - th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) { - th.LoginBasic() - publicChannel5 := th.CreatePublicChannel() - c.Logout(context.Background()) - c.Login(context.Background(), user.Id, user.Password) - resp, err := c.DeleteChannel(context.Background(), publicChannel5.Id) - require.Error(t, err) - CheckUnauthorizedStatus(t, resp) + th.LoginBasic() + publicChannel5 := th.CreatePublicChannel() + _, err := c.Logout(context.Background()) + require.NoError(t, err) - resp, err = c.DeleteChannel(context.Background(), "junk") - require.Error(t, err) - CheckUnauthorizedStatus(t, resp) + // Other users can't delete the channel + _, _, err = c.Login(context.Background(), user2.Email, user2.Password) + require.NoError(t, err) + resp, err := c.DeleteChannel(context.Background(), publicChannel5.Id) + require.Error(t, err) + CheckForbiddenStatus(t, resp) - c.Logout(context.Background()) - resp, err = c.DeleteChannel(context.Background(), GenerateTestID()) - require.Error(t, err) - CheckUnauthorizedStatus(t, resp) + resp, err = c.DeleteChannel(context.Background(), "junk") + require.Error(t, err) + CheckBadRequestStatus(t, resp) - _, err = client.DeleteChannel(context.Background(), publicChannel5.Id) - require.NoError(t, err) - }) + _, err = c.Logout(context.Background()) + require.NoError(t, err) + resp, err = c.DeleteChannel(context.Background(), GenerateTestID()) + require.Error(t, err) + CheckUnauthorizedStatus(t, resp) + + // The creator can delete the channel + _, err = c.Logout(context.Background()) + require.NoError(t, err) + _, _, err = c.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) + resp, err = c.DeleteChannel(context.Background(), publicChannel5.Id) + require.NoError(t, err) + CheckOKStatus(t, resp) } func TestDeleteChannel2(t *testing.T) { @@ -2849,9 +2942,12 @@ func TestDeleteChannel2(t *testing.T) { // channels created by SystemAdmin publicChannel6 := th.CreateChannelWithClient(th.SystemAdminClient, model.ChannelTypeOpen) privateChannel7 := th.CreateChannelWithClient(th.SystemAdminClient, model.ChannelTypePrivate) - th.App.AddUserToChannel(th.Context, user, publicChannel6, false) - th.App.AddUserToChannel(th.Context, user, privateChannel7, false) - th.App.AddUserToChannel(th.Context, user, privateChannel7, false) + _, appErr := th.App.AddUserToChannel(th.Context, user, publicChannel6, false) + require.Nil(t, appErr) + _, appErr = th.App.AddUserToChannel(th.Context, user, privateChannel7, false) + require.Nil(t, appErr) + _, appErr = th.App.AddUserToChannel(th.Context, user, privateChannel7, false) + require.Nil(t, appErr) // successful delete by user _, err := client.DeleteChannel(context.Background(), publicChannel6.Id) @@ -2869,9 +2965,12 @@ func TestDeleteChannel2(t *testing.T) { // channels created by SystemAdmin publicChannel6 = th.CreateChannelWithClient(th.SystemAdminClient, model.ChannelTypeOpen) privateChannel7 = th.CreateChannelWithClient(th.SystemAdminClient, model.ChannelTypePrivate) - th.App.AddUserToChannel(th.Context, user, publicChannel6, false) - th.App.AddUserToChannel(th.Context, user, privateChannel7, false) - th.App.AddUserToChannel(th.Context, user, privateChannel7, false) + _, appErr = th.App.AddUserToChannel(th.Context, user, publicChannel6, false) + require.Nil(t, appErr) + _, appErr = th.App.AddUserToChannel(th.Context, user, privateChannel7, false) + require.Nil(t, appErr) + _, appErr = th.App.AddUserToChannel(th.Context, user, privateChannel7, false) + require.Nil(t, appErr) // cannot delete by user resp, err := client.DeleteChannel(context.Background(), publicChannel6.Id) @@ -2954,7 +3053,8 @@ func TestUpdateChannelPrivacy(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() - defaultChannel, _ := th.App.GetChannelByName(th.Context, model.DefaultChannelName, th.BasicTeam.Id, false) + defaultChannel, appErr := th.App.GetChannelByName(th.Context, model.DefaultChannelName, th.BasicTeam.Id, false) + require.Nil(t, appErr) type testTable []struct { name string @@ -3050,10 +3150,12 @@ func TestRestoreChannel(t *testing.T) { defer th.TearDown() publicChannel1 := th.CreatePublicChannel() - th.Client.DeleteChannel(context.Background(), publicChannel1.Id) + _, err := th.Client.DeleteChannel(context.Background(), publicChannel1.Id) + require.NoError(t, err) privateChannel1 := th.CreatePrivateChannel() - th.Client.DeleteChannel(context.Background(), privateChannel1.Id) + _, err = th.Client.DeleteChannel(context.Background(), privateChannel1.Id) + require.NoError(t, err) _, resp, err := th.Client.RestoreChannel(context.Background(), publicChannel1.Id) require.Error(t, err) @@ -3069,12 +3171,16 @@ func TestRestoreChannel(t *testing.T) { // Because the permissions get set on initialization, // remove the manage_team permission from the User Management Role th.RemovePermissionFromRole(model.PermissionManageTeam.Id, model.SystemUserManagerRoleId) - th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserManagerRoleId, false) + _, appErr := th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserManagerRoleId, false) + require.Nil(t, appErr) defer func() { - th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, oldRoles, false) + _, appErr = th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, oldRoles, false) + require.Nil(t, appErr) }() - th.App.Srv().InvalidateAllCaches() - th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password) + appErr = th.App.Srv().InvalidateAllCaches() + require.Nil(t, appErr) + _, _, err = th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password) + require.NoError(t, err) _, resp, err = th.Client.RestoreChannel(context.Background(), publicChannel1.Id) require.NoError(t, err) @@ -3084,13 +3190,17 @@ func TestRestoreChannel(t *testing.T) { require.NoError(t, err) CheckOKStatus(t, resp) - th.Client.DeleteChannel(context.Background(), publicChannel1.Id) - th.Client.DeleteChannel(context.Background(), privateChannel1.Id) + _, err = th.Client.DeleteChannel(context.Background(), publicChannel1.Id) + require.NoError(t, err) + _, err = th.Client.DeleteChannel(context.Background(), privateChannel1.Id) + require.NoError(t, err) th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) { defer func() { - client.DeleteChannel(context.Background(), publicChannel1.Id) - client.DeleteChannel(context.Background(), privateChannel1.Id) + _, err = client.DeleteChannel(context.Background(), publicChannel1.Id) + require.NoError(t, err) + _, err = client.DeleteChannel(context.Background(), privateChannel1.Id) + require.NoError(t, err) }() _, resp, err = client.RestoreChannel(context.Background(), publicChannel1.Id) @@ -3128,11 +3238,13 @@ func TestGetChannelByName(t *testing.T) { require.NoError(t, err) require.Equal(t, th.BasicDeletedChannel.Name, channel.Name, "names did not match") - client.RemoveUserFromChannel(context.Background(), th.BasicChannel.Id, th.BasicUser.Id) + _, err = client.RemoveUserFromChannel(context.Background(), th.BasicChannel.Id, th.BasicUser.Id) + require.NoError(t, err) _, _, err = client.GetChannelByName(context.Background(), th.BasicChannel.Name, th.BasicTeam.Id, "") require.NoError(t, err) - client.RemoveUserFromChannel(context.Background(), th.BasicPrivateChannel.Id, th.BasicUser.Id) + _, err = client.RemoveUserFromChannel(context.Background(), th.BasicPrivateChannel.Id, th.BasicUser.Id) + require.NoError(t, err) _, resp, err = client.GetChannelByName(context.Background(), th.BasicPrivateChannel.Name, th.BasicTeam.Id, "") require.Error(t, err) CheckNotFoundStatus(t, resp) @@ -3145,13 +3257,15 @@ func TestGetChannelByName(t *testing.T) { require.Error(t, err) CheckBadRequestStatus(t, resp) - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) _, resp, err = client.GetChannelByName(context.Background(), th.BasicChannel.Name, th.BasicTeam.Id, "") require.Error(t, err) CheckUnauthorizedStatus(t, resp) user := th.CreateUser() - client.Login(context.Background(), user.Email, user.Password) + _, _, err = client.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) _, resp, err = client.GetChannelByName(context.Background(), th.BasicChannel.Name, th.BasicTeam.Id, "") require.Error(t, err) CheckForbiddenStatus(t, resp) @@ -3161,7 +3275,8 @@ func TestGetChannelByName(t *testing.T) { require.NoError(t, err) }) - th.SystemAdminClient.RemoveUserFromChannel(context.Background(), th.BasicPrivateChannel.Id, th.TeamAdminUser.Id) + _, err = th.SystemAdminClient.RemoveUserFromChannel(context.Background(), th.BasicPrivateChannel.Id, th.TeamAdminUser.Id) + require.NoError(t, err) TeamAdminClient := th.CreateClient() th.LoginTeamAdminWithClient(TeamAdminClient) channel, _, err = TeamAdminClient.GetChannelByName(context.Background(), th.BasicPrivateChannel.Name, th.BasicTeam.Id, "") @@ -3179,7 +3294,8 @@ func TestGetChannelByNameForTeamName(t *testing.T) { require.NoError(t, err) require.Equal(t, th.BasicChannel.Name, channel.Name, "names did not match") - th.SystemAdminClient.RemoveUserFromChannel(context.Background(), th.BasicPrivateChannel.Id, th.TeamAdminUser.Id) + _, err = th.SystemAdminClient.RemoveUserFromChannel(context.Background(), th.BasicPrivateChannel.Id, th.TeamAdminUser.Id) + require.NoError(t, err) TeamAdminClient := th.CreateClient() th.LoginTeamAdminWithClient(TeamAdminClient) channel, _, err = TeamAdminClient.GetChannelByNameForTeamName(context.Background(), th.BasicPrivateChannel.Name, th.BasicTeam.Name, "") @@ -3202,11 +3318,13 @@ func TestGetChannelByNameForTeamName(t *testing.T) { require.NoError(t, err) require.Equal(t, th.BasicDeletedChannel.Name, channel.Name, "names did not match") - client.RemoveUserFromChannel(context.Background(), th.BasicChannel.Id, th.BasicUser.Id) + _, err = client.RemoveUserFromChannel(context.Background(), th.BasicChannel.Id, th.BasicUser.Id) + require.NoError(t, err) _, _, err = client.GetChannelByNameForTeamName(context.Background(), th.BasicChannel.Name, th.BasicTeam.Name, "") require.NoError(t, err) - client.RemoveUserFromChannel(context.Background(), th.BasicPrivateChannel.Id, th.BasicUser.Id) + _, err = client.RemoveUserFromChannel(context.Background(), th.BasicPrivateChannel.Id, th.BasicUser.Id) + require.NoError(t, err) _, resp, err = client.GetChannelByNameForTeamName(context.Background(), th.BasicPrivateChannel.Name, th.BasicTeam.Name, "") require.Error(t, err) CheckNotFoundStatus(t, resp) @@ -3219,13 +3337,15 @@ func TestGetChannelByNameForTeamName(t *testing.T) { require.Error(t, err) CheckNotFoundStatus(t, resp) - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) _, resp, err = client.GetChannelByNameForTeamName(context.Background(), th.BasicChannel.Name, th.BasicTeam.Name, "") require.Error(t, err) CheckUnauthorizedStatus(t, resp) user := th.CreateUser() - client.Login(context.Background(), user.Email, user.Password) + _, _, err = client.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) _, resp, err = client.GetChannelByNameForTeamName(context.Background(), th.BasicChannel.Name, th.BasicTeam.Name, "") require.Error(t, err) CheckForbiddenStatus(t, resp) @@ -3268,13 +3388,15 @@ func TestGetChannelMembers(t *testing.T) { require.Error(t, err) CheckForbiddenStatus(t, resp) - th.Client.Logout(context.Background()) + _, err = th.Client.Logout(context.Background()) + require.NoError(t, err) _, resp, err = th.Client.GetChannelMembers(context.Background(), th.BasicChannel.Id, 0, 60, "") require.Error(t, err) CheckUnauthorizedStatus(t, resp) user := th.CreateUser() - th.Client.Login(context.Background(), user.Email, user.Password) + _, _, err = th.Client.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) _, resp, err = th.Client.GetChannelMembers(context.Background(), th.BasicChannel.Id, 0, 60, "") require.Error(t, err) CheckForbiddenStatus(t, resp) @@ -3314,7 +3436,8 @@ func TestGetChannelMembersByIds(t *testing.T) { require.Error(t, err) CheckForbiddenStatus(t, resp) - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) _, resp, err = client.GetChannelMembersByIds(context.Background(), th.BasicChannel.Id, []string{th.BasicUser.Id}) require.Error(t, err) CheckUnauthorizedStatus(t, resp) @@ -3361,13 +3484,15 @@ func TestGetChannelMember(t *testing.T) { require.Error(t, err) CheckForbiddenStatus(t, resp) - c.Logout(context.Background()) + _, err = c.Logout(context.Background()) + require.NoError(t, err) _, resp, err = c.GetChannelMember(context.Background(), th.BasicChannel.Id, th.BasicUser.Id, "") require.Error(t, err) CheckUnauthorizedStatus(t, resp) user := th.CreateUser() - c.Login(context.Background(), user.Email, user.Password) + _, _, err = c.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) _, resp, err = c.GetChannelMember(context.Background(), th.BasicChannel.Id, th.BasicUser.Id, "") require.Error(t, err) CheckForbiddenStatus(t, resp) @@ -3407,13 +3532,15 @@ func TestGetChannelMembersForUser(t *testing.T) { require.Error(t, err) CheckForbiddenStatus(t, resp) - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) _, resp, err = client.GetChannelMembersForUser(context.Background(), th.BasicUser.Id, th.BasicTeam.Id, "") require.Error(t, err) CheckUnauthorizedStatus(t, resp) user := th.CreateUser() - client.Login(context.Background(), user.Email, user.Password) + _, _, err = client.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) _, resp, err = client.GetChannelMembersForUser(context.Background(), th.BasicUser.Id, th.BasicTeam.Id, "") require.Error(t, err) CheckForbiddenStatus(t, resp) @@ -3436,7 +3563,8 @@ func TestViewChannel(t *testing.T) { require.NoError(t, err) require.Equal(t, "OK", viewResp.Status, "should have passed") - channel, _ := th.App.GetChannel(th.Context, th.BasicChannel.Id) + channel, appErr := th.App.GetChannel(th.Context, th.BasicChannel.Id) + require.Nil(t, appErr) require.Equal(t, channel.LastPostAt, viewResp.LastViewedAtTimes[channel.Id], "LastPostAt does not match returned LastViewedAt time") @@ -3492,7 +3620,8 @@ func TestViewChannel(t *testing.T) { require.Error(t, err) require.Equal(t, http.StatusBadRequest, r.StatusCode) - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) _, resp, err = client.ViewChannel(context.Background(), th.BasicUser.Id, view) require.Error(t, err) CheckUnauthorizedStatus(t, resp) @@ -3611,12 +3740,14 @@ func TestGetChannelUnread(t *testing.T) { CheckForbiddenStatus(t, resp) newUser := th.CreateUser() - client.Login(context.Background(), newUser.Email, newUser.Password) + _, _, err = client.Login(context.Background(), newUser.Email, newUser.Password) + require.NoError(t, err) _, resp, err = client.GetChannelUnread(context.Background(), th.BasicChannel.Id, user.Id) require.Error(t, err) CheckForbiddenStatus(t, resp) - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) _, _, err = th.SystemAdminClient.GetChannelUnread(context.Background(), channel.Id, user.Id) require.NoError(t, err) @@ -3674,7 +3805,8 @@ func TestGetChannelStats(t *testing.T) { require.Error(t, err) CheckForbiddenStatus(t, resp) - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) _, resp, err = client.GetChannelStats(context.Background(), channel.Id, "", false) require.Error(t, err) CheckUnauthorizedStatus(t, resp) @@ -3706,7 +3838,8 @@ func TestGetPinnedPosts(t *testing.T) { require.Len(t, posts.Posts, 1, "should have returned 1 pinned post") require.Contains(t, posts.Posts, pinnedPost.Id, "missing pinned post") - posts, resp, _ = client.GetPinnedPosts(context.Background(), channel.Id, resp.Etag) + posts, resp, err = client.GetPinnedPosts(context.Background(), channel.Id, resp.Etag) + require.NoError(t, err) CheckEtag(t, posts, resp) _, resp, err = client.GetPinnedPosts(context.Background(), GenerateTestID(), "") @@ -3717,7 +3850,8 @@ func TestGetPinnedPosts(t *testing.T) { require.Error(t, err) CheckBadRequestStatus(t, resp) - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) _, resp, err = client.GetPinnedPosts(context.Background(), channel.Id, "") require.Error(t, err) CheckUnauthorizedStatus(t, resp) @@ -3739,7 +3873,8 @@ func TestUpdateChannelRoles(t *testing.T) { channel := th.CreatePublicChannel() // Adds User 2 to the channel, making them a channel member by default. - th.App.AddUserToChannel(th.Context, th.BasicUser2, channel, false) + _, appErr := th.App.AddUserToChannel(th.Context, th.BasicUser2, channel, false) + require.Nil(t, appErr) // User 1 promotes User 2 _, err := client.UpdateChannelRoles(context.Background(), channel.Id, th.BasicUser2.Id, ChannelAdmin) @@ -3814,7 +3949,8 @@ func TestUpdateChannelMemberSchemeRoles(t *testing.T) { enableGuestAccounts := *th.App.Config().GuestAccountsSettings.Enable defer func() { th.App.UpdateConfig(func(cfg *model.Config) { *cfg.GuestAccountsSettings.Enable = enableGuestAccounts }) - th.App.Srv().RemoveLicense() + appErr := th.App.Srv().RemoveLicense() + require.Nil(t, appErr) }() th.App.UpdateConfig(func(cfg *model.Config) { *cfg.GuestAccountsSettings.Enable = true }) th.App.Srv().SetLicense(model.NewTestLicense()) @@ -3955,7 +4091,8 @@ func TestUpdateChannelMemberSchemeRoles(t *testing.T) { require.Error(t, err) CheckForbiddenStatus(t, resp) - SystemAdminClient.Logout(context.Background()) + _, err = SystemAdminClient.Logout(context.Background()) + require.NoError(t, err) resp, err = SystemAdminClient.UpdateChannelMemberSchemeRoles(context.Background(), th.BasicChannel.Id, th.SystemAdminUser.Id, s4) require.Error(t, err) CheckUnauthorizedStatus(t, resp) @@ -3998,7 +4135,8 @@ func TestUpdateChannelNotifyProps(t *testing.T) { _, err = client.UpdateChannelNotifyProps(context.Background(), th.BasicChannel.Id, th.BasicUser.Id, map[string]string{}) require.NoError(t, err) - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) resp, err = client.UpdateChannelNotifyProps(context.Background(), th.BasicChannel.Id, th.BasicUser.Id, props) require.Error(t, err) CheckUnauthorizedStatus(t, resp) @@ -4037,12 +4175,14 @@ func TestAddChannelMember(t *testing.T) { rpost, _, err := client.CreatePost(context.Background(), post) require.NoError(t, err) - client.RemoveUserFromChannel(context.Background(), publicChannel.Id, user.Id) + _, err = client.RemoveUserFromChannel(context.Background(), publicChannel.Id, user.Id) + require.NoError(t, err) _, resp, err = client.AddChannelMemberWithRootId(context.Background(), publicChannel.Id, user.Id, rpost.Id) require.NoError(t, err) CheckCreatedStatus(t, resp) - client.RemoveUserFromChannel(context.Background(), publicChannel.Id, user.Id) + _, err = client.RemoveUserFromChannel(context.Background(), publicChannel.Id, user.Id) + require.NoError(t, err) _, resp, err = client.AddChannelMemberWithRootId(context.Background(), publicChannel.Id, user.Id, "junk") require.Error(t, err) CheckBadRequestStatus(t, resp) @@ -4051,7 +4191,6 @@ func TestAddChannelMember(t *testing.T) { require.Error(t, err) CheckNotFoundStatus(t, resp) - client.RemoveUserFromChannel(context.Background(), publicChannel.Id, user.Id) _, _, err = client.AddChannelMember(context.Background(), publicChannel.Id, user.Id) require.NoError(t, err) @@ -4074,37 +4213,44 @@ func TestAddChannelMember(t *testing.T) { otherUser := th.CreateUser() otherChannel := th.CreatePublicChannel() - client.Logout(context.Background()) - client.Login(context.Background(), user2.Id, user2.Password) + + _, err = client.Logout(context.Background()) + require.NoError(t, err) + _, _, err = client.Login(context.Background(), user2.Email, user2.Password) + require.NoError(t, err) _, resp, err = client.AddChannelMember(context.Background(), publicChannel.Id, otherUser.Id) require.Error(t, err) - CheckUnauthorizedStatus(t, resp) + CheckNotFoundStatus(t, resp) _, resp, err = client.AddChannelMember(context.Background(), privateChannel.Id, otherUser.Id) require.Error(t, err) - CheckUnauthorizedStatus(t, resp) + CheckNotFoundStatus(t, resp) _, resp, err = client.AddChannelMember(context.Background(), otherChannel.Id, otherUser.Id) require.Error(t, err) - CheckUnauthorizedStatus(t, resp) + CheckForbiddenStatus(t, resp) - client.Logout(context.Background()) - client.Login(context.Background(), user.Id, user.Password) + _, err = client.Logout(context.Background()) + require.NoError(t, err) + _, _, err = client.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) // should fail adding user who is not a member of the team _, resp, err = client.AddChannelMember(context.Background(), otherChannel.Id, otherUser.Id) require.Error(t, err) - CheckUnauthorizedStatus(t, resp) + CheckNotFoundStatus(t, resp) - client.DeleteChannel(context.Background(), otherChannel.Id) + _, err = client.DeleteChannel(context.Background(), otherChannel.Id) + require.NoError(t, err) - // should fail adding user to a deleted channel + // Adding user to a deleted channel is fine _, resp, err = client.AddChannelMember(context.Background(), otherChannel.Id, user2.Id) - require.Error(t, err) - CheckUnauthorizedStatus(t, resp) + require.NoError(t, err) + CheckCreatedStatus(t, resp) - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) _, resp, err = client.AddChannelMember(context.Background(), publicChannel.Id, user2.Id) require.Error(t, err) CheckUnauthorizedStatus(t, resp) @@ -4130,44 +4276,55 @@ func TestAddChannelMember(t *testing.T) { th.AddPermissionToRole(model.PermissionManagePrivateChannelMembers.Id, model.ChannelUserRoleId) // Check that a regular channel user can add other users. - client.Login(context.Background(), user2.Username, user2.Password) + _, _, err = client.Login(context.Background(), user2.Username, user2.Password) + require.NoError(t, err) privateChannel = th.CreatePrivateChannel() _, _, err = client.AddChannelMember(context.Background(), privateChannel.Id, user.Id) require.NoError(t, err) - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) - client.Login(context.Background(), user.Username, user.Password) + _, _, err = client.Login(context.Background(), user.Username, user.Password) + require.NoError(t, err) _, _, err = client.AddChannelMember(context.Background(), privateChannel.Id, user3.Id) require.NoError(t, err) - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) // Restrict the permission for adding users to Channel Admins th.AddPermissionToRole(model.PermissionManagePrivateChannelMembers.Id, model.ChannelAdminRoleId) th.RemovePermissionFromRole(model.PermissionManagePrivateChannelMembers.Id, model.ChannelUserRoleId) - client.Login(context.Background(), user2.Username, user2.Password) + _, _, err = client.Login(context.Background(), user2.Username, user2.Password) + require.NoError(t, err) privateChannel = th.CreatePrivateChannel() _, _, err = client.AddChannelMember(context.Background(), privateChannel.Id, user.Id) require.NoError(t, err) - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) - client.Login(context.Background(), user.Username, user.Password) + _, _, err = client.Login(context.Background(), user.Username, user.Password) + require.NoError(t, err) _, resp, err = client.AddChannelMember(context.Background(), privateChannel.Id, user3.Id) require.Error(t, err) CheckForbiddenStatus(t, resp) - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) th.MakeUserChannelAdmin(user, privateChannel) - th.App.Srv().InvalidateAllCaches() + appErr := th.App.Srv().InvalidateAllCaches() + require.Nil(t, appErr) - client.Login(context.Background(), user.Username, user.Password) + _, _, err = client.Login(context.Background(), user.Username, user.Password) + require.NoError(t, err) _, _, err = client.AddChannelMember(context.Background(), privateChannel.Id, user3.Id) require.NoError(t, err) - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) // Set a channel to group-constrained privateChannel.GroupConstrained = model.NewPointer(true) - _, appErr := th.App.UpdateChannel(th.Context, privateChannel) + _, appErr = th.App.UpdateChannel(th.Context, privateChannel) require.Nil(t, appErr) th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) { @@ -4206,8 +4363,7 @@ func TestAddChannelMember(t *testing.T) { } else { require.EqualError(t, err, "Invalid or missing user_id in user_ids in request body.") } - defer res.Body.Close() - io.Copy(io.Discard, res.Body) + require.Equal(t, http.StatusBadRequest, res.StatusCode) // invalid type for user ids (should be string). requestBody = map[string]any{"user_ids": []any{45, user2.Id}} @@ -4220,8 +4376,7 @@ func TestAddChannelMember(t *testing.T) { } else { require.EqualError(t, err, "Invalid or missing user_id in user_ids in request body.") } - defer res.Body.Close() - io.Copy(io.Discard, res.Body) + require.Equal(t, http.StatusBadRequest, res.StatusCode) }) }) } @@ -4432,7 +4587,8 @@ func TestAddChannelMemberAddMyself(t *testing.T) { "", }, } - client.Login(context.Background(), user.Email, user.Password) + _, _, err := client.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) for _, tc := range testCases { t.Run(tc.Name, func(t *testing.T) { // Check the appropriate permissions are enforced. @@ -4468,7 +4624,8 @@ func TestRemoveChannelMember(t *testing.T) { *cfg.ServiceSettings.EnableBotAccountCreation = true }) bot := th.CreateBotWithSystemAdminClient() - th.App.AddUserToTeam(th.Context, team.Id, bot.UserId, "") + _, _, appErr := th.App.AddUserToTeam(th.Context, team.Id, bot.UserId, "") + require.Nil(t, appErr) _, err := client.RemoveUserFromChannel(context.Background(), th.BasicChannel.Id, th.BasicUser2.Id) require.NoError(t, err) @@ -4493,7 +4650,7 @@ func TestRemoveChannelMember(t *testing.T) { t.Run("success", func(t *testing.T) { // Setup the system administrator to listen for websocket events from the channels. th.LinkUserToTeam(th.SystemAdminUser, th.BasicTeam) - _, appErr := th.App.AddUserToChannel(th.Context, th.SystemAdminUser, th.BasicChannel, false) + _, appErr = th.App.AddUserToChannel(th.Context, th.SystemAdminUser, th.BasicChannel, false) require.Nil(t, appErr) _, appErr = th.App.AddUserToChannel(th.Context, th.SystemAdminUser, th.BasicChannel2, false) require.Nil(t, appErr) @@ -4519,7 +4676,8 @@ func TestRemoveChannelMember(t *testing.T) { } var post model.Post - json.Unmarshal([]byte(postData.(string)), &post) + err = json.Unmarshal([]byte(postData.(string)), &post) + require.NoError(t, err) if post.ChannelId == expectedPost.ChannelId && post.Message == expectedPost.Message { return } @@ -4530,7 +4688,8 @@ func TestRemoveChannelMember(t *testing.T) { } } - th.App.AddUserToChannel(th.Context, th.BasicUser2, th.BasicChannel, false) + _, appErr = th.App.AddUserToChannel(th.Context, th.BasicUser2, th.BasicChannel, false) + require.Nil(t, appErr) _, err2 := client.RemoveUserFromChannel(context.Background(), th.BasicChannel.Id, th.BasicUser2.Id) require.NoError(t, err2) @@ -4557,18 +4716,21 @@ func TestRemoveChannelMember(t *testing.T) { // Leave deleted channel th.LoginBasic() deletedChannel := th.CreatePublicChannel() - th.App.AddUserToChannel(th.Context, th.BasicUser, deletedChannel, false) - th.App.AddUserToChannel(th.Context, th.BasicUser2, deletedChannel, false) + _, appErr = th.App.AddUserToChannel(th.Context, th.BasicUser, deletedChannel, false) + require.Nil(t, appErr) + _, appErr = th.App.AddUserToChannel(th.Context, th.BasicUser2, deletedChannel, false) + require.Nil(t, appErr) - deletedChannel.DeleteAt = 1 - th.App.UpdateChannel(th.Context, deletedChannel) + appErr = th.App.DeleteChannel(th.Context, deletedChannel, "") + require.Nil(t, appErr) _, err = client.RemoveUserFromChannel(context.Background(), deletedChannel.Id, th.BasicUser.Id) require.NoError(t, err) th.LoginBasic() private := th.CreatePrivateChannel() - th.App.AddUserToChannel(th.Context, th.BasicUser2, private, false) + _, appErr = th.App.AddUserToChannel(th.Context, th.BasicUser2, private, false) + require.Nil(t, appErr) _, err = client.RemoveUserFromChannel(context.Background(), private.Id, th.BasicUser2.Id) require.NoError(t, err) @@ -4579,14 +4741,16 @@ func TestRemoveChannelMember(t *testing.T) { CheckForbiddenStatus(t, resp) th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) { - th.App.AddUserToChannel(th.Context, th.BasicUser, private, false) + _, appErr = th.App.AddUserToChannel(th.Context, th.BasicUser, private, false) + require.Nil(t, appErr) _, err = client.RemoveUserFromChannel(context.Background(), private.Id, th.BasicUser.Id) require.NoError(t, err) }) th.LoginBasic() th.UpdateUserToNonTeamAdmin(user1, team) - th.App.Srv().InvalidateAllCaches() + appErr = th.App.Srv().InvalidateAllCaches() + require.Nil(t, appErr) // Check the appropriate permissions are enforced. defaultRolePermissions := th.SaveDefaultRolePermissions() @@ -4625,7 +4789,8 @@ func TestRemoveChannelMember(t *testing.T) { CheckForbiddenStatus(t, resp) th.MakeUserChannelAdmin(user1, privateChannel) - th.App.Srv().InvalidateAllCaches() + appErr = th.App.Srv().InvalidateAllCaches() + require.Nil(t, appErr) _, err = client.RemoveUserFromChannel(context.Background(), privateChannel.Id, user2.Id) require.NoError(t, err) @@ -4635,7 +4800,7 @@ func TestRemoveChannelMember(t *testing.T) { // If the channel is group-constrained the user cannot be removed privateChannel.GroupConstrained = model.NewPointer(true) - _, appErr := th.App.UpdateChannel(th.Context, privateChannel) + _, appErr = th.App.UpdateChannel(th.Context, privateChannel) require.Nil(t, appErr) _, err = client.RemoveUserFromChannel(context.Background(), privateChannel.Id, user2.Id) CheckErrorID(t, err, "api.channel.remove_member.group_constrained.app_error") @@ -4682,21 +4847,25 @@ func TestAutocompleteChannels(t *testing.T) { defer th.TearDown() // A private channel to make sure private channels are used. - ptown, _, _ := th.Client.CreateChannel(context.Background(), &model.Channel{ + ptown, _, err := th.Client.CreateChannel(context.Background(), &model.Channel{ DisplayName: "Town", Name: "town", Type: model.ChannelTypePrivate, TeamId: th.BasicTeam.Id, }) - tower, _, _ := th.Client.CreateChannel(context.Background(), &model.Channel{ + require.NoError(t, err) + tower, _, err := th.Client.CreateChannel(context.Background(), &model.Channel{ DisplayName: "Tower", Name: "tower", Type: model.ChannelTypeOpen, TeamId: th.BasicTeam.Id, }) + require.NoError(t, err) defer func() { - th.Client.DeleteChannel(context.Background(), ptown.Id) - th.Client.DeleteChannel(context.Background(), tower.Id) + _, err = th.Client.DeleteChannel(context.Background(), ptown.Id) + require.NoError(t, err) + _, err = th.Client.DeleteChannel(context.Background(), tower.Id) + require.NoError(t, err) }() for _, tc := range []struct { @@ -4754,57 +4923,60 @@ func TestAutocompleteChannelsForSearch(t *testing.T) { th.LoginBasicWithClient(th.Client) u1 := th.CreateUserWithClient(th.SystemAdminClient) - defer th.App.PermanentDeleteUser(th.Context, u1) + defer func() { + appErr := th.App.PermanentDeleteUser(th.Context, u1) + require.Nil(t, appErr) + }() u2 := th.CreateUserWithClient(th.SystemAdminClient) - defer th.App.PermanentDeleteUser(th.Context, u2) + defer func() { + appErr := th.App.PermanentDeleteUser(th.Context, u2) + require.Nil(t, appErr) + }() u3 := th.CreateUserWithClient(th.SystemAdminClient) - defer th.App.PermanentDeleteUser(th.Context, u3) + defer func() { + appErr := th.App.PermanentDeleteUser(th.Context, u3) + require.Nil(t, appErr) + }() u4 := th.CreateUserWithClient(th.SystemAdminClient) - defer th.App.PermanentDeleteUser(th.Context, u4) + defer func() { + appErr := th.App.PermanentDeleteUser(th.Context, u4) + require.Nil(t, appErr) + }() // A private channel to make sure private channels are not used - ptown, _, _ := th.SystemAdminClient.CreateChannel(context.Background(), &model.Channel{ + ptown, _, err := th.SystemAdminClient.CreateChannel(context.Background(), &model.Channel{ DisplayName: "Town", Name: "town", Type: model.ChannelTypePrivate, TeamId: th.BasicTeam.Id, }) + require.NoError(t, err) defer func() { - th.Client.DeleteChannel(context.Background(), ptown.Id) + _, err = th.SystemAdminClient.DeleteChannel(context.Background(), ptown.Id) + require.NoError(t, err) }() - mypriv, _, _ := th.Client.CreateChannel(context.Background(), &model.Channel{ + + mypriv, _, err := th.Client.CreateChannel(context.Background(), &model.Channel{ DisplayName: "My private town", Name: "townpriv", Type: model.ChannelTypePrivate, TeamId: th.BasicTeam.Id, }) + require.NoError(t, err) defer func() { - th.Client.DeleteChannel(context.Background(), mypriv.Id) + _, err = th.SystemAdminClient.DeleteChannel(context.Background(), mypriv.Id) + require.NoError(t, err) }() dc1, _, err := th.Client.CreateDirectChannel(context.Background(), th.BasicUser.Id, u1.Id) require.NoError(t, err) - defer func() { - th.Client.DeleteChannel(context.Background(), dc1.Id) - }() - dc2, _, err := th.SystemAdminClient.CreateDirectChannel(context.Background(), u2.Id, u3.Id) require.NoError(t, err) - defer func() { - th.SystemAdminClient.DeleteChannel(context.Background(), dc2.Id) - }() gc1, _, err := th.Client.CreateGroupChannel(context.Background(), []string{th.BasicUser.Id, u2.Id, u3.Id}) require.NoError(t, err) - defer func() { - th.Client.DeleteChannel(context.Background(), gc1.Id) - }() - gc2, _, err := th.SystemAdminClient.CreateGroupChannel(context.Background(), []string{u2.Id, u3.Id, u4.Id}) require.NoError(t, err) - defer func() { - th.SystemAdminClient.DeleteChannel(context.Background(), gc2.Id) - }() for _, tc := range []struct { description string @@ -4865,12 +5037,16 @@ func TestAutocompleteChannelsForSearchGuestUsers(t *testing.T) { defer th.TearDown() u1 := th.CreateUserWithClient(th.SystemAdminClient) - defer th.App.PermanentDeleteUser(th.Context, u1) + defer func() { + appErr := th.App.PermanentDeleteUser(th.Context, u1) + require.Nil(t, appErr) + }() enableGuestAccounts := *th.App.Config().GuestAccountsSettings.Enable defer func() { th.App.UpdateConfig(func(cfg *model.Config) { *cfg.GuestAccountsSettings.Enable = enableGuestAccounts }) - th.App.Srv().RemoveLicense() + appErr := th.App.Srv().RemoveLicense() + require.Nil(t, appErr) }() th.App.UpdateConfig(func(cfg *model.Config) { *cfg.GuestAccountsSettings.Enable = true }) th.App.Srv().SetLicense(model.NewTestLicense()) @@ -4892,53 +5068,43 @@ func TestAutocompleteChannelsForSearchGuestUsers(t *testing.T) { require.NoError(t, err) // A private channel to make sure private channels are not used - town, _, _ := th.SystemAdminClient.CreateChannel(context.Background(), &model.Channel{ + town, _, err := th.SystemAdminClient.CreateChannel(context.Background(), &model.Channel{ DisplayName: "Town", Name: "town", Type: model.ChannelTypeOpen, TeamId: th.BasicTeam.Id, }) + require.NoError(t, err) defer func() { - th.SystemAdminClient.DeleteChannel(context.Background(), town.Id) + _, err = th.SystemAdminClient.DeleteChannel(context.Background(), town.Id) + require.NoError(t, err) }() _, _, err = th.SystemAdminClient.AddChannelMember(context.Background(), town.Id, guest.Id) require.NoError(t, err) - mypriv, _, _ := th.SystemAdminClient.CreateChannel(context.Background(), &model.Channel{ + mypriv, _, err := th.SystemAdminClient.CreateChannel(context.Background(), &model.Channel{ DisplayName: "My private town", Name: "townpriv", Type: model.ChannelTypePrivate, TeamId: th.BasicTeam.Id, }) + require.NoError(t, err) defer func() { - th.SystemAdminClient.DeleteChannel(context.Background(), mypriv.Id) + _, err = th.SystemAdminClient.DeleteChannel(context.Background(), mypriv.Id) + require.NoError(t, err) }() _, _, err = th.SystemAdminClient.AddChannelMember(context.Background(), mypriv.Id, guest.Id) require.NoError(t, err) dc1, _, err := th.SystemAdminClient.CreateDirectChannel(context.Background(), th.BasicUser.Id, guest.Id) require.NoError(t, err) - defer func() { - th.SystemAdminClient.DeleteChannel(context.Background(), dc1.Id) - }() - dc2, _, err := th.SystemAdminClient.CreateDirectChannel(context.Background(), th.BasicUser.Id, th.BasicUser2.Id) require.NoError(t, err) - defer func() { - th.SystemAdminClient.DeleteChannel(context.Background(), dc2.Id) - }() gc1, _, err := th.SystemAdminClient.CreateGroupChannel(context.Background(), []string{th.BasicUser.Id, th.BasicUser2.Id, guest.Id}) require.NoError(t, err) - defer func() { - th.SystemAdminClient.DeleteChannel(context.Background(), gc1.Id) - }() - gc2, _, err := th.SystemAdminClient.CreateGroupChannel(context.Background(), []string{th.BasicUser.Id, th.BasicUser2.Id, u1.Id}) require.NoError(t, err) - defer func() { - th.SystemAdminClient.DeleteChannel(context.Background(), gc2.Id) - }() _, _, err = th.Client.Login(context.Background(), guest.Username, "Password1") require.NoError(t, err) @@ -4996,7 +5162,8 @@ func TestUpdateChannelScheme(t *testing.T) { th.App.Srv().SetLicense(model.NewTestLicense("")) - th.App.SetPhase2PermissionsMigrationStatus(true) + err := th.App.SetPhase2PermissionsMigrationStatus(true) + require.NoError(t, err) team, _, err := th.SystemAdminClient.CreateTeam(context.Background(), &model.Team{ DisplayName: "Name", @@ -5067,7 +5234,8 @@ func TestUpdateChannelScheme(t *testing.T) { CheckBadRequestStatus(t, resp) // Test that an unauthenticated user gets rejected. - th.SystemAdminClient.Logout(context.Background()) + _, err = th.SystemAdminClient.Logout(context.Background()) + require.NoError(t, err) resp, err = th.SystemAdminClient.UpdateChannelScheme(context.Background(), channel.Id, channelScheme.Id) require.Error(t, err) CheckUnauthorizedStatus(t, resp) @@ -5220,7 +5388,8 @@ func TestGetChannelModerations(t *testing.T) { channel := th.BasicChannel team := th.BasicTeam - th.App.SetPhase2PermissionsMigrationStatus(true) + err := th.App.SetPhase2PermissionsMigrationStatus(true) + require.NoError(t, err) t.Run("Errors without a license", func(t *testing.T) { _, _, err := th.SystemAdminClient.GetChannelModerations(context.Background(), channel.Id, "") @@ -5298,11 +5467,13 @@ func TestGetChannelModerations(t *testing.T) { t.Run("Returns value false and enabled false for permissions that are not present in channel & team scheme", func(t *testing.T) { teamScheme := th.SetupTeamScheme() team.SchemeId = &teamScheme.Id - th.App.UpdateTeamScheme(team) + _, appErr := th.App.UpdateTeamScheme(team) + require.Nil(t, appErr) scheme := th.SetupChannelScheme() channel.SchemeId = &scheme.Id - th.App.UpdateChannelScheme(th.Context, channel) + _, appErr = th.App.UpdateChannelScheme(th.Context, channel) + require.Nil(t, appErr) th.RemovePermissionFromRole(model.PermissionCreatePost.Id, scheme.DefaultChannelGuestRole) th.RemovePermissionFromRole(model.PermissionCreatePost.Id, teamScheme.DefaultChannelGuestRole) @@ -5438,7 +5609,8 @@ func TestPatchChannelModerations(t *testing.T) { createPosts := model.ChannelModeratedPermissions[0] - th.App.SetPhase2PermissionsMigrationStatus(true) + err := th.App.SetPhase2PermissionsMigrationStatus(true) + require.NoError(t, err) t.Run("Errors without a license", func(t *testing.T) { _, _, err := th.SystemAdminClient.PatchChannelModerations(context.Background(), channel.Id, emptyPatch) @@ -5500,15 +5672,20 @@ func TestPatchChannelModerations(t *testing.T) { require.Equal(t, moderation.Roles.Members.Enabled, true) } } - channel, _ = th.App.GetChannel(th.Context, channel.Id) + var appErr *model.AppError + channel, appErr = th.App.GetChannel(th.Context, channel.Id) + require.Nil(t, appErr) require.NotNil(t, channel.SchemeId) }) t.Run("Removes the existing scheme when moderated permissions are set back to higher scoped values", func(t *testing.T) { - channel, _ = th.App.GetChannel(th.Context, channel.Id) + var appErr *model.AppError + channel, appErr = th.App.GetChannel(th.Context, channel.Id) + require.Nil(t, appErr) schemeId := channel.SchemeId - scheme, _ := th.App.GetScheme(*schemeId) + scheme, appErr := th.App.GetScheme(*schemeId) + require.Nil(t, appErr) require.Equal(t, scheme.DeleteAt, int64(0)) patch := []*model.ChannelModerationPatch{ @@ -5533,10 +5710,12 @@ func TestPatchChannelModerations(t *testing.T) { require.Equal(t, moderation.Roles.Members.Enabled, true) } - channel, _ = th.App.GetChannel(th.Context, channel.Id) + channel, appErr = th.App.GetChannel(th.Context, channel.Id) + require.Nil(t, appErr) require.Nil(t, channel.SchemeId) - scheme, _ = th.App.GetScheme(*schemeId) + scheme, appErr = th.App.GetScheme(*schemeId) + require.Nil(t, appErr) require.NotEqual(t, scheme.DeleteAt, int64(0)) }) @@ -5631,7 +5810,8 @@ func TestGetChannelMemberCountsByGroup(t *testing.T) { }) t.Run("Returns empty for a channel with no members or groups", func(t *testing.T) { - memberCounts, _, _ := th.SystemAdminClient.GetChannelMemberCountsByGroup(context.Background(), channel.Id, false, "") + memberCounts, _, err := th.SystemAdminClient.GetChannelMemberCountsByGroup(context.Background(), channel.Id, false, "") + require.NoError(t, err) require.Equal(t, []*model.ChannelMemberCountByGroup{}, memberCounts) }) @@ -5651,7 +5831,8 @@ func TestGetChannelMemberCountsByGroup(t *testing.T) { require.NoError(t, err) t.Run("Returns users in group without timezones", func(t *testing.T) { - memberCounts, _, _ := th.SystemAdminClient.GetChannelMemberCountsByGroup(context.Background(), channel.Id, false, "") + memberCounts, _, err := th.SystemAdminClient.GetChannelMemberCountsByGroup(context.Background(), channel.Id, false, "") + require.NoError(t, err) expectedMemberCounts := []*model.ChannelMemberCountByGroup{ { GroupId: th.Group.Id, @@ -5663,7 +5844,8 @@ func TestGetChannelMemberCountsByGroup(t *testing.T) { }) t.Run("Returns users in group with timezones", func(t *testing.T) { - memberCounts, _, _ := th.SystemAdminClient.GetChannelMemberCountsByGroup(context.Background(), channel.Id, true, "") + memberCounts, _, err := th.SystemAdminClient.GetChannelMemberCountsByGroup(context.Background(), channel.Id, true, "") + require.NoError(t, err) expectedMemberCounts := []*model.ChannelMemberCountByGroup{ { GroupId: th.Group.Id, @@ -5688,7 +5870,8 @@ func TestGetChannelMemberCountsByGroup(t *testing.T) { require.Nil(t, appErr) t.Run("Returns multiple groups with users in group with timezones", func(t *testing.T) { - memberCounts, _, _ := th.SystemAdminClient.GetChannelMemberCountsByGroup(context.Background(), channel.Id, true, "") + memberCounts, _, err := th.SystemAdminClient.GetChannelMemberCountsByGroup(context.Background(), channel.Id, true, "") + require.NoError(t, err) expectedMemberCounts := []*model.ChannelMemberCountByGroup{ { GroupId: group.Id, @@ -5758,7 +5941,8 @@ func TestGetChannelsMemberCount(t *testing.T) { }) t.Run("Should fail due to expired session when logged out", func(t *testing.T) { - client.Logout(context.Background()) + _, err := client.Logout(context.Background()) + require.NoError(t, err) channelIDs := []string{channel1.Id, channel2.Id} _, resp, err := client.GetChannelsMemberCount(context.Background(), channelIDs) require.Error(t, err) @@ -5813,7 +5997,7 @@ func TestMoveChannel(t *testing.T) { Type: model.ChannelTypePrivate, TeamId: team1.Id, } - channelT1, _, err := th.Client.CreateChannel(context.TODO(), channelT1) + channelT1, _, err := th.Client.CreateChannel(context.Background(), channelT1) require.NoError(t, err) channelT2 := &model.Channel{ @@ -5822,7 +6006,7 @@ func TestMoveChannel(t *testing.T) { Type: model.ChannelTypePrivate, TeamId: team2.Id, } - _, _, err = th.Client.CreateChannel(context.TODO(), channelT2) + _, _, err = th.Client.CreateChannel(context.Background(), channelT2) require.NoError(t, err) _, _, err = th.SystemAdminClient.MoveChannel(context.Background(), channelT1.Id, team2.Id, false)