2020-06-16 21:39:45 +00:00
|
|
|
#include "webfuse_provider/impl/jsonrpc/request.h"
|
2020-07-12 13:13:34 +00:00
|
|
|
#include "webfuse_provider/test_util/json_doc.hpp"
|
2020-07-11 22:39:55 +00:00
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
2019-05-19 12:33:42 +00:00
|
|
|
|
2020-07-12 13:13:34 +00:00
|
|
|
using webfuse_test::JsonDoc;
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
TEST(wfp_jsonrpc_is_request, request_with_object_params)
|
2019-05-19 12:33:42 +00:00
|
|
|
{
|
2020-07-12 13:13:34 +00:00
|
|
|
JsonDoc doc("{\"method\": \"method\", \"params\": {}, \"id\": 42}");
|
2019-05-19 12:33:42 +00:00
|
|
|
|
2020-07-12 13:13:34 +00:00
|
|
|
ASSERT_TRUE(wfp_jsonrpc_is_request(doc.root()));
|
2019-05-19 12:33:42 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
TEST(wfp_jsonrpc_is_request, request_with_array_params)
|
2019-05-19 12:33:42 +00:00
|
|
|
{
|
2020-07-12 13:13:34 +00:00
|
|
|
JsonDoc doc("{\"method\": \"method\", \"params\": [], \"id\": 42}");
|
2019-05-19 12:33:42 +00:00
|
|
|
|
2020-07-12 13:13:34 +00:00
|
|
|
ASSERT_TRUE(wfp_jsonrpc_is_request(doc.root()));
|
2019-05-19 12:33:42 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
TEST(wfp_jsonrpc_is_request, null_request)
|
2019-05-19 12:33:42 +00:00
|
|
|
{
|
2020-06-16 21:57:41 +00:00
|
|
|
ASSERT_FALSE(wfp_jsonrpc_is_request(nullptr));
|
2019-05-19 12:33:42 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
TEST(wfp_jsonrpc_is_request, invalid_request)
|
2019-05-19 12:33:42 +00:00
|
|
|
{
|
2020-07-12 13:13:34 +00:00
|
|
|
JsonDoc doc("[\"method\", { }, 42]");
|
2020-07-11 22:39:55 +00:00
|
|
|
|
2020-07-12 13:13:34 +00:00
|
|
|
ASSERT_FALSE(wfp_jsonrpc_is_request(doc.root()));
|
2019-05-19 12:33:42 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
TEST(wfp_jsonrpc_is_request, invalid_request_without_id)
|
2019-05-19 12:33:42 +00:00
|
|
|
{
|
2020-07-12 13:13:34 +00:00
|
|
|
JsonDoc doc("{\"method\": \"method\", \"params\": { }}");
|
2020-07-11 22:39:55 +00:00
|
|
|
|
2020-07-12 13:13:34 +00:00
|
|
|
ASSERT_FALSE(wfp_jsonrpc_is_request(doc.root()));
|
2019-05-19 12:33:42 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
TEST(wfp_jsonrpc_is_request, invalid_request_due_to_invalid_id)
|
2019-05-19 12:33:42 +00:00
|
|
|
{
|
2020-07-12 13:13:34 +00:00
|
|
|
JsonDoc doc("{\"method\": \"method\", \"params\": { }, \"id\": \"42\"}");
|
2020-07-11 22:39:55 +00:00
|
|
|
|
2020-07-12 13:13:34 +00:00
|
|
|
ASSERT_FALSE(wfp_jsonrpc_is_request(doc.root()));
|
2019-05-19 12:33:42 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
TEST(wfp_jsonrpc_is_request, invalid_request_without_method)
|
2019-05-19 12:33:42 +00:00
|
|
|
{
|
2020-07-12 13:13:34 +00:00
|
|
|
JsonDoc doc("{\"params\": { }, \"id\": 42}");
|
2020-07-11 22:39:55 +00:00
|
|
|
|
2020-07-12 13:13:34 +00:00
|
|
|
ASSERT_FALSE(wfp_jsonrpc_is_request(doc.root()));
|
2019-05-19 12:33:42 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
TEST(wfp_jsonrpc_is_request, invalid_request_due_to_invalid_method)
|
2019-05-19 12:33:42 +00:00
|
|
|
{
|
2020-07-12 13:13:34 +00:00
|
|
|
JsonDoc doc("{\"method\": 42, \"params\": {}, \"id\": 42}");
|
2020-07-11 22:39:55 +00:00
|
|
|
|
2020-07-12 13:13:34 +00:00
|
|
|
ASSERT_FALSE(wfp_jsonrpc_is_request(doc.root()));
|
2019-05-19 12:33:42 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
TEST(wfp_jsonrpc_is_request, invalid_request_without_params)
|
2019-05-19 12:33:42 +00:00
|
|
|
{
|
2020-07-12 13:13:34 +00:00
|
|
|
JsonDoc doc("{\"method\": \"method\", \"id\": 42}");
|
2020-07-11 22:39:55 +00:00
|
|
|
|
2020-07-12 13:13:34 +00:00
|
|
|
ASSERT_FALSE(wfp_jsonrpc_is_request(doc.root()));
|
2019-05-19 12:33:42 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
TEST(wfp_jsonrpc_is_request, invalid_request_due_to_invalid_params)
|
2019-05-19 12:33:42 +00:00
|
|
|
{
|
2020-07-12 13:13:34 +00:00
|
|
|
JsonDoc doc("{\"method\": \"method\", \"params\": \"params\", \"id\": 42}");
|
2020-07-11 22:39:55 +00:00
|
|
|
|
2020-07-12 13:13:34 +00:00
|
|
|
ASSERT_FALSE(wfp_jsonrpc_is_request(doc.root()));
|
2019-05-19 12:33:42 +00:00
|
|
|
}
|