更新
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import threading
|
||||
import unittest
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import patch
|
||||
|
||||
from rpa_engine.credential import validate_im_session
|
||||
|
||||
|
||||
class CredentialResponsivenessTests(unittest.IsolatedAsyncioTestCase):
|
||||
async def test_uid_lookup_does_not_block_event_loop(self):
|
||||
event_loop_thread_id = threading.get_ident()
|
||||
lookup_thread_ids = []
|
||||
|
||||
def get_uid():
|
||||
lookup_thread_ids.append(threading.get_ident())
|
||||
return 123456
|
||||
|
||||
session = SimpleNamespace(
|
||||
my_uid=0,
|
||||
can_direct_im=lambda: True,
|
||||
)
|
||||
auth = SimpleNamespace(
|
||||
get_uid=get_uid,
|
||||
is_sign_ready=lambda: True,
|
||||
)
|
||||
|
||||
with (
|
||||
patch(
|
||||
"rpa_engine.credential.ensure_frontier_ws",
|
||||
return_value=None,
|
||||
),
|
||||
patch(
|
||||
"rpa_engine.credential.DouyinAuth.from_im_session",
|
||||
return_value=auth,
|
||||
),
|
||||
):
|
||||
result = await validate_im_session(
|
||||
session,
|
||||
_bypass_global_limit=True,
|
||||
)
|
||||
|
||||
self.assertTrue(result[0])
|
||||
self.assertEqual(len(lookup_thread_ids), 1)
|
||||
self.assertNotEqual(
|
||||
lookup_thread_ids[0],
|
||||
event_loop_thread_id,
|
||||
"the synchronous UID lookup ran on the event-loop thread",
|
||||
)
|
||||
self.assertEqual(session.my_uid, 123456)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -171,7 +171,52 @@ class DesktopLoginSecUserIdTests(unittest.IsolatedAsyncioTestCase):
|
||||
|
||||
self.assertIs(result, response)
|
||||
db.execute.assert_not_awaited()
|
||||
build.assert_awaited_once_with(account, "cookie-json")
|
||||
build.assert_awaited_once_with(
|
||||
account,
|
||||
"cookie-json",
|
||||
runtime_check=False,
|
||||
)
|
||||
|
||||
async def test_cookie_response_forwards_static_management_check(self):
|
||||
account = self._account()
|
||||
summary = {
|
||||
"cookie_count": 2,
|
||||
"cookie_valid": True,
|
||||
"cookie_expired": False,
|
||||
"reason": "ok",
|
||||
"expires_at": None,
|
||||
"key_names": ["sessionid"],
|
||||
}
|
||||
detail = {
|
||||
"has_sessionid": True,
|
||||
"sessionid": "sid",
|
||||
"sessionid_ss": "",
|
||||
"im_ready": False,
|
||||
"im_status": "static",
|
||||
"can_skip_browser": False,
|
||||
"should_reset": False,
|
||||
}
|
||||
|
||||
with (
|
||||
patch.object(main, "cookie_summary", return_value=summary),
|
||||
patch.object(
|
||||
main,
|
||||
"build_cookie_credential_detail",
|
||||
new=AsyncMock(return_value=detail),
|
||||
) as build_detail,
|
||||
):
|
||||
result = await main._build_cookie_response(
|
||||
account,
|
||||
"cookie-json",
|
||||
runtime_check=False,
|
||||
)
|
||||
|
||||
self.assertTrue(result.has_sessionid)
|
||||
build_detail.assert_awaited_once_with(
|
||||
"cookie-json",
|
||||
None,
|
||||
runtime_check=False,
|
||||
)
|
||||
|
||||
async def test_legacy_cookie_request_is_guarded_for_existing_desktop_clients(self):
|
||||
account = self._account()
|
||||
|
||||
Reference in New Issue
Block a user