Source
xxxxxxxxxx
'request' => '{"jsonrpc": "2.0", "method": "apiinfo.version", "params": {}, "auth": "token", "id": 5}',
<?php
/*
** Zabbix
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
require_once dirname(__FILE__).'/../include/CAPITest.php';
class testJSONRPC extends CAPITest {
public static function json_rpc_data() {
return [
// rpc call with invalid JSON
[
'request' => '{"jsonrpc": "2.0", "method": "foobar, "params": "bar", "baz]',
'result' => [
'jsonrpc' => '2.0',
'error' => [
'code' => -32700,
'message' => 'Parse error',
'data' => 'Invalid JSON. An error occurred on the server while parsing the JSON text.'
],
'id' => null
]
],
// rpc call Batch, invalid JSON
[
'request' =>
'['.
'{"jsonrpc": "2.0", "method": "sum", "params": [1,2,4], "id": "1"},'.
'{"jsonrpc": "2.0", "method"'.
']',
'result' => [
'jsonrpc' => '2.0',
'error' => [
'code' => -32700,
'message' => 'Parse error',
'data' => 'Invalid JSON. An error occurred on the server while parsing the JSON text.'
],
'id' => null
]
],
// rpc call with an empty Array
[
'request' => '[]',
'result' => [
'jsonrpc' => '2.0',
'error' => [
'code' => -32600,
'message' => 'Invalid request.',
'data' => 'The received JSON is not a valid JSON-RPC request.'
],
'id' => null
]
],
// rpc call with an invalid scalar data
[
'request' => '12345',
'result' => [
'jsonrpc' => '2.0',
'error' => [
'code' => -32600,
'message' => 'Invalid request.',
'data' => 'The received JSON is not a valid JSON-RPC request.'
],
'id' => null
]
],
// rpc call with invalid "jsonrpc"
[
'request' => '{"jsonrpc": null}',
'result' => [
'jsonrpc' => '2.0',
'error' => [
'code' => -32600,
'message' => 'Invalid request.',