Fix nil dereference panic in SearchArchivedInTeam (#16064)
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
72432ab3ff
Коммит
9484366784
@@ -2544,15 +2544,19 @@ func (s SqlChannelStore) SearchArchivedInTeam(teamId string, term string, userId
|
|||||||
"UserId": userId,
|
"UserId": userId,
|
||||||
})
|
})
|
||||||
|
|
||||||
output := *publicChannels
|
|
||||||
output = append(output, *privateChannels...)
|
|
||||||
|
|
||||||
outputErr := publicErr
|
outputErr := publicErr
|
||||||
if privateErr != nil {
|
if privateErr != nil {
|
||||||
outputErr = privateErr
|
outputErr = privateErr
|
||||||
}
|
}
|
||||||
|
|
||||||
return &output, outputErr
|
if outputErr != nil {
|
||||||
|
return nil, outputErr
|
||||||
|
}
|
||||||
|
|
||||||
|
output := *publicChannels
|
||||||
|
output = append(output, *privateChannels...)
|
||||||
|
|
||||||
|
return &output, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SqlChannelStore) SearchForUserInTeam(userId string, teamId string, term string, includeDeleted bool) (*model.ChannelList, error) {
|
func (s SqlChannelStore) SearchForUserInTeam(userId string, teamId string, term string, includeDeleted bool) (*model.ChannelList, error) {
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ func TestChannelStore(t *testing.T, ss store.Store, s SqlSupplier) {
|
|||||||
t.Run("GetGuestCount", func(t *testing.T) { testGetGuestCount(t, ss) })
|
t.Run("GetGuestCount", func(t *testing.T) { testGetGuestCount(t, ss) })
|
||||||
t.Run("SearchMore", func(t *testing.T) { testChannelStoreSearchMore(t, ss) })
|
t.Run("SearchMore", func(t *testing.T) { testChannelStoreSearchMore(t, ss) })
|
||||||
t.Run("SearchInTeam", func(t *testing.T) { testChannelStoreSearchInTeam(t, ss, s) })
|
t.Run("SearchInTeam", func(t *testing.T) { testChannelStoreSearchInTeam(t, ss, s) })
|
||||||
|
t.Run("SearchArchivedInTeam", func(t *testing.T) { testChannelStoreSearchArchivedInTeam(t, ss, s) })
|
||||||
t.Run("SearchForUserInTeam", func(t *testing.T) { testChannelStoreSearchForUserInTeam(t, ss) })
|
t.Run("SearchForUserInTeam", func(t *testing.T) { testChannelStoreSearchForUserInTeam(t, ss) })
|
||||||
t.Run("SearchAllChannels", func(t *testing.T) { testChannelStoreSearchAllChannels(t, ss) })
|
t.Run("SearchAllChannels", func(t *testing.T) { testChannelStoreSearchAllChannels(t, ss) })
|
||||||
t.Run("GetMembersByIds", func(t *testing.T) { testChannelStoreGetMembersByIds(t, ss) })
|
t.Run("GetMembersByIds", func(t *testing.T) { testChannelStoreGetMembersByIds(t, ss) })
|
||||||
@@ -4947,6 +4948,28 @@ func (s ByChannelDisplayName) Less(i, j int) bool {
|
|||||||
return s[i].Id < s[j].Id
|
return s[i].Id < s[j].Id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testChannelStoreSearchArchivedInTeam(t *testing.T, ss store.Store, s SqlSupplier) {
|
||||||
|
teamId := model.NewId()
|
||||||
|
userId := model.NewId()
|
||||||
|
|
||||||
|
t.Run("empty result", func(t *testing.T) {
|
||||||
|
list, err := ss.Channel().SearchArchivedInTeam(teamId, "term", userId)
|
||||||
|
require.Nil(t, err)
|
||||||
|
require.NotNil(t, list)
|
||||||
|
require.Empty(t, list)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("error", func(t *testing.T) {
|
||||||
|
// trigger a SQL error
|
||||||
|
s.GetMaster().Exec("ALTER TABLE Channels RENAME TO Channels_renamed")
|
||||||
|
defer s.GetMaster().Exec("ALTER TABLE Channels_renamed RENAME TO Channels")
|
||||||
|
|
||||||
|
list, err := ss.Channel().SearchArchivedInTeam(teamId, "term", userId)
|
||||||
|
require.NotNil(t, err)
|
||||||
|
require.Nil(t, list)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func testChannelStoreSearchInTeam(t *testing.T, ss store.Store, s SqlSupplier) {
|
func testChannelStoreSearchInTeam(t *testing.T, ss store.Store, s SqlSupplier) {
|
||||||
teamId := model.NewId()
|
teamId := model.NewId()
|
||||||
otherTeamId := model.NewId()
|
otherTeamId := model.NewId()
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user