cloudflare/cloudflared

Public

mirrored from https://github.com/cloudflare/cloudflaredAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
2025.4.2

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

component-tests/conftest.py

67lines · modeblame

a7344435cthuang5 years ago1import os
1e8dea91Nuno Diegues4 years ago2from enum import Enum, auto
3from time import sleep
4
a7344435cthuang5 years ago5import pytest
6import yaml
7
93f8f6b5Devin Carr3 years ago8from config import NamedTunnelConfig, ProxyDnsConfig, QuickTunnelConfig
1e8dea91Nuno Diegues4 years ago9from constants import BACKOFF_SECS, PROXY_DNS_PORT
a7344435cthuang5 years ago10from util import LOGGER
11
f23e33c0cthuang5 years ago12
1e8dea91Nuno Diegues4 years ago13class CfdModes(Enum):
14NAMED = auto()
93f8f6b5Devin Carr3 years ago15QUICK = auto()
1e8dea91Nuno Diegues4 years ago16PROXY_DNS = auto()
17
18
a7344435cthuang5 years ago19@pytest.fixture(scope="session")
20def component_tests_config():
21config_file = os.getenv("COMPONENT_TESTS_CONFIG")
22if config_file is None:
f23e33c0cthuang5 years ago23raise Exception(
24"Need to provide path to config file in COMPONENT_TESTS_CONFIG")
a7344435cthuang5 years ago25with open(config_file, 'r') as stream:
26config = yaml.safe_load(stream)
27LOGGER.info(f"component tests base config {config}")
28
7b8b3f73Devin Carr3 years ago29def _component_tests_config(additional_config={}, cfd_mode=CfdModes.NAMED, run_proxy_dns=True, provide_ingress=True):
1e8dea91Nuno Diegues4 years ago30if run_proxy_dns:
31# Regression test for TUN-4177, running with proxy-dns should not prevent tunnels from running.
32# So we run all tests with it.
33additional_config["proxy-dns"] = True
34additional_config["proxy-dns-port"] = PROXY_DNS_PORT
35else:
36additional_config.pop("proxy-dns", None)
37additional_config.pop("proxy-dns-port", None)
38
7b8b3f73Devin Carr3 years ago39# Allows the ingress rules to be omitted from the provided config
40ingress = []
41if provide_ingress:
42ingress = config['ingress']
43
44# Provide the hostname to allow routing to the tunnel even if the ingress rule isn't defined in the config
45hostname = config['ingress'][0]['hostname']
46
1e8dea91Nuno Diegues4 years ago47if cfd_mode is CfdModes.NAMED:
25cfbec0cthuang5 years ago48return NamedTunnelConfig(additional_config=additional_config,
b25d38ddNuno Diegues5 years ago49cloudflared_binary=config['cloudflared_binary'],
50tunnel=config['tunnel'],
51credentials_file=config['credentials_file'],
7b8b3f73Devin Carr3 years ago52ingress=ingress,
53hostname=hostname)
1e8dea91Nuno Diegues4 years ago54elif cfd_mode is CfdModes.PROXY_DNS:
55return ProxyDnsConfig(cloudflared_binary=config['cloudflared_binary'])
93f8f6b5Devin Carr3 years ago56elif cfd_mode is CfdModes.QUICK:
57return QuickTunnelConfig(additional_config=additional_config, cloudflared_binary=config['cloudflared_binary'])
1e8dea91Nuno Diegues4 years ago58else:
59raise Exception(f"Unknown cloudflared mode {cfd_mode}")
a7344435cthuang5 years ago60
f23e33c0cthuang5 years ago61return _component_tests_config
62
63
64# This fixture is automatically called before each tests to make sure the previous cloudflared has been shutdown
65@pytest.fixture(autouse=True)
66def wait_previous_cloudflared():
67sleep(BACKOFF_SECS)