Skip to content

Commit

Permalink
test: add rpccookieperms test
Browse files Browse the repository at this point in the history
* tests one perm with and one without special bit set
  • Loading branch information
willcl-ark committed Nov 20, 2023
1 parent 1b0fa12 commit 4b469d3
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/functional/rpc_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
)

import http.client
import os
import urllib.parse
import subprocess
from random import SystemRandom
Expand Down Expand Up @@ -84,6 +85,17 @@ def test_auth(self, node, user, password):
self.log.info('Wrong...')
assert_equal(401, call_with_auth(node, user + 'wrong', password + 'wrong').status)

def test_rpccookieperms(self, perm: str):
self.restart_node(1, extra_args=[f"-rpccookieperms={perm}"])

# Pad perm to 4 chars for comparison as we always include special bits in test
perm = perm.zfill(4)

cookie_file_path = self.nodes[1].chain_path / '.cookie'
file_stat = os.stat(cookie_file_path)
actual_perms = f"{(file_stat.st_mode & 0o7777):04o}"
assert_equal(perm, actual_perms)

def run_test(self):
self.conf_setup()
self.log.info('Check correctness of the rpcauth config option')
Expand Down Expand Up @@ -115,6 +127,18 @@ def run_test(self):
(self.nodes[0].chain_path / ".cookie.tmp").mkdir()
self.nodes[0].assert_start_raises_init_error(expected_msg=init_error)

self.log.info('Check that cookie file permissions can be set using -rpccookieperms')
# Remove any leftover rpc{user|password} config options
conf = self.nodes[1].bitcoinconf
with conf.open('r') as file:
lines = file.readlines()
filtered_lines = [line for line in lines if not line.startswith('rpcuser') and not line.startswith('rpcpassword')]
with conf.open('w') as file:
file.writelines(filtered_lines)

custom_cookie_perms = ["0640", "666", "1666"]
[self.test_rpccookieperms(perm) for perm in custom_cookie_perms]


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

0 comments on commit 4b469d3

Please sign in to comment.