mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-19 22:50:55 +08:00
GET /api/conversations/{id}/messages passed limit through to the
database with no upper bound, so a huge query could load the whole
transcript. Clamp history pages to 200 and keep the since tail at 1000.
22 lines
558 B
Go
22 lines
558 B
Go
package server
|
|
|
|
import "testing"
|
|
|
|
func TestConvMessageLimit(t *testing.T) {
|
|
if got := convMessageLimit("", 200, 200); got != 200 {
|
|
t.Fatalf("default: %d", got)
|
|
}
|
|
if got := convMessageLimit("50", 200, 200); got != 50 {
|
|
t.Fatalf("50: %d", got)
|
|
}
|
|
if got := convMessageLimit("2147483646", 200, 200); got != 200 {
|
|
t.Fatalf("huge history: %d", got)
|
|
}
|
|
if got := convMessageLimit("2147483646", 1000, 1000); got != 1000 {
|
|
t.Fatalf("huge since: %d", got)
|
|
}
|
|
if got := convMessageLimit("-1", 200, 200); got != 200 {
|
|
t.Fatalf("negative: %d", got)
|
|
}
|
|
}
|