Harden DAV outbound URL validation (#2819)

This commit is contained in:
Vykos
2026-06-05 13:22:21 +02:00
committed by GitHub
parent 6d64055328
commit 370ae5d451
7 changed files with 326 additions and 22 deletions
+11 -2
View File
@@ -5,9 +5,13 @@ It did `(raw_url or "").strip()`, so a non-string scalar (e.g. an int from a
mis-typed config) reached `.strip()` and raised TypeError instead of the
function\'s own ValueError.
"""
import ipaddress
import pytest
from src.caldav_sync import validate_caldav_url
from src import caldav_sync
validate_caldav_url = caldav_sync.validate_caldav_url
def test_non_string_raises_valueerror_not_typeerror():
@@ -17,6 +21,11 @@ def test_non_string_raises_valueerror_not_typeerror():
validate_caldav_url(None)
def test_valid_url_passes():
def test_valid_url_passes(monkeypatch):
monkeypatch.setattr(
caldav_sync,
"_resolve_caldav_host_ips",
lambda host: [ipaddress.ip_address("93.184.216.34")],
)
out = validate_caldav_url("https://dav.example.com/calendars/")
assert "example.com" in out