Files
creator-hub/browser_gateway/test_identity_binding.py
T
rogee d9e57c4900 feat(gateway)!: drop HTTP listener, run outbound agent only
- delete GatewayHTTPServer/GatewayHandler, create_server, /healthz and
  /v1/channel; event_channel module removed
- load_config now requires CREATOR_PLATFORM_URL + CREATOR_GATEWAY_KEY
- run() wires Gateway into OutboundAgent; SIGINT/SIGTERM stop the agent
- deploy env example, install script, systemd unit docs and deployment
  docs updated to the outbound model; NATIVE_GATEWAY_ENDPOINT dead dev
  config removed
2026-10-09 08:25:27 +08:00

35 lines
1.7 KiB
Python

"""First login discovers a UID; subsequent logins must match that UID."""
import unittest
from contextlib import nullcontext
from unittest.mock import Mock, patch
from .server.http import Gateway, RequestError
class IdentityBindingTests(unittest.TestCase):
def setUp(self):
self.browser = Mock()
self.browser.identity.return_value = {"uid": "123456789", "sec_uid": "MS4wLjAB-test", "unique_id": "douyin-name"}
self.gateway = Gateway(Mock(), "node", browser=self.browser)
self.generation = {"binding_version": 1, "runtime_id": "a" * 64, "network_id": "native-" + "b" * 32}
self.lock = patch.object(self.gateway, "_alias_lock", return_value=nullcontext())
self.check = patch.object(self.gateway, "_require_douyin_generation")
self.lock.start()
self.check_mock = self.check.start()
self.addCleanup(self.lock.stop)
self.addCleanup(self.check.stop)
def test_first_login_reads_uid_without_a_preconfigured_key(self):
identity = self.gateway.douyin_identity("account-a", self.generation)
self.assertEqual(identity["uid"], "123456789")
self.check_mock.assert_called_once()
def test_bound_login_requires_same_uid(self):
identity = self.gateway.douyin_identity("account-a", {**self.generation, "expected_account_key": "123456789"})
self.assertEqual(identity["uid"], "123456789")
with self.assertRaises(RequestError) as caught:
self.gateway.douyin_identity("account-a", {**self.generation, "expected_account_key": "987654321"})
self.assertEqual(caught.exception.status, 409)
self.assertIn("987654321", str(caught.exception))
self.assertIn("123456789", str(caught.exception))