mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-08 23:38:49 +00:00
Merge pull request #793 from PR0M3TH3AN/codex/trace-and-test-add_new_fingerprint-functionality
Ensure add_new_fingerprint exits after seed setup
This commit is contained in:
@@ -529,6 +529,9 @@ class PasswordManager:
|
|||||||
print(colored("Invalid choice. Exiting.", "red"))
|
print(colored("Invalid choice. Exiting.", "red"))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
if not fingerprint:
|
||||||
|
return None
|
||||||
|
|
||||||
# Set current_fingerprint in FingerprintManager only
|
# Set current_fingerprint in FingerprintManager only
|
||||||
self.fingerprint_manager.current_fingerprint = fingerprint
|
self.fingerprint_manager.current_fingerprint = fingerprint
|
||||||
print(
|
print(
|
||||||
@@ -542,6 +545,8 @@ class PasswordManager:
|
|||||||
if getattr(self, "config_manager", None) is None:
|
if getattr(self, "config_manager", None) is None:
|
||||||
self.initialize_managers()
|
self.initialize_managers()
|
||||||
|
|
||||||
|
return fingerprint
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error adding new seed profile: {e}", exc_info=True)
|
logger.error(f"Error adding new seed profile: {e}", exc_info=True)
|
||||||
print(colored(f"Error: Failed to add new seed profile: {e}", "red"))
|
print(colored(f"Error: Failed to add new seed profile: {e}", "red"))
|
||||||
@@ -1000,8 +1005,8 @@ class PasswordManager:
|
|||||||
logging.error("Invalid BIP-85 seed phrase. Exiting.")
|
logging.error("Invalid BIP-85 seed phrase. Exiting.")
|
||||||
print(colored("Error: Invalid BIP-85 seed phrase.", "red"))
|
print(colored("Error: Invalid BIP-85 seed phrase.", "red"))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
fingerprint = self._finalize_existing_seed(parent_seed, password=password)
|
||||||
return self._finalize_existing_seed(parent_seed, password=password)
|
return fingerprint
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
logging.info("Operation cancelled by user.")
|
logging.info("Operation cancelled by user.")
|
||||||
self.notify("Operation cancelled by user.", level="WARNING")
|
self.notify("Operation cancelled by user.", level="WARNING")
|
||||||
|
35
src/tests/test_add_new_fingerprint_words.py
Normal file
35
src/tests/test_add_new_fingerprint_words.py
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import builtins
|
||||||
|
from types import SimpleNamespace
|
||||||
|
|
||||||
|
import seedpass.core.manager as manager_module
|
||||||
|
from helpers import TEST_SEED
|
||||||
|
|
||||||
|
|
||||||
|
def test_add_new_fingerprint_word_entry_exits(monkeypatch):
|
||||||
|
pm = manager_module.PasswordManager.__new__(manager_module.PasswordManager)
|
||||||
|
pm.fingerprint_manager = SimpleNamespace(current_fingerprint=None)
|
||||||
|
pm.initialize_managers = lambda: None
|
||||||
|
|
||||||
|
calls = {"count": 0}
|
||||||
|
original_setup = manager_module.PasswordManager.setup_existing_seed
|
||||||
|
|
||||||
|
def setup_wrapper(self, *a, **k):
|
||||||
|
calls["count"] += 1
|
||||||
|
return original_setup(self, *a, **k)
|
||||||
|
|
||||||
|
monkeypatch.setattr(
|
||||||
|
manager_module.PasswordManager, "setup_existing_seed", setup_wrapper
|
||||||
|
)
|
||||||
|
monkeypatch.setattr(manager_module, "prompt_seed_words", lambda *a, **k: TEST_SEED)
|
||||||
|
monkeypatch.setattr(
|
||||||
|
manager_module.PasswordManager,
|
||||||
|
"_finalize_existing_seed",
|
||||||
|
lambda self, seed, password=None: "fp",
|
||||||
|
)
|
||||||
|
monkeypatch.setattr(builtins, "input", lambda *_a, **_k: "2")
|
||||||
|
|
||||||
|
result = pm.add_new_fingerprint()
|
||||||
|
|
||||||
|
assert result == "fp"
|
||||||
|
assert calls["count"] == 1
|
||||||
|
assert pm.fingerprint_manager.current_fingerprint == "fp"
|
Reference in New Issue
Block a user