test: wallet: cover wallet passphrase with a null char #32675

pull brunoerg wants to merge 1 commits into bitcoin:master from brunoerg:2025-06-test-wallet-passphrase-null changing 1 files +3 −0
  1. brunoerg commented at 5:17 PM on June 3, 2025: contributor

    This PR adds test coverage for the walletpassphrase/walletpassphrasechange RPC when the passphrase is incorrect due to a null character.

    For reference: #27068 introduced the usage of SecureString to allow null characters.

  2. DrahtBot commented at 5:17 PM on June 3, 2025: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/32675.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #32290 (test: allow all functional tests to be run or skipped with --usecli by mzumsande)

    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-->

  3. DrahtBot added the label Tests on Jun 3, 2025
  4. test: wallet: cover wallet passphrase with a null char 7cfbb8575e
  5. in test/functional/wallet_encryption.py:99 in 3b90060a2d outdated
      94 | @@ -95,6 +95,7 @@ def run_test(self):
      95 |          self.nodes[0].walletpassphrasechange(passphrase2, passphrase_with_nulls)
      96 |          # walletpassphrasechange should not stop at null characters
      97 |          assert_raises_rpc_error(-14, "wallet passphrase entered was incorrect", self.nodes[0].walletpassphrase, passphrase_with_nulls.partition("\0")[0], 10)
      98 | +        assert_raises_rpc_error(-14, "wallet passphrase entered is incorrect. It contains a null character (ie - a zero byte)", self.nodes[0].walletpassphrase, passphrase_with_nulls + "\0", 10)
    


    maflcko commented at 7:39 PM on June 3, 2025:

    might as well add coverage for walletpassphrasechange as well?


    brunoerg commented at 12:36 PM on June 4, 2025:

    Yes, going to add it.


    brunoerg commented at 1:07 PM on June 4, 2025:

    Done

  6. brunoerg force-pushed on Jun 4, 2025
  7. brunoerg commented at 1:08 PM on June 4, 2025: contributor

    3b90060a2df2b65369117f3ee8afe26be631867d..7cfbb8575e1ffbad5c48e2c461b45dd6ac63d064 address #32675 (review)

  8. maflcko commented at 1:11 PM on June 4, 2025: member

    lgtm ACK 7cfbb8575e1ffbad5c48e2c461b45dd6ac63d064

  9. w0xlt commented at 11:39 PM on June 4, 2025: contributor
  10. BrandonOdiwuor commented at 10:37 AM on June 5, 2025: contributor

    Code Review ACK 7cfbb8575e1ffbad5c48e2c461b45dd6ac63d064

  11. in test/functional/wallet_encryption.py:100 in 7cfbb8575e
      94 | @@ -95,6 +95,9 @@ def run_test(self):
      95 |          self.nodes[0].walletpassphrasechange(passphrase2, passphrase_with_nulls)
      96 |          # walletpassphrasechange should not stop at null characters
      97 |          assert_raises_rpc_error(-14, "wallet passphrase entered was incorrect", self.nodes[0].walletpassphrase, passphrase_with_nulls.partition("\0")[0], 10)
      98 | +        assert_raises_rpc_error(-14, "The wallet passphrase entered was incorrect", self.nodes[0].walletpassphrasechange, passphrase_with_nulls.partition("\0")[0], "abc")
      99 | +        assert_raises_rpc_error(-14, "wallet passphrase entered is incorrect. It contains a null character (ie - a zero byte)", self.nodes[0].walletpassphrase, passphrase_with_nulls + "\0", 10)
     100 | +        assert_raises_rpc_error(-14, "The old wallet passphrase entered is incorrect. It contains a null character (ie - a zero byte)", self.nodes[0].walletpassphrasechange, passphrase_with_nulls + "\0", "abc")
    


    theStack commented at 12:58 PM on June 5, 2025:

    nit: as there is already a null character inside the string, could just append a regular character at the end to cause a mismatch with this error message

            assert_raises_rpc_error(-14, "wallet passphrase entered is incorrect. It contains a null character (ie - a zero byte)", self.nodes[0].walletpassphrase, passphrase_with_nulls + "x", 10)
            assert_raises_rpc_error(-14, "The old wallet passphrase entered is incorrect. It contains a null character (ie - a zero byte)", self.nodes[0].walletpassphrasechange, passphrase_with_nulls + "x", "abc")
    

    brunoerg commented at 2:24 PM on June 5, 2025:

    Yes, make sense, thanks. I will just keep as-is to not invalidate the reviews.

  12. theStack approved
  13. theStack commented at 12:59 PM on June 5, 2025: contributor

    ACK 7cfbb8575e1ffbad5c48e2c461b45dd6ac63d064

  14. in test/functional/wallet_encryption.py:99 in 7cfbb8575e
      94 | @@ -95,6 +95,9 @@ def run_test(self):
      95 |          self.nodes[0].walletpassphrasechange(passphrase2, passphrase_with_nulls)
      96 |          # walletpassphrasechange should not stop at null characters
      97 |          assert_raises_rpc_error(-14, "wallet passphrase entered was incorrect", self.nodes[0].walletpassphrase, passphrase_with_nulls.partition("\0")[0], 10)
      98 | +        assert_raises_rpc_error(-14, "The wallet passphrase entered was incorrect", self.nodes[0].walletpassphrasechange, passphrase_with_nulls.partition("\0")[0], "abc")
      99 | +        assert_raises_rpc_error(-14, "wallet passphrase entered is incorrect. It contains a null character (ie - a zero byte)", self.nodes[0].walletpassphrase, passphrase_with_nulls + "\0", 10)
    


    pablomartin4btc commented at 4:19 PM on June 5, 2025:

    nit: again if you have to retouch... otherwise when you search for that "similar" description in the code you get both places ("The wallet" and "The Old wallet")

            assert_raises_rpc_error(-14, "The wallet passphrase entered is incorrect. It contains a null character (ie - a zero byte)", self.nodes[0].walletpassphrase, passphrase_with_nulls + "\0", 10)
    

    brunoerg commented at 2:50 PM on June 6, 2025:

    I will leave as-is for now to not invalidate the reivews. Thanks.

  15. in test/functional/wallet_encryption.py:96 in 7cfbb8575e
      94 | @@ -95,6 +95,9 @@ def run_test(self):
      95 |          self.nodes[0].walletpassphrasechange(passphrase2, passphrase_with_nulls)
      96 |          # walletpassphrasechange should not stop at null characters
    


    pablomartin4btc commented at 4:19 PM on June 5, 2025:

    nit: if you have to retouch maybe... even if it's not entirely part of the scope of the change...

            # walletpassphrasechange should not stop at null characters as prior to v25.0
    

    And a test could be added in wallet_backcompatibility.py if it makes sense.


    brunoerg commented at 2:50 PM on June 6, 2025:

    Same. And maybe out of scope, will see.

  16. in test/functional/wallet_encryption.py:98 in 7cfbb8575e
      94 | @@ -95,6 +95,9 @@ def run_test(self):
      95 |          self.nodes[0].walletpassphrasechange(passphrase2, passphrase_with_nulls)
      96 |          # walletpassphrasechange should not stop at null characters
      97 |          assert_raises_rpc_error(-14, "wallet passphrase entered was incorrect", self.nodes[0].walletpassphrase, passphrase_with_nulls.partition("\0")[0], 10)
      98 | +        assert_raises_rpc_error(-14, "The wallet passphrase entered was incorrect", self.nodes[0].walletpassphrasechange, passphrase_with_nulls.partition("\0")[0], "abc")
    


    pablomartin4btc commented at 4:23 PM on June 5, 2025:

    nit: just if you retouch... to be consistent with other places where that error description is being compared...

            assert_raises_rpc_error(-14, "wallet passphrase entered was incorrect", self.nodes[0].walletpassphrasechange, passphrase_with_nulls.partition("\0")[0], "abc")
    

    brunoerg commented at 2:51 PM on June 6, 2025:

    Same

  17. pablomartin4btc commented at 4:29 PM on June 5, 2025: member

    cr ACK 7cfbb8575e1ffbad5c48e2c461b45dd6ac63d064

    In the description: "This PR adds test coverage for the walletpassphrase RPC..." should include also "walletpassphrasechange".

  18. achow101 commented at 10:05 PM on June 6, 2025: member

    ACK 7cfbb8575e1ffbad5c48e2c461b45dd6ac63d064

  19. achow101 merged this on Jun 6, 2025
  20. achow101 closed this on Jun 6, 2025


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-04-21 18:12 UTC

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