Skip to content

Commit

Permalink
feat: test composite commands in functional test for whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
knst committed Jul 7, 2024
1 parent 68df817 commit 12c5b4b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions test/functional/rpc_whitelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
assert_equal,
str_to_b64str
)
import json
import http.client
import urllib.parse

Expand All @@ -20,7 +21,14 @@ def rpccall(node, user, method):
headers = {"Authorization": "Basic " + str_to_b64str('{}:{}'.format(user[0], user[3]))}
conn = http.client.HTTPConnection(url.hostname, url.port)
conn.connect()
conn.request('POST', '/', '{"method": "' + method + '"}', headers)

params = []
if '_' in method:
method, param = method.split('_')
params = [param]
query = {"method" : method, "params" : params}

conn.request('POST', '/', json.dumps(query), headers)
resp = conn.getresponse()
conn.close()
return resp
Expand All @@ -39,7 +47,8 @@ def setup_chain(self):
# 3 => Password Plaintext
self.users = [
["user1", "50358aa884c841648e0700b073c32b2e$b73e95fff0748cc0b517859d2ca47d9bac1aa78231f3e48fa9222b612bd2083e", "getbestblockhash,getblockcount,", "12345"],
["user2", "8650ba41296f62092377a38547f361de$4620db7ba063ef4e2f7249853e9f3c5c3592a9619a759e3e6f1c63f2e22f1d21", "getblockcount", "54321"]
["user2", "8650ba41296f62092377a38547f361de$4620db7ba063ef4e2f7249853e9f3c5c3592a9619a759e3e6f1c63f2e22f1d21", "getblockcount", "54321"],
["platform-user", "8650ba41296f62092377a38547f361de$4620db7ba063ef4e2f7249853e9f3c5c3592a9619a759e3e6f1c63f2e22f1d21", "getblockcount,quorum_list", "54321"],
]
# For exceptions
self.strange_users = [
Expand All @@ -55,7 +64,7 @@ def setup_chain(self):
["strangedude5", "d12c6e962d47a454f962eb41225e6ec8$2dd39635b155536d3c1a2e95d05feff87d5ba55f2d5ff975e6e997a836b717c9", ":getblockcount,getblockcount", "s7R4nG3R7H1nGZ"]
]
# These commands shouldn't be allowed for any user to test failures
self.never_allowed = ["getnetworkinfo"]
self.never_allowed = ["getnetworkinfo", "quorum_sign"]
with open(os.path.join(get_datadir_path(self.options.tmpdir, 0), "dash.conf"), 'a', encoding='utf8') as f:
f.write("\nrpcwhitelistdefault=0\n")
for user in self.users:
Expand Down

0 comments on commit 12c5b4b

Please sign in to comment.