@@ -168,7 +168,15 @@ def test_auth(self, node, user, password, wallet_restrictions=None):
168
168
assert b'"Requested wallet does not exist or is not loaded"' in resp .data
169
169
170
170
def test_rpccookieperms (self ):
171
- p = {"owner" : 0o600 , "group" : 0o640 , "all" : 0o644 }
171
+ p = {
172
+ "owner" : 0o600 ,
173
+ "group" : 0o640 ,
174
+ "all" : 0o644 ,
175
+ "440" : 0o440 ,
176
+ "0640" : 0o640 ,
177
+ "444" : 0o444 ,
178
+ "1660" : 0o1660 ,
179
+ }
172
180
173
181
if platform .system () == 'Windows' :
174
182
self .log .info (f"Skip cookie file permissions checks as OS detected as: { platform .system ()= } " )
@@ -177,7 +185,7 @@ def test_rpccookieperms(self):
177
185
self .log .info ('Check cookie file permissions can be set using -rpccookieperms' )
178
186
179
187
cookie_file_path = self .nodes [1 ].chain_path / '.cookie'
180
- PERM_BITS_UMASK = 0o777
188
+ PERM_BITS_UMASK = 0o7777
181
189
182
190
def test_perm (perm : Optional [str ]):
183
191
if not perm :
@@ -190,17 +198,38 @@ def test_perm(perm: Optional[str]):
190
198
actual_perms = file_stat .st_mode & PERM_BITS_UMASK
191
199
expected_perms = p [perm ]
192
200
assert_equal (expected_perms , actual_perms )
201
+ return actual_perms
193
202
194
203
# Remove any leftover rpc{user|password} config options from previous tests
195
204
self .nodes [1 ].replace_in_config ([("rpcuser" , "#rpcuser" ), ("rpcpassword" , "#rpcpassword" )])
196
205
197
206
self .log .info ('Check default cookie permission' )
198
- test_perm (None )
207
+ default_perms = test_perm (None )
199
208
200
209
self .log .info ('Check custom cookie permissions' )
201
- for perm in [ "owner" , "group" , "all" ] :
210
+ for perm in p . keys () :
202
211
test_perm (perm )
203
212
213
+ self .log .info ('Check leaving cookie permissions alone' )
214
+ unassigned_perms = os .stat (self .nodes [1 ].chain_path / 'debug.log' ).st_mode & PERM_BITS_UMASK
215
+ self .restart_node (1 , extra_args = ["-rpccookieperms=0" ])
216
+ actual_perms = os .stat (cookie_file_path ).st_mode & PERM_BITS_UMASK
217
+ assert_equal (unassigned_perms , actual_perms )
218
+ self .restart_node (1 , extra_args = ["-norpccookieperms" ])
219
+ actual_perms = os .stat (cookie_file_path ).st_mode & PERM_BITS_UMASK
220
+ assert_equal (unassigned_perms , actual_perms )
221
+
222
+ self .log .info ('Check -norpccookieperms -rpccookieperms' )
223
+ self .restart_node (1 , extra_args = ["-rpccookieperms=0" , "-rpccookieperms=1" ])
224
+ actual_perms = os .stat (cookie_file_path ).st_mode & PERM_BITS_UMASK
225
+ assert_equal (default_perms , actual_perms )
226
+ self .restart_node (1 , extra_args = ["-norpccookieperms" , "-rpccookieperms" ])
227
+ actual_perms = os .stat (cookie_file_path ).st_mode & PERM_BITS_UMASK
228
+ assert_equal (default_perms , actual_perms )
229
+ self .restart_node (1 , extra_args = ["-rpccookieperms=1660" , "-norpccookieperms" , "-rpccookieperms" ])
230
+ actual_perms = os .stat (cookie_file_path ).st_mode & PERM_BITS_UMASK
231
+ assert_equal (default_perms , actual_perms )
232
+
204
233
def test_norpccookiefile (self , node0_cookie_path ):
205
234
assert self .nodes [0 ].is_node_stopped (), "We expect previous test to stopped the node"
206
235
assert not node0_cookie_path .exists ()
@@ -293,13 +322,28 @@ def run_test(self):
293
322
cookie_path = self .nodes [0 ].chain_path / ".cookie"
294
323
cookie_path_tmp = self .nodes [0 ].chain_path / ".cookie.tmp"
295
324
cookie_path_tmp .mkdir ()
325
+ cookie_path_tmp_subdir = cookie_path_tmp / "subdir"
326
+ cookie_path_tmp_subdir .mkdir ()
296
327
self .nodes [0 ].assert_start_raises_init_error (expected_msg = init_error )
328
+ cookie_path_tmp_subdir .rmdir ()
297
329
cookie_path_tmp .rmdir ()
298
330
assert not cookie_path .exists ()
299
331
self .restart_node (0 )
300
332
assert cookie_path .exists ()
301
333
self .stop_node (0 )
302
334
335
+ cookie_path .mkdir ()
336
+ cookie_path_subdir = cookie_path / "subdir"
337
+ cookie_path_subdir .mkdir ()
338
+ self .nodes [0 ].assert_start_raises_init_error (expected_msg = init_error )
339
+ cookie_path_subdir .rmdir ()
340
+ cookie_path .rmdir ()
341
+
342
+ self .log .info ('Check that a non-writable cookie file will get replaced gracefully' )
343
+ cookie_path .mkdir (mode = 1 )
344
+ self .restart_node (0 )
345
+ self .stop_node (0 )
346
+
303
347
self .test_rpccookieperms ()
304
348
305
349
self .test_norpccookiefile (cookie_path )
0 commit comments