Skip to content

The agent that grows with you

fix(wecom): scope WECOM_BOT_ID reads to the active profile under multiplexing

nftpoetrist07ee457a215b
diff --git a/plugins/platforms/wecom/adapter.py b/plugins/platforms/wecom/adapter.py
index c52af3dae60..1e05a2f7614 100644
--- a/plugins/platforms/wecom/adapter.py
+++ b/plugins/platforms/wecom/adapter.py
@@ -318,7 +318,7 @@ class WeComAdapter(BasePlatformAdapter):
super().__init__(config, Platform.WECOM)
extra = config.extra or {}
- self._bot_id = str(extra.get("bot_id") or os.getenv("WECOM_BOT_ID", "")).strip()
+ self._bot_id = str(extra.get("bot_id") or _get_scoped_secret("WECOM_BOT_ID", "")).strip()
self._secret = str(extra.get("secret") or _get_scoped_secret("WECOM_SECRET", "")).strip()
self._ws_url = str(
extra.get("websocket_url")
diff --git a/tests/gateway/test_wecom.py b/tests/gateway/test_wecom.py
index a46a1caded1..c1675245111 100644
--- a/tests/gateway/test_wecom.py
+++ b/tests/gateway/test_wecom.py
@@ -76,6 +76,38 @@ class TestWeComAdapterAuthzScope:
assert adapter._dm_policy == "pairing"
assert adapter._allow_from == []
+ def test_scoped_construction_reads_bot_id_from_scope_not_environ(self, multiplex_on, monkeypatch):
+ """bot_id must honor the same scope as its neighboring _secret read
+ (both are read on adjacent lines in __init__) -- a secondary profile's
+ own bot_id must never fall back to the default profile's os.environ
+ value."""
+ from agent import secret_scope
+ from plugins.platforms.wecom.adapter import WeComAdapter
+
+ monkeypatch.setenv("WECOM_BOT_ID", "default-profile-bot-id")
+ monkeypatch.setenv("WECOM_SECRET", "default-profile-secret")
+ token = secret_scope.set_secret_scope(
+ {"WECOM_BOT_ID": "scoped-bot-id", "WECOM_SECRET": "scoped-secret"}
+ )
+ try:
+ adapter = WeComAdapter(PlatformConfig(enabled=True))
+ finally:
+ secret_scope.reset_secret_scope(token)
+ assert adapter._bot_id == "scoped-bot-id"
+ assert adapter._secret == "scoped-secret"
+
+ def test_scoped_miss_does_not_leak_default_profiles_bot_id(self, multiplex_on, monkeypatch):
+ from agent import secret_scope
+ from plugins.platforms.wecom.adapter import WeComAdapter
+
+ monkeypatch.setenv("WECOM_BOT_ID", "default-profile-bot-id")
+ token = secret_scope.set_secret_scope({"SOMETHING_ELSE": "x"})
+ try:
+ adapter = WeComAdapter(PlatformConfig(enabled=True))
+ finally:
+ secret_scope.reset_secret_scope(token)
+ assert adapter._bot_id == ""
+
class TestWeComConnect: