| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- from pathlib import Path
- from httphound.main import BaseProxyTest, BackendConfig, ProxyConfig
- class FailForbiddenHeadersTest(BaseProxyTest):
- """Test that headers received by the client aren't the ones explicitly
- listed as forbidden ones.
- This test should fail
- """
- def __init__(self):
- super().__init__()
- self.description = "Forbidden client headers check (Fail)"
- # We don't expect these headers
- self.forbidden_client_headers = ['x-forbidden']
- self.proxy_config = ProxyConfig(
- binary_path=Path.home() / "bin/haproxy"
- )
- # Configure the backend to send the forbidden header and fail
- # the test
- self.backend_config = BackendConfig(
- response_headers={"X-Forbidden": "1234"},
- )
- async def run_test(self):
- await self.make_request()
- return True
- class PassForbiddenHeadersTest(BaseProxyTest):
- """Test that headers received by the client aren't the ones explicitly
- listed as forbidden ones.
- """
- def __init__(self):
- super().__init__()
- self.description = "Forbidden client headers check (Pass)"
- # We don't expect these headers
- self.forbidden_client_headers = ['x-forbidden']
- self.proxy_config = ProxyConfig(
- binary_path=Path.home() / "bin/haproxy"
- )
- self.backend_config = BackendConfig(
- response_headers={"X-Test": "1234"},
- )
- async def run_test(self):
- await self.make_request()
- return True
- class FailBackendForbiddenHeadersTest(BaseProxyTest):
- """Test that headers received by the backend aren't the ones explicitly
- listed as forbidden ones.
- This test should fail
- """
- def __init__(self):
- super().__init__()
- self.description = "Forbidden backend headers check (Fail)"
- # Backend doesn't expect these headers
- self.forbidden_backend_headers = ['x-forbidden']
- self.headers = {
- "X-Forbidden": "1234",
- }
- self.proxy_config = ProxyConfig(
- binary_path=Path.home() / "bin/haproxy"
- )
- async def run_test(self):
- await self.make_request()
- return True
- class PassBackendForbiddenHeadersTest(BaseProxyTest):
- """Test that headers received by the backend aren't the ones explicitly
- listed as forbidden ones.
- """
- def __init__(self):
- super().__init__()
- self.description = "Forbidden backend headers check (Pass)"
- # Backend doesn't expect these headers
- self.forbidden_backend_headers = ['x-forbidden']
- self.headers = {
- "X-Test": "1234",
- }
- self.proxy_config = ProxyConfig(
- binary_path=Path.home() / "bin/haproxy"
- )
- async def run_test(self):
- await self.make_request()
- return True
|