|
1 | 1 | import asyncio
|
2 | 2 | import json
|
| 3 | +import string |
3 | 4 | from binascii import unhexlify
|
| 5 | +from random import Random |
4 | 6 |
|
5 | 7 | from lbry.wallet import ENCRYPT_ON_DISK
|
6 | 8 | from lbry.error import InvalidPasswordError
|
@@ -385,9 +387,16 @@ async def test_sync_with_encryption_and_password_change(self):
|
385 | 387 | data = await daemon2.jsonrpc_sync_apply('password2')
|
386 | 388 | # sync_apply doesn't save password if encrypt-on-disk is False
|
387 | 389 | self.assertEqual(wallet2.encryption_password, None)
|
388 |
| - # need to use new password2 in sync_apply |
389 |
| - with self.assertRaises(InvalidPasswordError): |
390 |
| - await daemon.jsonrpc_sync_apply('password', data=data['data'], blocking=True) |
| 390 | + |
| 391 | + # Need to use new password2 in sync_apply. Attempts with other passwords |
| 392 | + # should fail consistently with InvalidPasswordError. |
| 393 | + random = Random('password') |
| 394 | + for i in range(200): |
| 395 | + bad_guess = ''.join(random.choices(string.digits + string.ascii_letters + string.punctuation, k=40)) |
| 396 | + self.assertNotEqual(bad_guess, 'password2') |
| 397 | + with self.assertRaises(InvalidPasswordError): |
| 398 | + await daemon.jsonrpc_sync_apply(bad_guess, data=data['data'], blocking=True) |
| 399 | + |
391 | 400 | await daemon.jsonrpc_sync_apply('password2', data=data['data'], blocking=True)
|
392 | 401 | # sync_apply with new password2 also sets it as new local password
|
393 | 402 | self.assertEqual(wallet.encryption_password, 'password2')
|
|
0 commit comments