""" Test custom proxy configuration (directives) """ from pathlib import Path from httphound.main import BaseProxyTest, BackendConfig, ProxyConfig class TemplateDirectivesTest(BaseProxyTest): """Test using custom proxy config directives """ def __init__(self): super().__init__() self.description = "Custom proxy config directives" # backend will run on port 9999 self.backend_config = BackendConfig( host='127.0.0.1', port=9999, response_status=200, response_body='OK', ) # configure haproxy to use production config self.proxy_config = ProxyConfig( binary_path=Path.home() / "bin/haproxy", config_mode="template", template_directives = { "global": [ "maxconn 1024", ], "defaults": [ "timeout client 30s", ], "frontend_http": [ "http-request deny deny_status 500 if { path_beg /test }", ], }, ) self.url = "http://127.0.0.1:4242/test" self.expected_status = 500 async def run_test(self): """Run the test""" await self.make_request() assert self.backend.request_count == 0 return True