05-forbidden_headers.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. from pathlib import Path
  2. from httphound.main import BaseProxyTest, BackendConfig, ProxyConfig
  3. class FailForbiddenHeadersTest(BaseProxyTest):
  4. """Test that headers received by the client aren't the ones explicitly
  5. listed as forbidden ones.
  6. This test should fail
  7. """
  8. def __init__(self):
  9. super().__init__()
  10. self.description = "Forbidden client headers check (Fail)"
  11. # We don't expect these headers
  12. self.forbidden_client_headers = ['x-forbidden']
  13. self.proxy_config = ProxyConfig(
  14. binary_path=Path.home() / "bin/haproxy"
  15. )
  16. # Configure the backend to send the forbidden header and fail
  17. # the test
  18. self.backend_config = BackendConfig(
  19. response_headers={"X-Forbidden": "1234"},
  20. )
  21. async def run_test(self):
  22. await self.make_request()
  23. return True
  24. class PassForbiddenHeadersTest(BaseProxyTest):
  25. """Test that headers received by the client aren't the ones explicitly
  26. listed as forbidden ones.
  27. """
  28. def __init__(self):
  29. super().__init__()
  30. self.description = "Forbidden client headers check (Pass)"
  31. # We don't expect these headers
  32. self.forbidden_client_headers = ['x-forbidden']
  33. self.proxy_config = ProxyConfig(
  34. binary_path=Path.home() / "bin/haproxy"
  35. )
  36. self.backend_config = BackendConfig(
  37. response_headers={"X-Test": "1234"},
  38. )
  39. async def run_test(self):
  40. await self.make_request()
  41. return True
  42. class FailBackendForbiddenHeadersTest(BaseProxyTest):
  43. """Test that headers received by the backend aren't the ones explicitly
  44. listed as forbidden ones.
  45. This test should fail
  46. """
  47. def __init__(self):
  48. super().__init__()
  49. self.description = "Forbidden backend headers check (Fail)"
  50. # Backend doesn't expect these headers
  51. self.forbidden_backend_headers = ['x-forbidden']
  52. self.headers = {
  53. "X-Forbidden": "1234",
  54. }
  55. self.proxy_config = ProxyConfig(
  56. binary_path=Path.home() / "bin/haproxy"
  57. )
  58. async def run_test(self):
  59. await self.make_request()
  60. return True
  61. class PassBackendForbiddenHeadersTest(BaseProxyTest):
  62. """Test that headers received by the backend aren't the ones explicitly
  63. listed as forbidden ones.
  64. """
  65. def __init__(self):
  66. super().__init__()
  67. self.description = "Forbidden backend headers check (Pass)"
  68. # Backend doesn't expect these headers
  69. self.forbidden_backend_headers = ['x-forbidden']
  70. self.headers = {
  71. "X-Test": "1234",
  72. }
  73. self.proxy_config = ProxyConfig(
  74. binary_path=Path.home() / "bin/haproxy"
  75. )
  76. async def run_test(self):
  77. await self.make_request()
  78. return True