Beispiel #1
0
 def run(
     self,
     hostname: str,
     port: int,
     *,
     password: Optional[str],
     ssl: bool,
     run_services: bool,
     valid_metadata_keys: Optional[Set[str]] = None,
     invalid_metadata_keys: Optional[Set[str]] = None,
 ) -> None:
     if valid_metadata_keys or invalid_metadata_keys:
         raise NotImplementedByController(
             "Defining valid and invalid METADATA keys."
         )
     if ssl:
         raise NotImplementedByController("TLS")
     if run_services:
         raise NotImplementedByController("Services")
     assert self.proc is None
     self.port = port
     self.hostname = hostname
     self.create_config()
     password_field = password if password else ""
     assert self.directory
     pidfile = os.path.join(self.directory, "ircd.pid")
     with self.open_file("server.conf") as fd:
         fd.write(
             TEMPLATE_CONFIG.format(
                 hostname=hostname,
                 port=port,
                 password_field=password_field,
                 pidfile=pidfile,
             )
         )
     self.proc = subprocess.Popen(
         [
             "ircd",
             "-s",  # no iauth
             "-p",
             "on",
             "-f",
             os.path.join(self.directory, "server.conf"),
         ],
         # stderr=subprocess.DEVNULL,
     )
Beispiel #2
0
    def run(
        self,
        hostname: str,
        port: int,
        *,
        password: Optional[str],
        ssl: bool,
        run_services: bool,
        valid_metadata_keys: Optional[Set[str]] = None,
        invalid_metadata_keys: Optional[Set[str]] = None,
    ) -> None:
        if valid_metadata_keys or invalid_metadata_keys:
            raise NotImplementedByController(
                "Defining valid and invalid METADATA keys.")
        assert self.proc is None
        self.port = port
        self.hostname = hostname
        self.create_config()
        (services_hostname, services_port) = find_hostname_and_port()
        password_field = 'password = "******";'.format(
            password) if password else ""
        if ssl:
            self.gen_ssl()
            ssl_config = TEMPLATE_SSL_CONFIG.format(key_path=self.key_path,
                                                    pem_path=self.pem_path,
                                                    dh_path=self.dh_path)
        else:
            ssl_config = ""
        with self.open_file("server.conf") as fd:
            fd.write((self.template_config).format(
                hostname=hostname,
                port=port,
                services_hostname=services_hostname,
                services_port=services_port,
                password_field=password_field,
                ssl_config=ssl_config,
            ))
        assert self.directory
        self.proc = subprocess.Popen([
            self.binary_name,
            "-foreground",
            "-configfile",
            os.path.join(self.directory, "server.conf"),
            "-pidfile",
            os.path.join(self.directory, "server.pid"),
        ],
                                     # stderr=subprocess.DEVNULL,
                                     )

        if run_services:
            self.wait_for_port()
            self.services_controller = self.services_controller_class(
                self.test_config, self)
            self.services_controller.run(
                protocol=self.services_protocol,
                server_hostname=hostname,
                server_port=services_port,
            )
Beispiel #3
0
 def run(
     self,
     hostname: str,
     port: int,
     *,
     password: Optional[str],
     ssl: bool,
     run_services: bool,
     valid_metadata_keys: Optional[Set[str]] = None,
     invalid_metadata_keys: Optional[Set[str]] = None,
     restricted_metadata_keys: Optional[Set[str]] = None,
 ) -> None:
     if password is not None:
         raise NotImplementedByController("PASS command")
     if ssl:
         raise NotImplementedByController("SSL")
     assert self.proc is None
     self.port = port
     self.create_config()
     with self.open_file("server.yml") as fd:
         fd.write(
             TEMPLATE_CONFIG.format(
                 directory=self.directory,
                 hostname=hostname,
                 port=port,
                 authorized_keys=make_list(valid_metadata_keys or set()),
                 restricted_keys=make_list(restricted_metadata_keys
                                           or set()),
             ))
     # with self.open_file('server.yml', 'r') as fd:
     #    print(fd.read())
     assert self.directory
     self.proc = subprocess.Popen([
         "mammond",
         "--nofork",  # '--debug',
         "--config",
         os.path.join(self.directory, "server.yml"),
     ])
Beispiel #4
0
    def run(
        self,
        hostname: str,
        port: int,
        auth: Optional[authentication.Authentication],
        tls_config: Optional[tls.TlsConfig] = None,
    ) -> None:
        if tls_config:
            print(tls_config)
            raise NotImplementedByController("TLS options")
        args = ["--host", hostname, "--port", str(port), "--quiet"]

        if auth and auth.username and auth.password:
            args += ["--sasl-name", auth.username]
            args += ["--sasl-pass", auth.password]
            args += ["--sasl-fail-is-ok"]

        # Runs a client with the config given as arguments
        self.proc = subprocess.Popen(["girc_test", "connect"] + args)
Beispiel #5
0
 def run(
     self,
     hostname: str,
     port: int,
     auth: Optional[authentication.Authentication],
     tls_config: Optional[tls.TlsConfig] = None,
 ) -> None:
     # Runs a client with the config given as arguments
     if tls_config is not None:
         raise NotImplementedByController("TLS configuration")
     assert self.proc is None
     self.create_config()
     with self.open_file(self.filename) as fd:
         fd.write(
             TEMPLATE_CONFIG.format(
                 hostname=hostname,
                 port=port,
                 username=auth.username if auth else "",
                 password=auth.password if auth else "",
                 auth_method="auth_method = sasl" if auth else "",
             ))
     self.proc = subprocess.Popen(["sopel", "--quiet", "-c", self.filename])
Beispiel #6
0
    def run(
        self,
        hostname: str,
        port: int,
        *,
        password: Optional[str],
        ssl: bool,
        run_services: bool,
        valid_metadata_keys: Optional[Set[str]] = None,
        invalid_metadata_keys: Optional[Set[str]] = None,
        restricted_metadata_keys: Optional[Set[str]] = None,
        config: Optional[Any] = None,
    ) -> None:
        if valid_metadata_keys or invalid_metadata_keys:
            raise NotImplementedByController(
                "Defining valid and invalid METADATA keys.")

        self.create_config()
        if config is None:
            config = copy.deepcopy(BASE_CONFIG)

        assert self.directory

        enable_chathistory = self.test_config.chathistory
        enable_roleplay = self.test_config.ergo_roleplay
        if enable_chathistory or enable_roleplay:
            config = self.addMysqlToConfig(config)

        if enable_roleplay:
            config["roleplay"] = {"enabled": True}

        if self.test_config.ergo_config:
            self.test_config.ergo_config(config)

        self.port = port
        bind_address = "127.0.0.1:%s" % (port, )
        listener_conf = None  # plaintext
        if ssl:
            self.key_path = os.path.join(self.directory, "ssl.key")
            self.pem_path = os.path.join(self.directory, "ssl.pem")
            listener_conf = {
                "tls": {
                    "cert": self.pem_path,
                    "key": self.key_path
                }
            }
        config["server"]["listeners"][
            bind_address] = listener_conf  # type: ignore

        config["datastore"]["path"] = os.path.join(  # type: ignore
            self.directory, "ircd.db")

        if password is not None:
            config["server"]["password"] = hash_password(
                password)  # type: ignore

        assert self.proc is None

        self._config_path = os.path.join(self.directory, "server.yml")
        self._config = config
        self._write_config()
        subprocess.call(
            ["ergo", "initdb", "--conf", self._config_path, "--quiet"])
        subprocess.call(
            ["ergo", "mkcerts", "--conf", self._config_path, "--quiet"])
        self.proc = subprocess.Popen(
            ["ergo", "run", "--conf", self._config_path, "--quiet"])
Beispiel #7
0
    def run(
        self,
        hostname: str,
        port: int,
        *,
        password: Optional[str],
        ssl: bool,
        run_services: bool,
        valid_metadata_keys: Optional[Set[str]] = None,
        invalid_metadata_keys: Optional[Set[str]] = None,
        restricted_metadata_keys: Optional[Set[str]] = None,
    ) -> None:
        if valid_metadata_keys or invalid_metadata_keys:
            raise NotImplementedByController(
                "Defining valid and invalid METADATA keys."
            )
        assert self.proc is None
        self.port = port
        self.hostname = hostname
        self.create_config()
        (unused_hostname, unused_port) = find_hostname_and_port()
        (services_hostname, services_port) = find_hostname_and_port()

        password_field = "passwd {};".format(password) if password else ""

        self.gen_ssl()

        assert self.directory

        # they are hardcoded... thankfully Bahamut reads them from the CWD.
        shutil.copy(self.pem_path, os.path.join(self.directory, "ircd.crt"))
        shutil.copy(self.key_path, os.path.join(self.directory, "ircd.key"))

        with self.open_file("server.conf") as fd:
            fd.write(
                TEMPLATE_CONFIG.format(
                    hostname=hostname,
                    port=port,
                    services_hostname=services_hostname,
                    services_port=services_port,
                    password_field=password_field,
                    # key_path=self.key_path,
                    # pem_path=self.pem_path,
                )
            )
        self.proc = subprocess.Popen(
            [
                # "strace", "-f", "-e", "file",
                "ircd",
                "-t",  # don't fork
                "-f",
                os.path.join(self.directory, "server.conf"),
            ],
            # stdout=subprocess.DEVNULL,
        )

        if run_services:
            self.wait_for_port()
            self.services_controller = self.services_controller_class(
                self.test_config, self
            )
            self.services_controller.run(
                protocol="bahamut",
                server_hostname=hostname,
                server_port=port,
            )
Beispiel #8
0
    def testEchoMessage(self, command, solo, server_time):
        """<http://ircv3.net/specs/extensions/echo-message-3.2.html>"""
        self.addClient()
        self.sendLine(1, "CAP LS 302")
        capabilities = self.getCapLs(1)
        if "echo-message" not in capabilities:
            raise NotImplementedByController("echo-message")
        if server_time and "server-time" not in capabilities:
            raise NotImplementedByController("server-time")

        # TODO: check also without this
        self.sendLine(
            1,
            "CAP REQ :echo-message{}".format(
                " server-time" if server_time else ""),
        )
        self.getRegistrationMessage(1)
        # TODO: Remove this one the trailing space issue is fixed in Charybdis
        # and Mammon:
        # self.assertMessageMatch(m, command='CAP',
        #        params=['*', 'ACK', 'echo-message'] +
        #        (['server-time'] if server_time else []),
        #        fail_msg='Did not ACK advertised capabilities: {msg}')
        self.sendLine(1, "USER f * * :foo")
        self.sendLine(1, "NICK baz")
        self.sendLine(1, "CAP END")
        self.skipToWelcome(1)
        self.getMessages(1)

        self.sendLine(1, "JOIN #chan")

        if not solo:
            capabilities = ["server-time"] if server_time else None
            self.connectClient("qux", capabilities=capabilities)
            self.sendLine(2, "JOIN #chan")

        # Synchronize and clean
        self.getMessages(1)
        if not solo:
            self.getMessages(2)
            self.getMessages(1)

        self.sendLine(1, "{} #chan :hello everyone".format(command))
        m1 = self.getMessage(1)
        self.assertMessageMatch(
            m1,
            command=command,
            params=["#chan", "hello everyone"],
            fail_msg="Did not echo “{} #chan :hello everyone”: {msg}",
            extra_format=(command, ),
        )

        if not solo:
            m2 = self.getMessage(2)
            self.assertMessageMatch(
                m2,
                command=command,
                params=["#chan", "hello everyone"],
                fail_msg="Did not propagate “{} #chan :hello everyone”: "
                "after echoing it to the author: {msg}",
                extra_format=(command, ),
            )
            self.assertEqual(
                m1.params,
                m2.params,
                fail_msg="Parameters of forwarded and echoed "
                "messages differ: {} {}",
                extra_format=(m1, m2),
            )
            if server_time:
                self.assertIn(
                    "time",
                    m1.tags,
                    fail_msg="Echoed message is missing server time: {}",
                    extra_format=(m1, ),
                )
                self.assertIn(
                    "time",
                    m2.tags,
                    fail_msg="Forwarded message is missing server time: {}",
                    extra_format=(m2, ),
                )
Beispiel #9
0
 def check_server_support(self):
     if "MONITOR" not in self.server_support:
         raise NotImplementedByController("MONITOR")
Beispiel #10
0
    def run(
        self,
        hostname: str,
        port: int,
        *,
        password: Optional[str],
        ssl: bool,
        run_services: bool,
        valid_metadata_keys: Optional[Set[str]] = None,
        invalid_metadata_keys: Optional[Set[str]] = None,
        restricted_metadata_keys: Optional[Set[str]] = None,
    ) -> None:
        if valid_metadata_keys or invalid_metadata_keys:
            raise NotImplementedByController(
                "Defining valid and invalid METADATA keys.")
        assert self.proc is None
        self.port = port
        self.hostname = hostname
        self.create_config()
        (unused_hostname, unused_port) = find_hostname_and_port()
        (services_hostname, services_port) = find_hostname_and_port()

        password_field = 'password "{}";'.format(password) if password else ""

        self.gen_ssl()
        if ssl:
            (tls_hostname, tls_port) = (hostname, port)
            (hostname, port) = (unused_hostname, unused_port)
        else:
            # Unreal refuses to start without TLS enabled
            (tls_hostname, tls_port) = (unused_hostname, unused_port)

        if installed_version() >= 6:
            extras = textwrap.dedent("""
                include "snomasks.default.conf";
                loadmodule "cloak_md5";
                """)
        else:
            extras = ""

        with self.open_file("empty.txt") as fd:
            fd.write("\n")

        assert self.directory
        with self.open_file("unrealircd.conf") as fd:
            fd.write(
                TEMPLATE_CONFIG.format(
                    hostname=hostname,
                    port=port,
                    services_hostname=services_hostname,
                    services_port=services_port,
                    tls_hostname=tls_hostname,
                    tls_port=tls_port,
                    password_field=password_field,
                    key_path=self.key_path,
                    pem_path=self.pem_path,
                    empty_file=os.path.join(self.directory, "empty.txt"),
                    extras=extras,
                ))
        self.proc = subprocess.Popen(
            [
                "unrealircd",
                "-t",
                "-F",  # BOOT_NOFORK
                "-f",
                os.path.join(self.directory, "unrealircd.conf"),
            ],
            # stdout=subprocess.DEVNULL,
        )

        if run_services:
            self.wait_for_port()
            self.services_controller = self.services_controller_class(
                self.test_config, self)
            self.services_controller.run(
                protocol="unreal4",
                server_hostname=services_hostname,
                server_port=services_port,
            )