mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-29 21:42:32 +02:00
RPC: getrpcwhitelist: Return all methods (or none) if no explicit whitelist defined
This commit is contained in:
parent
e52d7d2033
commit
651c171539
@ -328,7 +328,19 @@ void StopHTTPRPC()
|
||||
}
|
||||
}
|
||||
|
||||
const std::set<std::string>& GetWhitelistedRpcs(const std::string& user_name)
|
||||
std::set<std::string> GetWhitelistedRpcs(const std::string& user_name)
|
||||
{
|
||||
return g_rpc_whitelist.at(user_name);
|
||||
if (auto it = g_rpc_whitelist.find(user_name); it != g_rpc_whitelist.end()) {
|
||||
return it->second;
|
||||
}
|
||||
if (g_rpc_whitelist_default) {
|
||||
return std::set<std::string>();
|
||||
}
|
||||
|
||||
// Build a list of every method
|
||||
std::set<std::string> allowed_methods;
|
||||
for (const auto& method_name : tableRPC.listCommands()) {
|
||||
allowed_methods.insert(method_name);
|
||||
}
|
||||
return allowed_methods;
|
||||
}
|
||||
|
@ -35,6 +35,6 @@ void StopREST();
|
||||
|
||||
/** Returns a collection of whitelisted RPCs for the given user
|
||||
*/
|
||||
const std::set<std::string>& GetWhitelistedRpcs(const std::string& user_name);
|
||||
std::set<std::string> GetWhitelistedRpcs(const std::string& user_name);
|
||||
|
||||
#endif // BITCOIN_HTTPRPC_H
|
||||
|
@ -66,5 +66,9 @@ class RPCWhitelistTest(BitcoinTestFramework):
|
||||
result = call_rpc(self.nodes[0], self.settings_forbidden, 'getrpcwhitelist')
|
||||
assert_equal(result['status'], 403)
|
||||
|
||||
# should return a long list of allowed RPC methods (ie, all of them)
|
||||
result = self.nodes[0].getrpcwhitelist()
|
||||
assert len(result['methods']) > 10
|
||||
|
||||
if __name__ == "__main__":
|
||||
RPCWhitelistTest().main()
|
||||
|
Loading…
Reference in New Issue
Block a user