From b986f398253b7e47de90701c9179620f59785095 Mon Sep 17 00:00:00 2001 From: Arya Khochare <91268931+Aryakoste@users.noreply.github.com> Date: Wed, 20 Nov 2024 21:58:39 +0530 Subject: [PATCH] Fixed errcheck issues in server/channels/api4/user_test.go (#28647) Co-authored-by: Ben Schumacher --- server/.golangci.yml | 1 - server/channels/api4/user_test.go | 752 +++++++++++++++++++++--------- 2 files changed, 532 insertions(+), 221 deletions(-) diff --git a/server/.golangci.yml b/server/.golangci.yml index 811a765aef..391133918e 100644 --- a/server/.golangci.yml +++ b/server/.golangci.yml @@ -79,7 +79,6 @@ issues: channels/api4/system.go|\ channels/api4/system_local.go|\ channels/api4/team_local.go|\ - channels/api4/user_test.go|\ channels/api4/websocket_test.go|\ channels/app/bot_test.go|\ channels/app/brand.go|\ diff --git a/server/channels/api4/user_test.go b/server/channels/api4/user_test.go index 7e98e96af4..dad1d5cad4 100644 --- a/server/channels/api4/user_test.go +++ b/server/channels/api4/user_test.go @@ -67,7 +67,8 @@ func TestCreateUser(t *testing.T) { // Creating a user as a regular user with verified flag should not verify the new user. require.False(t, ruser.EmailVerified) - _, _, _ = th.Client.Login(context.Background(), user.Email, user.Password) + _, _, err = th.Client.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) require.Equal(t, user.Nickname, ruser.Nickname, "nickname didn't match") require.Equal(t, model.SystemUserRoleId, ruser.Roles, "did not clear roles") @@ -492,7 +493,8 @@ func TestCreateUserWithToken(t *testing.T) { require.NoError(t, err) CheckCreatedStatus(t, resp) - th.Client.Login(context.Background(), user.Email, user.Password) + _, _, err = th.Client.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) require.Equal(t, user.Nickname, ruser.Nickname) require.Equal(t, model.SystemUserRoleId, ruser.Roles, "should clear roles") CheckUserSanitization(t, ruser) @@ -517,7 +519,8 @@ func TestCreateUserWithToken(t *testing.T) { require.NoError(t, err) CheckCreatedStatus(t, resp) - th.Client.Login(context.Background(), user.Email, user.Password) + _, _, err = th.Client.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) require.Equal(t, user.Nickname, ruser.Nickname) require.Equal(t, model.SystemUserRoleId, ruser.Roles, "should clear roles") CheckUserSanitization(t, ruser) @@ -537,7 +540,10 @@ func TestCreateUserWithToken(t *testing.T) { model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id, "email": user.Email}), ) require.NoError(t, th.App.Srv().Store().Token().Save(token)) - defer th.App.DeleteToken(token) + defer func() { + appErr := th.App.DeleteToken(token) + require.Nil(t, appErr) + }() _, _, err := th.Client.CreateUserWithToken(context.Background(), &user, "") require.Error(t, err) @@ -554,7 +560,10 @@ func TestCreateUserWithToken(t *testing.T) { ) token.CreateAt = past49Hours require.NoError(t, th.App.Srv().Store().Token().Save(token)) - defer th.App.DeleteToken(token) + defer func() { + appErr := th.App.DeleteToken(token) + require.Nil(t, appErr) + }() _, resp, err := th.Client.CreateUserWithToken(context.Background(), &user, token.Token) require.Error(t, err) @@ -584,7 +593,10 @@ func TestCreateUserWithToken(t *testing.T) { model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id, "email": user.Email}), ) require.NoError(t, th.App.Srv().Store().Token().Save(token)) - defer th.App.DeleteToken(token) + defer func() { + appErr := th.App.DeleteToken(token) + require.Nil(t, appErr) + }() th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.EnableUserCreation = false }) @@ -604,7 +616,10 @@ func TestCreateUserWithToken(t *testing.T) { model.MapToJSON(map[string]string{"teamId": th.BasicTeam.Id, "email": user.Email}), ) require.NoError(t, th.App.Srv().Store().Token().Save(token)) - defer th.App.DeleteToken(token) + defer func() { + appErr := th.App.DeleteToken(token) + require.Nil(t, appErr) + }() th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.EnableUserCreation = false }) @@ -634,7 +649,8 @@ func TestCreateUserWithToken(t *testing.T) { require.NoError(t, err) CheckCreatedStatus(t, resp) - th.Client.Login(context.Background(), user.Email, user.Password) + _, _, err = th.Client.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) require.Equal(t, user.Nickname, ruser.Nickname) require.Equal(t, model.SystemUserRoleId, ruser.Roles, "should clear roles") CheckUserSanitization(t, ruser) @@ -656,7 +672,8 @@ func TestCreateUserWithToken(t *testing.T) { require.NoError(t, err) CheckCreatedStatus(t, resp) - th.Client.Login(context.Background(), user.Email, user.Password) + _, _, err = th.Client.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) require.Equal(t, user.Nickname, ruser.Nickname) require.Equal(t, model.SystemUserRoleId, ruser.Roles, "should clear roles") CheckUserSanitization(t, ruser) @@ -694,7 +711,8 @@ func TestCreateUserWithToken(t *testing.T) { require.NoError(t, err) CheckCreatedStatus(t, resp) - th.Client.Login(context.Background(), user.Email, user.Password) + _, _, err = th.Client.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) require.Equal(t, user.Nickname, ruser.Nickname) require.Equal(t, model.SystemUserRoleId, ruser.Roles, "should clear roles") CheckUserSanitization(t, ruser) @@ -808,7 +826,8 @@ func TestCreateUserWithInviteId(t *testing.T) { require.NoError(t, err) CheckCreatedStatus(t, resp) - th.Client.Login(context.Background(), user.Email, user.Password) + _, _, err = th.Client.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) require.Equal(t, user.Nickname, ruser.Nickname) require.Equal(t, model.SystemUserRoleId, ruser.Roles, "should clear roles") CheckUserSanitization(t, ruser) @@ -822,7 +841,8 @@ func TestCreateUserWithInviteId(t *testing.T) { require.NoError(t, err) CheckCreatedStatus(t, resp) - th.Client.Login(context.Background(), user.Email, user.Password) + _, _, err = th.Client.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) require.Equal(t, user.Nickname, ruser.Nickname) require.Equal(t, model.SystemUserRoleId, ruser.Roles, "should clear roles") CheckUserSanitization(t, ruser) @@ -949,7 +969,8 @@ func TestCreateUserWithInviteId(t *testing.T) { require.NoError(t, err) CheckCreatedStatus(t, resp) - th.Client.Login(context.Background(), user.Email, user.Password) + _, _, err = th.Client.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) require.Equal(t, user.Nickname, ruser.Nickname) require.Equal(t, model.SystemUserRoleId, ruser.Roles, "should clear roles") CheckUserSanitization(t, ruser) @@ -965,7 +986,8 @@ func TestGetMe(t *testing.T) { require.Equal(t, th.BasicUser.Id, ruser.Id) - th.Client.Logout(context.Background()) + _, err = th.Client.Logout(context.Background()) + require.NoError(t, err) _, resp, err := th.Client.GetMe(context.Background(), "") require.Error(t, err) CheckUnauthorizedStatus(t, resp) @@ -978,7 +1000,8 @@ func TestGetUser(t *testing.T) { user := th.CreateUser() user.Props = map[string]string{"testpropkey": "testpropvalue"} - th.App.UpdateUser(th.Context, user, false) + _, appErr := th.App.UpdateUser(th.Context, user, false) + require.Nil(t, appErr) th.TestForAllClients(t, func(t *testing.T, client *model.Client4) { ruser, resp, err := client.GetUser(context.Background(), user.Id, "") @@ -1014,7 +1037,8 @@ func TestGetUser(t *testing.T) { require.Empty(t, ruser.FirstName, "first name should be blank") require.Empty(t, ruser.LastName, "last name should be blank") - th.Client.Logout(context.Background()) + _, err = th.Client.Logout(context.Background()) + require.NoError(t, err) _, resp, err := th.Client.GetUser(context.Background(), user.Id, "") require.Error(t, err) CheckUnauthorizedStatus(t, resp) @@ -1034,7 +1058,8 @@ func TestGetUserWithAcceptedTermsOfServiceForOtherUser(t *testing.T) { tos, _ := th.App.CreateTermsOfService("Dummy TOS", user.Id) - th.App.UpdateUser(th.Context, user, false) + _, appErr := th.App.UpdateUser(th.Context, user, false) + require.Nil(t, appErr) ruser, _, err := th.Client.GetUser(context.Background(), user.Id, "") require.NoError(t, err) @@ -1044,7 +1069,8 @@ func TestGetUserWithAcceptedTermsOfServiceForOtherUser(t *testing.T) { assert.Empty(t, ruser.TermsOfServiceId) - th.App.SaveUserTermsOfService(user.Id, tos.Id, true) + appErr = th.App.SaveUserTermsOfService(user.Id, tos.Id, true) + require.Nil(t, appErr) ruser, _, err = th.Client.GetUser(context.Background(), user.Id, "") require.NoError(t, err) @@ -1072,7 +1098,8 @@ func TestGetUserWithAcceptedTermsOfService(t *testing.T) { assert.Empty(t, ruser.TermsOfServiceId) - th.App.SaveUserTermsOfService(user.Id, tos.Id, true) + appErr := th.App.SaveUserTermsOfService(user.Id, tos.Id, true) + require.Nil(t, appErr) ruser, _, err = th.Client.GetUser(context.Background(), user.Id, "") require.NoError(t, err) @@ -1101,7 +1128,8 @@ func TestGetUserWithAcceptedTermsOfServiceWithAdminUser(t *testing.T) { assert.Empty(t, ruser.TermsOfServiceId) - th.App.SaveUserTermsOfService(user.Id, tos.Id, true) + appErr := th.App.SaveUserTermsOfService(user.Id, tos.Id, true) + require.Nil(t, appErr) ruser, _, err = th.SystemAdminClient.GetUser(context.Background(), user.Id, "") require.NoError(t, err) @@ -1120,7 +1148,8 @@ func TestGetBotUser(t *testing.T) { defer th.RestoreDefaultRolePermissions(th.SaveDefaultRolePermissions()) th.AddPermissionToRole(model.PermissionCreateBot.Id, model.TeamUserRoleId) - th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.TeamUserRoleId, false) + _, appErr := th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.TeamUserRoleId, false) + require.Nil(t, appErr) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableBotAccountCreation = true @@ -1135,7 +1164,10 @@ func TestGetBotUser(t *testing.T) { createdBot, resp, err := th.Client.CreateBot(context.Background(), bot) require.NoError(t, err) CheckCreatedStatus(t, resp) - defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId) + defer func() { + appErr := th.App.PermanentDeleteBot(th.Context, createdBot.UserId) + require.Nil(t, appErr) + }() botUser, _, err := th.Client.GetUser(context.Background(), createdBot.UserId, "") require.NoError(t, err) @@ -1179,7 +1211,8 @@ func TestGetUserByUsername(t *testing.T) { require.NoError(t, err) require.NotEmpty(t, ruser.NotifyProps, "notify props should be sent") - th.Client.Logout(context.Background()) + _, err = th.Client.Logout(context.Background()) + require.NoError(t, err) _, resp, err := th.Client.GetUserByUsername(context.Background(), user.Username, "") require.Error(t, err) CheckUnauthorizedStatus(t, resp) @@ -1205,8 +1238,10 @@ func TestGetUserByUsernameWithAcceptedTermsOfService(t *testing.T) { require.Equal(t, user.Email, ruser.Email) - tos, _ := th.App.CreateTermsOfService("Dummy TOS", user.Id) - th.App.SaveUserTermsOfService(ruser.Id, tos.Id, true) + tos, appErr := th.App.CreateTermsOfService("Dummy TOS", user.Id) + require.Nil(t, appErr) + appErr = th.App.SaveUserTermsOfService(ruser.Id, tos.Id, true) + require.Nil(t, appErr) ruser, _, err = th.Client.GetUserByUsername(context.Background(), user.Username, "") require.NoError(t, err) @@ -1672,12 +1707,14 @@ func TestAutocompleteUsersInChannel(t *testing.T) { } } - th.Client.Logout(context.Background()) + _, err = th.Client.Logout(context.Background()) + require.NoError(t, err) _, resp, err := th.Client.AutocompleteUsersInChannel(context.Background(), tc.TeamId, tc.ChannelId, tc.Username, model.UserSearchDefaultLimit, "") require.Error(t, err) CheckUnauthorizedStatus(t, resp) - th.Client.Login(context.Background(), newUser.Email, newUser.Password) + _, _, err = th.Client.Login(context.Background(), newUser.Email, newUser.Password) + require.NoError(t, err) _, resp, err = th.Client.AutocompleteUsersInChannel(context.Background(), tc.TeamId, tc.ChannelId, tc.Username, model.UserSearchDefaultLimit, "") require.Error(t, err) CheckForbiddenStatus(t, resp) @@ -1696,8 +1733,18 @@ func TestAutocompleteUsersInChannel(t *testing.T) { }) t.Run("Check OutOfChannel results with/without VIEW_MEMBERS permissions", func(t *testing.T) { + t.Skip("https://mattermost.atlassian.net/browse/MM-61041") + + th.App.UpdateConfig(func(cfg *model.Config) { *cfg.GuestAccountsSettings.Enable = true }) + th.App.Srv().SetLicense(model.NewTestLicense()) + defer func() { + appErr := th.App.Srv().RemoveLicense() + require.Nil(t, appErr) + th.App.UpdateConfig(func(cfg *model.Config) { *cfg.GuestAccountsSettings.Enable = false }) + }() permissionsUser := th.CreateUser() - th.SystemAdminClient.DemoteUserToGuest(context.Background(), permissionsUser.Id) + _, err := th.SystemAdminClient.DemoteUserToGuest(context.Background(), permissionsUser.Id) + require.NoError(t, err) permissionsUser.Roles = "system_guest" th.LinkUserToTeam(permissionsUser, th.BasicTeam) th.AddUserToChannel(permissionsUser, th.BasicChannel) @@ -1705,7 +1752,8 @@ func TestAutocompleteUsersInChannel(t *testing.T) { otherUser := th.CreateUser() th.LinkUserToTeam(otherUser, th.BasicTeam) - th.Client.Login(context.Background(), permissionsUser.Email, permissionsUser.Password) + _, _, err = th.Client.Login(context.Background(), permissionsUser.Email, permissionsUser.Password) + require.NoError(t, err) rusers, _, err := th.Client.AutocompleteUsersInChannel(context.Background(), teamId, channelId, "", model.UserSearchDefaultLimit, "") require.NoError(t, err) @@ -1723,7 +1771,8 @@ func TestAutocompleteUsersInChannel(t *testing.T) { require.NoError(t, err) assert.Empty(t, rusers.OutOfChannel) - th.App.GetOrCreateDirectChannel(th.Context, permissionsUser.Id, otherUser.Id) + _, appErr := th.App.GetOrCreateDirectChannel(th.Context, permissionsUser.Id, otherUser.Id) + require.Nil(t, appErr) rusers, _, err = th.Client.AutocompleteUsersInChannel(context.Background(), teamId, channelId, "", model.UserSearchDefaultLimit, "") require.NoError(t, err) @@ -1783,12 +1832,14 @@ func TestAutocompleteUsersInTeam(t *testing.T) { } else { assert.Len(t, rusers.Users, tc.ExpectedResults) } - th.Client.Logout(context.Background()) + _, err = th.Client.Logout(context.Background()) + require.NoError(t, err) _, resp, err := th.Client.AutocompleteUsersInTeam(context.Background(), tc.TeamId, tc.Username, model.UserSearchDefaultLimit, "") require.Error(t, err) CheckUnauthorizedStatus(t, resp) - th.Client.Login(context.Background(), newUser.Email, newUser.Password) + _, _, err = th.Client.Login(context.Background(), newUser.Email, newUser.Password) + require.NoError(t, err) _, resp, err = th.Client.AutocompleteUsersInTeam(context.Background(), tc.TeamId, tc.Username, model.UserSearchDefaultLimit, "") require.Error(t, err) CheckForbiddenStatus(t, resp) @@ -1850,12 +1901,14 @@ func TestAutocompleteUsers(t *testing.T) { assert.Len(t, rusers.Users, tc.ExpectedResults) } - th.Client.Logout(context.Background()) + _, err = th.Client.Logout(context.Background()) + require.NoError(t, err) _, resp, err := th.Client.AutocompleteUsers(context.Background(), tc.Username, model.UserSearchDefaultLimit, "") require.Error(t, err) CheckUnauthorizedStatus(t, resp) - th.Client.Login(context.Background(), newUser.Email, newUser.Password) + _, _, err = th.Client.Login(context.Background(), newUser.Email, newUser.Password) + require.NoError(t, err) _, _, err = th.Client.AutocompleteUsers(context.Background(), tc.Username, model.UserSearchDefaultLimit, "") require.NoError(t, err) }) @@ -1897,7 +1950,8 @@ func TestGetProfileImage(t *testing.T) { require.Error(t, err) CheckNotFoundStatus(t, resp) - th.Client.Logout(context.Background()) + _, err = th.Client.Logout(context.Background()) + require.NoError(t, err) _, resp, err = th.Client.GetProfileImage(context.Background(), user.Id, "") require.Error(t, err) CheckUnauthorizedStatus(t, resp) @@ -1951,7 +2005,8 @@ func TestGetUsersByIds(t *testing.T) { }) t.Run("should return error when not logged in", func(t *testing.T) { - th.Client.Logout(context.Background()) + _, err := th.Client.Logout(context.Background()) + require.NoError(t, err) _, resp, err := th.Client.GetUsersByIds(context.Background(), []string{th.BasicUser.Id}) require.Error(t, err) @@ -2011,7 +2066,8 @@ func TestGetUsersByGroupChannelIds(t *testing.T) { _, ok = usersByChannelId[gc1.Id] require.False(t, ok) - th.Client.Logout(context.Background()) + _, err = th.Client.Logout(context.Background()) + require.NoError(t, err) _, resp, err := th.Client.GetUsersByGroupChannelIds(context.Background(), []string{gc1.Id}) require.Error(t, err) CheckUnauthorizedStatus(t, resp) @@ -2039,7 +2095,8 @@ func TestGetUsersByUsernames(t *testing.T) { require.NoError(t, err) require.Len(t, users, 1, "1 user should be returned") - th.Client.Logout(context.Background()) + _, err = th.Client.Logout(context.Background()) + require.NoError(t, err) _, resp, err = th.Client.GetUsersByUsernames(context.Background(), []string{th.BasicUser.Username}) require.Error(t, err) CheckUnauthorizedStatus(t, resp) @@ -2065,7 +2122,8 @@ func TestUpdateUser(t *testing.T) { defer th.TearDown() 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) user.Nickname = "Joram Wilander" user.Roles = model.SystemUserRoleId @@ -2119,7 +2177,8 @@ func TestUpdateUser(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.UpdateUser(context.Background(), user) require.Error(t, err) CheckUnauthorizedStatus(t, resp) @@ -2140,11 +2199,13 @@ func TestUpdateAdminUser(t *testing.T) { defer th.TearDown() user := th.CreateUser() - th.App.UpdateUserRoles(th.Context, user.Id, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false) + _, appErr := th.App.UpdateUserRoles(th.Context, user.Id, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false) + require.Nil(t, appErr) user.Email = th.GenerateTestEmail() th.AddPermissionToRole(model.PermissionEditOtherUsers.Id, model.SystemUserManagerRoleId) - th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserManagerRoleId+" "+model.SystemUserAccessTokenRoleId, false) + _, appErr = th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserManagerRoleId+" "+model.SystemUserAccessTokenRoleId, false) + require.Nil(t, appErr) _, resp, err := th.Client.UpdateUser(context.Background(), user) require.Error(t, err) @@ -2181,13 +2242,16 @@ func TestPatchUser(t *testing.T) { defer th.TearDown() 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) t.Run("Timezone limit error", func(t *testing.T) { patch := &model.UserPatch{} patch.Timezone = model.StringMap{} patch.Timezone["manualTimezone"] = string(make([]byte, model.UserTimezoneMaxRunes)) - ruser, resp, err := th.Client.PatchUser(context.Background(), user.Id, patch) + var resp *model.Response + var ruser *model.User + ruser, resp, err = th.Client.PatchUser(context.Background(), user.Id, patch) CheckBadRequestStatus(t, resp) CheckErrorID(t, err, "model.user.is_valid.timezone_limit.app_error") require.Nil(t, ruser) @@ -2273,7 +2337,8 @@ func TestPatchUser(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.PatchUser(context.Background(), user.Id, patch) require.Error(t, err) CheckUnauthorizedStatus(t, resp) @@ -2313,13 +2378,15 @@ func TestPatchAdminUser(t *testing.T) { defer th.TearDown() user := th.CreateUser() - th.App.UpdateUserRoles(th.Context, user.Id, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false) + _, appErr := th.App.UpdateUserRoles(th.Context, user.Id, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false) + require.Nil(t, appErr) patch := &model.UserPatch{} patch.Email = model.NewPointer(th.GenerateTestEmail()) th.AddPermissionToRole(model.PermissionEditOtherUsers.Id, model.SystemUserManagerRoleId) - th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserManagerRoleId+" "+model.SystemUserAccessTokenRoleId, false) + _, appErr = th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserManagerRoleId+" "+model.SystemUserAccessTokenRoleId, false) + require.Nil(t, appErr) _, resp, err := th.Client.PatchUser(context.Background(), user.Id, patch) require.Error(t, err) @@ -2348,7 +2415,8 @@ func TestUserUnicodeNames(t *testing.T) { require.NoError(t, err) CheckCreatedStatus(t, resp) - _, _, _ = client.Login(context.Background(), user.Email, user.Password) + _, _, err = client.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) require.Equal(t, "wiggin77", ruser.Username, "Bad Unicode not filtered from username") require.Equal(t, "Andrew Wiggin", ruser.GetDisplayName(model.ShowFullName), "Bad Unicode not filtered from displayname") @@ -2357,7 +2425,8 @@ func TestUserUnicodeNames(t *testing.T) { t.Run("update user unicode", func(t *testing.T) { user := th.CreateUser() - client.Login(context.Background(), user.Email, user.Password) + _, _, err := client.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) user.Username = "wiggin\ufff9" user.Nickname = "Ender\u0340 \ufffcWiggin" @@ -2374,7 +2443,8 @@ func TestUserUnicodeNames(t *testing.T) { t.Run("patch user unicode", func(t *testing.T) { user := th.CreateUser() - client.Login(context.Background(), user.Email, user.Password) + _, _, err := client.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) patch := &model.UserPatch{} patch.Nickname = model.NewPointer("\U000E0000Ender\u206d Wiggin\U000E007F") @@ -2424,8 +2494,8 @@ func TestUpdateUserAuth(t *testing.T) { // When AuthData or AuthService are empty, password must be valid userAuth.AuthData = user.AuthData userAuth.AuthService = "" - _, respErr, _ = th.SystemAdminClient.UpdateUserAuth(context.Background(), user.Id, userAuth) - require.NotNil(t, respErr) + _, _, err = th.SystemAdminClient.UpdateUserAuth(context.Background(), user.Id, userAuth) + require.Error(t, err) // Regular user can not use endpoint user2 := th.CreateUser() @@ -2433,12 +2503,13 @@ func TestUpdateUserAuth(t *testing.T) { _, err = th.App.Srv().Store().User().VerifyEmail(user2.Id, user2.Email) require.NoError(t, err) - th.SystemAdminClient.Login(context.Background(), user2.Email, "passwd1") + _, _, err = th.SystemAdminClient.Login(context.Background(), user2.Email, "Pa$$word11") + require.NoError(t, err) userAuth.AuthData = user.AuthData userAuth.AuthService = user.AuthService - _, respErr, _ = th.SystemAdminClient.UpdateUserAuth(context.Background(), user.Id, userAuth) - require.NotNil(t, respErr, "Should have errored") + _, _, err = th.SystemAdminClient.UpdateUserAuth(context.Background(), user.Id, userAuth) + require.Error(t, err, "Should have errored") } func TestDeleteUser(t *testing.T) { @@ -2450,7 +2521,8 @@ func TestDeleteUser(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.DeleteUser(context.Background(), th.BasicUser.Id) require.Error(t, err) CheckUnauthorizedStatus(t, resp) @@ -2475,7 +2547,8 @@ func TestDeleteUser(t *testing.T) { require.Error(t, err) CheckForbiddenStatus(t, resp) - th.Client.Login(context.Background(), selfDeleteUser.Email, selfDeleteUser.Password) + _, _, err = th.Client.Login(context.Background(), selfDeleteUser.Email, selfDeleteUser.Password) + require.NoError(t, err) th.App.UpdateConfig(func(c *model.Config) { *c.TeamSettings.EnableUserDeactivation = false }) @@ -2696,7 +2769,8 @@ func TestUpdateUserActive(t *testing.T) { require.Error(t, err) CheckBadRequestStatus(t, resp) - th.Client.Logout(context.Background()) + _, err = th.Client.Logout(context.Background()) + require.NoError(t, err) resp, err = th.Client.UpdateUserActive(context.Background(), user.Id, true) require.Error(t, err) @@ -2783,7 +2857,8 @@ func TestUpdateUserActive(t *testing.T) { } user, err := th.App.CreateGuest(th.Context, guest) require.Nil(t, err) - th.App.UpdateActive(th.Context, user, false) + _, appErr := th.App.UpdateActive(th.Context, user, false) + require.Nil(t, appErr) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.GuestAccountsSettings.Enable = false }) defer th.App.UpdateConfig(func(cfg *model.Config) { *cfg.GuestAccountsSettings.Enable = true }) @@ -2809,7 +2884,8 @@ func TestUpdateUserActive(t *testing.T) { } user, appErr := th.App.CreateGuest(th.Context, guest) require.Nil(t, appErr) - th.App.UpdateActive(th.Context, user, false) + _, appErr = th.App.UpdateActive(th.Context, user, false) + require.Nil(t, appErr) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.GuestAccountsSettings.Enable = true }) th.TestForSystemAdminAndLocal(t, func(t *testing.T, client *model.Client4) { @@ -2886,7 +2962,8 @@ func TestGetUsers(t *testing.T) { require.Equal(t, err.Error(), "Invalid or missing role in request body.") }) - th.Client.Logout(context.Background()) + _, err := th.Client.Logout(context.Background()) + require.NoError(t, err) _, resp, err := th.Client.GetUsers(context.Background(), 0, 60, "") require.Error(t, err) CheckUnauthorizedStatus(t, resp) @@ -2911,7 +2988,8 @@ func TestGetNewUsersInTeam(t *testing.T) { require.NoError(t, err) require.Len(t, rusers, 1, "should be 1 per page") - th.Client.Logout(context.Background()) + _, err = th.Client.Logout(context.Background()) + require.NoError(t, err) _, resp, err := th.Client.GetNewUsersInTeam(context.Background(), teamId, 1, 1, "") require.Error(t, err) CheckUnauthorizedStatus(t, resp) @@ -2936,7 +3014,8 @@ func TestGetRecentlyActiveUsersInTeam(t *testing.T) { require.NoError(t, err) require.Len(t, rusers, 1, "should be 1 per page") - th.Client.Logout(context.Background()) + _, err = th.Client.Logout(context.Background()) + require.NoError(t, err) _, resp, err := th.Client.GetRecentlyActiveUsersInTeam(context.Background(), teamId, 0, 1, "") require.Error(t, err) CheckUnauthorizedStatus(t, resp) @@ -2947,7 +3026,8 @@ func TestGetActiveUsersInTeam(t *testing.T) { defer th.TearDown() teamId := th.BasicTeam.Id - th.SystemAdminClient.UpdateUserActive(context.Background(), th.BasicUser2.Id, false) + _, err := th.SystemAdminClient.UpdateUserActive(context.Background(), th.BasicUser2.Id, false) + require.NoError(t, err) rusers, _, err := th.Client.GetActiveUsersInTeam(context.Background(), teamId, 0, 60, "") require.NoError(t, err) @@ -2966,7 +3046,8 @@ func TestGetActiveUsersInTeam(t *testing.T) { _, err = th.Client.DoAPIGet(context.Background(), "/users?inactive=true&active=true", "") require.Error(t, err) - th.Client.Logout(context.Background()) + _, err = th.Client.Logout(context.Background()) + require.NoError(t, err) _, resp, err := th.Client.GetActiveUsersInTeam(context.Background(), teamId, 0, 1, "") require.Error(t, err) CheckUnauthorizedStatus(t, resp) @@ -2988,7 +3069,10 @@ func TestGetUsersWithoutTeam(t *testing.T) { }) require.NoError(t, err) th.LinkUserToTeam(user, th.BasicTeam) - defer th.App.Srv().Store().User().PermanentDelete(th.Context, user.Id) + defer func() { + err = th.App.Srv().Store().User().PermanentDelete(th.Context, user.Id) + require.NoError(t, err) + }() user2, _, err := th.Client.CreateUser(context.Background(), &model.User{ Username: "a000000001" + model.NewId(), @@ -2996,7 +3080,10 @@ func TestGetUsersWithoutTeam(t *testing.T) { Password: "Password1", }) require.NoError(t, err) - defer th.App.Srv().Store().User().PermanentDelete(th.Context, user2.Id) + defer func() { + err = th.App.Srv().Store().User().PermanentDelete(th.Context, user2.Id) + require.NoError(t, err) + }() rusers, _, err := th.SystemAdminClient.GetUsersWithoutTeam(context.Background(), 0, 100, "") require.NoError(t, err) @@ -3042,13 +3129,15 @@ func TestGetUsersInTeam(t *testing.T) { require.NoError(t, err) require.Empty(t, rusers, "should be no users") - th.Client.Logout(context.Background()) + _, err = th.Client.Logout(context.Background()) + require.NoError(t, err) _, resp, err = th.Client.GetUsersInTeam(context.Background(), teamId, 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.GetUsersInTeam(context.Background(), teamId, 0, 60, "") require.Error(t, err) CheckForbiddenStatus(t, resp) @@ -3084,13 +3173,15 @@ func TestGetUsersNotInTeam(t *testing.T) { require.NoError(t, err) require.Empty(t, rusers, "should be no users") - th.Client.Logout(context.Background()) + _, err = th.Client.Logout(context.Background()) + require.NoError(t, err) _, resp, err = th.Client.GetUsersNotInTeam(context.Background(), teamId, 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.GetUsersNotInTeam(context.Background(), teamId, 0, 60, "") require.Error(t, err) CheckForbiddenStatus(t, resp) @@ -3122,13 +3213,15 @@ func TestGetUsersInChannel(t *testing.T) { require.NoError(t, err) require.Empty(t, rusers, "should be no users") - th.Client.Logout(context.Background()) + _, err = th.Client.Logout(context.Background()) + require.NoError(t, err) _, resp, err := th.Client.GetUsersInChannel(context.Background(), channelId, 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.GetUsersInChannel(context.Background(), channelId, 0, 60, "") require.Error(t, err) CheckForbiddenStatus(t, resp) @@ -3149,7 +3242,8 @@ func TestGetUsersInChannel(t *testing.T) { require.Nil(t, aErr) _, aErr = th.App.AddUserToChannel(th.Context, th.BasicUser2, channel, false) require.Nil(t, aErr) - th.SystemAdminClient.DeleteChannel(context.Background(), channel.Id) + _, err = th.SystemAdminClient.DeleteChannel(context.Background(), channel.Id) + require.NoError(t, err) experimentalViewArchivedChannels := *th.App.Config().TeamSettings.ExperimentalViewArchivedChannels th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.ExperimentalViewArchivedChannels = true }) @@ -3205,12 +3299,14 @@ func TestGetUsersNotInChannel(t *testing.T) { require.NoError(t, err) require.Empty(t, rusers, "should be no users") - th.Client.Logout(context.Background()) + _, err = th.Client.Logout(context.Background()) + require.NoError(t, err) _, resp, err := th.Client.GetUsersNotInChannel(context.Background(), teamId, channelId, 0, 60, "") require.Error(t, err) CheckUnauthorizedStatus(t, resp) - 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.GetUsersNotInChannel(context.Background(), teamId, channelId, 0, 60, "") require.Error(t, err) CheckForbiddenStatus(t, resp) @@ -3255,8 +3351,10 @@ func TestGetUsersInGroup(t *testing.T) { th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuProfessional)) t.Run("Requires manage system permission to access users in group", func(t *testing.T) { - th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password) - _, response, err := th.Client.GetUsersInGroup(context.Background(), group.Id, 0, 60, "") + _, _, err := th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password) + require.NoError(t, err) + var response *model.Response + _, response, err = th.Client.GetUsersInGroup(context.Background(), group.Id, 0, 60, "") require.Error(t, err) CheckForbiddenStatus(t, response) }) @@ -3280,15 +3378,18 @@ func TestGetUsersInGroup(t *testing.T) { assert.Nil(t, err) t.Run("Returns users in custom group when called by regular user", func(t *testing.T) { - th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password) + _, _, err := th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password) + require.NoError(t, err) users, _, err := th.Client.GetUsersInGroup(context.Background(), customGroup.Id, 0, 60, "") require.NoError(t, err) assert.Equal(t, users[0].Id, user1.Id) }) t.Run("Returns no users in custom group when called by guest user", func(t *testing.T) { - th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password) - th.App.DemoteUserToGuest(th.Context, th.BasicUser) + _, _, err := th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password) + require.NoError(t, err) + appErr := th.App.DemoteUserToGuest(th.Context, th.BasicUser) + require.Nil(t, appErr) users, _, err := th.Client.GetUsersInGroup(context.Background(), customGroup.Id, 0, 60, "") require.NoError(t, err) @@ -3472,7 +3573,8 @@ func TestGenerateMfaSecret(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.GenerateMfaSecret(context.Background(), th.BasicUser.Id) require.Error(t, err) @@ -3510,7 +3612,8 @@ func TestUpdateUserPassword(t *testing.T) { _, err = th.Client.UpdateUserPassword(context.Background(), th.BasicUser.Id, password, th.BasicUser.Password) require.NoError(t, err) - th.Client.Logout(context.Background()) + _, err = th.Client.Logout(context.Background()) + require.NoError(t, err) resp, err = th.Client.UpdateUserPassword(context.Background(), th.BasicUser.Id, password, password) require.Error(t, err) CheckUnauthorizedStatus(t, resp) @@ -3574,14 +3677,17 @@ func TestResetPassword(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() - th.Client.Logout(context.Background()) + _, err := th.Client.Logout(context.Background()) + require.NoError(t, err) user := th.BasicUser // Delete all the messages before check the reset password - mail.DeleteMailBox(user.Email) + err = mail.DeleteMailBox(user.Email) + require.NoError(t, err) th.TestForAllClients(t, func(t *testing.T, client *model.Client4) { - _, err := client.SendPasswordResetEmail(context.Background(), user.Email) + _, err = client.SendPasswordResetEmail(context.Background(), user.Email) require.NoError(t, err) - resp, err := client.SendPasswordResetEmail(context.Background(), "") + var resp *model.Response + resp, err = client.SendPasswordResetEmail(context.Background(), "") require.Error(t, err) CheckBadRequestStatus(t, resp) // Should not leak whether the email is attached to an account or not @@ -3590,8 +3696,7 @@ func TestResetPassword(t *testing.T) { }) // Check if the email was send to the right email address and the recovery key match var resultsMailbox mail.JSONMessageHeaderInbucket - err := mail.RetryInbucket(5, func() error { - var err error + err = mail.RetryInbucket(5, func() error { resultsMailbox, err = mail.GetMailBox(user.Email) return err }) @@ -3633,8 +3738,10 @@ func TestResetPassword(t *testing.T) { CheckBadRequestStatus(t, resp) _, err = th.Client.ResetPassword(context.Background(), recoveryToken.Token, "newpwd") require.NoError(t, err) - th.Client.Login(context.Background(), user.Email, "newpwd") - th.Client.Logout(context.Background()) + _, _, err = th.Client.Login(context.Background(), user.Email, "newpwd") + require.NoError(t, err) + _, err = th.Client.Logout(context.Background()) + require.NoError(t, err) resp, err = th.Client.ResetPassword(context.Background(), recoveryToken.Token, "newpwd") require.Error(t, err) CheckBadRequestStatus(t, resp) @@ -3654,7 +3761,8 @@ func TestGetSessions(t *testing.T) { user := th.BasicUser - th.Client.Login(context.Background(), user.Email, user.Password) + _, _, err := th.Client.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) sessions, _, err := th.Client.GetSessions(context.Background(), user.Id, "") require.NoError(t, err) @@ -3674,7 +3782,8 @@ func TestGetSessions(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.GetSessions(context.Background(), th.BasicUser2.Id, "") require.Error(t, err) CheckUnauthorizedStatus(t, resp) @@ -3694,7 +3803,8 @@ func TestRevokeSessions(t *testing.T) { defer th.TearDown() user := th.BasicUser - th.Client.Login(context.Background(), user.Email, user.Password) + _, _, err := th.Client.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) sessions, _, _ := th.Client.GetSessions(context.Background(), user.Id, "") require.NotZero(t, len(sessions), "sessions should exist") for _, session := range sessions { @@ -3726,7 +3836,8 @@ func TestRevokeSessions(t *testing.T) { require.Error(t, err) CheckBadRequestStatus(t, resp) - th.Client.Logout(context.Background()) + _, err = th.Client.Logout(context.Background()) + require.NoError(t, err) resp, err = th.Client.RevokeSession(context.Background(), user.Id, model.NewId()) require.Error(t, err) CheckUnauthorizedStatus(t, resp) @@ -3751,7 +3862,8 @@ func TestRevokeAllSessions(t *testing.T) { defer th.TearDown() user := th.BasicUser - 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.RevokeAllSessions(context.Background(), th.BasicUser2.Id) require.Error(t, err) @@ -3764,12 +3876,14 @@ func TestRevokeAllSessions(t *testing.T) { _, err = th.Client.RevokeAllSessions(context.Background(), user.Id) require.NoError(t, err) - th.Client.Logout(context.Background()) + _, err = th.Client.Logout(context.Background()) + require.NoError(t, err) resp, err = th.Client.RevokeAllSessions(context.Background(), user.Id) require.Error(t, err) CheckUnauthorizedStatus(t, resp) - th.Client.Login(context.Background(), user.Email, user.Password) + _, _, err = th.Client.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) sessions, _, _ := th.Client.GetSessions(context.Background(), user.Id, "") require.NotEmpty(t, sessions, "session should exist") @@ -3790,19 +3904,23 @@ func TestRevokeSessionsFromAllUsers(t *testing.T) { defer th.TearDown() user := th.BasicUser - 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.RevokeSessionsFromAllUsers(context.Background()) 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.RevokeSessionsFromAllUsers(context.Background()) require.Error(t, err) CheckUnauthorizedStatus(t, resp) - th.Client.Login(context.Background(), user.Email, user.Password) + _, _, err = th.Client.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) admin := th.SystemAdminUser - th.Client.Login(context.Background(), admin.Email, admin.Password) + _, _, err = th.Client.Login(context.Background(), admin.Email, admin.Password) + require.NoError(t, err) sessions, err := th.Server.Store().Session().GetSessions(th.Context, user.Id) require.NotEmpty(t, sessions) require.NoError(t, err) @@ -3863,7 +3981,8 @@ func TestAttachDeviceId(t *testing.T) { }) t.Run("not logged in", func(t *testing.T) { - th.Client.Logout(context.Background()) + _, err := th.Client.Logout(context.Background()) + require.NoError(t, err) resp, err := th.Client.AttachDeviceProps(context.Background(), map[string]string{}) require.Error(t, err) @@ -3878,7 +3997,8 @@ func TestAttachDeviceId(t *testing.T) { resetSession := func(session *model.Session) { session.AddProp(model.SessionPropDeviceNotificationDisabled, "") session.AddProp(model.SessionPropMobileVersion, "") - th.Server.Store().Session().UpdateProps(session) + err := th.Server.Store().Session().UpdateProps(session) + require.NoError(t, err) th.App.ClearSessionCacheForUser(session.UserId) } @@ -3961,7 +4081,8 @@ func TestGetUserAudits(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.GetUserAudits(context.Background(), user.Id, 0, 100, "") require.Error(t, err) CheckUnauthorizedStatus(t, resp) @@ -4009,7 +4130,8 @@ func TestSendVerificationEmail(t *testing.T) { _, err = th.Client.SendVerificationEmail(context.Background(), th.GenerateTestEmail()) require.NoError(t, err) - th.Client.Logout(context.Background()) + _, err = th.Client.Logout(context.Background()) + require.NoError(t, err) _, err = th.Client.SendVerificationEmail(context.Background(), th.BasicUser.Email) require.NoError(t, err) } @@ -4031,7 +4153,8 @@ func TestSetProfileImage(t *testing.T) { // status code returns either forbidden or unauthorized // note: forbidden is set as default at Client4.SetProfileImage when request is terminated early by server - th.Client.Logout(context.Background()) + _, err = th.Client.Logout(context.Background()) + require.NoError(t, err) resp, err = th.Client.SetProfileImage(context.Background(), user.Id, data) require.Error(t, err) if resp.StatusCode == http.StatusForbidden { @@ -4089,7 +4212,8 @@ func TestSetDefaultProfileImage(t *testing.T) { // status code returns either forbidden or unauthorized // note: forbidden is set as default at Client4.SetDefaultProfileImage when request is terminated early by server - th.Client.Logout(context.Background()) + _, err = th.Client.Logout(context.Background()) + require.NoError(t, err) resp, err = th.Client.SetDefaultProfileImage(context.Background(), user.Id) require.Error(t, err) if resp.StatusCode == http.StatusForbidden { @@ -4117,7 +4241,8 @@ func TestSetDefaultProfileImage(t *testing.T) { func TestLogin(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() - th.Client.Logout(context.Background()) + _, err := th.Client.Logout(context.Background()) + require.NoError(t, err) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableBotAccountCreation = true @@ -4190,7 +4315,8 @@ func TestLogin(t *testing.T) { func TestLoginWithLag(t *testing.T) { th := Setup(t).InitBasic() defer th.TearDown() - th.Client.Logout(context.Background()) + _, err := th.Client.Logout(context.Background()) + require.NoError(t, err) t.Run("with replication lag, caches cleared", func(t *testing.T) { if !replicaFlag { @@ -4212,7 +4338,10 @@ func TestLoginWithLag(t *testing.T) { cmdErr := mainHelper.SetReplicationLagForTesting(5) require.NoError(t, cmdErr) - defer mainHelper.SetReplicationLagForTesting(0) + defer func() { + err = mainHelper.SetReplicationLagForTesting(0) + require.NoError(t, err) + }() _, _, err := th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password) require.NoError(t, err) @@ -4419,14 +4548,16 @@ func TestCBALogin(t *testing.T) { }) t.Run("missing cert header", func(t *testing.T) { - th.Client.Logout(context.Background()) + _, err := th.Client.Logout(context.Background()) + require.NoError(t, err) _, resp, err := th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password) require.Error(t, err) CheckBadRequestStatus(t, resp) }) t.Run("missing cert subject", func(t *testing.T) { - th.Client.Logout(context.Background()) + _, err := th.Client.Logout(context.Background()) + require.NoError(t, err) th.Client.HTTPHeader["X-SSL-Client-Cert"] = "valid_cert_fake" _, resp, err := th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password) require.Error(t, err) @@ -4434,7 +4565,8 @@ func TestCBALogin(t *testing.T) { }) t.Run("emails mismatch", func(t *testing.T) { - th.Client.Logout(context.Background()) + _, err := th.Client.Logout(context.Background()) + require.NoError(t, err) th.Client.HTTPHeader["X-SSL-Client-Cert-Subject-DN"] = "C=US, ST=Maryland, L=Pasadena, O=Brent Baccala, OU=FreeSoft, CN=www.freesoft.org/emailAddress=mis_match" + th.BasicUser.Email _, resp, err := th.Client.Login(context.Background(), th.BasicUser.Email, "") require.Error(t, err) @@ -4522,7 +4654,8 @@ func TestSwitchAccount(t *testing.T) { th.App.UpdateConfig(func(cfg *model.Config) { *cfg.GitLabSettings.Enable = true }) - th.Client.Logout(context.Background()) + _, err := th.Client.Logout(context.Background()) + require.NoError(t, err) sr := &model.SwitchRequest{ CurrentService: model.UserAuthServiceEmail, @@ -4684,10 +4817,12 @@ func TestSwitchAccount(t *testing.T) { require.Equal(t, "/login?extra=signin_change", link) - th.Client.Logout(context.Background()) + _, err = th.Client.Logout(context.Background()) + require.NoError(t, err) _, _, err = th.Client.Login(context.Background(), th.BasicUser.Email, th.BasicUser.Password) require.NoError(t, err) - th.Client.Logout(context.Background()) + _, err = th.Client.Logout(context.Background()) + require.NoError(t, err) sr = &model.SwitchRequest{ CurrentService: model.UserAuthServiceGitlab, @@ -4834,7 +4969,8 @@ func TestCreateUserAccessToken(t *testing.T) { defer th.TearDown() th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = false }) - th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false) + _, appErr := th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false) + require.Nil(t, appErr) th.TestForAllClients(t, func(t *testing.T, client *model.Client4) { _, resp, err := client.CreateUserAccessToken(context.Background(), th.BasicUser.Id, "test token") @@ -4848,7 +4984,8 @@ func TestCreateUserAccessToken(t *testing.T) { defer th.TearDown() th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true }) - th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false) + _, appErr := th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false) + require.Nil(t, appErr) rtoken, _, err := th.Client.CreateUserAccessToken(context.Background(), th.BasicUser.Id, "test token") require.NoError(t, err) @@ -4879,7 +5016,8 @@ func TestCreateUserAccessToken(t *testing.T) { th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true }) th.AddPermissionToRole(model.PermissionEditOtherUsers.Id, model.SystemUserManagerRoleId) - th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserManagerRoleId+" "+model.SystemUserAccessTokenRoleId, false) + _, appErr := th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserManagerRoleId+" "+model.SystemUserAccessTokenRoleId, false) + require.Nil(t, appErr) rtoken, _, err := th.Client.CreateUserAccessToken(context.Background(), th.BasicUser2.Id, "test token") require.NoError(t, err) @@ -4897,7 +5035,8 @@ func TestCreateUserAccessToken(t *testing.T) { th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true }) th.AddPermissionToRole(model.PermissionEditOtherUsers.Id, model.SystemUserManagerRoleId) - th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserManagerRoleId+" "+model.SystemUserAccessTokenRoleId, false) + _, appErr := th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserManagerRoleId+" "+model.SystemUserAccessTokenRoleId, false) + require.Nil(t, appErr) _, resp, err := th.Client.CreateUserAccessToken(context.Background(), th.SystemAdminUser.Id, "test token") require.Error(t, err) @@ -4964,7 +5103,8 @@ func TestCreateUserAccessToken(t *testing.T) { defer th.RestoreDefaultRolePermissions(th.SaveDefaultRolePermissions()) th.AddPermissionToRole(model.PermissionCreateBot.Id, model.TeamUserRoleId) th.AddPermissionToRole(model.PermissionCreateUserAccessToken.Id, model.TeamUserRoleId) - th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false) + _, appErr := th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false) + require.Nil(t, appErr) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableBotAccountCreation = true }) @@ -4976,7 +5116,10 @@ func TestCreateUserAccessToken(t *testing.T) { }) require.NoError(t, err) CheckCreatedStatus(t, resp) - defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId) + defer func() { + appErr := th.App.PermanentDeleteBot(th.Context, createdBot.UserId) + require.Nil(t, appErr) + }() t.Run("without MANAGE_BOT permission", func(t *testing.T) { th.RemovePermissionFromRole(model.PermissionManageBots.Id, model.TeamUserRoleId) @@ -5006,7 +5149,8 @@ func TestCreateUserAccessToken(t *testing.T) { th.AddPermissionToRole(model.PermissionCreateBot.Id, model.TeamUserRoleId) th.AddPermissionToRole(model.PermissionManageBots.Id, model.TeamUserRoleId) th.AddPermissionToRole(model.PermissionCreateUserAccessToken.Id, model.TeamUserRoleId) - th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false) + _, appErr := th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false) + require.Nil(t, appErr) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableBotAccountCreation = true }) @@ -5018,7 +5162,10 @@ func TestCreateUserAccessToken(t *testing.T) { }) require.NoError(t, err) CheckCreatedStatus(t, resp) - defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId) + defer func() { + appErr := th.App.PermanentDeleteBot(th.Context, createdBot.UserId) + require.Nil(t, appErr) + }() t.Run("only having MANAGE_BOTS permission", func(t *testing.T) { _, resp, err = th.Client.CreateUserAccessToken(context.Background(), createdBot.UserId, "test token") @@ -5066,7 +5213,8 @@ func TestGetUserAccessToken(t *testing.T) { defer th.TearDown() th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true }) - th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false) + _, appErr := th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false) + require.Nil(t, appErr) token, _, err := th.Client.CreateUserAccessToken(context.Background(), th.BasicUser.Id, "test token") require.NoError(t, err) @@ -5086,7 +5234,8 @@ func TestGetUserAccessToken(t *testing.T) { th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true }) - th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false) + _, appErr := th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false) + require.Nil(t, appErr) token, _, err := th.Client.CreateUserAccessToken(context.Background(), th.BasicUser.Id, "test token") require.NoError(t, err) @@ -5111,7 +5260,8 @@ func TestGetUserAccessToken(t *testing.T) { th.AddPermissionToRole(model.PermissionManageBots.Id, model.TeamUserRoleId) th.AddPermissionToRole(model.PermissionCreateUserAccessToken.Id, model.TeamUserRoleId) th.AddPermissionToRole(model.PermissionReadUserAccessToken.Id, model.TeamUserRoleId) - th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false) + _, appErr := th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false) + require.Nil(t, appErr) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableBotAccountCreation = true }) @@ -5123,7 +5273,10 @@ func TestGetUserAccessToken(t *testing.T) { }) require.NoError(t, err) CheckCreatedStatus(t, resp) - defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId) + defer func() { + appErr := th.App.PermanentDeleteBot(th.Context, createdBot.UserId) + require.Nil(t, appErr) + }() token, _, err := th.Client.CreateUserAccessToken(context.Background(), createdBot.UserId, "test token") require.NoError(t, err) @@ -5159,7 +5312,8 @@ func TestGetUserAccessToken(t *testing.T) { th.AddPermissionToRole(model.PermissionManageBots.Id, model.TeamUserRoleId) th.AddPermissionToRole(model.PermissionCreateUserAccessToken.Id, model.TeamUserRoleId) th.AddPermissionToRole(model.PermissionReadUserAccessToken.Id, model.TeamUserRoleId) - th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false) + _, appErr := th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false) + require.Nil(t, appErr) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableBotAccountCreation = true }) @@ -5171,7 +5325,10 @@ func TestGetUserAccessToken(t *testing.T) { }) require.NoError(t, err) CheckCreatedStatus(t, resp) - defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId) + defer func() { + appErr := th.App.PermanentDeleteBot(th.Context, createdBot.UserId) + require.Nil(t, appErr) + }() token, _, err := th.SystemAdminClient.CreateUserAccessToken(context.Background(), createdBot.UserId, "test token") require.NoError(t, err) @@ -5202,7 +5359,8 @@ func TestGetUserAccessTokensForUser(t *testing.T) { th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true }) - th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false) + _, appErr := th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false) + require.Nil(t, appErr) _, _, err := th.Client.CreateUserAccessToken(context.Background(), th.BasicUser.Id, "test token") require.NoError(t, err) @@ -5227,7 +5385,8 @@ func TestGetUserAccessTokensForUser(t *testing.T) { th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true }) - th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false) + _, appErr := th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false) + require.Nil(t, appErr) _, _, err := th.Client.CreateUserAccessToken(context.Background(), th.BasicUser.Id, "test token") require.NoError(t, err) @@ -5254,7 +5413,8 @@ func TestGetUserAccessTokens(t *testing.T) { th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true }) - th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false) + _, appErr := th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false) + require.Nil(t, appErr) _, resp, err := th.Client.GetUserAccessTokens(context.Background(), 0, 100) require.Error(t, err) @@ -5267,7 +5427,8 @@ func TestGetUserAccessTokens(t *testing.T) { th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true }) - th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false) + _, appErr := th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false) + require.Nil(t, appErr) _, _, err := th.Client.CreateUserAccessToken(context.Background(), th.BasicUser.Id, "test token 2") require.NoError(t, err) @@ -5287,7 +5448,8 @@ func TestGetUserAccessTokens(t *testing.T) { th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true }) - th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false) + _, appErr := th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false) + require.Nil(t, appErr) _, _, err := th.Client.CreateUserAccessToken(context.Background(), th.BasicUser.Id, "test token 2") require.NoError(t, err) @@ -5310,7 +5472,8 @@ func TestSearchUserAccessToken(t *testing.T) { th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true }) - th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false) + _, appErr := th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false) + require.Nil(t, appErr) token, _, err := th.Client.CreateUserAccessToken(context.Background(), th.BasicUser.Id, testDescription) require.NoError(t, err) @@ -5346,7 +5509,8 @@ func TestRevokeUserAccessToken(t *testing.T) { th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true }) - th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false) + _, appErr := th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false) + require.Nil(t, appErr) th.TestForAllClients(t, func(t *testing.T, client *model.Client4) { token, _, err := client.CreateUserAccessToken(context.Background(), th.BasicUser.Id, "test token") require.NoError(t, err) @@ -5384,7 +5548,8 @@ func TestRevokeUserAccessToken(t *testing.T) { th.AddPermissionToRole(model.PermissionManageBots.Id, model.TeamUserRoleId) th.AddPermissionToRole(model.PermissionCreateUserAccessToken.Id, model.TeamUserRoleId) th.AddPermissionToRole(model.PermissionRevokeUserAccessToken.Id, model.TeamUserRoleId) - th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false) + _, appErr := th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false) + require.Nil(t, appErr) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableBotAccountCreation = true }) @@ -5396,7 +5561,10 @@ func TestRevokeUserAccessToken(t *testing.T) { }) require.NoError(t, err) CheckCreatedStatus(t, resp) - defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId) + defer func() { + appErr := th.App.PermanentDeleteBot(th.Context, createdBot.UserId) + require.Nil(t, appErr) + }() token, _, err := th.Client.CreateUserAccessToken(context.Background(), createdBot.UserId, "test token") require.NoError(t, err) @@ -5428,7 +5596,8 @@ func TestRevokeUserAccessToken(t *testing.T) { th.AddPermissionToRole(model.PermissionManageBots.Id, model.TeamUserRoleId) th.AddPermissionToRole(model.PermissionCreateUserAccessToken.Id, model.TeamUserRoleId) th.AddPermissionToRole(model.PermissionRevokeUserAccessToken.Id, model.TeamUserRoleId) - th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false) + _, appErr := th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false) + require.Nil(t, appErr) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableBotAccountCreation = true }) @@ -5440,7 +5609,10 @@ func TestRevokeUserAccessToken(t *testing.T) { }) require.NoError(t, err) CheckCreatedStatus(t, resp) - defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId) + defer func() { + appErr := th.App.PermanentDeleteBot(th.Context, createdBot.UserId) + require.Nil(t, appErr) + }() token, _, err := th.SystemAdminClient.CreateUserAccessToken(context.Background(), createdBot.UserId, "test token") require.NoError(t, err) @@ -5467,7 +5639,8 @@ func TestDisableUserAccessToken(t *testing.T) { th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true }) - th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false) + _, appErr := th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false) + require.Nil(t, appErr) token, _, err := th.Client.CreateUserAccessToken(context.Background(), th.BasicUser.Id, "test token") require.NoError(t, err) assertToken(t, th, token, th.BasicUser.Id) @@ -5503,7 +5676,8 @@ func TestDisableUserAccessToken(t *testing.T) { th.AddPermissionToRole(model.PermissionManageBots.Id, model.TeamUserRoleId) th.AddPermissionToRole(model.PermissionCreateUserAccessToken.Id, model.TeamUserRoleId) th.AddPermissionToRole(model.PermissionRevokeUserAccessToken.Id, model.TeamUserRoleId) - th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false) + _, appErr := th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false) + require.Nil(t, appErr) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableBotAccountCreation = true }) @@ -5515,7 +5689,10 @@ func TestDisableUserAccessToken(t *testing.T) { }) require.NoError(t, err) CheckCreatedStatus(t, resp) - defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId) + defer func() { + appErr := th.App.PermanentDeleteBot(th.Context, createdBot.UserId) + require.Nil(t, appErr) + }() token, _, err := th.Client.CreateUserAccessToken(context.Background(), createdBot.UserId, "test token") require.NoError(t, err) @@ -5547,7 +5724,8 @@ func TestDisableUserAccessToken(t *testing.T) { th.AddPermissionToRole(model.PermissionManageBots.Id, model.TeamUserRoleId) th.AddPermissionToRole(model.PermissionCreateUserAccessToken.Id, model.TeamUserRoleId) th.AddPermissionToRole(model.PermissionRevokeUserAccessToken.Id, model.TeamUserRoleId) - th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false) + _, appErr := th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false) + require.Nil(t, appErr) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableBotAccountCreation = true }) @@ -5559,7 +5737,10 @@ func TestDisableUserAccessToken(t *testing.T) { }) require.NoError(t, err) CheckCreatedStatus(t, resp) - defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId) + defer func() { + appErr := th.App.PermanentDeleteBot(th.Context, createdBot.UserId) + require.Nil(t, appErr) + }() token, _, err := th.SystemAdminClient.CreateUserAccessToken(context.Background(), createdBot.UserId, "test token") require.NoError(t, err) @@ -5586,7 +5767,8 @@ func TestEnableUserAccessToken(t *testing.T) { th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true }) - th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false) + _, appErr := th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false) + require.Nil(t, appErr) token, _, err := th.Client.CreateUserAccessToken(context.Background(), th.BasicUser.Id, "test token") require.NoError(t, err) assertToken(t, th, token, th.BasicUser.Id) @@ -5630,7 +5812,8 @@ func TestEnableUserAccessToken(t *testing.T) { th.AddPermissionToRole(model.PermissionManageBots.Id, model.TeamUserRoleId) th.AddPermissionToRole(model.PermissionCreateUserAccessToken.Id, model.TeamUserRoleId) th.AddPermissionToRole(model.PermissionRevokeUserAccessToken.Id, model.TeamUserRoleId) - th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false) + _, appErr := th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false) + require.Nil(t, appErr) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableBotAccountCreation = true }) @@ -5642,7 +5825,10 @@ func TestEnableUserAccessToken(t *testing.T) { }) require.NoError(t, err) CheckCreatedStatus(t, resp) - defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId) + defer func() { + appErr := th.App.PermanentDeleteBot(th.Context, createdBot.UserId) + require.Nil(t, appErr) + }() token, _, err := th.Client.CreateUserAccessToken(context.Background(), createdBot.UserId, "test token") require.NoError(t, err) @@ -5677,7 +5863,8 @@ func TestEnableUserAccessToken(t *testing.T) { th.AddPermissionToRole(model.PermissionManageBots.Id, model.TeamUserRoleId) th.AddPermissionToRole(model.PermissionCreateUserAccessToken.Id, model.TeamUserRoleId) th.AddPermissionToRole(model.PermissionRevokeUserAccessToken.Id, model.TeamUserRoleId) - th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false) + _, appErr := th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.TeamUserRoleId, false) + require.Nil(t, appErr) th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableBotAccountCreation = true }) @@ -5689,7 +5876,10 @@ func TestEnableUserAccessToken(t *testing.T) { }) require.NoError(t, err) CheckCreatedStatus(t, resp) - defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId) + defer func() { + appErr := th.App.PermanentDeleteBot(th.Context, createdBot.UserId) + require.Nil(t, appErr) + }() token, _, err := th.SystemAdminClient.CreateUserAccessToken(context.Background(), createdBot.UserId, "test token") require.NoError(t, err) @@ -5720,7 +5910,8 @@ func TestUserAccessTokenInactiveUser(t *testing.T) { th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true }) - th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false) + _, appErr := th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false) + require.Nil(t, appErr) token, _, err := th.Client.CreateUserAccessToken(context.Background(), th.BasicUser.Id, testDescription) require.NoError(t, err) @@ -5728,7 +5919,8 @@ func TestUserAccessTokenInactiveUser(t *testing.T) { _, _, err = th.Client.GetMe(context.Background(), "") require.NoError(t, err) - th.App.UpdateActive(th.Context, th.BasicUser, false) + _, appErr = th.App.UpdateActive(th.Context, th.BasicUser, false) + require.Nil(t, appErr) _, resp, err := th.Client.GetMe(context.Background(), "") require.Error(t, err) @@ -5743,7 +5935,8 @@ func TestUserAccessTokenDisableConfig(t *testing.T) { th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true }) - th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false) + _, appErr := th.App.UpdateUserRoles(th.Context, th.BasicUser.Id, model.SystemUserRoleId+" "+model.SystemUserAccessTokenRoleId, false) + require.Nil(t, appErr) token, _, err := th.Client.CreateUserAccessToken(context.Background(), th.BasicUser.Id, testDescription) require.NoError(t, err) @@ -6044,7 +6237,8 @@ func TestDemoteUserToGuest(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()) @@ -6106,7 +6300,10 @@ func TestDemoteUserToGuest(t *testing.T) { require.NoError(t, err) _, err = th.SystemAdminClient.DemoteUserToGuest(context.Background(), user.Id) require.NoError(t, err) - defer th.SystemAdminClient.PromoteGuestToUser(context.Background(), user.Id) + defer func() { + _, err = th.SystemAdminClient.PromoteGuestToUser(context.Background(), user.Id) + require.NoError(t, err) + }() assertExpectedWebsocketEvent(t, webSocketClient, model.WebsocketEventUserUpdated, func(event *model.WebSocketEvent) { eventUser, ok := event.GetData()["user"].(*model.User) @@ -6128,13 +6325,15 @@ func TestPromoteGuestToUser(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()) user := th.BasicUser - th.App.UpdateUserRoles(th.Context, user.Id, model.SystemGuestRoleId, false) + _, appErr := th.App.UpdateUserRoles(th.Context, user.Id, model.SystemGuestRoleId, false) + require.Nil(t, appErr) th.TestForSystemAdminAndLocal(t, func(t *testing.T, c *model.Client4) { _, _, err := c.GetUser(context.Background(), user.Id, "") @@ -6172,7 +6371,10 @@ func TestPromoteGuestToUser(t *testing.T) { require.NoError(t, err) _, err = th.SystemAdminClient.PromoteGuestToUser(context.Background(), user.Id) require.NoError(t, err) - defer th.SystemAdminClient.DemoteUserToGuest(context.Background(), user.Id) + defer func() { + _, err = th.SystemAdminClient.DemoteUserToGuest(context.Background(), user.Id) + require.NoError(t, err) + }() assertExpectedWebsocketEvent(t, webSocketClient, model.WebsocketEventUserUpdated, func(event *model.WebSocketEvent) { eventUser, ok := event.GetData()["user"].(*model.User) @@ -6273,13 +6475,25 @@ func TestGetKnownUsers(t *testing.T) { require.Nil(t, err, "failed to create channel") u1 := th.CreateUser() - defer th.App.PermanentDeleteUser(th.Context, u1) + defer func() { + appErr := th.App.PermanentDeleteUser(th.Context, u1) + require.Nil(t, appErr) + }() u2 := th.CreateUser() - defer th.App.PermanentDeleteUser(th.Context, u2) + defer func() { + appErr := th.App.PermanentDeleteUser(th.Context, u2) + require.Nil(t, appErr) + }() u3 := th.CreateUser() - defer th.App.PermanentDeleteUser(th.Context, u3) + defer func() { + appErr := th.App.PermanentDeleteUser(th.Context, u3) + require.Nil(t, appErr) + }() u4 := th.CreateUser() - defer th.App.PermanentDeleteUser(th.Context, u4) + defer func() { + appErr := th.App.PermanentDeleteUser(th.Context, u4) + require.Nil(t, appErr) + }() th.LinkUserToTeam(u1, t1) th.LinkUserToTeam(u1, t2) @@ -6287,11 +6501,16 @@ func TestGetKnownUsers(t *testing.T) { th.LinkUserToTeam(u3, t2) th.LinkUserToTeam(u4, t3) - th.App.AddUserToChannel(th.Context, u1, c1, false) - th.App.AddUserToChannel(th.Context, u1, c2, false) - th.App.AddUserToChannel(th.Context, u2, c1, false) - th.App.AddUserToChannel(th.Context, u3, c2, false) - th.App.AddUserToChannel(th.Context, u4, c3, false) + _, appErr := th.App.AddUserToChannel(th.Context, u1, c1, false) + require.Nil(t, appErr) + _, appErr = th.App.AddUserToChannel(th.Context, u1, c2, false) + require.Nil(t, appErr) + _, appErr = th.App.AddUserToChannel(th.Context, u2, c1, false) + require.Nil(t, appErr) + _, appErr = th.App.AddUserToChannel(th.Context, u3, c2, false) + require.Nil(t, appErr) + _, appErr = th.App.AddUserToChannel(th.Context, u4, c3, false) + require.Nil(t, appErr) t.Run("get know users sharing no channels", func(t *testing.T) { _, _, _ = th.Client.Login(context.Background(), u4.Email, u4.Password) @@ -6545,7 +6764,10 @@ func TestGetThreadsForUser(t *testing.T) { require.NoError(t, err) CheckCreatedStatus(t, resp) - defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) + defer func() { + err = th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) + require.NoError(t, err) + }() uss, _, err := th.Client.GetUserThreads(context.Background(), th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{}) require.NoError(t, err) @@ -6562,7 +6784,10 @@ func TestGetThreadsForUser(t *testing.T) { require.NoError(t, err) CheckCreatedStatus(t, resp) - defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) + defer func() { + err = th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) + require.NoError(t, err) + }() uss, _, err := th.Client.GetUserThreads(context.Background(), th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{}) require.NoError(t, err) @@ -6581,7 +6806,10 @@ func TestGetThreadsForUser(t *testing.T) { require.NoError(t, err) CheckCreatedStatus(t, resp) - defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) + defer func() { + err = th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) + require.NoError(t, err) + }() uss, _, err := th.Client.GetUserThreads(context.Background(), th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{ Extended: true, @@ -6603,7 +6831,10 @@ func TestGetThreadsForUser(t *testing.T) { require.NoError(t, err) CheckCreatedStatus(t, resp) - defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) + defer func() { + err = th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) + require.NoError(t, err) + }() uss, _, err := th.Client.GetUserThreads(context.Background(), th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{ Deleted: false, @@ -6658,7 +6889,10 @@ func TestGetThreadsForUser(t *testing.T) { client := th.Client - defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) + defer func() { + err := th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) + require.NoError(t, err) + }() rpost, resp, err := client.CreatePost(context.Background(), &model.Post{ChannelId: th.BasicChannel.Id, Message: "testMsg"}) require.NoError(t, err) @@ -6700,7 +6934,10 @@ func TestGetThreadsForUser(t *testing.T) { require.NoError(t, err) CheckCreatedStatus(t, resp) - defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) + defer func() { + err = th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) + require.NoError(t, err) + }() uss, _, err := th.Client.GetUserThreads(context.Background(), th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{}) require.NoError(t, err) @@ -6722,7 +6959,10 @@ func TestGetThreadsForUser(t *testing.T) { CheckCreatedStatus(t, resp) } - defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) + defer func() { + err := th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) + require.NoError(t, err) + }() uss, _, err := th.Client.GetUserThreads(context.Background(), th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{ Deleted: false, @@ -6749,7 +6989,10 @@ func TestGetThreadsForUser(t *testing.T) { rootIdBefore := rootIds[14].Id rootIdAfter := rootIds[16].Id - defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) + defer func() { + err := th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) + require.NoError(t, err) + }() uss, _, err := th.Client.GetUserThreads(context.Background(), th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{ Deleted: false, @@ -6800,8 +7043,12 @@ func TestGetThreadsForUser(t *testing.T) { CheckCreatedStatus(t, resp) } - defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) - defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.SystemAdminUser.Id) + defer func() { + err := th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) + require.NoError(t, err) + err = th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.SystemAdminUser.Id) + require.NoError(t, err) + }() uss, _, err := th.Client.GetUserThreads(context.Background(), th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{ Deleted: false, @@ -6836,8 +7083,12 @@ func TestGetThreadsForUser(t *testing.T) { CheckCreatedStatus(t, resp) } - defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) - defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.SystemAdminUser.Id) + defer func() { + err := th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) + require.NoError(t, err) + err = th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.SystemAdminUser.Id) + require.NoError(t, err) + }() uss, _, err := th.Client.GetUserThreads(context.Background(), th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{ Deleted: false, @@ -6859,7 +7110,10 @@ func TestGetThreadsForUser(t *testing.T) { }) t.Run("setting both threadsOnly, and totalsOnly params is not allowed", func(t *testing.T) { - defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) + defer func() { + err := th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) + require.NoError(t, err) + }() _, resp, err := th.Client.GetUserThreads(context.Background(), th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{ ThreadsOnly: true, @@ -6986,8 +7240,12 @@ func TestThreadSocketEvents(t *testing.T) { replyPost, appErr := th.App.CreatePostAsUser(th.Context, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testReply @" + th.BasicUser.Username, UserId: th.BasicUser2.Id, RootId: rpost.Id}, th.Context.Session().Id, false) require.Nil(t, appErr) - defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) - defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser2.Id) + defer func() { + err = th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) + require.NoError(t, err) + err = th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser2.Id) + require.NoError(t, err) + }() t.Run("Listed for update event", func(t *testing.T) { var caught bool @@ -7250,7 +7508,10 @@ func TestFollowThreads(t *testing.T) { require.NoError(t, err) CheckCreatedStatus(t, resp) - defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) + defer func() { + err = th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) + require.NoError(t, err) + }() var uss *model.Threads uss, _, err = th.Client.GetUserThreads(context.Background(), th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{ Deleted: false, @@ -7284,7 +7545,10 @@ func TestFollowThreads(t *testing.T) { // Add user1 to private channel _, appErr := th.App.AddUserToChannel(th.Context, th.BasicUser, th.BasicPrivateChannel2, false) require.Nil(t, appErr) - defer th.App.RemoveUserFromChannel(th.Context, th.BasicUser.Id, "", th.BasicPrivateChannel2) + defer func() { + appErr = th.App.RemoveUserFromChannel(th.Context, th.BasicUser.Id, "", th.BasicPrivateChannel2) + require.Nil(t, appErr) + }() // create thread in private channel rpost, resp, err := th.Client.CreatePost(context.Background(), &model.Post{ChannelId: th.BasicPrivateChannel2.Id, Message: "root post"}) @@ -7349,8 +7613,12 @@ func TestMaintainUnreadRepliesInThread(t *testing.T) { }) client := th.Client - defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) - defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.SystemAdminUser.Id) + defer func() { + err := th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) + require.NoError(t, err) + err = th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.SystemAdminUser.Id) + require.NoError(t, err) + }() // create a post by regular user rpost, _ := postAndCheck(t, client, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testMsg"}) @@ -7404,8 +7672,12 @@ func TestThreadCounts(t *testing.T) { }) client := th.Client - defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) - defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.SystemAdminUser.Id) + defer func() { + err := th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) + require.NoError(t, err) + err = th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.SystemAdminUser.Id) + require.NoError(t, err) + }() // create a post by regular user rpost, _ := postAndCheck(t, client, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testMsg"}) @@ -7424,7 +7696,8 @@ func TestThreadCounts(t *testing.T) { }) // delete first thread - th.App.Srv().Store().Post().Delete(th.Context, rpost.Id, model.GetMillis(), th.BasicUser.Id) + err := th.App.Srv().Store().Post().Delete(th.Context, rpost.Id, model.GetMillis(), th.BasicUser.Id) + require.NoError(t, err) // we should now have 1 thread with 2 replies checkThreadListReplies(t, th, th.Client, th.BasicUser.Id, 2, 1, &model.GetUserThreadsOpts{ @@ -7451,8 +7724,12 @@ func TestSingleThreadGet(t *testing.T) { client := th.Client t.Run("get single thread", func(t *testing.T) { - defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) - defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.SystemAdminUser.Id) + defer func() { + err := th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) + require.NoError(t, err) + err = th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.SystemAdminUser.Id) + require.NoError(t, err) + }() // create a post by regular user rpost, _ := postAndCheck(t, client, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testMsg"}) @@ -7538,8 +7815,12 @@ func TestMaintainUnreadMentionsInThread(t *testing.T) { return uss, resp } - defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) - defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.SystemAdminUser.Id) + defer func() { + err := th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) + require.NoError(t, err) + err = th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.SystemAdminUser.Id) + require.NoError(t, err) + }() // create regular post rpost, _ := postAndCheck(t, client, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testMsg"}) @@ -7592,7 +7873,10 @@ func TestReadThreads(t *testing.T) { _, resp, err = client.CreatePost(context.Background(), &model.Post{ChannelId: th.BasicChannel.Id, Message: "testReply", RootId: rpost.Id}) require.NoError(t, err) CheckCreatedStatus(t, resp) - defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) + defer func() { + err = th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) + require.NoError(t, err) + }() var uss, uss2 *model.Threads uss, _, err = th.Client.GetUserThreads(context.Background(), th.BasicUser.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{ @@ -7614,8 +7898,12 @@ func TestReadThreads(t *testing.T) { }) t.Run("1 thread by timestamp", func(t *testing.T) { - defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) - defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.SystemAdminUser.Id) + defer func() { + err := th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) + require.NoError(t, err) + err = th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.SystemAdminUser.Id) + require.NoError(t, err) + }() rpost, _ := postAndCheck(t, client, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testMsgC1"}) postAndCheck(t, th.SystemAdminClient, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testReplyC1", RootId: rpost.Id}) @@ -7642,8 +7930,12 @@ func TestReadThreads(t *testing.T) { }) t.Run("1 thread by post id", func(t *testing.T) { - defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) - defer th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.SystemAdminUser.Id) + defer func() { + err := th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.BasicUser.Id) + require.NoError(t, err) + err = th.App.Srv().Store().Post().PermanentDeleteByUser(th.Context, th.SystemAdminUser.Id) + require.NoError(t, err) + }() rpost, _ := postAndCheck(t, client, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testMsgC1"}) reply1, _ := postAndCheck(t, th.SystemAdminClient, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testReplyC1", RootId: rpost.Id}) @@ -7717,22 +8009,26 @@ func TestMarkThreadUnreadMentionCount(t *testing.T) { reply1, _ := postAndCheck(t, client, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testReply1 @" + th.BasicUser2.Username, RootId: rpost.Id}) reply2, _ := postAndCheck(t, client, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testReply2", RootId: rpost.Id}) - th.SystemAdminClient.UpdateThreadReadForUser(context.Background(), th.BasicUser2.Id, th.BasicTeam.Id, rpost.Id, model.GetMillis()) + _, _, err := th.SystemAdminClient.UpdateThreadReadForUser(context.Background(), th.BasicUser2.Id, th.BasicTeam.Id, rpost.Id, model.GetMillis()) + require.NoError(t, err) u, _, _ := th.SystemAdminClient.GetUserThreads(context.Background(), th.BasicUser2.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{}) require.EqualValues(t, 0, u.TotalUnreadMentions) - th.SystemAdminClient.UpdateThreadReadForUser(context.Background(), th.BasicUser2.Id, th.BasicTeam.Id, rpost.Id, rpost.CreateAt) + _, _, err = th.SystemAdminClient.UpdateThreadReadForUser(context.Background(), th.BasicUser2.Id, th.BasicTeam.Id, rpost.Id, rpost.CreateAt) + require.NoError(t, err) u, _, _ = th.SystemAdminClient.GetUserThreads(context.Background(), th.BasicUser2.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{}) require.EqualValues(t, 1, u.TotalUnreadMentions) - th.SystemAdminClient.UpdateThreadReadForUser(context.Background(), th.BasicUser2.Id, th.BasicTeam.Id, rpost.Id, reply1.CreateAt) + _, _, err = th.SystemAdminClient.UpdateThreadReadForUser(context.Background(), th.BasicUser2.Id, th.BasicTeam.Id, rpost.Id, reply1.CreateAt) + require.NoError(t, err) u, _, _ = th.SystemAdminClient.GetUserThreads(context.Background(), th.BasicUser2.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{}) require.EqualValues(t, 1, u.TotalUnreadMentions) - th.SystemAdminClient.UpdateThreadReadForUser(context.Background(), th.BasicUser2.Id, th.BasicTeam.Id, rpost.Id, reply2.CreateAt) + _, _, err = th.SystemAdminClient.UpdateThreadReadForUser(context.Background(), th.BasicUser2.Id, th.BasicTeam.Id, rpost.Id, reply2.CreateAt) + require.NoError(t, err) u, _, _ = th.SystemAdminClient.GetUserThreads(context.Background(), th.BasicUser2.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{}) require.EqualValues(t, 0, u.TotalUnreadMentions) @@ -7753,9 +8049,11 @@ func TestPatchAndUpdateWithProviderAttributes(t *testing.T) { ).Return("") th.App.Channels().Ldap = ldapMock // CheckProviderAttributes should be called for both Patch and Update - th.SystemAdminClient.PatchUser(context.Background(), user.Id, &model.UserPatch{}) + _, _, err := th.SystemAdminClient.PatchUser(context.Background(), user.Id, &model.UserPatch{}) + require.NoError(t, err) ldapMock.AssertNumberOfCalls(t, "CheckProviderAttributes", 1) - th.SystemAdminClient.UpdateUser(context.Background(), user) + _, _, err = th.SystemAdminClient.UpdateUser(context.Background(), user) + require.NoError(t, err) ldapMock.AssertNumberOfCalls(t, "CheckProviderAttributes", 2) }) t.Run("SAML user", func(t *testing.T) { @@ -7773,9 +8071,11 @@ func TestPatchAndUpdateWithProviderAttributes(t *testing.T) { "CheckProviderAttributes", mock.AnythingOfType("*request.Context"), mock.AnythingOfType("*model.LdapSettings"), mock.AnythingOfType("*model.User"), mock.AnythingOfType("*model.UserPatch"), ).Return("") th.App.Channels().Ldap = ldapMock - th.SystemAdminClient.PatchUser(context.Background(), user.Id, &model.UserPatch{}) + _, _, err := th.SystemAdminClient.PatchUser(context.Background(), user.Id, &model.UserPatch{}) + require.NoError(t, err) ldapMock.AssertNumberOfCalls(t, "CheckProviderAttributes", 1) - th.SystemAdminClient.UpdateUser(context.Background(), user) + _, _, err = th.SystemAdminClient.UpdateUser(context.Background(), user) + require.NoError(t, err) ldapMock.AssertNumberOfCalls(t, "CheckProviderAttributes", 2) }) t.Run("without LDAP sync", func(t *testing.T) { @@ -7787,9 +8087,11 @@ func TestPatchAndUpdateWithProviderAttributes(t *testing.T) { "CheckProviderAttributes", mock.AnythingOfType("*request.Context"), mock.AnythingOfType("*model.SamlSettings"), mock.AnythingOfType("*model.User"), mock.AnythingOfType("*model.UserPatch"), ).Return("") th.App.Channels().Saml = samlMock - th.SystemAdminClient.PatchUser(context.Background(), user.Id, &model.UserPatch{}) + _, _, err := th.SystemAdminClient.PatchUser(context.Background(), user.Id, &model.UserPatch{}) + require.NoError(t, err) samlMock.AssertNumberOfCalls(t, "CheckProviderAttributes", 1) - th.SystemAdminClient.UpdateUser(context.Background(), user) + _, _, err = th.SystemAdminClient.UpdateUser(context.Background(), user) + require.NoError(t, err) samlMock.AssertNumberOfCalls(t, "CheckProviderAttributes", 2) }) }) @@ -8118,7 +8420,8 @@ func TestGetUsersByNames(t *testing.T) { }) t.Run("Get users without permissions", func(t *testing.T) { - th.Client.Logout(context.Background()) + _, err := th.Client.Logout(context.Background()) + require.NoError(t, err) defer th.LoginBasic() // Ensure the client is logged back in after the test _, resp, err := th.Client.GetUsersByUsernames(context.Background(), []string{th.BasicUser.Username}) @@ -8267,7 +8570,8 @@ func TestGetDefaultProfileImage(t *testing.T) { t.Run("Get default profile image without proper permissions", func(t *testing.T) { user := th.CreateUser() - th.Client.Logout(context.Background()) + _, err := th.Client.Logout(context.Background()) + require.NoError(t, err) _, resp, err := th.Client.GetDefaultProfileImage(context.Background(), user.Id) require.Error(t, err) CheckUnauthorizedStatus(t, resp) @@ -8288,7 +8592,8 @@ func TestGetDefaultProfileImage(t *testing.T) { user := th.CreateUser() // Login as the newly created user - th.Client.Login(context.Background(), user.Email, user.Password) + _, _, err := th.Client.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) img1, resp, err := th.Client.GetDefaultProfileImage(context.Background(), user.Id) require.NoError(t, err) @@ -8301,7 +8606,8 @@ func TestGetDefaultProfileImage(t *testing.T) { require.Equal(t, img1, img2, "Default profile images should be consistent for the same user") // Logout after the test - th.Client.Logout(context.Background()) + _, err = th.Client.Logout(context.Background()) + require.NoError(t, err) }) } @@ -8374,7 +8680,8 @@ func TestGetUserThread(t *testing.T) { require.NoError(t, err) // Log out - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) _, resp, err := client.GetUserThread(context.Background(), user.Id, team.Id, post.Id, false) require.Error(t, err) @@ -8383,7 +8690,8 @@ func TestGetUserThread(t *testing.T) { t.Run("get thread for different user", func(t *testing.T) { // Log back in - client.Login(context.Background(), user.Email, user.Password) + _, _, err := client.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) post, _, err := client.CreatePost(context.Background(), &model.Post{ ChannelId: th.BasicChannel.Id, @@ -8474,7 +8782,8 @@ func TestUpdateReadStateThreadByUser(t *testing.T) { require.NoError(t, err) // Log out - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) _, resp, err := client.UpdateThreadReadForUser(context.Background(), user.Id, team.Id, post.Id, model.GetMillis()) require.Error(t, err) @@ -8483,7 +8792,8 @@ func TestUpdateReadStateThreadByUser(t *testing.T) { t.Run("update read state for different user", func(t *testing.T) { // Log back in - client.Login(context.Background(), user.Email, user.Password) + _, _, err := client.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) post, _, err := client.CreatePost(context.Background(), &model.Post{ ChannelId: th.BasicChannel.Id, @@ -8555,7 +8865,8 @@ func TestSetUnreadThreadByPostId(t *testing.T) { require.NoError(t, err) // Log out - client.Logout(context.Background()) + _, err = client.Logout(context.Background()) + require.NoError(t, err) _, resp, err := client.SetThreadUnreadByPostId(context.Background(), user.Id, team.Id, post.Id, post.Id) require.Error(t, err) @@ -8564,7 +8875,8 @@ func TestSetUnreadThreadByPostId(t *testing.T) { t.Run("set unread state for different user", func(t *testing.T) { // Log back in - client.Login(context.Background(), user.Email, user.Password) + _, _, err := client.Login(context.Background(), user.Email, user.Password) + require.NoError(t, err) post, _, err := client.CreatePost(context.Background(), &model.Post{ ChannelId: th.BasicChannel.Id,