| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- """
- Example test using production (static) HAProxy configuration
- """
- from pathlib import Path
- from httphound.main import BaseProxyTest, BackendConfig, ProxyConfig
- class ProductionConfigBasicTest(BaseProxyTest):
- """Test using a production haproxy config with automatic
- backend patching
- """
- def __init__(self):
- super().__init__()
- self.description = "Production config with backend patching"
- # backend will run on port 9999
- self.backend_config = BackendConfig(
- host='127.0.0.1',
- port=9999,
- response_status=200,
- response_body='Production test response',
- response_headers={"X-Test-Mode":"production"}
- )
- # configure haproxy to use production config
- self.proxy_config = ProxyConfig(
- binary_path=Path.home() / "bin/haproxy",
- config_mode="production",
- production_config_file_path="example_config/haproxy.cfg",
- backend_name_to_patch="app_backend",
- bind_address_override="*:4242",
- skip_backend_injection=False,
- )
- self.url = "http://127.0.0.1:4242"
- self.expected_status = 200
- self.expected_headers = {
- "x-test-mode": "production",
- }
- async def run_test(self):
- """Run the test"""
- await self.make_request()
- assert self.backend.request_count == 1
- assert "Host" in self.backend.received_headers
- return True
- class ProductionConfigWithExtraArgsTest(BaseProxyTest):
- """Test with custom HAProxy command-line arguments"""
-
- def __init__(self):
- super().__init__()
- self.description = "Production config with extra HAProxy args"
-
- self.backend_config = BackendConfig(
- host="127.0.0.1",
- port=9999,
- )
-
- self.proxy_config = ProxyConfig(
- binary_path=Path.home() / "bin/haproxy",
- config_mode="production",
- production_config_file_path="example_config/haproxy.cfg",
- backend_name_to_patch="app_backend",
- bind_address_override="*:4242",
-
- # Add custom HAProxy arguments
- extra_args=[
- "-dM",
- ]
- )
-
- self.url = "http://127.0.0.1:4242/"
- self.expected_status = 200
-
- async def run_test(self):
- await self.make_request()
- return True
|