mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-07-20 01:02:49 +02:00
Turn rpcauth.py test into functional test
This commit is contained in:
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
@ -390,9 +390,6 @@ jobs:
|
|||||||
(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"
|
(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"
|
||||||
Get-Content "test/config.ini"
|
Get-Content "test/config.ini"
|
||||||
|
|
||||||
- name: Run rpcauth test
|
|
||||||
run: py -3 test/util/rpcauth-test.py
|
|
||||||
|
|
||||||
- name: Set previous release directory
|
- name: Set previous release directory
|
||||||
run: |
|
run: |
|
||||||
echo "PREVIOUS_RELEASES_DIR=${{ runner.temp }}/previous_releases" >> "$GITHUB_ENV"
|
echo "PREVIOUS_RELEASES_DIR=${{ runner.temp }}/previous_releases" >> "$GITHUB_ENV"
|
||||||
|
@ -592,7 +592,7 @@ mark_as_advanced(Python3_FIND_FRAMEWORK Python3_FIND_UNVERSIONED_NAMES)
|
|||||||
find_package(Python3 3.10 COMPONENTS Interpreter)
|
find_package(Python3 3.10 COMPONENTS Interpreter)
|
||||||
if(NOT TARGET Python3::Interpreter)
|
if(NOT TARGET Python3::Interpreter)
|
||||||
list(APPEND configure_warnings
|
list(APPEND configure_warnings
|
||||||
"Minimum required Python not found. Rpcauth tests are disabled."
|
"Minimum required Python not found."
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@ -636,8 +636,6 @@ add_subdirectory(doc)
|
|||||||
|
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
|
|
||||||
include(cmake/tests.cmake)
|
|
||||||
|
|
||||||
include(Maintenance)
|
include(Maintenance)
|
||||||
setup_split_debug_script()
|
setup_split_debug_script()
|
||||||
add_maintenance_targets()
|
add_maintenance_targets()
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
# Copyright (c) 2023-present The Bitcoin Core developers
|
|
||||||
# Distributed under the MIT software license, see the accompanying
|
|
||||||
# file COPYING or https://opensource.org/license/mit/.
|
|
||||||
|
|
||||||
add_test(NAME util_rpcauth_test
|
|
||||||
COMMAND Python3::Interpreter ${PROJECT_BINARY_DIR}/test/util/rpcauth-test.py
|
|
||||||
)
|
|
||||||
set_tests_properties(util_rpcauth_test PROPERTIES
|
|
||||||
DISABLED $<NOT:$<TARGET_EXISTS:Python3::Interpreter>>
|
|
||||||
)
|
|
@ -37,7 +37,7 @@ file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/fuzz)
|
|||||||
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/util)
|
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/util)
|
||||||
|
|
||||||
file(GLOB_RECURSE functional_tests RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} functional/*)
|
file(GLOB_RECURSE functional_tests RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} functional/*)
|
||||||
foreach(script ${functional_tests} fuzz/test_runner.py util/rpcauth-test.py)
|
foreach(script ${functional_tests} fuzz/test_runner.py)
|
||||||
if(CMAKE_HOST_WIN32)
|
if(CMAKE_HOST_WIN32)
|
||||||
set(symlink)
|
set(symlink)
|
||||||
else()
|
else()
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
# These environment variables are set by the build process and read by
|
# These environment variables are set by the build process and read by
|
||||||
# test/*/test_runner.py and test/util/rpcauth-test.py
|
# test/*/test_runner.py
|
||||||
|
|
||||||
[environment]
|
[environment]
|
||||||
CLIENT_NAME=@CLIENT_NAME@
|
CLIENT_NAME=@CLIENT_NAME@
|
||||||
|
@ -353,6 +353,7 @@ BASE_SCRIPTS = [
|
|||||||
'rpc_getdescriptorinfo.py',
|
'rpc_getdescriptorinfo.py',
|
||||||
'rpc_mempool_info.py',
|
'rpc_mempool_info.py',
|
||||||
'rpc_help.py',
|
'rpc_help.py',
|
||||||
|
'tool_rpcauth.py',
|
||||||
'p2p_handshake.py',
|
'p2p_handshake.py',
|
||||||
'p2p_handshake.py --v2transport',
|
'p2p_handshake.py --v2transport',
|
||||||
'feature_dirsymlinks.py',
|
'feature_dirsymlinks.py',
|
||||||
|
@ -1,37 +1,46 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# Copyright (c) 2015-2018 The Bitcoin Core developers
|
# Copyright (c) 2015-present The Bitcoin Core developers
|
||||||
# Distributed under the MIT software license, see the accompanying
|
# Distributed under the MIT software license, see the accompanying
|
||||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
"""Test share/rpcauth/rpcauth.py
|
"""Test share/rpcauth/rpcauth.py
|
||||||
"""
|
"""
|
||||||
import re
|
|
||||||
import configparser
|
|
||||||
import hmac
|
import hmac
|
||||||
import importlib
|
import importlib
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
|
||||||
|
|
||||||
class TestRPCAuth(unittest.TestCase):
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
|
from test_framework.util import assert_equal
|
||||||
|
|
||||||
|
|
||||||
|
class RpcAuthTest(BitcoinTestFramework):
|
||||||
|
def set_test_params(self):
|
||||||
|
self.num_nodes = 0 # No node/datadir needed
|
||||||
|
|
||||||
|
def setup_network(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
config = configparser.ConfigParser()
|
sys.path.insert(0, os.path.dirname(self.config["environment"]["RPCAUTH"]))
|
||||||
config_path = os.path.abspath(
|
|
||||||
os.path.join(os.sep, os.path.abspath(os.path.dirname(__file__)),
|
|
||||||
"../config.ini"))
|
|
||||||
with open(config_path, encoding="utf8") as config_file:
|
|
||||||
config.read_file(config_file)
|
|
||||||
sys.path.insert(0, os.path.dirname(config['environment']['RPCAUTH']))
|
|
||||||
self.rpcauth = importlib.import_module('rpcauth')
|
self.rpcauth = importlib.import_module('rpcauth')
|
||||||
|
|
||||||
|
def run_test(self):
|
||||||
|
self.setUp()
|
||||||
|
|
||||||
|
self.test_generate_salt()
|
||||||
|
self.test_generate_password()
|
||||||
|
self.test_check_password_hmac()
|
||||||
|
|
||||||
def test_generate_salt(self):
|
def test_generate_salt(self):
|
||||||
for i in range(16, 32 + 1):
|
for i in range(16, 32 + 1):
|
||||||
self.assertEqual(len(self.rpcauth.generate_salt(i)), i * 2)
|
assert_equal(len(self.rpcauth.generate_salt(i)), i * 2)
|
||||||
|
|
||||||
def test_generate_password(self):
|
def test_generate_password(self):
|
||||||
"""Test that generated passwords only consist of urlsafe characters."""
|
"""Test that generated passwords only consist of urlsafe characters."""
|
||||||
r = re.compile(r"[0-9a-zA-Z_-]*")
|
r = re.compile(r"[0-9a-zA-Z_-]*")
|
||||||
password = self.rpcauth.generate_password()
|
password = self.rpcauth.generate_password()
|
||||||
self.assertTrue(r.fullmatch(password))
|
assert r.fullmatch(password)
|
||||||
|
|
||||||
def test_check_password_hmac(self):
|
def test_check_password_hmac(self):
|
||||||
salt = self.rpcauth.generate_salt(16)
|
salt = self.rpcauth.generate_salt(16)
|
||||||
@ -41,7 +50,8 @@ class TestRPCAuth(unittest.TestCase):
|
|||||||
m = hmac.new(salt.encode('utf-8'), password.encode('utf-8'), 'SHA256')
|
m = hmac.new(salt.encode('utf-8'), password.encode('utf-8'), 'SHA256')
|
||||||
expected_password_hmac = m.hexdigest()
|
expected_password_hmac = m.hexdigest()
|
||||||
|
|
||||||
self.assertEqual(expected_password_hmac, password_hmac)
|
assert_equal(expected_password_hmac, password_hmac)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
RpcAuthTest(__file__).main()
|
Reference in New Issue
Block a user