mirror of
https://github.com/waku-org/nwaku.git
synced 2025-01-31 17:17:03 +00:00
d832f92a43
* Add allowOrigin configuration for wakunode and WakuRestServer Update nim-presto to the latest master that contains middleware support Rework Rest Server in waku to utilize chronos' and presto's new middleware design and added proper CORS handling. Added cors tests and fixes Co-authored-by: Ivan FB <128452529+Ivansete-status@users.noreply.github.com>
88 lines
2.4 KiB
Nim
88 lines
2.4 KiB
Nim
{.used.}
|
|
|
|
import
|
|
stew/shims/net,
|
|
testutils/unittests,
|
|
presto,
|
|
presto/client as presto_client,
|
|
libp2p/peerinfo,
|
|
libp2p/multiaddress,
|
|
libp2p/crypto/crypto
|
|
import
|
|
../../waku/waku_node,
|
|
../../waku/node/waku_node as waku_node2, # TODO: Remove after moving `git_version` to the app code.
|
|
../../waku/waku_api/rest/server,
|
|
../../waku/waku_api/rest/client,
|
|
../../waku/waku_api/rest/responses,
|
|
../../waku/waku_api/rest/debug/handlers as debug_api,
|
|
../../waku/waku_api/rest/debug/client as debug_api_client,
|
|
../testlib/common,
|
|
../testlib/wakucore,
|
|
../testlib/wakunode
|
|
|
|
|
|
proc testWakuNode(): WakuNode =
|
|
let
|
|
privkey = crypto.PrivateKey.random(Secp256k1, rng[]).tryGet()
|
|
bindIp = parseIpAddress("0.0.0.0")
|
|
extIp = parseIpAddress("127.0.0.1")
|
|
port = Port(58000)
|
|
|
|
newTestWakuNode(privkey, bindIp, port, some(extIp), some(port))
|
|
|
|
|
|
suite "Waku v2 REST API - Debug":
|
|
asyncTest "Get node info - GET /debug/v1/info":
|
|
# Given
|
|
let node = testWakuNode()
|
|
await node.start()
|
|
await node.mountRelay()
|
|
|
|
let restPort = Port(58001)
|
|
let restAddress = parseIpAddress("0.0.0.0")
|
|
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
|
|
|
|
installDebugApiHandlers(restServer.router, node)
|
|
restServer.start()
|
|
|
|
# When
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
|
let response = await client.debugInfoV1()
|
|
|
|
# Then
|
|
check:
|
|
response.status == 200
|
|
$response.contentType == $MIMETYPE_JSON
|
|
response.data.listenAddresses == @[$node.switch.peerInfo.addrs[^1] & "/p2p/" & $node.switch.peerInfo.peerId]
|
|
|
|
await restServer.stop()
|
|
await restServer.closeWait()
|
|
await node.stop()
|
|
|
|
asyncTest "Get node version - GET /debug/v1/version":
|
|
# Given
|
|
let node = testWakuNode()
|
|
await node.start()
|
|
await node.mountRelay()
|
|
|
|
let restPort = Port(58002)
|
|
let restAddress = parseIpAddress("0.0.0.0")
|
|
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
|
|
|
|
installDebugApiHandlers(restServer.router, node)
|
|
restServer.start()
|
|
|
|
# When
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
|
let response = await client.debugVersionV1()
|
|
|
|
# Then
|
|
check:
|
|
response.status == 200
|
|
$response.contentType == $MIMETYPE_TEXT
|
|
response.data == waku_node2.git_version
|
|
|
|
await restServer.stop()
|
|
await restServer.closeWait()
|
|
await node.stop()
|