From cc732db80747330bc9068d73b99d4f536172a6d7 Mon Sep 17 00:00:00 2001 From: kodaline Date: Wed, 24 Jul 2024 10:40:08 +0200 Subject: [PATCH] fix: CCAT_CORE_USE_SECURE_PROTOCOLS - 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://...` --- core/cat/utils.py | 4 +--- core/tests/test_cat_utils.py | 8 ++++++++ 2 files changed, 9 insertions(+), 3 deletions(-) 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():