aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCarl Dong <contact@carldong.me>2019-07-03 14:39:49 -0400
committerCarl Dong <contact@carldong.me>2019-07-08 16:13:33 -0400
commitc73d871799982ca29c29cef90e1a78814cf34019 (patch)
treefe4b19666b326c0e51a1d3e83e90d98f8c160439 /test
parent604e2a997ff26202dd0fa1932d60dc14cc53ac6d (diff)
test: rpc_users: Add function for testing auth params.
Diffstat (limited to 'test')
-rwxr-xr-xtest/functional/rpc_users.py59
1 files changed, 18 insertions, 41 deletions
diff --git a/test/functional/rpc_users.py b/test/functional/rpc_users.py
index 8bb4676069..be21c837f4 100755
--- a/test/functional/rpc_users.py
+++ b/test/functional/rpc_users.py
@@ -61,63 +61,40 @@ class HTTPBasicsTest(BitcoinTestFramework):
f.write(rpcuser+"\n")
f.write(rpcpassword+"\n")
- def run_test(self):
-
- ##################################################
- # Check correctness of the rpcauth config option #
- ##################################################
- url = urllib.parse.urlparse(self.nodes[0].url)
-
- password = "cA773lm788buwYe4g4WT+05pKyNruVKjQ25x3n0DQcM="
- password2 = "8/F3uMDw4KSEbw96U3CA1C4X05dkHDN2BPFjTgZW4KI="
-
+ def test_auth(self, node, user, password):
self.log.info('Correct...')
- assert_equal(200, call_with_auth(self.nodes[0], url.username, url.password).status)
+ assert_equal(200, call_with_auth(node, user, password).status)
- #Use new authpair to confirm both work
- self.log.info('Correct...')
- assert_equal(200, call_with_auth(self.nodes[0], 'rt', password).status)
+ self.log.info('Wrong...')
+ assert_equal(401, call_with_auth(node, user, password+'wrong').status)
- #Wrong login name with rt's password
self.log.info('Wrong...')
- assert_equal(401, call_with_auth(self.nodes[0], 'rtwrong', password).status)
+ assert_equal(401, call_with_auth(node, user+'wrong', password).status)
- #Wrong password for rt
self.log.info('Wrong...')
- assert_equal(401, call_with_auth(self.nodes[0], 'rt', password+'wrong').status)
+ assert_equal(401, call_with_auth(node, user+'wrong', password+'wrong').status)
- #Correct for rt2
- self.log.info('Correct...')
- assert_equal(200, call_with_auth(self.nodes[0], 'rt2', password2).status)
+ def run_test(self):
- #Wrong password for rt2
- self.log.info('Wrong...')
- assert_equal(401, call_with_auth(self.nodes[0], 'rt2', password2+'wrong').status)
+ ##################################################
+ # Check correctness of the rpcauth config option #
+ ##################################################
+ url = urllib.parse.urlparse(self.nodes[0].url)
- #Correct for randomly generated user
- self.log.info('Correct...')
- assert_equal(200, call_with_auth(self.nodes[0], self.user, self.password).status)
+ password = "cA773lm788buwYe4g4WT+05pKyNruVKjQ25x3n0DQcM="
+ password2 = "8/F3uMDw4KSEbw96U3CA1C4X05dkHDN2BPFjTgZW4KI="
- #Wrong password for randomly generated user
- self.log.info('Wrong...')
- assert_equal(401, call_with_auth(self.nodes[0], self.user, self.password+'Wrong').status)
+ self.test_auth(self.nodes[0], url.username, url.password)
+ self.test_auth(self.nodes[0], 'rt', password)
+ self.test_auth(self.nodes[0], 'rt2', password2)
+ self.test_auth(self.nodes[0], self.user, self.password)
###############################################################
# Check correctness of the rpcuser/rpcpassword config options #
###############################################################
url = urllib.parse.urlparse(self.nodes[1].url)
- # rpcuser and rpcpassword authpair
- self.log.info('Correct...')
- assert_equal(200, call_with_auth(self.nodes[1], "rpcuser💻", "rpcpassword🔑").status)
-
- #Wrong login name with rpcuser's password
- self.log.info('Wrong...')
- assert_equal(401, call_with_auth(self.nodes[1], 'rpcuserwrong', 'rpcpassword').status)
-
- #Wrong password for rpcuser
- self.log.info('Wrong...')
- assert_equal(401, call_with_auth(self.nodes[1], 'rpcuser', 'rpcpasswordwrong').status)
+ self.test_auth(self.nodes[1], "rpcuser💻", "rpcpassword🔑")
if __name__ == '__main__':
HTTPBasicsTest ().main ()