@@ -16,16 +16,21 @@ class HTTPBasicsTest (BitcoinTestFramework):
16
16
def __init__ (self ):
17
17
super ().__init__ ()
18
18
self .setup_clean_chain = False
19
- self .num_nodes = 1
19
+ self .num_nodes = 2
20
20
21
21
def setup_chain (self ):
22
22
super ().setup_chain ()
23
23
#Append rpcauth to bitcoin.conf before initialization
24
24
rpcauth = "rpcauth=rt:93648e835a54c573682c2eb19f882535$7681e9c5b74bdd85e78166031d2058e1069b3ed7ed967c93fc63abba06f31144"
25
25
rpcauth2 = "rpcauth=rt2:f8607b1a88861fac29dfccf9b52ff9f$ff36a0c23c8c62b4846112e50fa888416e94c17bfd4c42f88fd8f55ec6a3137e"
26
+ rpcuser = "rpcuser=rpcuser💻"
27
+ rpcpassword = "rpcpassword=rpcpassword🔑"
26
28
with open (os .path .join (self .options .tmpdir + "/node0" , "bitcoin.conf" ), 'a' , encoding = 'utf8' ) as f :
27
29
f .write (rpcauth + "\n " )
28
30
f .write (rpcauth2 + "\n " )
31
+ with open (os .path .join (self .options .tmpdir + "/node1" , "bitcoin.conf" ), 'a' , encoding = 'utf8' ) as f :
32
+ f .write (rpcuser + "\n " )
33
+ f .write (rpcpassword + "\n " )
29
34
30
35
def run_test (self ):
31
36
@@ -50,7 +55,7 @@ def run_test(self):
50
55
conn .connect ()
51
56
conn .request ('POST' , '/' , '{"method": "getbestblockhash"}' , headers )
52
57
resp = conn .getresponse ()
53
- assert_equal (resp .status == 401 , False )
58
+ assert_equal (resp .status , 200 )
54
59
conn .close ()
55
60
56
61
#Use new authpair to confirm both work
@@ -60,7 +65,7 @@ def run_test(self):
60
65
conn .connect ()
61
66
conn .request ('POST' , '/' , '{"method": "getbestblockhash"}' , headers )
62
67
resp = conn .getresponse ()
63
- assert_equal (resp .status == 401 , False )
68
+ assert_equal (resp .status , 200 )
64
69
conn .close ()
65
70
66
71
#Wrong login name with rt's password
@@ -71,7 +76,7 @@ def run_test(self):
71
76
conn .connect ()
72
77
conn .request ('POST' , '/' , '{"method": "getbestblockhash"}' , headers )
73
78
resp = conn .getresponse ()
74
- assert_equal (resp .status == 401 , True )
79
+ assert_equal (resp .status , 401 )
75
80
conn .close ()
76
81
77
82
#Wrong password for rt
@@ -82,7 +87,7 @@ def run_test(self):
82
87
conn .connect ()
83
88
conn .request ('POST' , '/' , '{"method": "getbestblockhash"}' , headers )
84
89
resp = conn .getresponse ()
85
- assert_equal (resp .status == 401 , True )
90
+ assert_equal (resp .status , 401 )
86
91
conn .close ()
87
92
88
93
#Correct for rt2
@@ -93,7 +98,7 @@ def run_test(self):
93
98
conn .connect ()
94
99
conn .request ('POST' , '/' , '{"method": "getbestblockhash"}' , headers )
95
100
resp = conn .getresponse ()
96
- assert_equal (resp .status == 401 , False )
101
+ assert_equal (resp .status , 200 )
97
102
conn .close ()
98
103
99
104
#Wrong password for rt2
@@ -104,7 +109,46 @@ def run_test(self):
104
109
conn .connect ()
105
110
conn .request ('POST' , '/' , '{"method": "getbestblockhash"}' , headers )
106
111
resp = conn .getresponse ()
107
- assert_equal (resp .status == 401 , True )
112
+ assert_equal (resp .status , 401 )
113
+ conn .close ()
114
+
115
+ ###############################################################
116
+ # Check correctness of the rpcuser/rpcpassword config options #
117
+ ###############################################################
118
+ url = urllib .parse .urlparse (self .nodes [1 ].url )
119
+
120
+ # rpcuser and rpcpassword authpair
121
+ rpcuserauthpair = "rpcuser💻:rpcpassword🔑"
122
+
123
+ headers = {"Authorization" : "Basic " + str_to_b64str (rpcuserauthpair )}
124
+
125
+ conn = http .client .HTTPConnection (url .hostname , url .port )
126
+ conn .connect ()
127
+ conn .request ('POST' , '/' , '{"method": "getbestblockhash"}' , headers )
128
+ resp = conn .getresponse ()
129
+ assert_equal (resp .status , 200 )
130
+ conn .close ()
131
+
132
+ #Wrong login name with rpcuser's password
133
+ rpcuserauthpair = "rpcuserwrong:rpcpassword"
134
+ headers = {"Authorization" : "Basic " + str_to_b64str (rpcuserauthpair )}
135
+
136
+ conn = http .client .HTTPConnection (url .hostname , url .port )
137
+ conn .connect ()
138
+ conn .request ('POST' , '/' , '{"method": "getbestblockhash"}' , headers )
139
+ resp = conn .getresponse ()
140
+ assert_equal (resp .status , 401 )
141
+ conn .close ()
142
+
143
+ #Wrong password for rpcuser
144
+ rpcuserauthpair = "rpcuser:rpcpasswordwrong"
145
+ headers = {"Authorization" : "Basic " + str_to_b64str (rpcuserauthpair )}
146
+
147
+ conn = http .client .HTTPConnection (url .hostname , url .port )
148
+ conn .connect ()
149
+ conn .request ('POST' , '/' , '{"method": "getbestblockhash"}' , headers )
150
+ resp = conn .getresponse ()
151
+ assert_equal (resp .status , 401 )
108
152
conn .close ()
109
153
110
154
0 commit comments