diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 1f2d5a6f1..744862670 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -2982,6 +2982,87 @@ def test_commando_listrunes(node_factory): assert not_our_rune['our_rune'] is False +def test_commando_blacklist(node_factory): + l1, l2 = node_factory.get_nodes(2) + + l2.connect(l1) + rune0 = l1.rpc.commando_rune() + assert rune0['unique_id'] == '0' + rune1 = l1.rpc.commando_rune() + assert rune1['unique_id'] == '1' + + # Make sure runes work! + assert l2.rpc.call(method='commando', + payload={'peer_id': l1.info['id'], + 'rune': rune0['rune'], + 'method': 'getinfo', + 'params': []})['id'] == l1.info['id'] + + assert l2.rpc.call(method='commando', + payload={'peer_id': l1.info['id'], + 'rune': rune1['rune'], + 'method': 'getinfo', + 'params': []})['id'] == l1.info['id'] + + blacklist = l1.rpc.commando_blacklist(start=1) + assert blacklist == {'blacklist': [{'start': 1, 'end': 1}]} + + # Make sure rune id 1 does not work! + with pytest.raises(RpcError, match='Not authorized: Blacklisted rune'): + assert l2.rpc.call(method='commando', + payload={'peer_id': l1.info['id'], + 'rune': rune1['rune'], + 'method': 'getinfo', + 'params': []})['id'] == l1.info['id'] + + # But, other rune still works! + assert l2.rpc.call(method='commando', + payload={'peer_id': l1.info['id'], + 'rune': rune0['rune'], + 'method': 'getinfo', + 'params': []})['id'] == l1.info['id'] + + blacklist = l1.rpc.commando_blacklist(start=2) + assert blacklist == {'blacklist': [{'start': 1, 'end': 2}]} + + blacklist = l1.rpc.commando_blacklist(start=6) + assert blacklist == {'blacklist': [{'start': 1, 'end': 2}, + {'start': 6, 'end': 6}]} + + blacklist = l1.rpc.commando_blacklist(start=3, end=5) + assert blacklist == {'blacklist': [{'start': 1, 'end': 6}]} + + blacklist = l1.rpc.commando_blacklist(start=9) + assert blacklist == {'blacklist': [{'start': 1, 'end': 6}, + {'start': 9, 'end': 9}]} + + blacklist = l1.rpc.commando_blacklist(start=0) + assert blacklist == {'blacklist': [{'start': 0, 'end': 6}, + {'start': 9, 'end': 9}]} + + # Now both runes fail! + with pytest.raises(RpcError, match='Not authorized: Blacklisted rune'): + assert l2.rpc.call(method='commando', + payload={'peer_id': l1.info['id'], + 'rune': rune0['rune'], + 'method': 'getinfo', + 'params': []})['id'] == l1.info['id'] + + with pytest.raises(RpcError, match='Not authorized: Blacklisted rune'): + assert l2.rpc.call(method='commando', + payload={'peer_id': l1.info['id'], + 'rune': rune1['rune'], + 'method': 'getinfo', + 'params': []})['id'] == l1.info['id'] + + blacklist = l1.rpc.commando_blacklist() + assert blacklist == {'blacklist': [{'start': 0, 'end': 6}, + {'start': 9, 'end': 9}]} + + blacklisted_rune = l1.rpc.commando_listrunes(rune='geZmO6U7yqpHn-moaX93FVMVWrDRfSNY4AXx9ypLcqg9MQ==')['runes'][0]['blacklisted'] + assert blacklisted_rune is True + + def test_commando_stress(node_factory, executor): """Stress test to slam commando with many large queries""" nodes = node_factory.get_nodes(5)