Ejemplo n.º 1
0
    def launchd_service_scenario(self, config, extra_assertions=None, use_token=False):
        with self.run_service(Path(default_config_dir()), config, use_token=use_token):
            self.launchctl_cmd("list")
            self.launchctl_cmd("start")
            wait_tunnel_ready(tunnel_url=config.get_url())
            if extra_assertions is not None:
                extra_assertions()
            self.launchctl_cmd("stop")

        os.remove(default_config_file())
        self.launchctl_cmd("list", success=False)
Ejemplo n.º 2
0
 def test_logging_to_dir(self, tmp_path, component_tests_config):
     log_dir = tmp_path / "logs"
     extra_config = {
         "loglevel": "debug",
         # Convert from pathlib.Path to str
         "log-directory": str(log_dir),
     }
     config = component_tests_config(extra_config)
     with start_cloudflared(tmp_path,
                            config,
                            new_process=True,
                            capture_output=False):
         wait_tunnel_ready(tunnel_url=config.get_url())
         self.assert_log_to_dir(config, log_dir)
Ejemplo n.º 3
0
 def test_logging_to_file(self, tmp_path, component_tests_config):
     log_file = tmp_path / self.default_log_file
     extra_config = {
         # Convert from pathlib.Path to str
         "logfile": str(log_file),
     }
     config = component_tests_config(extra_config)
     with start_cloudflared(tmp_path,
                            config,
                            new_process=True,
                            capture_output=False):
         wait_tunnel_ready(tunnel_url=config.get_url())
         self.assert_log_in_file(log_file)
         self.assert_json_log(log_file)
Ejemplo n.º 4
0
    def sysv_service_scenario(self,
                              config,
                              tmp_path,
                              extra_assertions=None,
                              use_token=False):
        with self.run_service(tmp_path, config, root=True,
                              use_token=use_token):
            self.sysv_cmd("status")
            wait_tunnel_ready(tunnel_url=config.get_url())
            if extra_assertions is not None:
                extra_assertions()

        # Service install copies config file to /etc/cloudflared/config.yml
        subprocess.run(["sudo", "rm", "/etc/cloudflared/config.yml"])
        self.sysv_cmd("status", success=False)
Ejemplo n.º 5
0
    def test_shutdown_once_no_connection(self, tmp_path, component_tests_config, signal, protocol):
        config = component_tests_config(self._extra_config(protocol))
        with start_cloudflared(
                tmp_path, config, new_process=True, capture_output=False) as cloudflared:
            wait_tunnel_ready(tunnel_url=config.get_url())

            connected = threading.Condition()
            in_flight_req = threading.Thread(
                target=self.stream_request, args=(config, connected, True, ))
            in_flight_req.start()

            with connected:
                connected.wait(self.timeout)
            with self.within_grace_period():
                # Send signal after the SSE connection is established
                self.terminate_by_signal(cloudflared, signal)
                self.wait_eyeball_thread(in_flight_req, self.grace_period)
Ejemplo n.º 6
0
 def expect_address_connections(self, tmp_path, component_tests_config, protocol, edge_ip_version, assert_address_type):
     config = component_tests_config(
         self._extra_config(protocol, edge_ip_version))
     config_path = write_config(tmp_path, config.full_config)
     LOGGER.debug(config)
     with CloudflaredCli(config, config_path, LOGGER):
         wait_tunnel_ready(tunnel_url=config.get_url(),
                           require_min_connections=4)
         cfd_cli = CloudflaredCli(config, config_path, LOGGER)
         tunnel_id = config.get_tunnel_id()
         info = cfd_cli.get_tunnel_info(tunnel_id)
         connector_id = get_tunnel_connector_id()
         connector = next(
             (c for c in info["conns"] if c["id"] == connector_id), None)
         assert connector, f"Expected connection info from get tunnel info for the connected instance: {info}"
         conns = connector["conns"]
         assert conns == None or len(
             conns) == 4, f"There should be 4 connections registered: {conns}"
         for conn in conns:
             origin_ip = conn["origin_ip"]
             assert origin_ip, f"No available origin_ip for this connection: {conn}"
             assert_address_type(origin_ip)
Ejemplo n.º 7
0
    def assert_reconnect(self, config, cloudflared, repeat):
        wait_tunnel_ready(tunnel_url=config.get_url())
        for _ in range(repeat):
            for i in range(self.default_ha_conns):
                self.send_reconnect(cloudflared, self.default_reconnect_secs)
                expect_connections = self.default_ha_conns - i - 1
                if expect_connections > 0:
                    # Don't check if tunnel returns 200 here because there is a race condition between wait_tunnel_ready
                    # retrying to get 200 response and reconnecting
                    wait_tunnel_ready(
                        require_min_connections=expect_connections)
                else:
                    check_tunnel_not_connected()

            sleep(self.default_reconnect_secs + 10)
            wait_tunnel_ready(tunnel_url=config.get_url(),
                              require_min_connections=self.default_ha_conns)
Ejemplo n.º 8
0
 def test_logging_to_terminal(self, tmp_path, component_tests_config):
     config = component_tests_config()
     with start_cloudflared(tmp_path, config,
                            new_process=True) as cloudflared:
         wait_tunnel_ready(tunnel_url=config.get_url())
         self.assert_log_to_terminal(cloudflared)