mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
lightningd/plugin_control: don't control non-dynamic plugins
This commit is contained in:
@@ -39,6 +39,10 @@ static struct command_result *json_plugin_control(struct command *cmd,
|
||||
plugin_found = false;
|
||||
list_for_each(&cmd->ld->plugins->plugins, p, list) {
|
||||
if (plugin_paths_match(p->cmd, plugin_name)) {
|
||||
if (!p->dynamic)
|
||||
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"%s plugin cannot be managed when lightningd is up",
|
||||
plugin_name);
|
||||
plugin_found = true;
|
||||
plugin_hook_unregister_all(p);
|
||||
plugin_kill(p, "%s stopped by lightningd via RPC",
|
||||
|
||||
25
tests/plugins/static.py
Executable file
25
tests/plugins/static.py
Executable file
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Simple plugin to test the dynamic behavior.
|
||||
|
||||
A plugin started with dynamic to False cannot be controlled after lightningd
|
||||
has been started.
|
||||
"""
|
||||
|
||||
from lightning import Plugin
|
||||
|
||||
plugin = Plugin(dynamic=False)
|
||||
|
||||
|
||||
@plugin.init()
|
||||
def init(configuration, options, plugin):
|
||||
plugin.log("Static plugin initialized.")
|
||||
|
||||
|
||||
@plugin.method('hello')
|
||||
def reject(plugin):
|
||||
"""Mark a given node_id as reject for future connections.
|
||||
"""
|
||||
return "Hello, you cannot stop me without stopping lightningd"
|
||||
|
||||
|
||||
plugin.run()
|
||||
@@ -130,6 +130,13 @@ def test_plugin_command(node_factory):
|
||||
cmd = [hlp for hlp in n.rpc.help()["help"] if "hello" in hlp["command"]]
|
||||
assert(len(cmd) == 0)
|
||||
|
||||
# Test that we cannot stop a plugin with 'dynamic' set to False in
|
||||
# getmanifest
|
||||
n.rpc.plugin_start(plugin=os.path.join(os.getcwd(), "tests/plugins/static.py"))
|
||||
n.daemon.wait_for_log(r"Static plugin initialized.")
|
||||
with pytest.raises(RpcError, match=r"plugin cannot be managed when lightningd is up"):
|
||||
n.rpc.plugin_stop(plugin="static.py")
|
||||
|
||||
|
||||
def test_plugin_disable(node_factory):
|
||||
"""--disable-plugin works"""
|
||||
|
||||
Reference in New Issue
Block a user