Initial commit
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.insert(0, os.path.abspath(
|
||||
os.path.join(os.path.dirname(__file__), "..")))
|
||||
@@ -0,0 +1,23 @@
|
||||
from core.account_manager import AccountManager
|
||||
|
||||
|
||||
def test_crud_operations(tmp_path):
|
||||
db_file = tmp_path / "accounts.json"
|
||||
manager = AccountManager(db_file)
|
||||
|
||||
# Добавление
|
||||
manager.add_user("alice", "hash1", "salt1")
|
||||
assert "alice" in manager.list_users()
|
||||
|
||||
# Чтение
|
||||
user = manager.get_user("alice")
|
||||
assert user["hash"] == "hash1"
|
||||
|
||||
# Обновление
|
||||
assert manager.update_user("alice", "hash2", "salt2")
|
||||
user = manager.get_user("alice")
|
||||
assert user["hash"] == "hash2"
|
||||
|
||||
# Удаление
|
||||
assert manager.delete_user("alice")
|
||||
assert "alice" not in manager.list_users()
|
||||
@@ -0,0 +1,12 @@
|
||||
from core.audit_logger import AuditLogger
|
||||
|
||||
|
||||
def test_log_event(tmp_path):
|
||||
log_file = tmp_path / "audit.log"
|
||||
logger = AuditLogger(log_file)
|
||||
|
||||
logger.log("Test event")
|
||||
content = log_file.read_text(encoding="utf-8")
|
||||
|
||||
assert "Test event" in content
|
||||
assert "[" in content # должно быть время
|
||||
@@ -0,0 +1,17 @@
|
||||
from core.crypto_manager import CryptoManager
|
||||
|
||||
|
||||
def test_encrypt_decrypt_file(tmp_path):
|
||||
file = tmp_path / "plain.txt"
|
||||
file.write_text("super secret", encoding="utf-8")
|
||||
|
||||
enc_file = tmp_path / "plain.enc"
|
||||
dec_file = tmp_path / "plain.dec"
|
||||
|
||||
crypto = CryptoManager()
|
||||
key = crypto.generate_key()
|
||||
|
||||
crypto.encrypt_file(file, key, enc_file)
|
||||
crypto.decrypt_file(enc_file, key, dec_file)
|
||||
|
||||
assert dec_file.read_text(encoding="utf-8") == "super secret"
|
||||
@@ -0,0 +1,17 @@
|
||||
from pathlib import Path
|
||||
from core.integrity_checker import IntegrityChecker
|
||||
|
||||
|
||||
def test_calculate_and_verify_hash(tmp_path: Path):
|
||||
file = tmp_path / "data.txt"
|
||||
file.write_text("hello", encoding="utf-8")
|
||||
|
||||
hash_file = tmp_path / "data.hash"
|
||||
checker = IntegrityChecker()
|
||||
|
||||
checker.save_hash(file, hash_file)
|
||||
assert checker.verify_hash(file, hash_file)
|
||||
|
||||
# Нарушим целостность
|
||||
file.write_text("changed", encoding="utf-8")
|
||||
assert not checker.verify_hash(file, hash_file)
|
||||
@@ -0,0 +1,12 @@
|
||||
import pytest
|
||||
from core.password_hasher import PasswordHasher
|
||||
|
||||
|
||||
def test_hash_and_verify():
|
||||
hasher = PasswordHasher()
|
||||
salt = hasher.generate_salt()
|
||||
pwd = "secret123"
|
||||
hashed = hasher.hash_password(pwd, salt)
|
||||
|
||||
assert hasher.verify_password(pwd, salt, hashed)
|
||||
assert not hasher.verify_password("wrong", salt, hashed)
|
||||
Reference in New Issue
Block a user