From 56619de96e35e4a129f8a7c06f823a067bb5a9a7 Mon Sep 17 00:00:00 2001 From: Volker Theile Date: Tue, 21 Nov 2023 15:32:05 +0100 Subject: [PATCH] The s3gw-ui container does not start Fixes: https://github.com/aquarist-labs/s3gw/issues/821 Signed-off-by: Volker Theile --- src/backend/config.py | 4 ++-- src/backend/tests/unit/test_config.py | 28 +++++++++++++++++++-------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/backend/config.py b/src/backend/config.py index 18b792f8..334253fe 100644 --- a/src/backend/config.py +++ b/src/backend/config.py @@ -118,9 +118,9 @@ def get_ui_path() -> str: """ def post_process(key: str, value: str | None) -> str: - if value is None: + if value is None or value == "/": return "/" - match = re.fullmatch(r"/?[\w.-/]+(?:[\w]+)/?", value) + match = re.fullmatch(r"/?[\w./-]+(?:[\w]+)/?", value) if match is None: logger.error( f"The value of the environment variable {key} is malformed: {value}" # noqa: E501 diff --git a/src/backend/tests/unit/test_config.py b/src/backend/tests/unit/test_config.py index 50089913..451feb55 100644 --- a/src/backend/tests/unit/test_config.py +++ b/src/backend/tests/unit/test_config.py @@ -21,6 +21,7 @@ from backend.api import s3gw_config from backend.config import ( Config, + EnvironMalformedError, S3AddressingStyle, get_environ_enum, get_environ_str, @@ -109,14 +110,25 @@ def test_malformed_ui_path() -> None: ) -def test_good_ui_path() -> None: - path = "/s3store" - os.environ["S3GW_UI_PATH"] = path - try: - cfg = Config() - assert cfg.ui_path == path - except Exception as e: - pytest.fail(str(e)) +def test_malformed_ui_path_2() -> None: + os.environ["S3GW_UI_PATH"] = "/foo-bar/baz?aaa" + with pytest.raises(EnvironMalformedError): + get_ui_path() + + +def test_good_ui_path_1() -> None: + os.environ["S3GW_UI_PATH"] = "/s3store" + assert "/s3store" == get_ui_path() + + +def test_good_ui_path_2() -> None: + os.environ["S3GW_UI_PATH"] = "/" + assert "/" == get_ui_path() + + +def test_good_ui_path_3() -> None: + os.environ["S3GW_UI_PATH"] = "/foo-bar/baz/" + assert "/foo-bar/baz/" == get_ui_path() def test_no_ui_path() -> None: