mirror of
https://github.com/home-assistant/supervisor.git
synced 2026-10-02 14:24:22 +01:00
* Strip whitespace from repository URLs in store validation * Reject repository URLs containing internal whitespace Tighten RE_REPOSITORY so the URL group rejects whitespace that .strip() cannot fix, failing validation with a clear error instead of an unclear git clone failure later. Also parametrize the existing add repository API test instead of duplicating it and collapse the strip test cases into one mixed-whitespace case. --------- Co-authored-by: Stefan Agner <stefan@agner.ch>
47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
"""Test schema validation."""
|
|
|
|
import pytest
|
|
from voluptuous import Invalid
|
|
|
|
from supervisor.store.validate import repositories
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("repo_list", "valid"),
|
|
[
|
|
(["core", "local"], True),
|
|
(["https://github.com/hassio-addons/repository"], True),
|
|
(["https://github.com/hassio-addons/repository#beta"], True),
|
|
(["https://github.com/hassio-addons/repository#feature/hot-new-stuff"], True),
|
|
(["not_a_url"], False),
|
|
(
|
|
["https://github.com/hassio-addons/repository #beta"],
|
|
False,
|
|
),
|
|
(["https://fail.com/duplicate", "https://fail.com/duplicate"], False),
|
|
],
|
|
)
|
|
async def test_repository_validate(repo_list: list[str], valid: bool):
|
|
"""Test repository list validate."""
|
|
if valid:
|
|
assert repositories(repo_list) == repo_list
|
|
else:
|
|
with pytest.raises(Invalid):
|
|
repositories(repo_list)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("repo_list", "expected"),
|
|
[
|
|
(
|
|
[" \t\nhttps://github.com/hassio-addons/repository \n\t"],
|
|
["https://github.com/hassio-addons/repository"],
|
|
),
|
|
],
|
|
)
|
|
async def test_repository_validate_strips_whitespace(
|
|
repo_list: list[str], expected: list[str]
|
|
):
|
|
"""Test repository validation strips leading/trailing whitespace."""
|
|
assert repositories(repo_list) == expected
|