feat(archive): respond with error on more than 10 content topics query

This commit is contained in:
Lorenzo Delgado 2023-01-11 12:19:59 +01:00 committed by GitHub
parent 982cd28265
commit 3ee87d1848
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 0 deletions

View File

@ -214,6 +214,29 @@ procSuite "Waku Archive - find messages":
response.messages.anyIt(it == msg1)
response.messages.anyIt(it == msg3)
test "handle query with more than 10 content filters":
## Setup
let
driver = newTestArchiveDriver()
archive = newTestWakuArchive(driver)
let queryTopics = toSeq(1..15).mapIt(ContentTopic($it))
## Given
let req = ArchiveQuery(contentTopics: queryTopics)
## When
let queryRes = archive.findMessages(req)
## Then
check:
queryRes.isErr()
let error = queryRes.tryError()
check:
error.kind == ArchiveErrorKind.INVALID_QUERY
error.cause == "too many content topics"
test "handle query with pubsub topic filter":
## Setup
let

View File

@ -126,6 +126,8 @@ proc findMessages*(w: WakuArchive, query: ArchiveQuery): ArchiveResult {.gcsafe.
else: min(query.pageSize, MaxPageSize)
qAscendingOrder = query.ascending
if qContentTopics.len > 10:
return err(ArchiveError.invalidQuery("too many content topics"))
let queryStartTime = getTime().toUnixFloat()

View File

@ -85,3 +85,6 @@ proc `$`*(err: ArchiveError): string =
"INVALID_QUERY: " & err.cause
of ArchiveErrorKind.UNKNOWN:
"UNKNOWN"
proc invalidQuery*(T: type ArchiveError, cause: string): T =
ArchiveError(kind: ArchiveErrorKind.INVALID_QUERY, cause: cause)