mirror of
https://github.com/waku-org/nwaku.git
synced 2025-01-14 00:46:44 +00:00
fix: add protection in rest service to always publish with timestamp if user doesn't provide it (#2261)
This commit is contained in:
parent
103d3981ad
commit
42f1957920
@ -20,7 +20,7 @@ import
|
||||
|
||||
suite "Waku Archive - message handling":
|
||||
|
||||
test "it should driver a valid and non-ephemeral message":
|
||||
test "it should archive a valid and non-ephemeral message":
|
||||
## Setup
|
||||
let driver = newSqliteArchiveDriver()
|
||||
let archive = newWakuArchive(driver)
|
||||
@ -36,7 +36,7 @@ suite "Waku Archive - message handling":
|
||||
check:
|
||||
(waitFor driver.getMessagesCount()).tryGet() == 1
|
||||
|
||||
test "it should not driver an ephemeral message":
|
||||
test "it should not archive ephemeral messages":
|
||||
## Setup
|
||||
let driver = newSqliteArchiveDriver()
|
||||
let archive = newWakuArchive(driver)
|
||||
@ -58,7 +58,7 @@ suite "Waku Archive - message handling":
|
||||
check:
|
||||
(waitFor driver.getMessagesCount()).tryGet() == 2
|
||||
|
||||
test "it should driver a message with no sender timestamp":
|
||||
test "it should archive a message with no sender timestamp":
|
||||
## Setup
|
||||
let driver = newSqliteArchiveDriver()
|
||||
let archive = newWakuArchive(driver)
|
||||
@ -74,7 +74,7 @@ suite "Waku Archive - message handling":
|
||||
check:
|
||||
(waitFor driver.getMessagesCount()).tryGet() == 1
|
||||
|
||||
test "it should not driver a message with a sender time variance greater than max time variance (future)":
|
||||
test "it should not archive a message with a sender time variance greater than max time variance (future)":
|
||||
## Setup
|
||||
let driver = newSqliteArchiveDriver()
|
||||
let archive = newWakuArchive(driver)
|
||||
@ -93,7 +93,7 @@ suite "Waku Archive - message handling":
|
||||
check:
|
||||
(waitFor driver.getMessagesCount()).tryGet() == 0
|
||||
|
||||
test "it should not driver a message with a sender time variance greater than max time variance (past)":
|
||||
test "it should not archive a message with a sender time variance greater than max time variance (past)":
|
||||
## Setup
|
||||
let driver = newSqliteArchiveDriver()
|
||||
let archive = newWakuArchive(driver)
|
||||
|
@ -125,7 +125,7 @@ proc installRelayApiHandlers*(router: var RestRouter, node: WakuNode, cache: Mes
|
||||
return error
|
||||
|
||||
var message: WakuMessage = reqWakuMessage.toWakuMessage(version = 0).valueOr:
|
||||
return RestApiResponse.badRequest()
|
||||
return RestApiResponse.badRequest($error)
|
||||
|
||||
# if RLN is mounted, append the proof to the message
|
||||
if not node.wakuRlnRelay.isNil():
|
||||
|
@ -4,7 +4,7 @@ else:
|
||||
{.push raises: [].}
|
||||
|
||||
import
|
||||
std/[sets, strformat],
|
||||
std/[sets, strformat, times],
|
||||
chronicles,
|
||||
json_serialization,
|
||||
json_serialization/std/options,
|
||||
@ -43,9 +43,13 @@ proc toWakuMessage*(msg: RelayWakuMessage, version = 0): Result[WakuMessage, str
|
||||
payload = ?msg.payload.decode()
|
||||
contentTopic = msg.contentTopic.get(DefaultContentTopic)
|
||||
version = uint32(msg.version.get(version))
|
||||
timestamp = msg.timestamp.get(0)
|
||||
|
||||
ok(WakuMessage(payload: payload, contentTopic: contentTopic, version: version, timestamp: timestamp))
|
||||
var timestamp = msg.timestamp.get(0)
|
||||
|
||||
if timestamp == 0:
|
||||
timestamp = getNanosecondTime(getTime().toUnixFloat())
|
||||
|
||||
return ok(WakuMessage(payload: payload, contentTopic: contentTopic, version: version, timestamp: timestamp))
|
||||
|
||||
|
||||
#### Serialization and deserialization
|
||||
|
Loading…
x
Reference in New Issue
Block a user