@@ -2982,6 +2982,87 @@ def test_commando_listrunes(node_factory):
29822982 assert not_our_rune ['our_rune' ] is False
29832983
29842984
2985+ def test_commando_blacklist (node_factory ):
2986+ l1 , l2 = node_factory .get_nodes (2 )
2987+
2988+ l2 .connect (l1 )
2989+ rune0 = l1 .rpc .commando_rune ()
2990+ assert rune0 ['unique_id' ] == '0'
2991+ rune1 = l1 .rpc .commando_rune ()
2992+ assert rune1 ['unique_id' ] == '1'
2993+
2994+ # Make sure runes work!
2995+ assert l2 .rpc .call (method = 'commando' ,
2996+ payload = {'peer_id' : l1 .info ['id' ],
2997+ 'rune' : rune0 ['rune' ],
2998+ 'method' : 'getinfo' ,
2999+ 'params' : []})['id' ] == l1 .info ['id' ]
3000+
3001+ assert l2 .rpc .call (method = 'commando' ,
3002+ payload = {'peer_id' : l1 .info ['id' ],
3003+ 'rune' : rune1 ['rune' ],
3004+ 'method' : 'getinfo' ,
3005+ 'params' : []})['id' ] == l1 .info ['id' ]
3006+
3007+ blacklist = l1 .rpc .commando_blacklist (start = 1 )
3008+ assert blacklist == {'blacklist' : [{'start' : 1 , 'end' : 1 }]}
3009+
3010+ # Make sure rune id 1 does not work!
3011+ with pytest .raises (RpcError , match = 'Not authorized: Blacklisted rune' ):
3012+ assert l2 .rpc .call (method = 'commando' ,
3013+ payload = {'peer_id' : l1 .info ['id' ],
3014+ 'rune' : rune1 ['rune' ],
3015+ 'method' : 'getinfo' ,
3016+ 'params' : []})['id' ] == l1 .info ['id' ]
3017+
3018+ # But, other rune still works!
3019+ assert l2 .rpc .call (method = 'commando' ,
3020+ payload = {'peer_id' : l1 .info ['id' ],
3021+ 'rune' : rune0 ['rune' ],
3022+ 'method' : 'getinfo' ,
3023+ 'params' : []})['id' ] == l1 .info ['id' ]
3024+
3025+ blacklist = l1 .rpc .commando_blacklist (start = 2 )
3026+ assert blacklist == {'blacklist' : [{'start' : 1 , 'end' : 2 }]}
3027+
3028+ blacklist = l1 .rpc .commando_blacklist (start = 6 )
3029+ assert blacklist == {'blacklist' : [{'start' : 1 , 'end' : 2 },
3030+ {'start' : 6 , 'end' : 6 }]}
3031+
3032+ blacklist = l1 .rpc .commando_blacklist (start = 3 , end = 5 )
3033+ assert blacklist == {'blacklist' : [{'start' : 1 , 'end' : 6 }]}
3034+
3035+ blacklist = l1 .rpc .commando_blacklist (start = 9 )
3036+ assert blacklist == {'blacklist' : [{'start' : 1 , 'end' : 6 },
3037+ {'start' : 9 , 'end' : 9 }]}
3038+
3039+ blacklist = l1 .rpc .commando_blacklist (start = 0 )
3040+ assert blacklist == {'blacklist' : [{'start' : 0 , 'end' : 6 },
3041+ {'start' : 9 , 'end' : 9 }]}
3042+
3043+ # Now both runes fail!
3044+ with pytest .raises (RpcError , match = 'Not authorized: Blacklisted rune' ):
3045+ assert l2 .rpc .call (method = 'commando' ,
3046+ payload = {'peer_id' : l1 .info ['id' ],
3047+ 'rune' : rune0 ['rune' ],
3048+ 'method' : 'getinfo' ,
3049+ 'params' : []})['id' ] == l1 .info ['id' ]
3050+
3051+ with pytest .raises (RpcError , match = 'Not authorized: Blacklisted rune' ):
3052+ assert l2 .rpc .call (method = 'commando' ,
3053+ payload = {'peer_id' : l1 .info ['id' ],
3054+ 'rune' : rune1 ['rune' ],
3055+ 'method' : 'getinfo' ,
3056+ 'params' : []})['id' ] == l1 .info ['id' ]
3057+
3058+ blacklist = l1 .rpc .commando_blacklist ()
3059+ assert blacklist == {'blacklist' : [{'start' : 0 , 'end' : 6 },
3060+ {'start' : 9 , 'end' : 9 }]}
3061+
3062+ blacklisted_rune = l1 .rpc .commando_listrunes (rune = 'geZmO6U7yqpHn-moaX93FVMVWrDRfSNY4AXx9ypLcqg9MQ==' )['runes' ][0 ]['blacklisted' ]
3063+ assert blacklisted_rune is True
3064+
3065+
29853066def test_commando_stress (node_factory , executor ):
29863067 """Stress test to slam commando with many large queries"""
29873068 nodes = node_factory .get_nodes (5 )
0 commit comments