Page research without exact counts and bound candidate scans [skip ci]
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package research
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCursorValidation(t *testing.T) {
|
||||
f := Filters{Query: "graph", Sort: "title", SearchIn: "text", PageSize: 8}
|
||||
f.Cursor = encodeCursor(f, position{ID: 9223372036854775807, Key: "duplicate\x01title"}, true)
|
||||
p, err := decodeCursor(f)
|
||||
if err != nil || !p.Before || p.ID != 9223372036854775807 || p.Key != "duplicate\x01title" {
|
||||
t.Fatalf("roundtrip %+v %v", p, err)
|
||||
}
|
||||
if _, err := parseFilters("q=graph&sort=title&cursor=" + url.QueryEscape(f.Cursor)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, raw := range []string{"!", strings.Repeat("a", 32769), base64.RawURLEncoding.EncodeToString([]byte(`{"v":2}`)), f.Cursor + "="} {
|
||||
bad := f
|
||||
bad.Cursor = raw
|
||||
if _, err := decodeCursor(bad); err == nil {
|
||||
t.Fatal("accepted invalid cursor")
|
||||
}
|
||||
}
|
||||
for _, change := range []func(*Filters){func(f *Filters) { f.Query = "other" }, func(f *Filters) { f.Sort = "recent" }, func(f *Filters) { f.PageSize = 9 }, func(f *Filters) { f.SearchIn = "author" }, func(f *Filters) { f.Topic = "cs.AI" }} {
|
||||
bad := f
|
||||
change(&bad)
|
||||
if _, err := decodeCursor(bad); err == nil {
|
||||
t.Fatal("accepted mismatched filter")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user