From ab50cfa5c1017d72b910fd26d59e3c3baa0a06bd Mon Sep 17 00:00:00 2001 From: Jonathan Moody <103143855+moodyjon@users.noreply.github.com> Date: Tue, 20 Sep 2022 11:02:32 -0500 Subject: [PATCH] Add test steps to repeatedly sync_apply() using a bad password. --- .../blockchain/test_wallet_commands.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/integration/blockchain/test_wallet_commands.py b/tests/integration/blockchain/test_wallet_commands.py index 35aaad4f84..9bf8e98270 100644 --- a/tests/integration/blockchain/test_wallet_commands.py +++ b/tests/integration/blockchain/test_wallet_commands.py @@ -1,6 +1,8 @@ import asyncio import json +import string from binascii import unhexlify +from random import Random from lbry.wallet import ENCRYPT_ON_DISK from lbry.error import InvalidPasswordError @@ -385,9 +387,16 @@ async def test_sync_with_encryption_and_password_change(self): data = await daemon2.jsonrpc_sync_apply('password2') # sync_apply doesn't save password if encrypt-on-disk is False self.assertEqual(wallet2.encryption_password, None) - # need to use new password2 in sync_apply - with self.assertRaises(InvalidPasswordError): - await daemon.jsonrpc_sync_apply('password', data=data['data'], blocking=True) + + # Need to use new password2 in sync_apply. Attempts with other passwords + # should fail consistently with InvalidPasswordError. + random = Random('password') + for i in range(200): + bad_guess = ''.join(random.choices(string.digits + string.ascii_letters + string.punctuation, k=40)) + self.assertNotEqual(bad_guess, 'password2') + with self.assertRaises(InvalidPasswordError): + await daemon.jsonrpc_sync_apply(bad_guess, data=data['data'], blocking=True) + await daemon.jsonrpc_sync_apply('password2', data=data['data'], blocking=True) # sync_apply with new password2 also sets it as new local password self.assertEqual(wallet.encryption_password, 'password2')