Skip to content

Commit

Permalink
fix: CCAT_CORE_USE_SECURE_PROTOCOLS
Browse files Browse the repository at this point in the history
- In compose/env file, set `CCAT_CORE_USE_SECURE_PROTOCOLS=0`
issue: `get_base_url()` will return `http0://...`

This commit rewrites the condition in order to get the expected
behavior:
- `CCAT_CORE_USE_SECURE_PROTOCOLS=1 | true` will give `https://...`
- everything else will give `http://...`
  • Loading branch information
kodaline committed Jul 24, 2024
1 parent c0cb4ad commit cc732db
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 1 addition & 3 deletions core/cat/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ def verbal_timedelta(td: timedelta) -> str:

def get_base_url():
"""Allows exposing the base url."""
secure = get_env("CCAT_CORE_USE_SECURE_PROTOCOLS")
if secure not in ["", "false", "0"]:
secure = "s"
secure = "s" if get_env("CCAT_CORE_USE_SECURE_PROTOCOLS") in ("true", "1") else ""
cat_host = get_env("CCAT_CORE_HOST")
cat_port = get_env("CCAT_CORE_PORT")
return f"http{secure}://{cat_host}:{cat_port}/"
Expand Down
8 changes: 8 additions & 0 deletions core/tests/test_cat_utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import os
import pytest

from cat import utils


def test_get_base_url():
assert utils.get_base_url() == "http://localhost:1865/"
# test when CCAT_CORE_USE_SECURE_PROTOCOLS is set
os.environ["CCAT_CORE_USE_SECURE_PROTOCOLS"] = "1"
assert utils.get_base_url() == "https://localhost:1865/"
os.environ["CCAT_CORE_USE_SECURE_PROTOCOLS"] = "0"
assert utils.get_base_url() == "http://localhost:1865/"
os.environ["CCAT_CORE_USE_SECURE_PROTOCOLS"] = ""
assert utils.get_base_url() == "http://localhost:1865/"


def test_get_base_path():
Expand Down

0 comments on commit cc732db

Please sign in to comment.