From b843581e3f102c379e88b7edd31db61567ec7897 Mon Sep 17 00:00:00 2001 From: Val Lorentz Date: Sun, 8 Dec 2024 17:23:30 +0100 Subject: [PATCH] sable: Rely on SASL PLAIN instead of NickServ to check for services availability --- irctest/controllers/sable.py | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/irctest/controllers/sable.py b/irctest/controllers/sable.py index df6313a0..eb28be29 100644 --- a/irctest/controllers/sable.py +++ b/irctest/controllers/sable.py @@ -14,6 +14,7 @@ NotImplementedByController, ) from irctest.cases import BaseServerTestCase +from irctest.client_mock import ClientMock from irctest.exceptions import NoMessageException from irctest.patma import ANYSTR @@ -554,6 +555,42 @@ class SableServicesController(BaseServicesController): faketime_cmd: Sequence[str] + def wait_for_services(self) -> None: + """Overrides the default implementation, as it relies on + ``PRIVMSG NickServ: HELP``, which always succeeds on Sable. + + Instead, this relies on SASL PLAIN availability.""" + if self.services_up: + # Don't check again if they are already available + return + self.server_controller.wait_for_port() + + c = ClientMock(name="chkSASL", show_io=True) + c.connect(self.server_controller.hostname, self.server_controller.port) + + def wait() -> None: + while True: + c.sendLine("CAP LS 302") + for msg in c.getMessages(synchronize=False): + if msg.command == "CAP": + assert msg.params[-2] == "LS", msg + for cap in msg.params[-1].split(): + if cap.startswith("sasl="): + mechanisms = cap.split("=", 1)[1].split(",") + if "PLAIN" in mechanisms: + return + else: + if msg.params[0] == "*": + # End of CAP LS + time.sleep(self.server_controller.sync_sleep_time) + + wait() + + c.sendLine("QUIT") + c.getMessages() + c.disconnect() + self.services_up = True + def run(self, protocol: str, server_hostname: str, server_port: int) -> None: assert protocol == "sable" assert self.server_controller.directory is not None