测试并修复api导入路径错误

This commit is contained in:
2026-02-02 11:09:43 +08:00
parent 807e634318
commit 35abaa1ebb
13 changed files with 211 additions and 250 deletions

View File

@@ -0,0 +1,41 @@
"""
测试加密功能
"""
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()