初步实现数据加密、权限管理、日志审计等功能

This commit is contained in:
2026-02-02 10:09:28 +08:00
parent b6b37a453b
commit 807e634318
27 changed files with 3787 additions and 59 deletions

37
tests/test_encryption.py Normal file
View File

@@ -0,0 +1,37 @@
"""
测试加密功能
"""
import os
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
def test_encryption():
"""测试加密和解密功能"""
from app.core.encryption import Encryptor
# 生成测试密钥
key = Encryptor.generate_key()
print(f"✓ 生成密钥: {key}")
# 创建加密器
encryptor = Encryptor(key=key.encode())
# 测试加密
test_data = "这是敏感数据 - 数据库密码: password123"
encrypted = encryptor.encrypt(test_data)
print(f"✓ 加密成功: {encrypted[:50]}...")
# 测试解密
decrypted = encryptor.decrypt(encrypted)
assert decrypted == test_data, "解密数据不匹配!"
print(f"✓ 解密成功: {decrypted}")
# 测试空数据
assert encryptor.encrypt("") == ""
assert encryptor.decrypt("") == ""
print("✓ 空数据处理正确")
print("\n✅ 所有加密测试通过!")
if __name__ == "__main__":
test_encryption()