Skip to content

Commit fa4d68c

Browse files
author
MarcoFalke
committed
Turn rpcauth.py test into functional test
1 parent e3f416d commit fa4d68c

File tree

7 files changed

+30
-34
lines changed

7 files changed

+30
-34
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,9 +390,6 @@ jobs:
390390
(Get-Content "test/config.ini") -replace '(?<=^SRCDIR=).*', '${{ github.workspace }}' -replace '(?<=^BUILDDIR=).*', '${{ github.workspace }}' -replace '(?<=^RPCAUTH=).*', '${{ github.workspace }}/share/rpcauth/rpcauth.py' | Set-Content "test/config.ini"
391391
Get-Content "test/config.ini"
392392
393-
- name: Run rpcauth test
394-
run: py -3 test/util/rpcauth-test.py
395-
396393
- name: Set previous release directory
397394
run: |
398395
echo "PREVIOUS_RELEASES_DIR=${{ runner.temp }}/previous_releases" >> "$GITHUB_ENV"

CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ mark_as_advanced(Python3_FIND_FRAMEWORK Python3_FIND_UNVERSIONED_NAMES)
592592
find_package(Python3 3.10 COMPONENTS Interpreter)
593593
if(NOT TARGET Python3::Interpreter)
594594
list(APPEND configure_warnings
595-
"Minimum required Python not found. Rpcauth tests are disabled."
595+
"Minimum required Python not found."
596596
)
597597
endif()
598598

@@ -636,8 +636,6 @@ add_subdirectory(doc)
636636

637637
add_subdirectory(src)
638638

639-
include(cmake/tests.cmake)
640-
641639
include(Maintenance)
642640
setup_split_debug_script()
643641
add_maintenance_targets()

cmake/tests.cmake

Lines changed: 0 additions & 10 deletions
This file was deleted.

test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/fuzz)
3737
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/util)
3838

3939
file(GLOB_RECURSE functional_tests RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} functional/*)
40-
foreach(script ${functional_tests} fuzz/test_runner.py util/rpcauth-test.py)
40+
foreach(script ${functional_tests} fuzz/test_runner.py)
4141
if(CMAKE_HOST_WIN32)
4242
set(symlink)
4343
else()

test/config.ini.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
# These environment variables are set by the build process and read by
6-
# test/*/test_runner.py and test/util/rpcauth-test.py
6+
# test/*/test_runner.py
77

88
[environment]
99
CLIENT_NAME=@CLIENT_NAME@

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@
353353
'rpc_getdescriptorinfo.py',
354354
'rpc_mempool_info.py',
355355
'rpc_help.py',
356+
'tool_rpcauth.py',
356357
'p2p_handshake.py',
357358
'p2p_handshake.py --v2transport',
358359
'feature_dirsymlinks.py',
Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,46 @@
11
#!/usr/bin/env python3
2-
# Copyright (c) 2015-2018 The Bitcoin Core developers
2+
# Copyright (c) 2015-present The Bitcoin Core developers
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test share/rpcauth/rpcauth.py
66
"""
7-
import re
8-
import configparser
97
import hmac
108
import importlib
119
import os
10+
import re
1211
import sys
13-
import unittest
1412

15-
class TestRPCAuth(unittest.TestCase):
13+
from test_framework.test_framework import BitcoinTestFramework
14+
from test_framework.util import assert_equal
15+
16+
17+
class RpcAuthTest(BitcoinTestFramework):
18+
def set_test_params(self):
19+
self.num_nodes = 0 # No node/datadir needed
20+
21+
def setup_network(self):
22+
pass
23+
1624
def setUp(self):
17-
config = configparser.ConfigParser()
18-
config_path = os.path.abspath(
19-
os.path.join(os.sep, os.path.abspath(os.path.dirname(__file__)),
20-
"../config.ini"))
21-
with open(config_path, encoding="utf8") as config_file:
22-
config.read_file(config_file)
23-
sys.path.insert(0, os.path.dirname(config['environment']['RPCAUTH']))
25+
sys.path.insert(0, os.path.dirname(self.config["environment"]["RPCAUTH"]))
2426
self.rpcauth = importlib.import_module('rpcauth')
2527

28+
def run_test(self):
29+
self.setUp()
30+
31+
self.test_generate_salt()
32+
self.test_generate_password()
33+
self.test_check_password_hmac()
34+
2635
def test_generate_salt(self):
2736
for i in range(16, 32 + 1):
28-
self.assertEqual(len(self.rpcauth.generate_salt(i)), i * 2)
37+
assert_equal(len(self.rpcauth.generate_salt(i)), i * 2)
2938

3039
def test_generate_password(self):
3140
"""Test that generated passwords only consist of urlsafe characters."""
3241
r = re.compile(r"[0-9a-zA-Z_-]*")
3342
password = self.rpcauth.generate_password()
34-
self.assertTrue(r.fullmatch(password))
43+
assert r.fullmatch(password)
3544

3645
def test_check_password_hmac(self):
3746
salt = self.rpcauth.generate_salt(16)
@@ -41,7 +50,8 @@ def test_check_password_hmac(self):
4150
m = hmac.new(salt.encode('utf-8'), password.encode('utf-8'), 'SHA256')
4251
expected_password_hmac = m.hexdigest()
4352

44-
self.assertEqual(expected_password_hmac, password_hmac)
53+
assert_equal(expected_password_hmac, password_hmac)
54+
4555

4656
if __name__ == '__main__':
47-
unittest.main()
57+
RpcAuthTest(__file__).main()

0 commit comments

Comments
 (0)