From 69d748bf8ff600fad95ad9a5d2c0651575861efd Mon Sep 17 00:00:00 2001 From: Xubin Ren Date: Thu, 9 Apr 2026 15:47:37 +0000 Subject: [PATCH] Merge origin/main; warn on partial proxy credentials; add only-password test - Merged latest main (no conflicts) - Added warning log when only one of proxy_username/proxy_password is set - Added test_start_no_proxy_auth_when_only_password for coverage parity Made-with: Cursor --- nanobot/channels/discord.py | 9 ++++++++- tests/channels/test_discord_channel.py | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/nanobot/channels/discord.py b/nanobot/channels/discord.py index c50b4ff19..6e8c673a3 100644 --- a/nanobot/channels/discord.py +++ b/nanobot/channels/discord.py @@ -308,13 +308,20 @@ class DiscordChannel(BaseChannel): intents.value = self.config.intents proxy_auth = None - if self.config.proxy_username and self.config.proxy_password: + has_user = bool(self.config.proxy_username) + has_pass = bool(self.config.proxy_password) + if has_user and has_pass: import aiohttp proxy_auth = aiohttp.BasicAuth( login=self.config.proxy_username, password=self.config.proxy_password, ) + elif has_user != has_pass: + logger.warning( + "Discord proxy auth incomplete: both proxy_username and " + "proxy_password must be set; ignoring partial credentials", + ) self._client = DiscordBotClient( self, diff --git a/tests/channels/test_discord_channel.py b/tests/channels/test_discord_channel.py index 3f0f3388a..3a31a5912 100644 --- a/tests/channels/test_discord_channel.py +++ b/tests/channels/test_discord_channel.py @@ -845,3 +845,25 @@ async def test_start_no_proxy_auth_when_only_username(monkeypatch) -> None: assert channel.is_running is False assert _FakeDiscordClient.instances[0].proxy_auth is None + + +@pytest.mark.asyncio +async def test_start_no_proxy_auth_when_only_password(monkeypatch) -> None: + _FakeDiscordClient.instances.clear() + channel = DiscordChannel( + DiscordConfig( + enabled=True, + token="token", + allow_from=["*"], + proxy="http://127.0.0.1:7890", + proxy_password="pass", + ), + MessageBus(), + ) + monkeypatch.setattr("nanobot.channels.discord.DiscordBotClient", _FakeDiscordClient) + + await channel.start() + + assert channel.is_running is False + assert _FakeDiscordClient.instances[0].proxy == "http://127.0.0.1:7890" + assert _FakeDiscordClient.instances[0].proxy_auth is None