mirror of https://git.kore.io/kore.git
Compliantly don't return anything to notifications
And don't return anything either if protocol doesn't match.
This commit is contained in:
parent
db02e990ea
commit
4ffe43cf87
|
@ -53,39 +53,39 @@ printrep() {
|
|||
printf "%s\n" "$result"
|
||||
}
|
||||
|
||||
@test "requests with no protocol raise errors" {
|
||||
query='{"method":"foo"}'
|
||||
@test "requests with no protocol returns nothing" {
|
||||
query='{"method":"foo","id":"foo"}'
|
||||
result=`query "$query"`
|
||||
printrep "$query" "$result"
|
||||
grepstr "$result" '"error"[ \t\n]*:[ \t\n]*{[ \t\n]*"code"'
|
||||
[ "$result" = "" ]
|
||||
}
|
||||
@test "requests with invalid protocol (1) raise errors" {
|
||||
query='{"jsonrpc":"1.0","method":"foo"}'
|
||||
@test "requests with invalid protocol (1) returns nothing" {
|
||||
query='{"jsonrpc":"1.0","method":"foo","id":"foo"}'
|
||||
result=`query "$query"`
|
||||
printrep "$query" "$result"
|
||||
grepstr "$result" '"error"[ \t\n]*:[ \t\n]*{[ \t\n]*"code"'
|
||||
[ "$result" = "" ]
|
||||
}
|
||||
@test "requests with invalid protocol (2) raise errors" {
|
||||
query='{"jsonrpc":2.0,"method":"foo"}'
|
||||
@test "requests with invalid protocol (2) returns nothing" {
|
||||
query='{"jsonrpc":2.0,"method":"foo","id":"foo"}'
|
||||
result=`query "$query"`
|
||||
printrep "$query" "$result"
|
||||
grepstr "$result" '"error"[ \t\n]*:[ \t\n]*{[ \t\n]*"code"'
|
||||
[ "$result" = "" ]
|
||||
}
|
||||
|
||||
@test "requests with no method raise errors" {
|
||||
query='{"jsonrpc":"2.0"}'
|
||||
query='{"jsonrpc":"2.0","id":"foo"}'
|
||||
result=`query "$query"`
|
||||
printrep "$query" "$result"
|
||||
grepstr "$result" '"error"[ \t\n]*:[ \t\n]*{[ \t\n]*"code"'
|
||||
}
|
||||
@test "requests with invalid method raise errors" {
|
||||
query='{"jsonrpc":"2.0","method":1}'
|
||||
query='{"jsonrpc":"2.0","method":1,"id":"foo"}'
|
||||
result=`query "$query"`
|
||||
printrep "$query" "$result"
|
||||
grepstr "$result" '"error"[ \t\n]*:[ \t\n]*{[ \t\n]*"code"'
|
||||
}
|
||||
@test "requests with unknown method raise errors" {
|
||||
query='{"jsonrpc":"2.0","method":"foobar"}'
|
||||
query='{"jsonrpc":"2.0","method":"foobar","id":"foo"}'
|
||||
result=`query "$query"`
|
||||
printrep "$query" "$result"
|
||||
grepstr "$result" '"error"[ \t\n]*:[ \t\n]*{[ \t\n]*"code"'
|
||||
|
|
|
@ -236,9 +236,6 @@ write_id(yajl_gen gen, yajl_val id)
|
|||
{
|
||||
int status;
|
||||
|
||||
if (id == NULL)
|
||||
return (yajl_gen_status_ok);
|
||||
|
||||
if (YAJL_GEN_KO(status = YAJL_GEN_CONST_STRING(gen, "id")))
|
||||
return (status);
|
||||
|
||||
|
@ -248,7 +245,7 @@ write_id(yajl_gen gen, yajl_val id)
|
|||
if (YAJL_IS_NUMBER(id)) {
|
||||
if (YAJL_IS_INTEGER(id))
|
||||
return yajl_gen_integer(gen, YAJL_GET_INTEGER(id));
|
||||
return (-2);
|
||||
return yajl_gen_null(gen);
|
||||
}
|
||||
|
||||
if (YAJL_IS_STRING(id)) {
|
||||
|
@ -258,7 +255,7 @@ write_id(yajl_gen gen, yajl_val id)
|
|||
strlen(id_str));
|
||||
}
|
||||
|
||||
return (-1);
|
||||
return yajl_gen_null(gen);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -393,10 +390,13 @@ int
|
|||
jsonrpc_error(struct jsonrpc_request *req, int code, const char *msg)
|
||||
{
|
||||
char *msg_fallback;
|
||||
const unsigned char *body;
|
||||
size_t body_len;
|
||||
const unsigned char *body = NULL;
|
||||
size_t body_len = 0;
|
||||
int status;
|
||||
|
||||
if (req->id == NULL)
|
||||
goto succeeded;
|
||||
|
||||
if ((req->gen = yajl_gen_alloc(NULL)) == NULL) {
|
||||
kore_log(LOG_ERR, "jsonrpc_error: Failed to allocate yajl gen");
|
||||
goto failed;
|
||||
|
@ -427,7 +427,9 @@ jsonrpc_error(struct jsonrpc_request *req, int code, const char *msg)
|
|||
kore_log(LOG_ERR, "jsonrpc_error: Body length overflow");
|
||||
goto failed;
|
||||
}
|
||||
succeeded:
|
||||
http_response(req->http, 200, body, body_len);
|
||||
if (req->gen != NULL)
|
||||
yajl_gen_clear(req->gen);
|
||||
free_request(req);
|
||||
return (KORE_RESULT_OK);
|
||||
|
@ -441,8 +443,11 @@ int
|
|||
jsonrpc_result(struct jsonrpc_request *req,
|
||||
int (*write_result)(struct jsonrpc_request *, void *), void *ctx)
|
||||
{
|
||||
const unsigned char *body;
|
||||
size_t body_len;
|
||||
const unsigned char *body = NULL;
|
||||
size_t body_len = 0;
|
||||
|
||||
if (req->id == NULL)
|
||||
goto succeeded;
|
||||
|
||||
if ((req->gen = yajl_gen_alloc(NULL)) == NULL) {
|
||||
kore_log(LOG_ERR, "jsonrpc_result: Failed to allocate yajl gen");
|
||||
|
@ -469,7 +474,9 @@ jsonrpc_result(struct jsonrpc_request *req,
|
|||
kore_log(LOG_ERR, "jsonrpc_result: Body length overflow");
|
||||
goto failed;
|
||||
}
|
||||
succeeded:
|
||||
http_response(req->http, 200, body, body_len);
|
||||
if (req->gen != NULL)
|
||||
yajl_gen_clear(req->gen);
|
||||
free_request(req);
|
||||
return (KORE_RESULT_OK);
|
||||
|
|
Loading…
Reference in New Issue