feat(weibo): 增加外部 CK 单行复制

This commit is contained in:
yml2213
2026-11-08 14:13:01 +08:00
parent 5b42577b0b
commit 66b4f72994
8 changed files with 126 additions and 1 deletions
+53 -1
View File
@@ -18,9 +18,10 @@ from core.weibo import (
WeiboRechargeError,
WeiboRechargeOrder,
)
from web.backend.models import User, WeiboAccount
from web.backend.models import AuditLog, User, WeiboAccount
from web.backend.routers import weibo as weibo_router
from web.backend.routers.weibo import (
copy_account_ck,
create_bind_qrcodes,
disable_account,
enable_account,
@@ -221,6 +222,57 @@ def test_refresh_marks_payment_login_expiry_as_invalid(db, current_user):
assert "6102" in account.ck_check_message
def test_copy_account_ck_returns_plaintext_and_audits_without_ck(db, current_user):
account_out = import_cookies(
WeiboCookieImport(text="SCF=a; SUB=b", tag=""),
db=db,
current=current_user,
).accounts[0]
result = copy_account_ck(account_out.id, db=db, current=current_user)
dumped = result.model_dump()
assert dumped["account_id"] == account_out.id
assert dumped["ck_text"] == "SCF=a; SUB=b"
audit = (
db.query(AuditLog).filter(AuditLog.action == "weibo:account:ck_export").one()
)
assert dumped["uid"] in audit.detail
assert "SUB=b" not in audit.detail
def test_copy_account_ck_uses_export_permission_defaults(db, current_user):
account_out = import_cookies(
WeiboCookieImport(text="SCF=a; SUB=b", tag=""),
db=db,
current=current_user,
).accounts[0]
support = User(
username="weibo-copy-support",
password_hash="hash",
role="support",
is_active=True,
)
db.add(support)
db.commit()
with pytest.raises(HTTPException) as exc_info:
copy_account_ck(account_out.id, db=db, current=support)
assert exc_info.value.status_code == 403
operator = User(
username="weibo-copy-operator",
password_hash="hash",
role="operation",
is_active=True,
)
db.add(operator)
db.commit()
result = copy_account_ck(account_out.id, db=db, current=operator)
assert result.ck_text == "SCF=a; SUB=b"
def test_list_accounts_returns_parallel_page_shape(db, current_user):
assert (
import_cookies(