Repository navigation
test: Add coverage for Tor control HASHEDPASSWORD authentication - #35292
winterrdog wants to merge 1 commit into
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
|
@winterrdog can you re-write the description in your own words without following this LLM-formulaic format? This would give reviewers more confidence that you understand the change. |
thanks! done edition (seems like i followed the wrong examples online). |
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
8b2af28 to
f886aa2
Compare
| assert_equal(mock_tor.received_commands[1], 'AUTHENTICATE "wrong_password"') | ||
| # After auth failure, no further commands should be sent and authentication failure should be logged | ||
| ensure_for(duration=2, f=lambda: len(mock_tor.received_commands) == 2) | ||
| self.wait_until(lambda: any("Authentication failed" in line for line in self.nodes[0].debug_log_path.read_text().splitlines())) |
There was a problem hiding this comment.
What is this testing separately from the correct password test?
There was a problem hiding this comment.
this log check was an extra step i added to fully confirm that the error was actually noticed and reported instead of being silently swallowed. it was not needed in the correct password test since there we already verify that Bitcoin Core continues past authentication by checking that more than 2 commands (AUTHENTICATE and PROTOCOLINFO - the initial commands) are sent.
here comes the long story. let's assume the correct password is the happy path and the wrong password is not.
so in the happy path (correct password), this is what happens in Bitcoin Core:
correct password sent
-> tor daemon returns `250 OK`
-> `TorController::auth_cb` hits the `if` branch & continues on to `GETINFO` and `ADD_ONION`
-> connection stays activenow for the sad path (wrong password):
incorrect password sent
-> tor daemon returns `515 Bad authentication`
-> `TorController::auth_cb` hits the `else` branch
-> `"tor: Authentication failed"` is logged
-> no further commands are sent
-> connection effectively stopsthe key difference here is that the wrong password test verifies Bitcoin Core logs and stops trying to do anything else when authentication fails, which is not the case with a correct password as you saw above.
did you have something different in mind ?
f886aa2 to
a09fd43
Compare
a09fd43 to
a47adf8
Compare
99e6ee3 to
f24ef5b
Compare
f24ef5b to
b4f0141
Compare
|
#36374 fixes |
|
that is a valid catch you got going on in #36374. backslashes are not escaped on present
anyway, i see 2 ways we can handle this:
for the second & third commit, i can add you as a co-author. so #36374 effectively becomes part of this PR's shadow. essentially, it comes down to whether we want to keep the PRs separate and rebase later, or combine them now my take: option 1 what do you propose ? |
b4f0141 to
35683fc
Compare
|
pushed changes:
P.S: looks like the Ralph bot edited the original message. so, you might have to look for the edit just below the latest edition it made on the comment |
|
Thanks for checking it against the spec. Option 1 sounds good to me, keeping them separate makes each one easier to review. One small adjustment: since #36374 carries its own minimal mock test, it doesn't strictly need to wait for this one. Whichever gets merged first, I'll rebase the other on top and fold the overlapping mock code into yours, so the escaping case ends up as a test in your HASHEDPASSWORD coverage. Does that work for you? |
alright! then, your PR becomes the C++ fix plus one subcase function called diff --git a/test/functional/feature_torcontrol.py b/test/functional/feature_torcontrol.py
index d404467f4e..0bb6047c0c 100755
--- a/test/functional/feature_torcontrol.py
+++ b/test/functional/feature_torcontrol.py
@@ -367,6 +367,24 @@ class TorControlTest(BitcoinTestFramework):
mock_tor.stop()
+ def test_hashedpassword_escaping(self):
+ self.log.info("Test that -torpassword is sent as a correctly escaped quoted string")
+
+ expected_auth = 'AUTHENTICATE "pa\\\\ss\\"word\\\\"'
+ mock_tor = HashedPasswordServer(self.next_port(), expected_auth)
+ mock_tor.start()
+ self.restart_node(0, extra_args=[
+ f"-torcontrol=127.0.0.1:{mock_tor.port}",
+ "-listenonion=1",
+ '-torpassword=pa\\ss"word\\',
+ ])
+ self.wait_until(lambda: len(mock_tor.received_commands) >= 2, timeout=10)
+
+ # Backslashes and quotes must both be escaped, otherwise Tor decodes a different password
+ assert_equal(mock_tor.received_commands[1], expected_auth)
+
+ mock_tor.stop()
+
def run_test(self):
self.test_basic()
self.test_partial_data()
@@ -376,6 +394,7 @@ class TorControlTest(BitcoinTestFramework):
self.test_reconnect_backoff()
self.test_hashedpassword_auth_success()
self.test_hashedpassword_auth_wrong_password()
+ self.test_hashedpassword_escaping()
self.test_hashedpassword_auth_no_password()
self.test_hashedpassword_auth_unsupported()but, in the event that yours goes first, i will rebase, fold your mock into mine, and move your escaping test into |
35683fc to
9be411d
Compare
done in the latest push |
|
after some thought, i think your PR can go in first. it is lighter and straightforward to review than this one
with the PR's current state, i think making this change in order to incorporate your new test case into this PR is trivial to do |
9be411d to
153baf0
Compare
153baf0 to
5ba52ae
Compare
|
pushed changes:
|
|
Ping for rebase. |
add functional test coverage for `HASHEDPASSWORD` authentication, including a correctly quoted password, an incorrect password, an unset `-torpassword`, and a TOR server that does not advertise `HASHEDPASSWORD`
5ba52ae to
1d277d1
Compare
|
rebased |

this is a tests-only PR aimed at adding functional test coverage for
Tor control
HASHEDPASSWORDauthentication.currently, the functional test suite does not explicitly explore this
authentication path, which means regressions in tor authentication
handling could go unnoticed. for instance incorrectly formatted
AUTHENTICATEcommands, broken fallback behavior, or authenticationattempts being made when no password is configured.
The 4 tests herein extend the existing mock tor control server to
simulate
METHODS=HASHEDPASSWORDresponses and cover successfulauthentication with the correct password, failing with an incorrect
password, behavior when
-torpasswordis not set, and cases where theserver does not choose to advertise
HASHEDPASSWORDas a way ofauthenticating.