Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gateway/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,7 @@ def _apply_env_overrides(config: GatewayConfig) -> None:
"token": os.getenv("WECOM_CALLBACK_TOKEN", ""),
"encoding_aes_key": os.getenv("WECOM_CALLBACK_ENCODING_AES_KEY", ""),
"host": os.getenv("WECOM_CALLBACK_HOST", "0.0.0.0"),
"port": int(os.getenv("WECOM_CALLBACK_PORT", "8645")),
"port": _coerce_int(os.getenv("WECOM_CALLBACK_PORT"), 8645),
})

# Weixin (personal WeChat via iLink Bot API)
Expand Down Expand Up @@ -1469,7 +1469,7 @@ def _apply_env_overrides(config: GatewayConfig) -> None:
"server_url": bluebubbles_server_url.rstrip("/"),
"password": bluebubbles_password,
"webhook_host": os.getenv("BLUEBUBBLES_WEBHOOK_HOST", "127.0.0.1"),
"webhook_port": int(os.getenv("BLUEBUBBLES_WEBHOOK_PORT", "8645")),
"webhook_port": _coerce_int(os.getenv("BLUEBUBBLES_WEBHOOK_PORT"), 8645),
"webhook_path": os.getenv("BLUEBUBBLES_WEBHOOK_PATH", "/bluebubbles-webhook"),
"send_read_receipts": os.getenv("BLUEBUBBLES_SEND_READ_RECEIPTS", "true").lower() in ("true", "1", "yes"),
})
Expand Down
24 changes: 24 additions & 0 deletions tests/gateway/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,3 +609,27 @@ def test_existing_platform_configs_accept_home_channel_env_overrides(self):
home = config.platforms[platform].home_channel
assert home is not None, f"{platform.value}: home_channel should not be None"
assert (home.chat_id, home.name) == expected, platform.value


class TestMalformedEnvPortOverrides:
def test_invalid_bluebubbles_webhook_port_falls_back_to_default(self, monkeypatch):
monkeypatch.setenv("BLUEBUBBLES_SERVER_URL", "http://localhost:1234")
monkeypatch.setenv("BLUEBUBBLES_PASSWORD", "secret")
monkeypatch.setenv("BLUEBUBBLES_WEBHOOK_PORT", "not-a-port")

config = GatewayConfig()

_apply_env_overrides(config)

assert config.platforms[Platform.BLUEBUBBLES].extra["webhook_port"] == 8645

def test_invalid_wecom_callback_port_falls_back_to_default(self, monkeypatch):
monkeypatch.setenv("WECOM_CALLBACK_CORP_ID", "corp-id")
monkeypatch.setenv("WECOM_CALLBACK_CORP_SECRET", "corp-secret")
monkeypatch.setenv("WECOM_CALLBACK_PORT", "not-a-port")

config = GatewayConfig()

_apply_env_overrides(config)

assert config.platforms[Platform.WECOM_CALLBACK].extra["port"] == 8645