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 0ae5c91e50 not reverted, we fail test 3.
This commit is contained in:
jeffro256 2024-03-11 23:39:04 -05:00
parent 1bec71279e
commit 8e80585ef5
No known key found for this signature in database
GPG key ID: 6F79797A6E392442
5 changed files with 135 additions and 17 deletions

View file

@ -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