feat: Added message size check before relay for lightpush (#2695)

This commit is contained in:
Akhil 2024-05-15 14:13:13 +04:00 committed by GitHub
parent 3a2caaec6f
commit 9dfdfa2774
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import
testutils/unittests,
chronos,
chronicles,
std/strformat,
os,
libp2p/[peerstore, crypto/crypto]
@ -23,7 +24,8 @@ import
waku_lightpush/protocol_metrics,
waku_lightpush/rpc,
],
../testlib/[assertions, common, wakucore, wakunode, testasync, futures, testutils]
../testlib/[assertions, common, wakucore, wakunode, testasync, futures, testutils],
../resources/payloads
suite "Waku Lightpush - End To End":
var
@ -85,3 +87,20 @@ suite "Waku Lightpush - End To End":
# Then the message is relayed to the server
assertResultOk publishResponse
suite "Waku LightPush Validation Tests":
asyncTest "Validate message size exceeds limit":
let
msgOverLimit = fakeWakuMessage(
contentTopic = contentTopic,
payload = getByteSequence(DefaultMaxWakuMessageSize + 64 * 1024),
)
# When the client publishes an over-limit message
let publishResponse = await client.lightpushPublish(
some(pubsubTopic), msgOverLimit, serverRemotePeerInfo
)
check:
publishResponse.isErr()
publishResponse.error == fmt"Message size exceeded maximum of {DefaultMaxWakuMessageSize} bytes"

View File

@ -917,6 +917,10 @@ proc mountLightPush*(
pushHandler = proc(
peer: PeerId, pubsubTopic: string, message: WakuMessage
): Future[WakuLightPushResult[void]] {.async.} =
let validationRes = await node.wakuRelay.validateMessage(pubSubTopic, message)
if validationRes.isErr():
return err(validationRes.error)
let publishedCount =
await node.wakuRelay.publish(pubsubTopic, message.encode().buffer)