feat: channel key support for +k channels

Add channel_keys dict to NetworkConfig for storing per-channel keys.
Keys are used in KICK rejoin, passed via AUTOJOIN +#channel key syntax,
supported in ADDNETWORK channel_keys= parameter, and propagated through
REHASH. Extract rehash() as reusable async function for SIGHUP reuse.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
user
2026-02-21 19:03:23 +01:00
parent bf4a589fc5
commit c11bd5555a
7 changed files with 240 additions and 12 deletions

View File

@@ -479,6 +479,25 @@ class TestHandleKick:
# Should rejoin (rejoin_delay=0)
writer.write.assert_called_with(b"JOIN #test\r\n")
@pytest.mark.asyncio
async def test_kick_rejoin_with_key(self) -> None:
cfg = _cfg(channels=["#secret"])
cfg.channel_keys = {"#secret": "hunter2"}
net = _net(cfg=cfg)
net.state = State.READY
net._running = True
net.nick = "me"
net.channels = {"#secret"}
writer = MagicMock()
writer.is_closing.return_value = False
writer.drain = AsyncMock()
net._writer = writer
await net._handle(_msg(":op!user@host KICK #secret me :reason"))
assert "#secret" not in net.channels
# Should rejoin with key (rejoin_delay=0)
writer.write.assert_called_with(b"JOIN #secret hunter2\r\n")
@pytest.mark.asyncio
async def test_kick_other_user_ignored(self) -> None:
net = _net()