aboutsummaryrefslogtreecommitdiff
path: root/utils/python-rpc
diff options
context:
space:
mode:
authorjeffro256 <jeffro256@tutanota.com>2024-03-11 23:39:04 -0500
committerjeffro256 <jeffro256@tutanota.com>2024-03-11 23:54:50 -0500
commit8e80585ef5024151f019422b1b0b5d8a40da701f (patch)
treeb6c0b88ce6ccc21ade491827709ec227789af8cd /utils/python-rpc
parentMerge pull request #9225 (diff)
downloadmonero-8e80585ef5024151f019422b1b0b5d8a40da701f.tar.xz
functional_tests: test HTTP digest auth
Test: 1. Can't login to RPC server with --rpc-login enabled, but no auth provided 2. Can access RPC server with correct login 3. Can use internal HTTP client to access RPC server with correct login With commit 0ae5c91e504b8007dedc2b89c9b2b49c404ffec6 not reverted, we fail test 3.
Diffstat (limited to 'utils/python-rpc')
-rw-r--r--utils/python-rpc/framework/daemon.py5
-rw-r--r--utils/python-rpc/framework/rpc.py8
-rw-r--r--utils/python-rpc/framework/wallet.py5
3 files changed, 12 insertions, 6 deletions
diff --git a/utils/python-rpc/framework/daemon.py b/utils/python-rpc/framework/daemon.py
index c7831d1ee..4ac24332d 100644
--- a/utils/python-rpc/framework/daemon.py
+++ b/utils/python-rpc/framework/daemon.py
@@ -33,11 +33,12 @@ from .rpc import JSONRPC
class Daemon(object):
- def __init__(self, protocol='http', host='127.0.0.1', port=0, idx=0, restricted_rpc = False):
+ def __init__(self, protocol='http', host='127.0.0.1', port=0, idx=0, restricted_rpc = False, username=None, password=None):
base = 18480 if restricted_rpc else 18180
self.host = host
self.port = port
- self.rpc = JSONRPC('{protocol}://{host}:{port}'.format(protocol=protocol, host=host, port=port if port else base+idx))
+ self.rpc = JSONRPC('{protocol}://{host}:{port}'.format(protocol=protocol, host=host, port=port if port else base+idx),
+ username, password)
def getblocktemplate(self, address, prev_block = "", client = ""):
getblocktemplate = {
diff --git a/utils/python-rpc/framework/rpc.py b/utils/python-rpc/framework/rpc.py
index 6d9a4b27e..567bdd78d 100644
--- a/utils/python-rpc/framework/rpc.py
+++ b/utils/python-rpc/framework/rpc.py
@@ -28,6 +28,7 @@
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import requests
+from requests.auth import HTTPDigestAuth
import json
class Response(dict):
@@ -60,14 +61,17 @@ class Response(dict):
return True
class JSONRPC(object):
- def __init__(self, url):
+ def __init__(self, url, username=None, password=None):
self.url = url
+ self.username = username
+ self.password = password
def send_request(self, path, inputs, result_field = None):
res = requests.post(
self.url + path,
data=json.dumps(inputs),
- headers={'content-type': 'application/json'})
+ headers={'content-type': 'application/json'},
+ auth=HTTPDigestAuth(self.username, self.password) if self.username is not None else None)
res = res.json()
assert 'error' not in res, res
diff --git a/utils/python-rpc/framework/wallet.py b/utils/python-rpc/framework/wallet.py
index 18af4edc4..8fa3eaafd 100644
--- a/utils/python-rpc/framework/wallet.py
+++ b/utils/python-rpc/framework/wallet.py
@@ -33,10 +33,11 @@ from .rpc import JSONRPC
class Wallet(object):
- def __init__(self, protocol='http', host='127.0.0.1', port=0, idx=0):
+ def __init__(self, protocol='http', host='127.0.0.1', port=0, idx=0, username=None, password=None):
self.host = host
self.port = port
- self.rpc = JSONRPC('{protocol}://{host}:{port}'.format(protocol=protocol, host=host, port=port if port else 18090+idx))
+ self.rpc = JSONRPC('{protocol}://{host}:{port}'.format(protocol=protocol, host=host,
+ port=port if port else 18090+idx), username, password)
def transfer(self, destinations, account_index = 0, subaddr_indices = [], priority = 0, ring_size = 0, unlock_time = 0, payment_id = '', get_tx_key = True, do_not_relay = False, get_tx_hex = False, get_tx_metadata = False, subtract_fee_from_outputs = []):
transfer = {