99 lines
2.3 KiB
Python
99 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
测试登录功能
|
|
"""
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
# 添加项目根目录到path
|
|
sys.path.insert(0, str(Path(__file__).parent))
|
|
|
|
from douyu.config import Config, Account
|
|
from douyu.crypto import encrypt_password, encrypt_nickname_or_phone
|
|
from douyu.email_verifier import EmailVerifier
|
|
from utils.logger import setup_logger
|
|
|
|
|
|
def test_crypto():
|
|
"""测试加密功能"""
|
|
print("=== 测试加密功能 ===")
|
|
|
|
# 测试密码加密
|
|
password = "test_password"
|
|
encrypted = encrypt_password(password)
|
|
print(f"密码: {password}")
|
|
print(f"MD5: {encrypted}")
|
|
|
|
# 测试用户名加密
|
|
username = "test_user"
|
|
encrypted = encrypt_nickname_or_phone(username)
|
|
print(f"用户名: {username}")
|
|
print(f"加密后: {encrypted}")
|
|
|
|
print()
|
|
|
|
|
|
def test_config():
|
|
"""测试配置加载"""
|
|
print("=== 测试配置加载 ===")
|
|
|
|
try:
|
|
config = Config("config.yaml")
|
|
accounts = config.get_accounts()
|
|
|
|
print(f"加载了 {len(accounts)} 个账号")
|
|
for i, acc in enumerate(accounts):
|
|
print(f" [{i}] {acc.username} - {acc.email}")
|
|
|
|
proxy = config.get_proxy()
|
|
print(f"代理: {'启用' if proxy.enabled else '禁用'}")
|
|
|
|
except FileNotFoundError as e:
|
|
print(f"配置文件不存在: {e}")
|
|
except Exception as e:
|
|
print(f"加载配置失败: {e}")
|
|
|
|
print()
|
|
|
|
|
|
def test_email_verifier():
|
|
"""测试邮箱验证器(不实际连接)"""
|
|
print("=== 测试邮箱验证器 ===")
|
|
|
|
# 测试验证码提取
|
|
verifier = EmailVerifier("", "", "", "")
|
|
|
|
# 模拟邮件内容
|
|
test_cases = [
|
|
"您的验证码是:123456,请在5分钟内完成验证。",
|
|
"验证码:654321",
|
|
"Your verification code is 789012",
|
|
"【斗鱼】安全验证码:345678,切勿泄露给他人!",
|
|
]
|
|
|
|
for text in test_cases:
|
|
code = verifier._extract_verification_code(text)
|
|
print(f"文本: {text[:30]}...")
|
|
print(f"验证码: {code}")
|
|
print()
|
|
|
|
print()
|
|
|
|
|
|
def main():
|
|
"""运行所有测试"""
|
|
setup_logger(level="INFO")
|
|
|
|
print("斗鱼自动登录工具 - 测试\n")
|
|
|
|
test_crypto()
|
|
test_config()
|
|
test_email_verifier()
|
|
|
|
print("测试完成!")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|