tests: add test to validate jsonrpc
What changed, and why it matters
This commit only adds a new test case (currently skipped) and a tiny helper plugin. It does not change any production code, so it cannot by itself fix or introduce a security vulnerability. The test is meant to check that the lightning-cli command-line tool sends JSON values correctly when a numeric-looking string has a leading zero, which some JSON parsers reject as invalid integers.
No immediate action is required for this commit. If the underlying concern (lightning-cli serializing numeric strings with leading zeros as bare numbers) is later confirmed, review the CLI's JSON encoding and add an unskipped regression test.
Security signals we found
Test-only commit with no production code changes
Skipped test, so no runtime effect
Comment references JSON parsing failure in Rust serde_json for leading-zero integers
Potential concern about CLI argument serialization of numeric-looking strings
Evidence from the diff
The diff creates tests/plugins/validatejson.py, a minimal pyln plugin exposing a validate-json-rpc method, and adds test_valid_json_cli in tests/test_misc.py. The test is decorated with @pytest.mark.skip, so it does not run by default. It invokes lightning-cli with -k (keyword arguments) and a nodeid parameter set to a 33-byte hex string starting with 030000… The comment explains the concern: if the CLI mistakenly sent such a value as a bare JSON number, Rust’s serde_json would reject it because of the leading zero. The commit adds the test scaffolding but no fix or behavior change to lightning-cli or the JSON-RPC layer.
Changed components
tests/plugins/validatejson.pytests/test_misc.pyInspect captured patch +37 / −0
diff --git a/tests/plugins/validatejson.py b/tests/plugins/validatejson.py
new file mode 100755
index 00000000..8c32d4da
--- /dev/null
+++ b/tests/plugins/validatejson.py
@@ -0,0 +1,12 @@
+#!/usr/bin/env python3
+from pyln.client import Plugin
+
+plugin = Plugin()
+
+
+@plugin.method('validate-json-rpc')
+def validate_json_rpc(plugin, *args, **kwargs):
+ return {}
+
+
+plugin.run()
diff --git a/tests/test_misc.py b/tests/test_misc.py
index faac4c7a..16adac66 100644
--- a/tests/test_misc.py
+++ b/tests/test_misc.py
@@ -1011,6 +1011,31 @@ def test_malformed_rpc(node_factory):
sock.close()
+@pytest.mark.skip
+def test_valid_json_cli(node_factory):
+ """Make sure lightning-cli passes valid json values, so that rust and python plugins
+ don't crash."""
+ l1 = node_factory.get_node(
+ options={
+ "log-level": "io",
+ "plugin": os.path.join(os.getcwd(), "tests/plugins/validatejson.py"),
+ }
+ )
+ # If passed as a literal number rust's serde_json::from_str will fail as the
+ # leading zero makes it invalid for an integer.
+ nodeid = "030000000000000000000000000000000000000000000000000000000000000001"
+ subprocess.check_output(
+ [
+ "cli/lightning-cli",
+ "--network={}".format(TEST_NETWORK),
+ "--lightning-dir={}".format(l1.daemon.lightning_dir),
+ "-k",
+ "validate-json-rpc",
+ f"nodeid={nodeid}",
+ ]
+ ).decode("utf-8")
+
+
def test_cli(node_factory):
l1 = node_factory.get_node(options={'log-level': 'io'})
Why this scored 11/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.