Fix nil dereference panic in SearchArchivedInTeam (#16064)

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Claudio Costa
2020-10-26 15:19:14 +01:00
коммит произвёл GitHub
родитель 72432ab3ff
Коммит 9484366784
2 изменённых файлов: 31 добавлений и 4 удалений

Просмотреть файл

@@ -2544,15 +2544,19 @@ func (s SqlChannelStore) SearchArchivedInTeam(teamId string, term string, userId
"UserId": userId,
})
output := *publicChannels
output = append(output, *privateChannels...)
outputErr := publicErr
if privateErr != nil {
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) {

Просмотреть файл

@@ -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("SearchMore", func(t *testing.T) { testChannelStoreSearchMore(t, ss) })
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("SearchAllChannels", func(t *testing.T) { testChannelStoreSearchAllChannels(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
}
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) {
teamId := model.NewId()
otherTeamId := model.NewId()