Skip to content

Commit

Permalink
Merge eff35ad into 3a2caae
Browse files Browse the repository at this point in the history
  • Loading branch information
shash256 authored May 15, 2024
2 parents 3a2caae + eff35ad commit 241ef99
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
21 changes: 20 additions & 1 deletion tests/node/test_wakunode_lightpush.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import
testutils/unittests,
chronos,
chronicles,
std/strformat,
os,
libp2p/[peerstore, crypto/crypto]

Expand All @@ -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
Expand Down Expand Up @@ -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"
4 changes: 4 additions & 0 deletions waku/node/waku_node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 241ef99

Please sign in to comment.