cloudflare/cloudflared

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
31f45fb5056bef48efae27fdc5b74bbd26fdf8a3

Branches

Tags

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

Clone

HTTPS

Download ZIP

component-tests/conftest.py

67lines · modecode

1import os
2from enum import Enum, auto
3from time import sleep
4
5import pytest
6import yaml
7
8from config import NamedTunnelConfig, ProxyDnsConfig, QuickTunnelConfig
9from constants import BACKOFF_SECS, PROXY_DNS_PORT
10from util import LOGGER
11
12
13class CfdModes(Enum):
14 NAMED = auto()
15 QUICK = auto()
16 PROXY_DNS = auto()
17
18
19@pytest.fixture(scope="session")
20def component_tests_config():
21 config_file = os.getenv("COMPONENT_TESTS_CONFIG")
22 if config_file is None:
23 raise Exception(
24 "Need to provide path to config file in COMPONENT_TESTS_CONFIG")
25 with open(config_file, 'r') as stream:
26 config = yaml.safe_load(stream)
27 LOGGER.info(f"component tests base config {config}")
28
29 def _component_tests_config(additional_config={}, cfd_mode=CfdModes.NAMED, run_proxy_dns=True, provide_ingress=True):
30 if 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.
33 additional_config["proxy-dns"] = True
34 additional_config["proxy-dns-port"] = PROXY_DNS_PORT
35 else:
36 additional_config.pop("proxy-dns", None)
37 additional_config.pop("proxy-dns-port", None)
38
39 # Allows the ingress rules to be omitted from the provided config
40 ingress = []
41 if provide_ingress:
42 ingress = config['ingress']
43
44 # Provide the hostname to allow routing to the tunnel even if the ingress rule isn't defined in the config
45 hostname = config['ingress'][0]['hostname']
46
47 if cfd_mode is CfdModes.NAMED:
48 return NamedTunnelConfig(additional_config=additional_config,
49 cloudflared_binary=config['cloudflared_binary'],
50 tunnel=config['tunnel'],
51 credentials_file=config['credentials_file'],
52 ingress=ingress,
53 hostname=hostname)
54 elif cfd_mode is CfdModes.PROXY_DNS:
55 return ProxyDnsConfig(cloudflared_binary=config['cloudflared_binary'])
56 elif cfd_mode is CfdModes.QUICK:
57 return QuickTunnelConfig(additional_config=additional_config, cloudflared_binary=config['cloudflared_binary'])
58 else:
59 raise Exception(f"Unknown cloudflared mode {cfd_mode}")
60
61 return _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():
67 sleep(BACKOFF_SECS)
68