Skip to content

Commit

Permalink
recognize sqashed composite commands
Browse files Browse the repository at this point in the history
  • Loading branch information
UdjinM6 committed Jul 7, 2024
1 parent badd22c commit 37e6d7b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/httprpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static bool whitelisted(JSONRPCRequest jreq)
if (!jreq.params.isArray() || jreq.params.empty()) return false;
if (!jreq.params[0].isStr()) return false;

return g_rpc_whitelist[jreq.authUser].count(jreq.strMethod + "_" + jreq.params[0].get_str());
return g_rpc_whitelist[jreq.authUser].count(jreq.strMethod + jreq.params[0].get_str());
}
static void JSONErrorReply(HTTPRequest* req, const UniValue& objError, const UniValue& id)
{
Expand Down
11 changes: 7 additions & 4 deletions src/rpc/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,12 @@ std::string CRPCTable::help(const std::string& strCommand, const std::string& st
for (const std::pair<std::string, const CRPCCommand*>& command : vCommands)
{
const CRPCCommand *pcmd = command.second;
std::string strMethod = pcmd->name;
if ((strCommand != "" || pcmd->category == "hidden") && strMethod != strCommand)
if ((strCommand != "" || pcmd->category == "hidden") && pcmd->name != strCommand && pcmd->name + pcmd->subname != strCommand)
continue;

if (strSubCommand != pcmd->subname) continue;
if (pcmd->name == strCommand && strSubCommand != pcmd->subname) continue;

jreq.strMethod = strMethod;
jreq.strMethod = pcmd->name;
try
{
if (!strSubCommand.empty()) {
Expand Down Expand Up @@ -307,6 +306,10 @@ void CRPCTable::appendCommand(const std::string& name, const std::string& subnam
CHECK_NONFATAL(!IsRPCRunning()); // Only add commands before rpc is running

mapCommands[std::make_pair(name, subname)].push_back(pcmd);
if (!subname.empty()) {
// add a squashed version of a composite command
mapCommands[std::make_pair(name + subname, "")].push_back(pcmd);
}
}

bool CRPCTable::removeCommand(const std::string& name, const std::string& subname, const CRPCCommand* pcmd)
Expand Down
14 changes: 3 additions & 11 deletions test/functional/rpc_whitelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
assert_equal,
str_to_b64str
)
import json
import http.client
import urllib.parse

Expand All @@ -21,14 +20,7 @@ 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()

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

conn.request('POST', '/', json.dumps(query), headers)
conn.request('POST', '/', '{"method": "' + method + '"}', headers)
resp = conn.getresponse()
conn.close()
return resp
Expand All @@ -48,7 +40,7 @@ def setup_chain(self):
self.users = [
["user1", "50358aa884c841648e0700b073c32b2e$b73e95fff0748cc0b517859d2ca47d9bac1aa78231f3e48fa9222b612bd2083e", "getbestblockhash,getblockcount,", "12345"],
["user2", "8650ba41296f62092377a38547f361de$4620db7ba063ef4e2f7249853e9f3c5c3592a9619a759e3e6f1c63f2e22f1d21", "getblockcount", "54321"],
["platform-user", "8650ba41296f62092377a38547f361de$4620db7ba063ef4e2f7249853e9f3c5c3592a9619a759e3e6f1c63f2e22f1d21", "getblockcount,quorum_list", "54321"],
["platform-user", "8650ba41296f62092377a38547f361de$4620db7ba063ef4e2f7249853e9f3c5c3592a9619a759e3e6f1c63f2e22f1d21", "getblockcount,quorumlist", "54321"],
]
# For exceptions
self.strange_users = [
Expand All @@ -64,7 +56,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", "quorum_sign"]
self.never_allowed = ["getnetworkinfo", "quorumsign"]
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 37e6d7b

Please sign in to comment.