cloudflare/cloudflared

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
2026.5.2

Branches

Tags

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

Clone

HTTPS

Download ZIP

component-tests/test_config.py

57lines · modeblame

e5d6f969cthuang5 years ago1#!/usr/bin/env python
2from util import start_cloudflared
3
f23e33c0cthuang5 years ago4
e5d6f969cthuang5 years ago5class TestConfig:
6# tmp_path is a fixture provides a temporary directory unique to the test invocation
a7344435cthuang5 years ago7def test_validate_ingress_rules(self, tmp_path, component_tests_config):
8extra_config = {
e5d6f969cthuang5 years ago9'ingress': [
10{
11"hostname": "example.com",
12"service": "https://localhost:8000",
13"originRequest": {
14"originServerName": "test.example.com",
15"caPool": "/etc/certs/ca.pem"
16},
17},
18{
19"hostname": "api.example.com",
20"path": "login",
21"service": "https://localhost:9000",
22},
23{
24"hostname": "wss.example.com",
25"service": "wss://localhost:8000",
26},
27{
28"hostname": "ssh.example.com",
29"service": "ssh://localhost:8000",
30},
31{"service": "http_status:404"}
32],
33}
25cfbec0cthuang5 years ago34config = component_tests_config(extra_config)
e5d6f969cthuang5 years ago35validate_args = ["ingress", "validate"]
25cfbec0cthuang5 years ago36_ = start_cloudflared(tmp_path, config, validate_args)
a7344435cthuang5 years ago37
25cfbec0cthuang5 years ago38self.match_rule(tmp_path, config,
adb7d400João Oliveirinha2 years ago39"http://example.com/index.html", 0)
25cfbec0cthuang5 years ago40self.match_rule(tmp_path, config,
adb7d400João Oliveirinha2 years ago41"https://example.com/index.html", 0)
25cfbec0cthuang5 years ago42self.match_rule(tmp_path, config,
adb7d400João Oliveirinha2 years ago43"https://api.example.com/login", 1)
25cfbec0cthuang5 years ago44self.match_rule(tmp_path, config,
adb7d400João Oliveirinha2 years ago45"https://wss.example.com", 2)
25cfbec0cthuang5 years ago46self.match_rule(tmp_path, config,
adb7d400João Oliveirinha2 years ago47"https://ssh.example.com", 3)
25cfbec0cthuang5 years ago48self.match_rule(tmp_path, config,
adb7d400João Oliveirinha2 years ago49"https://api.example.com", 4)
e5d6f969cthuang5 years ago50
51# This is used to check that the command tunnel ingress url <url> matches rule number <rule_num>. Note that rule number uses 1-based indexing
f23e33c0cthuang5 years ago52
25cfbec0cthuang5 years ago53def match_rule(self, tmp_path, config, url, rule_num):
e5d6f969cthuang5 years ago54args = ["ingress", "rule", url]
25cfbec0cthuang5 years ago55match_rule = start_cloudflared(tmp_path, config, args)
e5d6f969cthuang5 years ago56
f23e33c0cthuang5 years ago57assert f"Matched rule #{rule_num}" .encode() in match_rule.stdout