test_config.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env python
  2. from util import start_cloudflared
  3. class TestConfig:
  4. # tmp_path is a fixture provides a temporary directory unique to the test invocation
  5. def test_validate_ingress_rules(self, tmp_path, component_tests_config):
  6. extra_config = {
  7. 'ingress': [
  8. {
  9. "hostname": "example.com",
  10. "service": "https://localhost:8000",
  11. "originRequest": {
  12. "originServerName": "test.example.com",
  13. "caPool": "/etc/certs/ca.pem"
  14. },
  15. },
  16. {
  17. "hostname": "api.example.com",
  18. "path": "login",
  19. "service": "https://localhost:9000",
  20. },
  21. {
  22. "hostname": "wss.example.com",
  23. "service": "wss://localhost:8000",
  24. },
  25. {
  26. "hostname": "ssh.example.com",
  27. "service": "ssh://localhost:8000",
  28. },
  29. {"service": "http_status:404"}
  30. ],
  31. }
  32. config = component_tests_config(extra_config)
  33. validate_args = ["ingress", "validate"]
  34. _ = start_cloudflared(tmp_path, config, validate_args)
  35. self.match_rule(tmp_path, config,
  36. "http://example.com/index.html", 0)
  37. self.match_rule(tmp_path, config,
  38. "https://example.com/index.html", 0)
  39. self.match_rule(tmp_path, config,
  40. "https://api.example.com/login", 1)
  41. self.match_rule(tmp_path, config,
  42. "https://wss.example.com", 2)
  43. self.match_rule(tmp_path, config,
  44. "https://ssh.example.com", 3)
  45. self.match_rule(tmp_path, config,
  46. "https://api.example.com", 4)
  47. # 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
  48. def match_rule(self, tmp_path, config, url, rule_num):
  49. args = ["ingress", "rule", url]
  50. match_rule = start_cloudflared(tmp_path, config, args)
  51. assert f"Matched rule #{rule_num}" .encode() in match_rule.stdout