diff --git a/ceryx/tests/base.py b/ceryx/tests/base.py index cb2f8af..eaad0d2 100644 --- a/ceryx/tests/base.py +++ b/ceryx/tests/base.py @@ -10,5 +10,7 @@ class BaseTest: def setup_method(self): self.uuid = uuid.uuid4() self.host = f"{self.uuid}.ceryx.test" + self.redis_target_key = f"ceryx:routes:{self.host}" + self.redis_settings_key = f"ceryx:settings:{self.host}" self.client = CeryxTestClient() self.redis = redis.Redis(host='redis') \ No newline at end of file diff --git a/ceryx/tests/test_certificates.py b/ceryx/tests/test_certificates.py index 8e7d836..75fd2ff 100644 --- a/ceryx/tests/test_certificates.py +++ b/ceryx/tests/test_certificates.py @@ -11,12 +11,9 @@ def test_custom_certificate(self): certificate_path , key_path = create_certificates_for_host(self.host) api_base_url = "http://api:5555/" + self.redis.set(self.redis_target_key, api_base_url) - route_redis_key = f"ceryx:routes:{self.host}" - self.redis.set(route_redis_key, api_base_url) - - settings_redis_key = f"ceryx:settings:{self.host}" - self.redis.hset(settings_redis_key, "certificate_path", certificate_path) - self.redis.hset(settings_redis_key, "key_path", key_path) + self.redis.hset(self.redis_settings_key, "certificate_path", certificate_path) + self.redis.hset(self.redis_settings_key, "key_path", key_path) self.client.get(f"https://{self.host}/", verify=certificate_path) diff --git a/ceryx/tests/test_routes.py b/ceryx/tests/test_routes.py index 19982c4..1688e56 100644 --- a/ceryx/tests/test_routes.py +++ b/ceryx/tests/test_routes.py @@ -1,16 +1,6 @@ -import os - -import requests - from base import BaseTest -CERYX_API_URL = os.getenv("CERYX_API_URL", "http://api:5555") -CERYX_API_ROUTES_ROOT = os.path.join(CERYX_API_URL, "api/routes") - -CERYX_HOST = "http://ceryx" - - class TestRoutes(BaseTest): def test_no_route(self): """ @@ -26,18 +16,12 @@ def test_proxy(self): Ceryx should successfully proxy the upstream request to the client, for a registered route. """ - api_upstream_host = "api" - ceryx_route_source = "api.ceryx.test" - ceryx_route_target = f"http://{api_upstream_host}:5555/api/routes" - # Register the local Ceryx API as a route - register_api_response = requests.post( - CERYX_API_ROUTES_ROOT, - json={"source": ceryx_route_source, "target": ceryx_route_target}, - ) + target = f"http://api:5555/api/routes/" + self.redis.set(self.redis_target_key, target) - upstream_response = self.client.get(ceryx_route_target) - ceryx_response = self.client.get(f"http://{ceryx_route_source}/") + upstream_response = self.client.get(target) + ceryx_response = self.client.get(f"http://{self.host}/") assert upstream_response.status_code == ceryx_response.status_code assert upstream_response.content == ceryx_response.content @@ -48,22 +32,13 @@ def test_redirect(self): Ceryx should respond with 301 status and the appropriate `Location` header for redirected routes. """ - api_upstream_host = "api" - ceryx_route_target = "http://api:5555/api/routes" - ceryx_route_source = "redirected-api.ceryx.test" - - # Register the local Ceryx API as a route - register_api_response = requests.post( - CERYX_API_ROUTES_ROOT, - json={ - "source": ceryx_route_source, - "target": ceryx_route_target, - "settings": {"mode": "redirect"}, - }, - ) + # Register the local Ceryx API as a redirect route + target = "http://api:5555/api/routes" + self.redis.set(self.redis_target_key, target) + self.redis.hset(self.redis_settings_key, "mode", "redirect") - url = f"http://{ceryx_route_source}/some/path/?some=args&more=args" - target_url = f"{ceryx_route_target}/some/path/?some=args&more=args" + url = f"http://{self.host}/some/path/?some=args&more=args" + target_url = f"{target}/some/path/?some=args&more=args" ceryx_response = self.client.get(url, allow_redirects=False) @@ -76,21 +51,12 @@ def test_enforce_https(self): Ceryx should respond with 301 status and the appropriate `Location` header for routes with HTTPS enforced. """ - api_upstream_host = "api" - api_upstream_target = "http://api:5555/" - ceryx_route_source = "secure-api.ceryx.test" - - # Register the local Ceryx API as a route - register_api_response = requests.post( - CERYX_API_ROUTES_ROOT, - json={ - "source": ceryx_route_source, - "target": api_upstream_target, - "settings": {"enforce_https": True}, - }, - ) + # Register the local Ceryx API as a redirect route + target = "http://api:5555/" + self.redis.set(self.redis_target_key, target) + self.redis.hset(self.redis_settings_key, "enforce_https", "1") - base_url = f"{ceryx_route_source}/some/path/?some=args&more=args" + base_url = f"{self.host}/some/path/?some=args&more=args" http_url = f"http://{base_url}" https_url = f"https://{base_url}" ceryx_response = self.client.get(http_url, allow_redirects=False)