@@ -605,6 +605,58 @@ async def probe_quota(self, _data):
605605 assert app .state .credentials .credential_data (first ["id" ])["expires_at" ] == 2
606606
607607
608+ def test_raccoon_reimport_preserves_saved_login_secret (admin_client ):
609+ """重贴新 token 时继承已存手机号/密码,`login_secret` 不被清空。
610+
611+ 导入框只让贴 token;若整份覆盖,按需登录凭据会静默丢失
612+ (2026-12-03 045920 重导入后 `login_secret` 1 → NULL)。
613+ """
614+ from src .provider .base import Quota
615+ from src .provider .raccoon .client import RaccoonProvider
616+ from src .provider .raccoon .credential import RaccoonCredential
617+
618+ app , client = admin_client
619+ real = RaccoonProvider ()
620+
621+ class Stub :
622+ id = "raccoon"
623+ endpoint = "https://e"
624+
625+ def import_credential (self , raw ):
626+ credential = RaccoonCredential .from_import (raw )
627+ if not credential .access_token :
628+ raise ValueError ("missing access token" )
629+ return credential .to_dict ()
630+
631+ def preserve_on_import (self , previous , incoming ):
632+ return real .preserve_on_import (previous , incoming )
633+
634+ async def probe_quota (self , _data ):
635+ return Quota (remaining = 1 , total = 2 , probed_at = 1 )
636+
637+ app .state .executor ._deps .providers ["raccoon" ] = Stub ()
638+ first = client .post ("/api/credentials" , json = {
639+ "provider" : "raccoon" ,
640+ "credential" : {"access_token" : _jwt ({"sub" : "pu-1" , "exp" : 1 }),
641+ "phone" : "13800000000" , "password" : "pw12345678" }}).json ()
642+ assert first ["merged" ] is False
643+ credential_id = first ["id" ]
644+ assert next (row for row in app .state .credentials .list_all ()
645+ if row ["id" ] == credential_id )["login_secret" ] == 1
646+
647+ second = client .post ("/api/credentials" , json = {
648+ "provider" : "raccoon" ,
649+ "credential" : {"access_token" : _jwt ({"sub" : "pu-1" , "exp" : 2 })}}).json ()
650+
651+ assert second ["merged" ] is True and second ["id" ] == credential_id
652+ data = app .state .credentials .credential_data (credential_id )
653+ assert data ["phone" ] == "13800000000"
654+ assert data ["password" ] == "pw12345678"
655+ assert data ["expires_at" ] == 2 # 新 token 仍生效
656+ assert next (row for row in app .state .credentials .list_all ()
657+ if row ["id" ] == credential_id )["login_secret" ] == 1
658+
659+
608660def test_raccoon_import_without_uid_does_not_merge (admin_client ):
609661 """解不出 uid(非 JWT / claims 坏)→ 无法安全合并,退回新增(绝不猜)。"""
610662 from src .provider .base import Quota
0 commit comments