02-basic_header_check.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. from pathlib import Path
  2. from proxytester.main import BaseProxyTest, BackendConfig, ProxyConfig
  3. class FailHeaderCheck(BaseProxyTest):
  4. """Minimal test to demonstrate the basic header checks functionality
  5. This test should fail as the backend or the reverse proxy aren't configured
  6. to answer this header.
  7. """
  8. def __init__(self):
  9. super().__init__()
  10. self.description = "Client custom header (Fail)"
  11. self.url = "http://localhost:4242/"
  12. # expected_headers must match with the headers received by
  13. # the client or will fail
  14. self.expected_headers = {
  15. "x-test": "1234",
  16. }
  17. self.proxy_config = ProxyConfig(
  18. binary_path=Path.home() / "bin/haproxy"
  19. )
  20. async def run_test(self):
  21. await self.make_request()
  22. return True
  23. class PassHeaderCheck(BaseProxyTest):
  24. """Minimal test to demonstrate the basic header checks functionality
  25. This test should succeed.
  26. """
  27. def __init__(self):
  28. super().__init__()
  29. self.description = "Client custom header (Pass)"
  30. self.url = "http://localhost:4242/"
  31. # expected_headers must match with the headers received by
  32. # the client or will fail
  33. self.expected_headers = {
  34. "x-test": "1234",
  35. }
  36. self.proxy_config = ProxyConfig(
  37. binary_path=Path.home() / "bin/haproxy"
  38. )
  39. # Defining a backend configuration with headers
  40. # to answer to the client
  41. self.backend_config = BackendConfig(
  42. response_headers={"X-Test": "1234"},
  43. )
  44. async def run_test(self):
  45. """The run_test() method is always the same as all logic
  46. is defined entirely in the classes configuration.
  47. """
  48. await self.make_request()
  49. return True