Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,40 @@
from vllm_router import utils


@pytest.mark.parametrize(
"url,expected_result",
(
("http://oss-20b:8000", True),
("http://oss-20b/v1", True),
("http://oss_20b:8000", True),
("https://x:8000", True),
("http://-host:8000", False),
("http://host-:8000/v1", False),
("https://example.com:8000/v1", True),
("http://oss_20b.example.com:8000", True),
("http://oss-20b.example.com:8000", True),
# Preserve existing multi-label acceptance.
("http://-host.example.com:8000", True),
("http://host-.example.com:8000", True),
("http://localhost:8000", True),
("http://127.0.0.1:8000", True),
("", False),
("ftp://localhost:8000", False),
("http://host..example.com:8000", False),
("http://host:", False),
("http://[::1]:8000", False),
),
)
def test_validate_url(url: str, expected_result: bool) -> None:
assert utils.validate_url(url) is expected_result


def test_parse_static_urls_keeps_single_label_backends() -> None:
assert utils.parse_static_urls(
"http://oss-20b:8000,http://-host:8000,http://oss_20b/v1,http://localhost:8000"
) == ["http://oss-20b:8000", "http://oss_20b/v1", "http://localhost:8000"]


@pytest.mark.parametrize(
"aliases,expected_result",
(
Expand Down
2 changes: 1 addition & 1 deletion src/vllm_router/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def validate_url(url: str) -> bool:
regex = re.compile(
r"^(http|https)://" # Protocol
r"(([a-zA-Z0-9_-]+\.)+[a-zA-Z]{2,}|" # Domain name
r"localhost|" # Or localhost
r"(?!-)[a-zA-Z0-9_-]+(?<!-)|" # Or single-label hostname (including localhost)
r"\d{1,3}(\.\d{1,3}){3})" # Or IPv4 address
r"(:\d+)?" # Optional port
r"(/.*)?$" # Optional path
Expand Down