mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-07 14:58:56 +00:00
Add config and NostrClient tests
This commit is contained in:
2
.github/workflows/python-ci.yml
vendored
2
.github/workflows/python-ci.yml
vendored
@@ -19,4 +19,4 @@ jobs:
|
|||||||
python -m pip install --upgrade pip
|
python -m pip install --upgrade pip
|
||||||
pip install -r src/requirements.txt
|
pip install -r src/requirements.txt
|
||||||
- name: Test with pytest
|
- name: Test with pytest
|
||||||
run: pytest
|
run: pytest -q src/tests
|
||||||
|
@@ -40,3 +40,34 @@ def test_pin_verification_and_change():
|
|||||||
assert not cfg_mgr.verify_pin("0000")
|
assert not cfg_mgr.verify_pin("0000")
|
||||||
assert cfg_mgr.change_pin("1234", "5678")
|
assert cfg_mgr.change_pin("1234", "5678")
|
||||||
assert cfg_mgr.verify_pin("5678")
|
assert cfg_mgr.verify_pin("5678")
|
||||||
|
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
def test_config_file_encrypted_after_save():
|
||||||
|
with TemporaryDirectory() as tmpdir:
|
||||||
|
key = Fernet.generate_key()
|
||||||
|
enc_mgr = EncryptionManager(key, Path(tmpdir))
|
||||||
|
cfg_mgr = ConfigManager(enc_mgr, Path(tmpdir))
|
||||||
|
|
||||||
|
data = {"relays": ["wss://r"], "pin_hash": ""}
|
||||||
|
cfg_mgr.save_config(data)
|
||||||
|
|
||||||
|
file_path = Path(tmpdir) / cfg_mgr.CONFIG_FILENAME
|
||||||
|
raw = file_path.read_bytes()
|
||||||
|
assert raw != json.dumps(data).encode()
|
||||||
|
|
||||||
|
loaded = cfg_mgr.load_config(require_pin=False)
|
||||||
|
assert loaded == data
|
||||||
|
|
||||||
|
|
||||||
|
def test_set_relays_persists_changes():
|
||||||
|
with TemporaryDirectory() as tmpdir:
|
||||||
|
key = Fernet.generate_key()
|
||||||
|
enc_mgr = EncryptionManager(key, Path(tmpdir))
|
||||||
|
cfg_mgr = ConfigManager(enc_mgr, Path(tmpdir))
|
||||||
|
|
||||||
|
cfg_mgr.set_relays(["wss://custom"], require_pin=False)
|
||||||
|
cfg = cfg_mgr.load_config(require_pin=False)
|
||||||
|
assert cfg["relays"] == ["wss://custom"]
|
||||||
|
26
src/tests/test_nostr_client.py
Normal file
26
src/tests/test_nostr_client.py
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
from tempfile import TemporaryDirectory
|
||||||
|
from unittest.mock import patch
|
||||||
|
from cryptography.fernet import Fernet
|
||||||
|
|
||||||
|
sys.path.append(str(Path(__file__).resolve().parents[1]))
|
||||||
|
|
||||||
|
from password_manager.encryption import EncryptionManager
|
||||||
|
from nostr.client import NostrClient
|
||||||
|
|
||||||
|
|
||||||
|
def test_nostr_client_uses_custom_relays():
|
||||||
|
with TemporaryDirectory() as tmpdir:
|
||||||
|
key = Fernet.generate_key()
|
||||||
|
enc_mgr = EncryptionManager(key, Path(tmpdir))
|
||||||
|
custom_relays = ["wss://relay1", "wss://relay2"]
|
||||||
|
|
||||||
|
with patch("nostr.client.ClientPool") as MockPool, patch(
|
||||||
|
"nostr.client.KeyManager"
|
||||||
|
), patch.object(NostrClient, "initialize_client_pool"):
|
||||||
|
with patch.object(enc_mgr, "decrypt_parent_seed", return_value="seed"):
|
||||||
|
client = NostrClient(enc_mgr, "fp", relays=custom_relays)
|
||||||
|
|
||||||
|
MockPool.assert_called_with(custom_relays)
|
||||||
|
assert client.relays == custom_relays
|
Reference in New Issue
Block a user