Skip to content

Commit c73d871

Browse files
committed
test: rpc_users: Add function for testing auth params.
1 parent 604e2a9 commit c73d871

File tree

1 file changed

+18
-41
lines changed

1 file changed

+18
-41
lines changed

test/functional/rpc_users.py

Lines changed: 18 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -61,63 +61,40 @@ def setup_chain(self):
6161
f.write(rpcuser+"\n")
6262
f.write(rpcpassword+"\n")
6363

64-
def run_test(self):
65-
66-
##################################################
67-
# Check correctness of the rpcauth config option #
68-
##################################################
69-
url = urllib.parse.urlparse(self.nodes[0].url)
70-
71-
password = "cA773lm788buwYe4g4WT+05pKyNruVKjQ25x3n0DQcM="
72-
password2 = "8/F3uMDw4KSEbw96U3CA1C4X05dkHDN2BPFjTgZW4KI="
73-
64+
def test_auth(self, node, user, password):
7465
self.log.info('Correct...')
75-
assert_equal(200, call_with_auth(self.nodes[0], url.username, url.password).status)
66+
assert_equal(200, call_with_auth(node, user, password).status)
7667

77-
#Use new authpair to confirm both work
78-
self.log.info('Correct...')
79-
assert_equal(200, call_with_auth(self.nodes[0], 'rt', password).status)
68+
self.log.info('Wrong...')
69+
assert_equal(401, call_with_auth(node, user, password+'wrong').status)
8070

81-
#Wrong login name with rt's password
8271
self.log.info('Wrong...')
83-
assert_equal(401, call_with_auth(self.nodes[0], 'rtwrong', password).status)
72+
assert_equal(401, call_with_auth(node, user+'wrong', password).status)
8473

85-
#Wrong password for rt
8674
self.log.info('Wrong...')
87-
assert_equal(401, call_with_auth(self.nodes[0], 'rt', password+'wrong').status)
75+
assert_equal(401, call_with_auth(node, user+'wrong', password+'wrong').status)
8876

89-
#Correct for rt2
90-
self.log.info('Correct...')
91-
assert_equal(200, call_with_auth(self.nodes[0], 'rt2', password2).status)
77+
def run_test(self):
9278

93-
#Wrong password for rt2
94-
self.log.info('Wrong...')
95-
assert_equal(401, call_with_auth(self.nodes[0], 'rt2', password2+'wrong').status)
79+
##################################################
80+
# Check correctness of the rpcauth config option #
81+
##################################################
82+
url = urllib.parse.urlparse(self.nodes[0].url)
9683

97-
#Correct for randomly generated user
98-
self.log.info('Correct...')
99-
assert_equal(200, call_with_auth(self.nodes[0], self.user, self.password).status)
84+
password = "cA773lm788buwYe4g4WT+05pKyNruVKjQ25x3n0DQcM="
85+
password2 = "8/F3uMDw4KSEbw96U3CA1C4X05dkHDN2BPFjTgZW4KI="
10086

101-
#Wrong password for randomly generated user
102-
self.log.info('Wrong...')
103-
assert_equal(401, call_with_auth(self.nodes[0], self.user, self.password+'Wrong').status)
87+
self.test_auth(self.nodes[0], url.username, url.password)
88+
self.test_auth(self.nodes[0], 'rt', password)
89+
self.test_auth(self.nodes[0], 'rt2', password2)
90+
self.test_auth(self.nodes[0], self.user, self.password)
10491

10592
###############################################################
10693
# Check correctness of the rpcuser/rpcpassword config options #
10794
###############################################################
10895
url = urllib.parse.urlparse(self.nodes[1].url)
10996

110-
# rpcuser and rpcpassword authpair
111-
self.log.info('Correct...')
112-
assert_equal(200, call_with_auth(self.nodes[1], "rpcuser💻", "rpcpassword🔑").status)
113-
114-
#Wrong login name with rpcuser's password
115-
self.log.info('Wrong...')
116-
assert_equal(401, call_with_auth(self.nodes[1], 'rpcuserwrong', 'rpcpassword').status)
117-
118-
#Wrong password for rpcuser
119-
self.log.info('Wrong...')
120-
assert_equal(401, call_with_auth(self.nodes[1], 'rpcuser', 'rpcpasswordwrong').status)
97+
self.test_auth(self.nodes[1], "rpcuser💻", "rpcpassword🔑")
12198

12299
if __name__ == '__main__':
123100
HTTPBasicsTest ().main ()

0 commit comments

Comments
 (0)