mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:50:37 +00:00
test: Add coverage for Tor control HASHEDPASSWORD authentication #35292
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!35292
Loading…
Reference in a new issue
No description provided.
Delete branch "test/torcontrol-hashedpassword-auth"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
A summary of reviews will appear here.
Conflicts
Reviewers, this pull request conflicts with the following ones:
SAFECOOKIEauthentication by winterrdog)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.
Task
lint: https://github.com/bitcoin/bitcoin/actions/runs/25877900203/job/76052468485LLM reason (✨ experimental): CI failed due to Python lint errors from
ruff(F541: extraneousf-string prefixes) intest/functional/feature_torcontrol.py.Hints
Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:
Possibly due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
A sanitizer issue, which can only be found by compiling with the sanitizer and running the
affected test.
An intermittent issue.
Leave a comment here, if you need help tracking down a confusing failure.
What is this testing separately from the correct password test?
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 (
AUTHENTICATEandPROTOCOLINFO- 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:
now for the sad path (wrong password):
the 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 ?
🐙 This pull request conflicts with the target branch and needs rebase.
#36374 fixes
-torpasswordvalues containing a backslash, which aren't escaped in AUTHENTICATE. It adds a small HASHEDPASSWORD mock to feature_torcontrol.py that overlaps with yours. Would you like to add an escaping case (e.g.pa\ss"word\) here, and I'll drop the test from #36374 and keep just the fix? Or I can rebase onto this once it's merged.🔵 Suggestion · New HASHEDPASSWORD cases miss embedded-quote escaping
Removing the existing quote-escaping step would leave all four new tests' assertions satisfied because none supplies a password containing a quote.
Location:
test/functional/feature_torcontrol.py:115(head).Review coverage was incomplete.
Reviewed:
1d277d1c2316· Full review report · Previous reportspermalink
@0xShadowX
that is a valid catch you got going on in #36374. backslashes are not escaped on present
master. i verified that this is also required by the tor control spec:from https://spec.torproject.org/control-spec/message-format.html#description-format.
anyway, i see 2 ways we can handle this:
wait for this PR to be merged into mainline, then rebase #36374 on top of it
combine both PRs into one, with three commits:
src/torcontrol.cppfor 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 ?
pushed changes:
PROTOCOLINFO/AUTHENTICATEexchange inside theassert_debug_logcontext and give it a 10s timeout so that the"Authentication failed"check no longer races the515response (less likely to trigger in practice, but cheap to make robust)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
test_hashedpassword_escaping. currently, the hashedpassword mock tor server checksif command != f'AUTHENTICATE "{test_password}"'by default, so i would have to pass in'AUTHENTICATE "pa\\\\ss\\"word\\\\"'asexpected_auth's argument inHashedPasswordServer's constructor and then your subcase can just become this:but, in the event that yours goes first, i will rebase, fold your mock into mine, and move your escaping test into
test_hashedpassword_escapingas a subcase. whichever way it goes, i am fine with itdone in the latest push
@0xShadowX
after some thought, i think your PR can go in first. it is lighter and straightforward to review than this one
in https://github.com/bitcoin/bitcoin/pull/35292#issuecomment-5970759968
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
pushed changes:
test_hashedpassword_authinto 4 per-scenario tests (_success,_wrong_password,_no_password,_unsupported) for easier reviewHashedPasswordServerto module level and the password into aTEST_PASSWORDconstant so that all test case functions can share itPing for rebase.
🐙 This pull request conflicts with the target branch and needs rebase.
rebased