add --no_password_change flag to sync apply

This commit is contained in:
zeppi 2022-07-21 11:15:46 -04:00
parent ba60aeeebc
commit 8529b7a6a8
2 changed files with 15 additions and 6 deletions

View file

@ -1960,23 +1960,23 @@ class Daemon(metaclass=JSONRPCServerType):
return hexlify(wallet.hash).decode() return hexlify(wallet.hash).decode()
@requires("wallet") @requires("wallet")
async def jsonrpc_sync_apply(self, password, data=None, wallet_id=None, blocking=False): async def jsonrpc_sync_apply(self, password, data=None, wallet_id=None, no_password_change=False, blocking=False):
""" """
Apply incoming synchronization data, if provided, and return a sync hash and update wallet data. Apply incoming synchronization data, if provided, and return a sync hash and update wallet data.
Wallet must be unlocked to perform this operation. Wallet must be unlocked to perform this operation.
If "encrypt-on-disk" preference is True and supplied password is different from local password, If "encrypt-on-disk" preference is True, then in all cases the wallet will be updated to use the
or there is no local password (because local wallet was not encrypted), then the supplied password supplied password for local encryption unless --only_export is passed.
will be used for local encryption (overwriting previous local encryption password).
Usage: Usage:
sync_apply <password> [--data=<data>] [--wallet_id=<wallet_id>] [--blocking] sync_apply <password> [--data=<data>] [--wallet_id=<wallet_id>] [--no_password_change] [--blocking]
Options: Options:
--password=<password> : (str) password to decrypt incoming and encrypt outgoing data --password=<password> : (str) password to decrypt incoming and encrypt outgoing data
--data=<data> : (str) incoming sync data, if any --data=<data> : (str) incoming sync data, if any
--wallet_id=<wallet_id> : (str) wallet being sync'ed --wallet_id=<wallet_id> : (str) wallet being sync'ed
--no_password_change : (bool) do not update existing wallet encryption password
--blocking : (bool) wait until any new accounts have sync'ed --blocking : (bool) wait until any new accounts have sync'ed
Returns: Returns:
@ -1998,7 +1998,11 @@ class Daemon(metaclass=JSONRPCServerType):
for new_account in added_accounts: for new_account in added_accounts:
asyncio.create_task(self.ledger.subscribe_account(new_account)) asyncio.create_task(self.ledger.subscribe_account(new_account))
wallet_changed = True wallet_changed = True
if wallet.preferences.get(ENCRYPT_ON_DISK, False) and password != wallet.encryption_password: if (
wallet.preferences.get(ENCRYPT_ON_DISK, False) and
password != wallet.encryption_password and
not no_password_change
):
wallet.encryption_password = password wallet.encryption_password = password
wallet_changed = True wallet_changed = True
if wallet_changed: if wallet_changed:

View file

@ -387,6 +387,11 @@ class WalletEncryptionAndSynchronization(CommandTestCase):
# need to use new password2 in sync_apply # need to use new password2 in sync_apply
with self.assertRaises(InvalidPasswordError): with self.assertRaises(InvalidPasswordError):
await daemon.jsonrpc_sync_apply('password', data=data['data'], blocking=True) await daemon.jsonrpc_sync_apply('password', data=data['data'], blocking=True)
# first test --no_password_change
await daemon.jsonrpc_sync_apply('password2', data=data['data'], blocking=True, no_password_change=True)
# sync_apply should leave original password
self.assertEqual(wallet.encryption_password, 'password')
# now test with password change to password2
await daemon.jsonrpc_sync_apply('password2', 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 # sync_apply with new password2 also sets it as new local password
self.assertEqual(wallet.encryption_password, 'password2') self.assertEqual(wallet.encryption_password, 'password2')