Skip to content

Commit

Permalink
Merge pull request #291 from votdev/issue_821_malformed_ui_path
Browse files Browse the repository at this point in the history
  • Loading branch information
votdev authored Nov 21, 2023
2 parents 706d644 + 56619de commit 4b0181e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/backend/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 20 additions & 8 deletions src/backend/tests/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from backend.api import s3gw_config
from backend.config import (
Config,
EnvironMalformedError,
S3AddressingStyle,
get_environ_enum,
get_environ_str,
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 4b0181e

Please sign in to comment.