Skip to content

Commit

Permalink
Fix Ceryx tests
Browse files Browse the repository at this point in the history
  • Loading branch information
parisk committed Apr 26, 2019
1 parent cf4aadf commit 2ed1f4b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 55 deletions.
2 changes: 2 additions & 0 deletions ceryx/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
9 changes: 3 additions & 6 deletions ceryx/tests/test_certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
64 changes: 15 additions & 49 deletions ceryx/tests/test_routes.py
Original file line number Diff line number Diff line change
@@ -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):
"""
Expand All @@ -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
Expand All @@ -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)

Expand All @@ -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)
Expand Down

0 comments on commit 2ed1f4b

Please sign in to comment.