diff --git a/tests/wakunode_rest/test_rest_admin.nim b/tests/wakunode_rest/test_rest_admin.nim index 194846e2fb..a418e6ab6d 100644 --- a/tests/wakunode_rest/test_rest_admin.nim +++ b/tests/wakunode_rest/test_rest_admin.nim @@ -136,44 +136,6 @@ suite "Waku v2 Rest API - Admin": ($getRes.data).contains(expectedFilterData2) ($getRes.data).contains(expectedFilterData3) - asyncTest "Get filter data": - await allFutures(node1.mountFilter(), node2.mountFilterClient(), node3.mountFilterClient()) - - let - contentFiltersNode2 = @[DefaultContentTopic, ContentTopic("2"), ContentTopic("3")] - contentFiltersNode3 = @[ContentTopic("3"), ContentTopic("4")] - pubsubTopicNode2 = DefaultPubsubTopic - pubsubTopicNode3 = PubsubTopic("/waku/2/custom-waku/proto") - - expectedFilterData2 = fmt"(peerId: ""{$peerInfo2}"", filterCriteria:" & - fmt" @[(pubsubTopic: ""{pubsubTopicNode2}"", contentTopic: ""{contentFiltersNode2[0]}""), " & - fmt"(pubsubTopic: ""{pubsubTopicNode2}"", contentTopic: ""{contentFiltersNode2[1]}""), " & - fmt"(pubsubTopic: ""{pubsubTopicNode2}"", contentTopic: ""{contentFiltersNode2[2]}"")]" - - expectedFilterData3 = fmt"(peerId: ""{$peerInfo3}"", filterCriteria:" & - fmt" @[(pubsubTopic: ""{pubsubTopicNode3}"", contentTopic: ""{contentFiltersNode3[0]}""), " & - fmt"(pubsubTopic: ""{pubsubTopicNode3}"", contentTopic: ""{contentFiltersNode3[1]}"")]" - - let - subscribeResponse2 = await node2.wakuFilterClient.subscribe( - peerInfo1, pubsubTopicNode2, contentFiltersNode2 - ) - subscribeResponse3 = await node3.wakuFilterClient.subscribe( - peerInfo1, pubsubTopicNode3, contentFiltersNode3 - ) - - assert subscribeResponse2.isOk(), $subscribeResponse2.error - assert subscribeResponse3.isOk(), $subscribeResponse3.error - - let getRes = await client.getFilterSubscriptions() - - check: - getRes.status == 200 - $getRes.contentType == $MIMETYPE_JSON - getRes.data.len() == 2 - ($getRes.data).contains(expectedFilterData2) - ($getRes.data).contains(expectedFilterData3) - asyncTest "Get filter data - no filter subscribers": await node1.mountFilter() @@ -185,9 +147,8 @@ suite "Waku v2 Rest API - Admin": getRes.data.len() == 0 asyncTest "Get filter data - filter not mounted": - let getRes = await client.getFilterSubscriptions() - + let getRes = await client.getFilterSubscriptionsFilterNotMounted() + check: - getRes.status == 200 - $getRes.contentType == $MIMETYPE_JSON - getRes.data.len() == 0 \ No newline at end of file + getRes.status == 400 + getRes.data == "Error: Filter Protocol is not mounted to the node" \ No newline at end of file diff --git a/waku/waku_api/rest/admin/client.nim b/waku/waku_api/rest/admin/client.nim index f0e55dcb59..9768536560 100644 --- a/waku/waku_api/rest/admin/client.nim +++ b/waku/waku_api/rest/admin/client.nim @@ -37,3 +37,7 @@ proc postPeers*(body: seq[string]): proc getFilterSubscriptions*(): RestResponse[seq[FilterSubscription]] {.rest, endpoint: "/admin/v1/filter/subscriptions", meth: HttpMethod.MethodGet.} + +proc getFilterSubscriptionsFilterNotMounted*(): + RestResponse[string] + {.rest, endpoint: "/admin/v1/filter/subscriptions", meth: HttpMethod.MethodGet.} diff --git a/waku/waku_api/rest/admin/handlers.nim b/waku/waku_api/rest/admin/handlers.nim index 12de215b48..f150d58388 100644 --- a/waku/waku_api/rest/admin/handlers.nim +++ b/waku/waku_api/rest/admin/handlers.nim @@ -113,7 +113,10 @@ proc installAdminV1PostPeersHandler(router: var RestRouter, node: WakuNode) = proc installAdminV1GetFilterSubsHandler(router: var RestRouter, node: WakuNode) = router.api(MethodGet, ROUTE_ADMIN_V1_FILTER_SUBS) do () -> RestApiResponse: - + + if node.wakuFilter.isNil(): + return RestApiResponse.badRequest("Error: Filter Protocol is not mounted to the node") + var subscriptions: seq[FilterSubscription] = @[] if not node.wakuFilter.isNil(): @@ -121,7 +124,6 @@ proc installAdminV1GetFilterSubsHandler(router: var RestRouter, node: WakuNode) var filterCriteria: seq[FilterTopic] for (peerId, criteria) in node.wakuFilter.subscriptions.pairs(): - filterCriteria = criteria.toSeq().mapIt(FilterTopic(pubsubTopic: it[0], contentTopic: it[1]))