Return 400 error if limit_after is zero (#15049)

Этот коммит содержится в:
Claudio Costa
2020-07-20 10:08:52 +02:00
коммит произвёл GitHub
родитель aae3b9650f
Коммит 484e813dca
4 изменённых файлов: 30 добавлений и 1 удалений

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

@@ -691,6 +691,11 @@ func (s *SqlPostStore) GetPostsAfter(options model.GetPostsOptions) (*model.Post
}
func (s *SqlPostStore) getPostsAround(before bool, options model.GetPostsOptions) (*model.PostList, *model.AppError) {
if options.Page < 0 || options.PerPage < 0 {
return nil, model.NewAppError("SqlPostStore.GetPostContext", "store.sql_post.get_posts_around.get.app_error", nil,
fmt.Sprintf("Page=%d and PerPage=%d must be non-negative", options.Page, options.PerPage), http.StatusBadRequest)
}
offset := options.Page * options.PerPage
var posts, parents []*model.Post

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

@@ -5,6 +5,7 @@ package storetest
import (
"fmt"
"net/http"
"sort"
"strings"
"testing"
@@ -893,6 +894,18 @@ func testPostStoreGetPostsBeforeAfter(t *testing.T, ss store.Store) {
time.Sleep(time.Millisecond)
}
t.Run("should return error if negative Page/PerPage options are passed", func(t *testing.T) {
postList, err := ss.Post().GetPostsAfter(model.GetPostsOptions{ChannelId: channelId, PostId: posts[0].Id, Page: 0, PerPage: -1})
assert.Nil(t, postList)
assert.Error(t, err)
assert.Equal(t, http.StatusBadRequest, err.StatusCode)
postList, err = ss.Post().GetPostsAfter(model.GetPostsOptions{ChannelId: channelId, PostId: posts[0].Id, Page: -1, PerPage: 10})
assert.Nil(t, postList)
assert.Error(t, err)
assert.Equal(t, http.StatusBadRequest, err.StatusCode)
})
t.Run("should not return anything before the first post", func(t *testing.T) {
postList, err := ss.Post().GetPostsBefore(model.GetPostsOptions{ChannelId: channelId, PostId: posts[0].Id, Page: 0, PerPage: 10})
assert.Nil(t, err)