|
|
@@ -0,0 +1,104 @@
|
|
|
+from pathlib import Path
|
|
|
+from proxytester.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
|