fix(feishu): preserve QR query values and registration expiry

Restrict the launcher workaround to its known host and exact path. Honor expires_in while retaining the legacy expire_in response. Cover both hosts, opaque query values and old/new TTL fields.
This commit is contained in:
Xubin Ren committed 2026-09-15 14:02:29 +08:00
1 parent 1fd0cca7e2
commit 4535496064
2 files changed
+48 -8

No files matched your search

+37
View File
@@ -42,3 +42,40 @@ def test_cli_url_passed_through_unchanged() -> None:
return_value=_begin_response(uri)):
start = feishu_runtime._begin_registration("feishu")
assert start["qr_url"] == uri
@pytest.mark.parametrize("uri", [
"https://open.feishu.cn/page/cli?return_to=/page/launcher?user_code=OTHER",
"https://open.feishu.cn/other/page/launcher?user_code=ABCD",
"https://other.example/page/launcher?user_code=ABCD",
])
def test_other_urls_and_embedded_query_values_are_not_rewritten(uri):
with patch.object(feishu_runtime, "_post_registration", return_value=_begin_response(uri)):
assert feishu_runtime._begin_registration()["qr_url"] == uri
@pytest.mark.parametrize("domain,host", [
("feishu", "open.feishu.cn"), ("lark", "open.larksuite.com"),
])
def test_launcher_rewrite_preserves_opaque_query_and_fragment(domain, host):
suffix = "?user_code=AB%2BCD&return_to=/page/launcher?other=1#confirm"
uri = f"https://{host}/page/launcher{suffix}"
with patch.object(feishu_runtime, "_post_registration", return_value=_begin_response(uri)):
start = feishu_runtime._begin_registration(domain)
assert start["qr_url"] == f"https://{host}/page/cli{suffix}"
assert start["device_code"] == "dc-test"
assert start["interval"] == 5
@pytest.mark.parametrize("ttl_fields,expected", [
({"expires_in": 3600}, 3600),
({"expire_in": 1200}, 1200),
({"expires_in": 3600, "expire_in": 1200}, 3600),
({}, 600),
])
def test_registration_uses_server_expiry_with_legacy_fallback(ttl_fields, expected):
response = _begin_response("https://open.feishu.cn/page/launcher?user_code=ABCD")
response.pop("expire_in")
response.update(ttl_fields)
with patch.object(feishu_runtime, "_post_registration", return_value=response):
assert feishu_runtime._begin_registration()["expire_in"] == expected