diff --git a/core/cat/utils.py b/core/cat/utils.py index 0ccb5aec..d9c806f5 100644 --- a/core/cat/utils.py +++ b/core/cat/utils.py @@ -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}/" diff --git a/core/tests/test_cat_utils.py b/core/tests/test_cat_utils.py index e64f4673..a7824824 100644 --- a/core/tests/test_cat_utils.py +++ b/core/tests/test_cat_utils.py @@ -1,3 +1,4 @@ +import os import pytest from cat import utils @@ -5,6 +6,13 @@ 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():