Browse Source

rpc.py: restore SSL to Monero wallet client, minor cleanups

Fixes a regression introduced by commit f9a483f3
The MMGen Project 4 years ago
parent
commit
28538babcc
3 changed files with 25 additions and 15 deletions
  1. 16 11
      mmgen/rpc.py
  2. 2 1
      test/unit_tests.py
  3. 7 3
      test/unit_tests_d/ut_rpc.py

+ 16 - 11
mmgen/rpc.py

@@ -144,7 +144,7 @@ class RPCBackends:
 
 		def __init__(self,caller):
 
-			def gen():
+			def gen_opts():
 				for k,v in caller.http_hdrs.items():
 					for s in ('--header',f'{k}: {v}'):
 						yield s
@@ -157,9 +157,11 @@ class RPCBackends:
 						yield s
 				if caller.auth_type == 'digest':
 					yield '--digest'
+				if caller.proto == 'https' and caller.verify_server == False:
+					yield '--insecure'
 
 			self.url = caller.url
-			self.exec_opts = list(gen()) + ['--silent']
+			self.exec_opts = list(gen_opts()) + ['--silent']
 			self.arg_max = 8192 # set way below system ARG_MAX, just to be safe
 			self.timeout = caller.timeout
 
@@ -189,8 +191,10 @@ auth_data = namedtuple('rpc_auth_data',['user','passwd'])
 
 class RPCClient(MMGenObject):
 
+	auth_type = None
 	has_auth_cookie = False
-	url_fs = 'http://{}:{}'
+	proto = 'http'
+	host_path = ''
 
 	def __init__(self,host,port):
 
@@ -204,7 +208,7 @@ class RPCClient(MMGenObject):
 			raise SocketError('Unable to connect to {}:{}'.format(host,port))
 
 		self.http_hdrs = { 'Content-Type': 'application/json' }
-		self.url = self.url_fs.format(host,port)
+		self.url = f'{self.proto}://{host}:{port}{self.host_path}'
 		self.host = host
 		self.port = port
 		self.timeout = g.http_timeout
@@ -436,8 +440,6 @@ class BitcoinRPCClient(RPCClient,metaclass=aInitMeta):
 
 class EthereumRPCClient(RPCClient,metaclass=aInitMeta):
 
-	auth_type = None
-
 	def __init__(self,*args,**kwargs): pass
 
 	async def __ainit__(self,backend=None):
@@ -510,16 +512,19 @@ class EthereumRPCClient(RPCClient,metaclass=aInitMeta):
 class MoneroWalletRPCClient(RPCClient):
 
 	auth_type = 'digest'
-	url_fs = 'http://{}:{}/json_rpc'
+	proto = 'https'
+	host_path = '/json_rpc'
+	verify_server = False
 
 	def __init__(self,host,port,user,passwd):
 		super().__init__(host,port)
 		self.auth = auth_data(user,passwd)
-		self.set_backend('requests')
-		if False: # insecure, for debugging only
-			self.backend = RPCBackends.curl(self)
+		if True:
+			self.set_backend('requests')
+		else: # insecure, for debugging only
+			self.set_backend('curl')
 			self.backend.exec_opts.remove('--silent')
-			self.backend.exec_opts.extend(['--insecure','--verbose'])
+			self.backend.exec_opts.append('--verbose')
 
 	async def call(self,method,*params,**kwargs):
 		assert params == (), f'{type(self).__name__}.call() accepts keyword arguments only'

+ 2 - 1
test/unit_tests.py

@@ -32,6 +32,7 @@ opts_data = {
 		'options': """
 -h, --help       Print this help message
 -A, --no-daemon-autostart Don't start and stop daemons automatically
+-D, --no-daemon-stop Don't stop auto-started daemons after running tests
 -f, --fast       Speed up execution by reducing rounds on some tests
 -l, --list       List available tests
 -n, --names      Print command names instead of descriptions
@@ -45,7 +46,7 @@ If no test is specified, all available tests are run
 }
 
 sys.argv.insert(1,'--skip-cfg-file')
-cmd_args = opts.init(opts_data,add_opts=['no_daemon_stop'])
+cmd_args = opts.init(opts_data)
 
 def exit_msg():
 	t = int(time.time()) - start_time

+ 7 - 3
test/unit_tests_d/ut_rpc.py

@@ -84,7 +84,8 @@ class unit_tests:
 
 		async def run():
 			md = CoinDaemon('xmr',test_suite=True)
-			md.start()
+			if not opt.no_daemon_autostart:
+				md.start()
 
 			g.monero_wallet_rpc_password = 'passwOrd'
 			mwd = MoneroWalletDaemon(wallet_dir='test/trash',test_suite=True)
@@ -99,10 +100,13 @@ class unit_tests:
 			await c.call('get_version')
 
 			gmsg('OK')
+
 			mwd.wait = False
 			mwd.stop()
-			md.wait = False
-			md.stop()
+
+			if not opt.no_daemon_stop:
+				md.wait = False
+				md.stop()
 
 		run_session(run(),do_rpc_init=False)
 		return True