测试并修复api导入路径错误
This commit is contained in:
41
tests/auth/test_encryption.py
Normal file
41
tests/auth/test_encryption.py
Normal 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()
|
||||
Reference in New Issue
Block a user