test: Add rpcauth pair that generated by rpcauth
This commit is contained in:
parent
615f7c2884
commit
8b8032e283
2 changed files with 48 additions and 0 deletions
|
@ -9,6 +9,7 @@
|
||||||
SRCDIR=@abs_top_srcdir@
|
SRCDIR=@abs_top_srcdir@
|
||||||
BUILDDIR=@abs_top_builddir@
|
BUILDDIR=@abs_top_builddir@
|
||||||
EXEEXT=@EXEEXT@
|
EXEEXT=@EXEEXT@
|
||||||
|
RPCAUTH=@abs_top_srcdir@/share/rpcauth/rpcauth.py
|
||||||
|
|
||||||
[components]
|
[components]
|
||||||
# Which components are enabled. These are commented out by `configure` if they were disabled when running config.
|
# Which components are enabled. These are commented out by `configure` if they were disabled when running config.
|
||||||
|
|
|
@ -14,6 +14,10 @@ from test_framework.util import (
|
||||||
import os
|
import os
|
||||||
import http.client
|
import http.client
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
import subprocess
|
||||||
|
from random import SystemRandom
|
||||||
|
import string
|
||||||
|
import configparser
|
||||||
|
|
||||||
|
|
||||||
class HTTPBasicsTest(BitcoinTestFramework):
|
class HTTPBasicsTest(BitcoinTestFramework):
|
||||||
|
@ -27,9 +31,20 @@ class HTTPBasicsTest(BitcoinTestFramework):
|
||||||
rpcauth2 = "rpcauth=rt2:f8607b1a88861fac29dfccf9b52ff9f$ff36a0c23c8c62b4846112e50fa888416e94c17bfd4c42f88fd8f55ec6a3137e"
|
rpcauth2 = "rpcauth=rt2:f8607b1a88861fac29dfccf9b52ff9f$ff36a0c23c8c62b4846112e50fa888416e94c17bfd4c42f88fd8f55ec6a3137e"
|
||||||
rpcuser = "rpcuser=rpcuser💻"
|
rpcuser = "rpcuser=rpcuser💻"
|
||||||
rpcpassword = "rpcpassword=rpcpassword🔑"
|
rpcpassword = "rpcpassword=rpcpassword🔑"
|
||||||
|
|
||||||
|
self.user = ''.join(SystemRandom().choice(string.ascii_letters + string.digits) for _ in range(10))
|
||||||
|
config = configparser.ConfigParser()
|
||||||
|
config.read_file(open(self.options.configfile))
|
||||||
|
gen_rpcauth = config['environment']['RPCAUTH']
|
||||||
|
p = subprocess.Popen([gen_rpcauth, self.user], stdout=subprocess.PIPE, universal_newlines=True)
|
||||||
|
lines = p.stdout.read().splitlines()
|
||||||
|
rpcauth3 = lines[1]
|
||||||
|
self.password = lines[3]
|
||||||
|
|
||||||
with open(os.path.join(get_datadir_path(self.options.tmpdir, 0), "bitcoin.conf"), 'a', encoding='utf8') as f:
|
with open(os.path.join(get_datadir_path(self.options.tmpdir, 0), "bitcoin.conf"), 'a', encoding='utf8') as f:
|
||||||
f.write(rpcauth+"\n")
|
f.write(rpcauth+"\n")
|
||||||
f.write(rpcauth2+"\n")
|
f.write(rpcauth2+"\n")
|
||||||
|
f.write(rpcauth3+"\n")
|
||||||
with open(os.path.join(get_datadir_path(self.options.tmpdir, 1), "bitcoin.conf"), 'a', encoding='utf8') as f:
|
with open(os.path.join(get_datadir_path(self.options.tmpdir, 1), "bitcoin.conf"), 'a', encoding='utf8') as f:
|
||||||
f.write(rpcuser+"\n")
|
f.write(rpcuser+"\n")
|
||||||
f.write(rpcpassword+"\n")
|
f.write(rpcpassword+"\n")
|
||||||
|
@ -51,6 +66,7 @@ class HTTPBasicsTest(BitcoinTestFramework):
|
||||||
password2 = "8/F3uMDw4KSEbw96U3CA1C4X05dkHDN2BPFjTgZW4KI="
|
password2 = "8/F3uMDw4KSEbw96U3CA1C4X05dkHDN2BPFjTgZW4KI="
|
||||||
authpairnew = "rt:"+password
|
authpairnew = "rt:"+password
|
||||||
|
|
||||||
|
self.log.info('Correct...')
|
||||||
headers = {"Authorization": "Basic " + str_to_b64str(authpair)}
|
headers = {"Authorization": "Basic " + str_to_b64str(authpair)}
|
||||||
|
|
||||||
conn = http.client.HTTPConnection(url.hostname, url.port)
|
conn = http.client.HTTPConnection(url.hostname, url.port)
|
||||||
|
@ -61,6 +77,7 @@ class HTTPBasicsTest(BitcoinTestFramework):
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
#Use new authpair to confirm both work
|
#Use new authpair to confirm both work
|
||||||
|
self.log.info('Correct...')
|
||||||
headers = {"Authorization": "Basic " + str_to_b64str(authpairnew)}
|
headers = {"Authorization": "Basic " + str_to_b64str(authpairnew)}
|
||||||
|
|
||||||
conn = http.client.HTTPConnection(url.hostname, url.port)
|
conn = http.client.HTTPConnection(url.hostname, url.port)
|
||||||
|
@ -71,6 +88,7 @@ class HTTPBasicsTest(BitcoinTestFramework):
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
#Wrong login name with rt's password
|
#Wrong login name with rt's password
|
||||||
|
self.log.info('Wrong...')
|
||||||
authpairnew = "rtwrong:"+password
|
authpairnew = "rtwrong:"+password
|
||||||
headers = {"Authorization": "Basic " + str_to_b64str(authpairnew)}
|
headers = {"Authorization": "Basic " + str_to_b64str(authpairnew)}
|
||||||
|
|
||||||
|
@ -82,6 +100,7 @@ class HTTPBasicsTest(BitcoinTestFramework):
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
#Wrong password for rt
|
#Wrong password for rt
|
||||||
|
self.log.info('Wrong...')
|
||||||
authpairnew = "rt:"+password+"wrong"
|
authpairnew = "rt:"+password+"wrong"
|
||||||
headers = {"Authorization": "Basic " + str_to_b64str(authpairnew)}
|
headers = {"Authorization": "Basic " + str_to_b64str(authpairnew)}
|
||||||
|
|
||||||
|
@ -93,6 +112,7 @@ class HTTPBasicsTest(BitcoinTestFramework):
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
#Correct for rt2
|
#Correct for rt2
|
||||||
|
self.log.info('Correct...')
|
||||||
authpairnew = "rt2:"+password2
|
authpairnew = "rt2:"+password2
|
||||||
headers = {"Authorization": "Basic " + str_to_b64str(authpairnew)}
|
headers = {"Authorization": "Basic " + str_to_b64str(authpairnew)}
|
||||||
|
|
||||||
|
@ -104,6 +124,7 @@ class HTTPBasicsTest(BitcoinTestFramework):
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
#Wrong password for rt2
|
#Wrong password for rt2
|
||||||
|
self.log.info('Wrong...')
|
||||||
authpairnew = "rt2:"+password2+"wrong"
|
authpairnew = "rt2:"+password2+"wrong"
|
||||||
headers = {"Authorization": "Basic " + str_to_b64str(authpairnew)}
|
headers = {"Authorization": "Basic " + str_to_b64str(authpairnew)}
|
||||||
|
|
||||||
|
@ -114,12 +135,37 @@ class HTTPBasicsTest(BitcoinTestFramework):
|
||||||
assert_equal(resp.status, 401)
|
assert_equal(resp.status, 401)
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
#Correct for randomly generated user
|
||||||
|
self.log.info('Correct...')
|
||||||
|
authpairnew = self.user+":"+self.password
|
||||||
|
headers = {"Authorization": "Basic " + str_to_b64str(authpairnew)}
|
||||||
|
|
||||||
|
conn = http.client.HTTPConnection(url.hostname, url.port)
|
||||||
|
conn.connect()
|
||||||
|
conn.request('POST', '/', '{"method": "getbestblockhash"}', headers)
|
||||||
|
resp = conn.getresponse()
|
||||||
|
assert_equal(resp.status, 200)
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
#Wrong password for randomly generated user
|
||||||
|
self.log.info('Wrong...')
|
||||||
|
authpairnew = self.user+":"+self.password+"Wrong"
|
||||||
|
headers = {"Authorization": "Basic " + str_to_b64str(authpairnew)}
|
||||||
|
|
||||||
|
conn = http.client.HTTPConnection(url.hostname, url.port)
|
||||||
|
conn.connect()
|
||||||
|
conn.request('POST', '/', '{"method": "getbestblockhash"}', headers)
|
||||||
|
resp = conn.getresponse()
|
||||||
|
assert_equal(resp.status, 401)
|
||||||
|
conn.close()
|
||||||
|
|
||||||
###############################################################
|
###############################################################
|
||||||
# Check correctness of the rpcuser/rpcpassword config options #
|
# Check correctness of the rpcuser/rpcpassword config options #
|
||||||
###############################################################
|
###############################################################
|
||||||
url = urllib.parse.urlparse(self.nodes[1].url)
|
url = urllib.parse.urlparse(self.nodes[1].url)
|
||||||
|
|
||||||
# rpcuser and rpcpassword authpair
|
# rpcuser and rpcpassword authpair
|
||||||
|
self.log.info('Correct...')
|
||||||
rpcuserauthpair = "rpcuser💻:rpcpassword🔑"
|
rpcuserauthpair = "rpcuser💻:rpcpassword🔑"
|
||||||
|
|
||||||
headers = {"Authorization": "Basic " + str_to_b64str(rpcuserauthpair)}
|
headers = {"Authorization": "Basic " + str_to_b64str(rpcuserauthpair)}
|
||||||
|
@ -143,6 +189,7 @@ class HTTPBasicsTest(BitcoinTestFramework):
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
#Wrong password for rpcuser
|
#Wrong password for rpcuser
|
||||||
|
self.log.info('Wrong...')
|
||||||
rpcuserauthpair = "rpcuser:rpcpasswordwrong"
|
rpcuserauthpair = "rpcuser:rpcpasswordwrong"
|
||||||
headers = {"Authorization": "Basic " + str_to_b64str(rpcuserauthpair)}
|
headers = {"Authorization": "Basic " + str_to_b64str(rpcuserauthpair)}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue