cloudflare/cloudflared

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
b0e69c4b8ad27dcc74283f0cdaa6744cf8fe41a4

Branches

Tags

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

Clone

HTTPS

Download ZIP

component-tests/test_config.py

53lines · modecode

1#!/usr/bin/env python
2from util import start_cloudflared
3
4class TestConfig:
5 # tmp_path is a fixture provides a temporary directory unique to the test invocation
6 def test_validate_ingress_rules(self, tmp_path):
7 config = {
8 'metrics': 'localhost:50000',
9 '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 }
34 validate_args = ["ingress", "validate"]
35 pre_args = ["tunnel"]
36 validate = start_cloudflared(tmp_path, config, validate_args, pre_args)
37 assert validate.returncode == 0, "failed to validate ingress" + validate.stderr.decode("utf-8")
38
39 self.match_rule(tmp_path, config, "http://example.com/index.html", 1)
40 self.match_rule(tmp_path, config, "https://example.com/index.html", 1)
41 self.match_rule(tmp_path, config, "https://api.example.com/login", 2)
42 self.match_rule(tmp_path, config, "https://wss.example.com", 3)
43 self.match_rule(tmp_path, config, "https://ssh.example.com", 4)
44 self.match_rule(tmp_path, config, "https://api.example.com", 5)
45
46 # 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
47 def match_rule(self, tmp_path, config, url, rule_num):
48 args = ["ingress", "rule", url]
49 pre_args = ["tunnel"]
50 match_rule = start_cloudflared(tmp_path, config, args, pre_args)
51
52 assert match_rule.returncode == 0, "failed to check rule" + match_rule.stderr.decode("utf-8")
53 assert f"Matched rule #{rule_num}" .encode() in match_rule.stdout