2017-10-11 21:56:31 +02:00
|
|
|
#!/usr/bin/env python3
|
2018-07-27 00:36:45 +02:00
|
|
|
# Copyright (c) 2017-2018 The Bitcoin Core developers
|
2017-10-11 21:56:31 +02:00
|
|
|
# Distributed under the MIT software license, see the accompanying
|
|
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
"""Test the -uacomment option."""
|
|
|
|
|
2018-02-07 16:38:25 +01:00
|
|
|
import re
|
|
|
|
|
2017-10-11 21:56:31 +02:00
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
2018-03-28 15:37:09 +02:00
|
|
|
from test_framework.test_node import ErrorMatch
|
2017-10-11 21:56:31 +02:00
|
|
|
from test_framework.util import assert_equal
|
|
|
|
|
2018-02-07 16:38:25 +01:00
|
|
|
|
2017-10-11 21:56:31 +02:00
|
|
|
class UacommentTest(BitcoinTestFramework):
|
|
|
|
def set_test_params(self):
|
|
|
|
self.num_nodes = 1
|
|
|
|
self.setup_clean_chain = True
|
|
|
|
|
|
|
|
def run_test(self):
|
|
|
|
self.log.info("test multiple -uacomment")
|
|
|
|
test_uacomment = self.nodes[0].getnetworkinfo()["subversion"][-12:-1]
|
|
|
|
assert_equal(test_uacomment, "(testnode0)")
|
|
|
|
|
|
|
|
self.restart_node(0, ["-uacomment=foo"])
|
|
|
|
foo_uacomment = self.nodes[0].getnetworkinfo()["subversion"][-17:-1]
|
|
|
|
assert_equal(foo_uacomment, "(testnode0; foo)")
|
|
|
|
|
|
|
|
self.log.info("test -uacomment max length")
|
|
|
|
self.stop_node(0)
|
2019-02-02 02:00:02 +01:00
|
|
|
expected = r"Error: Total length of network version string \([0-9]+\) exceeds maximum length \(256\). Reduce the number or size of uacomments."
|
2018-03-28 15:37:09 +02:00
|
|
|
self.nodes[0].assert_start_raises_init_error(["-uacomment=" + 'a' * 256], expected, match=ErrorMatch.FULL_REGEX)
|
2017-10-11 21:56:31 +02:00
|
|
|
|
|
|
|
self.log.info("test -uacomment unsafe characters")
|
2018-08-05 18:38:25 +02:00
|
|
|
for unsafe_char in ['/', ':', '(', ')', '₿', '🏃']:
|
2019-02-02 02:00:02 +01:00
|
|
|
expected = r"Error: User Agent comment \(" + re.escape(unsafe_char) + r"\) contains unsafe characters."
|
2018-03-28 15:37:09 +02:00
|
|
|
self.nodes[0].assert_start_raises_init_error(["-uacomment=" + unsafe_char], expected, match=ErrorMatch.FULL_REGEX)
|
2017-10-11 21:56:31 +02:00
|
|
|
|
2018-02-07 16:38:25 +01:00
|
|
|
|
2017-10-11 21:56:31 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
UacommentTest().main()
|