Import ECS deployed relay source and historical patches (2026-10-27)
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import httpx
|
||||
import pytest
|
||||
from relay.platform import Feishu, PlatformError
|
||||
|
||||
|
||||
async def test_private_platform_domain_and_reply_target(env):
|
||||
seen = []
|
||||
def handler(request):
|
||||
seen.append(request)
|
||||
if request.url.path.endswith("app_access_token/internal"):
|
||||
return httpx.Response(200, json={"code": 0, "app_access_token": "fake-app-token", "expire": 7200})
|
||||
if request.url.path.endswith("tenant_access_token/internal"):
|
||||
return httpx.Response(200, json={"code": 0, "tenant_access_token": "fake-tenant-token", "expire": 7200})
|
||||
if request.url.path.endswith("oidc/access_token"):
|
||||
return httpx.Response(200, json={"code": 0, "data": {"access_token": "fake-user-token",
|
||||
"refresh_token": "fake-refresh", "expires_in": 6900, "open_id": "ou_test"}})
|
||||
return httpx.Response(200, json={"code": 0, "data": {}})
|
||||
env["settings"].feishu_api_base = "https://private.example.invalid"
|
||||
f = Feishu(env["settings"], transport=httpx.MockTransport(handler))
|
||||
result = await f.exchange("fake-code")
|
||||
assert result["expires_in"] == 6900
|
||||
await f.reply("om_original", "你好")
|
||||
assert all(x.url.host == "private.example.invalid" for x in seen)
|
||||
assert seen[-1].url.path == "/open-apis/im/v1/messages/om_original/reply"
|
||||
assert seen[-1].headers["Authorization"] == "Bearer fake-tenant-token"
|
||||
assert len([x for x in seen if x.url.path.endswith("app_access_token/internal")]) == 1
|
||||
await f.close()
|
||||
|
||||
|
||||
async def test_platform_errors_never_echo_credentials(env):
|
||||
f = Feishu(env["settings"], transport=httpx.MockTransport(
|
||||
lambda request: httpx.Response(400, text="fake-secret-that-must-not-appear")))
|
||||
with pytest.raises(PlatformError) as error:
|
||||
await f.app_token()
|
||||
assert "fake-secret" not in str(error.value)
|
||||
await f.close()
|
||||
Reference in New Issue
Block a user