11-proxy-config.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. """
  2. Test custom proxy configuration (directives)
  3. """
  4. from pathlib import Path
  5. from httphound.main import BaseProxyTest, BackendConfig, ProxyConfig
  6. class TemplateDirectivesTest(BaseProxyTest):
  7. """Test using custom proxy config directives
  8. """
  9. def __init__(self):
  10. super().__init__()
  11. self.description = "Custom proxy config directives"
  12. # backend will run on port 9999
  13. self.backend_config = BackendConfig(
  14. host='127.0.0.1',
  15. port=9999,
  16. response_status=200,
  17. response_body='OK',
  18. )
  19. # configure haproxy to use production config
  20. self.proxy_config = ProxyConfig(
  21. binary_path=Path.home() / "bin/haproxy",
  22. config_mode="template",
  23. template_directives = {
  24. "global": [
  25. "maxconn 1024",
  26. ],
  27. "defaults": [
  28. "timeout client 30s",
  29. ],
  30. "frontend_http": [
  31. "http-request deny deny_status 500 if { path_beg /test }",
  32. ],
  33. },
  34. )
  35. self.url = "http://127.0.0.1:4242/test"
  36. self.expected_status = 500
  37. async def run_test(self):
  38. """Run the test"""
  39. await self.make_request()
  40. assert self.backend.request_count == 0
  41. return True