the mock could explicitly check the received hex and reply with a 515 Bad authentication if it does not match, rather than accepting any AUTHENTICATE
<details><summary>diff</summary>
diff --git a/test/functional/feature_torcontrol.py b/test/functional/feature_torcontrol.py
index 064bc87848..568d3ef685 100755
--- a/test/functional/feature_torcontrol.py
+++ b/test/functional/feature_torcontrol.py
@@ -190,6 +190,10 @@ class TorControlTest(BitcoinTestFramework):
self.log.info("Test that -torpassword is sent hex-encoded, so special characters survive")
class HashedPasswordServer(MockTorControlServer):
+ def __init__(self, port, expected_password):
+ self.expected_hex = expected_password.encode().hex()
+ super().__init__(port)
+
def _get_response(self, command):
if command == "PROTOCOLINFO 1":
return (
@@ -199,20 +203,22 @@ class TorControlTest(BitcoinTestFramework):
"250 OK\r\n"
)
elif command.startswith("AUTHENTICATE "):
+ sent_hex = command.removeprefix("AUTHENTICATE ")
+ if sent_hex != self.expected_hex:
+ return "515 Bad authentication\r\n"
return "250 OK\r\n"
return super()._get_response(command)
password = 'pa\\ss"word\\'
- mock_tor = HashedPasswordServer(self.next_port())
+ mock_tor = HashedPasswordServer(self.next_port(), password)
self.restart_with_mock(mock_tor, extra_args=[f"-torpassword={password}"])
self.wait_until(lambda: len(mock_tor.received_commands) >= 2, timeout=10)
- assert_equal(mock_tor.received_commands[1], f"AUTHENTICATE {password.encode().hex()}")
+ assert_equal(mock_tor.received_commands[1], f"AUTHENTICATE {mock_tor.expected_hex}")
# Authentication succeeded, so the node goes on to create the onion service
self.wait_until(lambda: any(c.startswith("ADD_ONION ") for c in mock_tor.received_commands), timeout=10)
- # Clean up
mock_tor.stop()
def test_pow_fallback(self):
</details>
#36637 (review) is worth exploring too :)