fix: add protection in rest service to always publish with timestamp if user doesn't provide it (#2261)

This commit is contained in:
Ivan FB 2023-12-06 14:02:21 +01:00 committed by GitHub
parent 103d3981ad
commit 42f1957920
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 9 deletions

View File

@ -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)

View File

@ -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():

View File

@ -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