1
0

qml: enforce use of existing password for wallet creation

When creating a new wallet in a Electrum instance with existing wallets
this change forces the user to reuse a password of any existing wallet
if `SimpleConfig.WALLET_USE_SINGLE_PASSWORD` is True.
This prevents the amount of different passwords from increasing and
guides the user towards a single wallet password (the intended default).
This commit is contained in:
f321x
2025-12-04 12:21:21 +01:00
parent 5e53f82bc6
commit 3b028b06a0
7 changed files with 119 additions and 23 deletions

View File

@@ -52,7 +52,7 @@ class TestUnifiedPassword(DaemonTestCase):
def setUp(self):
super().setUp()
self.config.WALLET_USE_SINGLE_PASSWORD = True
self.config.WALLET_SHOULD_USE_SINGLE_PASSWORD = True
def _run_post_unif_sanity_checks(self, paths: Iterable[str], *, password: str):
for path in paths:
@@ -64,8 +64,11 @@ class TestUnifiedPassword(DaemonTestCase):
self.assertTrue(w.has_keystore_encryption())
if w.has_seed():
self.assertIsInstance(w.get_seed(password), str)
can_be_unified, is_unified = self.daemon._check_password_for_directory(old_password=password, wallet_dir=self.wallet_dir)
self.assertEqual((True, True), (can_be_unified, is_unified))
can_be_unified, is_unified, wallet_paths_can_unlock = self.daemon.check_password_for_directory(
old_password=password,
wallet_dir=self.wallet_dir,
)
self.assertEqual((True, True, len(paths)), (can_be_unified, is_unified, len(wallet_paths_can_unlock)))
# "cannot unify pw" tests --->
@@ -77,7 +80,7 @@ class TestUnifiedPassword(DaemonTestCase):
with open(path2, "rb") as f:
raw2_before = f.read()
can_be_unified, is_unified = self.daemon._check_password_for_directory(old_password="123456", wallet_dir=self.wallet_dir)
can_be_unified, is_unified, _ = self.daemon.check_password_for_directory(old_password="123456", wallet_dir=self.wallet_dir)
self.assertEqual((False, False), (can_be_unified, is_unified))
is_unified = self.daemon.update_password_for_directory(old_password="123456", new_password="123456")
self.assertFalse(is_unified)
@@ -100,7 +103,7 @@ class TestUnifiedPassword(DaemonTestCase):
with open(path3, "rb") as f:
raw3_before = f.read()
can_be_unified, is_unified = self.daemon._check_password_for_directory(old_password="123456", wallet_dir=self.wallet_dir)
can_be_unified, is_unified, _ = self.daemon.check_password_for_directory(old_password="123456", wallet_dir=self.wallet_dir)
self.assertEqual((False, False), (can_be_unified, is_unified))
is_unified = self.daemon.update_password_for_directory(old_password="123456", new_password="123456")
self.assertFalse(is_unified)
@@ -120,7 +123,7 @@ class TestUnifiedPassword(DaemonTestCase):
async def test_can_unify_two_std_wallets_both_have_ks_and_sto_enc(self):
path1 = self._restore_wallet_from_text("9dk", password="123456", encrypt_file=True)
path2 = self._restore_wallet_from_text("x8", password="123456", encrypt_file=True)
can_be_unified, is_unified = self.daemon._check_password_for_directory(old_password="123456", wallet_dir=self.wallet_dir)
can_be_unified, is_unified, _ = self.daemon.check_password_for_directory(old_password="123456", wallet_dir=self.wallet_dir)
self.assertEqual((True, True), (can_be_unified, is_unified))
is_unified = self.daemon.update_password_for_directory(old_password="123456", new_password="123456")
self.assertTrue(is_unified)
@@ -132,7 +135,7 @@ class TestUnifiedPassword(DaemonTestCase):
with open(path2, "rb") as f:
raw2_before = f.read()
can_be_unified, is_unified = self.daemon._check_password_for_directory(old_password="123456", wallet_dir=self.wallet_dir)
can_be_unified, is_unified, _ = self.daemon.check_password_for_directory(old_password="123456", wallet_dir=self.wallet_dir)
self.assertEqual((True, False), (can_be_unified, is_unified))
is_unified = self.daemon.update_password_for_directory(old_password="123456", new_password="123456")
self.assertTrue(is_unified)
@@ -145,7 +148,7 @@ class TestUnifiedPassword(DaemonTestCase):
async def test_can_unify_two_std_wallets_one_without_password(self):
path1 = self._restore_wallet_from_text("9dk", password=None)
path2 = self._restore_wallet_from_text("x8", password="123456", encrypt_file=True)
can_be_unified, is_unified = self.daemon._check_password_for_directory(old_password="123456", wallet_dir=self.wallet_dir)
can_be_unified, is_unified, _ = self.daemon.check_password_for_directory(old_password="123456", wallet_dir=self.wallet_dir)
self.assertEqual((True, False), (can_be_unified, is_unified))
is_unified = self.daemon.update_password_for_directory(old_password="123456", new_password="123456")
self.assertTrue(is_unified)
@@ -179,7 +182,7 @@ class TestUnifiedPassword(DaemonTestCase):
paths.append(self._restore_wallet_from_text(addrs, password="123456", encrypt_file=False))
paths.append(self._restore_wallet_from_text(addrs, password=None))
# do unification
can_be_unified, is_unified = self.daemon._check_password_for_directory(old_password="123456", wallet_dir=self.wallet_dir)
can_be_unified, is_unified, _ = self.daemon.check_password_for_directory(old_password="123456", wallet_dir=self.wallet_dir)
self.assertEqual((True, False), (can_be_unified, is_unified))
is_unified = self.daemon.update_password_for_directory(old_password="123456", new_password="123456")
self.assertTrue(is_unified)