test: Add coverage for TorControl `SAFECOOKIE` authentication #36497

pull winterrdog wants to merge 1 commits into bitcoin:master from winterrdog:test/torcontrol-safecookie-auth changing 1 files +206 −0
  1. winterrdog commented at 7:04 PM on October 10, 2026: contributor

    adds functional test coverage for SAFECOOKIE authentication, including successful authentication, AUTHCHALLENGE failure, an invalid server nonce, a mismatched server hash, an invalid-length cookie file, and a missing cookie file

    while working on #35292, i realised we did not have coverage for SAFECOOKIE authentication either, so i added it here

  2. test: Add coverage for TorControl `SAFECOOKIE` authentication
    Test successful authentication and failures caused by an unsuccessful
    `AUTHCHALLENGE`, an invalid server nonce or hash, and a missing or
    invalid-length cookie file.
    6827006f4f
  3. DrahtBot added the label Tests on Oct 10, 2026
  4. DrahtBot commented at 7:04 PM on October 10, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    ACK jpk68
    Concept ACK mercie-ux

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #36374 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36374.svg"></sub> (torcontrol: escape backslashes in -torpassword by 0xShadowX)
    • #36142 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36142.svg"></sub> (net: validate Tor onion service replies and cached keys by l0rinc)
    • #35292 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35292.svg"></sub> (test: Add coverage for Tor control HASHEDPASSWORD authentication 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.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  5. winterrdog commented at 7:15 PM on October 10, 2026: contributor

    "Targeted" Test Coverage Improvements

    Scope Metric Before (merge-base at cf80493e2367786ce9946c522eb8313a52c90557) After (PR HEAD) Change
    src/torcontrol\.cpp$ Lines 71.7% (281/392) 81.9% (321/392) +10.2 pp (+40 lines)
    src/torcontrol\.cpp$ Functions 88.9% (24/27) 96.3% (26/27) +7.4 pp (+2 funcs)
    src/torcontrol\.cpp$ Branches 39.7% (265/668) 47.9% (320/668) +8.2 pp (+55 branches)

    to get these results, i only ran feature_torcontrol.py before and after the change on the same build, using GCC's coverage instrumentation and lcov 2.0

    <details><summary>bash script used to get test coverage locally</summary>

    # 1. compile once with coverage baked in
    cmake -B build -DCMAKE_BUILD_TYPE=Coverage
    cmake --build build -j$(nproc)
    
    # 2. BEFORE: run the merge-base version of the test file
    git checkout $(git merge-base HEAD master) -- test/functional/feature_torcontrol.py
    find build -name '*.gcda' -delete
    python3 test/functional/feature_torcontrol.py --configfile=build/test/config.ini
    lcov --capture --directory build --gcov-tool gcov-$(gcc -dumpversion | cut -d. -f1) \
         --rc branch_coverage=1 --ignore-errors inconsistent,mismatch,unused,negative \
         --output-file base.info
    
    # 3. AFTER: run the PR version of the test file
    git checkout HEAD -- test/functional/feature_torcontrol.py
    find build -name '*.gcda' -delete
    python3 test/functional/feature_torcontrol.py --configfile=build/test/config.ini
    lcov --capture --directory build --gcov-tool gcov-$(gcc -dumpversion | cut -d. -f1) \
         --rc branch_coverage=1 --ignore-errors inconsistent,mismatch,unused,negative \
         --output-file after.info
    
    # 4. keep only the file under test, then build the HTML report
    lcov --extract base.info  '*/src/torcontrol.cpp' --rc branch_coverage=1 -o base_tor.info
    lcov --extract after.info '*/src/torcontrol.cpp' --rc branch_coverage=1 -o after_tor.info
    genhtml after_tor.info --baseline-file base_tor.info --branch-coverage -o cov_diff
    
    ## DONE...
    
    # opens the system's default browser on linux. on other systems, just open the
    # differential coverage report (./cov_diff/index.html) in your browser of choice
    xdg-open cov_diff/index.html
    

    </details>

  6. jpk68 commented at 1:59 AM on October 20, 2026: contributor

    ACK 6827006f4f0d144248244731e75191bf203e1dd6

  7. mercie-ux commented at 9:53 PM on October 21, 2026: contributor

    Concept ACK 6827006f4f

    I introduced a few changes in torcontrol.cpp skipping the ServerHash comparison, dropping the ServerNonce length check, using the wrong key for the client hash and accepting any cookie length, all of this pass on master and fail on this branch, so the new tests catch them.


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-10-25 14:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me