Skip to content

Commit

Permalink
tests: commando-blacklist
Browse files Browse the repository at this point in the history
  • Loading branch information
ShahanaFarooqui authored and rustyrussell committed Apr 1, 2023
1 parent 9d7afba commit 61b0634
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 61b0634

Please sign in to comment.