lightningd: refuse to create rune with empty fields.

These look like uniqueids, and so can confuse us (I discovered this by
making a typo in a test!)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2023-09-12 10:22:44 +09:30
parent bb38f83b88
commit ecb09778db
2 changed files with 12 additions and 0 deletions

View File

@ -419,6 +419,10 @@ static struct rune_altern *rune_altern_from_json(const tal_t *ctx,
alt->fieldname = tal_strndup(alt, unescape, condoff);
alt->condition = unescape[condoff];
alt->value = tal_strdup(alt, unescape + condoff + 1);
/* don't let them add empty fieldnames */
if (streq(alt->fieldname, ""))
return tal_free(alt);
return alt;
}

View File

@ -514,6 +514,14 @@ def test_missing_method_or_nodeid(node_factory):
l1.rpc.checkrune(rune=rune4, nodeid=l1.info['id'])
def test_invalid_restrictions(node_factory):
# I meant "method!" not "!method"!
l1 = node_factory.get_node()
for cond in "!=/^$~<>{}#,":
with pytest.raises(RpcError, match='not a valid restriction'):
print(l1.rpc.createrune(restrictions=[[f"{cond}method"]]))
def test_showrune_id(node_factory):
l1 = node_factory.get_node()