mirror of https://github.com/waku-org/nwaku.git
fix: check max message size in validator according to configured value (#2424)
This commit is contained in:
parent
d00065e9d3
commit
731dfcbdf6
|
@ -523,7 +523,7 @@ suite "Waku v2 Rest API - Relay":
|
||||||
check:
|
check:
|
||||||
response.status == 400
|
response.status == 400
|
||||||
$response.contentType == $MIMETYPE_TEXT
|
$response.contentType == $MIMETYPE_TEXT
|
||||||
response.data == fmt"Failed to publish: Message size exceeded maximum of {DefaultMaxWakuMessageSizeStr}"
|
response.data == fmt"Failed to publish: Message size exceeded maximum of {MaxWakuMessageSize} bytes"
|
||||||
|
|
||||||
await restServer.stop()
|
await restServer.stop()
|
||||||
await restServer.closeWait()
|
await restServer.closeWait()
|
||||||
|
@ -567,7 +567,7 @@ suite "Waku v2 Rest API - Relay":
|
||||||
check:
|
check:
|
||||||
response.status == 400
|
response.status == 400
|
||||||
$response.contentType == $MIMETYPE_TEXT
|
$response.contentType == $MIMETYPE_TEXT
|
||||||
response.data == fmt"Failed to publish: Message size exceeded maximum of {DefaultMaxWakuMessageSizeStr}"
|
response.data == fmt"Failed to publish: Message size exceeded maximum of {MaxWakuMessageSize} bytes"
|
||||||
|
|
||||||
await restServer.stop()
|
await restServer.stop()
|
||||||
await restServer.closeWait()
|
await restServer.closeWait()
|
||||||
|
|
|
@ -216,21 +216,15 @@ proc generateOrderedValidator*(w: WakuRelay): auto {.gcsafe.} =
|
||||||
return ValidationResult.Accept
|
return ValidationResult.Accept
|
||||||
return wrappedValidator
|
return wrappedValidator
|
||||||
|
|
||||||
proc isValidSize(message: WakuMessage): Future[Result[void, string]] {.async.} =
|
|
||||||
let messageSizeBytes = uint64(message.encode().buffer.len)
|
|
||||||
|
|
||||||
if(messageSizeBytes > MaxWakuMessageSize):
|
|
||||||
let message = fmt"Message size exceeded maximum of {DefaultMaxWakuMessageSizeStr}"
|
|
||||||
debug "Invalid Waku Message", error=message
|
|
||||||
return err(message)
|
|
||||||
|
|
||||||
return ok()
|
|
||||||
|
|
||||||
proc validateMessage*(w: WakuRelay, pubsubTopic: string, msg: WakuMessage):
|
proc validateMessage*(w: WakuRelay, pubsubTopic: string, msg: WakuMessage):
|
||||||
Future[Result[void, string]] {.async.} =
|
Future[Result[void, string]] {.async.} =
|
||||||
|
|
||||||
(await msg.isValidSize()).isOkOr:
|
let messageSizeBytes = msg.encode().buffer.len
|
||||||
return err(error)
|
|
||||||
|
if messageSizeBytes > w.maxMessageSize:
|
||||||
|
let message = fmt"Message size exceeded maximum of {w.maxMessageSize} bytes"
|
||||||
|
debug "Invalid Waku Message", error=message
|
||||||
|
return err(message)
|
||||||
|
|
||||||
for (validator, message) in w.wakuValidators:
|
for (validator, message) in w.wakuValidators:
|
||||||
let validatorRes = await validator(pubsubTopic, msg)
|
let validatorRes = await validator(pubsubTopic, msg)
|
||||||
|
|
Loading…
Reference in New Issue