Skip to content
Merged
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
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ This library is tightly dependent on the CalDAV-library, particularly the `compa

## Unreleased

This release works with caldav 3.7.0.
This release works with caldav 3.7.0: the tester carries the definitions of the features below that caldav has not released yet.

### Added

- **`move`**, **`move.overwrite`** and **`move.if-match`** - whether WebDAV MOVE (RFC 4918 section 9.9) moves an object into another calendar, whether a MOVE with `Overwrite: F` onto an existing object fails with 412 as RFC 4918 requires, and whether one with an outdated If-Match does. caldav does not define these features yet, so the tester adds their definitions itself until a caldav release has them. Radicale and Xandikos ignore the If-Match, Zimbra and SOGo also ignore `Overwrite: F`, and Bedework refuses the MOVE. See https://github.com/python-caldav/caldav/issues/841 and https://github.com/python-caldav/caldav-server-tester/issues/50.
- **`save-load.todo.status`**, **`save-load.todo.status.rfc10051`** and **`save-load.todo.priority`** - which STATUS values (RFC 5545's four; PENDING and FAILED from RFC 10051 apart) and which PRIORITY values (0 to 9) a task keeps, with the extra keys `values`, `map` and `refused`. Ox drops PENDING and FAILED and keeps priorities 1, 5 and 9 only; Zimbra stores PENDING and FAILED as NEEDS-ACTION and refuses CANCELLED. PRIORITY:0 dropped is `full`: no PRIORITY means the same.
- **`supported-task-modes`** - whether the server advertises RFC 10051 with `CALDAV:supported-task-mode-set` on the calendar home or a calendar. Neither Ox nor Zimbra does, and the RFC 10051 status verdict says so.
- **`save-load.icalendar.x-parameter`** - whether an X- parameter on SUMMARY is stored, in an event and then in a task. Ox and Zimbra drop it from the event.
- **`multiget.deleted`** - whether a calendar-multiget answers a deleted object as missing. Zimbra still returns its data, while a GET answers 404.
- **`save-load.stable-url`** also stores a task under a name that is not its UID, and records `uid_ics_components: [VTODO]` where only the task is renamed `<uid>.ics` (Ox).

### Fixed

Expand Down
304 changes: 295 additions & 9 deletions src/caldav_server_tester/checks.py

Large diffs are not rendered by default.

46 changes: 46 additions & 0 deletions src/caldav_server_tester/future_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,52 @@
"move.if-match": {
"description": "A MOVE with an If-Match the object no longer has fails with 412 and moves nothing (RFC 9110 section 13.1.1). Where unsupported, a MOVE cannot guard against an object changed since it was read."
},
## caldav PR 848 (https://github.com/python-caldav/caldav/pull/848)
"save-load.todo.status": {
"description": "Each STATUS RFC 5545 section 3.8.1.11 gives a task (NEEDS-ACTION, IN-PROCESS, COMPLETED, CANCELLED) is stored as sent. 'unsupported' when one is dropped or stored as another, 'ungraceful' when a task with one is refused, the worse of the two where both apply; the extra keys say which. Zimbra refuses CANCELLED. The statuses RFC 10051 adds are save-load.todo.status.rfc10051.",
"default": {"support": "full"},
"extra_keys": {
"values": "The statuses stored as sent.",
"map": "A status, to the one stored instead.",
"refused": "The statuses a task is refused with.",
},
"links": ["https://datatracker.ietf.org/doc/html/rfc5545#section-3.8.1.11"],
},
"save-load.todo.status.rfc10051": {
"description": "The statuses RFC 10051 adds for a task, PENDING and FAILED, are stored as sent. Graded and keyed as save-load.todo.status. A profile stating save-load.todo.status states this one too: without it, this feature would answer with the parent's node, values and all. A server not advertising RFC 10051 (supported-task-modes) need not keep them, and the behaviour says so: Ox drops both, Zimbra stores both as NEEDS-ACTION, and neither advertises it. 'unknown' by default, as for supported-task-modes: an optional extension is not assumed on a server not probed.",
"default": {"support": "unknown"},
"extra_keys": {
"values": "The statuses stored as sent.",
"map": "A status, to the one stored instead.",
"refused": "The statuses a task is refused with.",
},
"links": ["https://datatracker.ietf.org/doc/html/rfc10051"],
},
"save-load.todo.priority": {
"description": "Each PRIORITY from 0 to 9 (RFC 5545 section 3.8.1.9) is stored as sent. PRIORITY:0 means no priority given, so a server dropping it changes nothing. 'unsupported' when one is dropped or stored as another, 'ungraceful' when a task with one is refused, the worse of the two where both apply; the extra keys say which, with the priorities as integers. Ox keeps 1, 5 and 9 only: it stores 2 as 1, 0 and 3 to 6 as 5, and 7 and 8 as 9.",
"default": {"support": "full"},
"extra_keys": {
"values": "The priorities stored as sent.",
"map": "A priority, to the one stored instead.",
"refused": "The priorities a task is refused with.",
},
"links": ["https://datatracker.ietf.org/doc/html/rfc5545#section-3.8.1.9"],
},
"supported-task-modes": {
"description": "The server advertises the CALDAV:supported-task-mode-set property (RFC 10051 section 13.1) on the calendar home or a calendar, which is how it says it supports RFC 10051. Without it a client must assume the server does not. 'unsupported' when neither has it (Ox, Zimbra); the extra key values lists the TASK-MODE values advertised. 'unknown' by default: few servers advertise it, but one not probed is not known to lack it.",
"default": {"support": "unknown"},
"extra_keys": {"values": "The TASK-MODE values the property lists."},
"links": ["https://datatracker.ietf.org/doc/html/rfc10051#section-13.1"],
},
"save-load.icalendar.x-parameter": {
"description": "An X- parameter (RFC 5545 section 3.2) on a standard property is stored with it, in an event and in a task. 'unsupported' when it is dropped (Ox and Zimbra drop SUMMARY's); the behaviour names the first component it was dropped from.",
"default": {"support": "full"},
"links": ["https://datatracker.ietf.org/doc/html/rfc5545#section-3.2"],
},
"multiget.deleted": {
"description": "A calendar-multiget naming an object that was deleted answers it as missing, as a GET does. 'broken' when it still returns the object's data after the DELETE succeeded and a GET answers 404, so a client fetching by multiget sees deleted objects.",
"default": {"support": "full"},
},
}


Expand Down
16 changes: 15 additions & 1 deletion tests/test_icalendar_roundtrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from caldav.compatibility_hints import FeatureSet
from caldav.lib.error import AuthorizationError

from caldav_server_tester.checks import CheckParticipant, CheckVtimezone, CheckXProperty
from caldav_server_tester.checks import CheckParticipant, CheckVtimezone, CheckXParameter, CheckXProperty

from .test_floating_event import RewritingServer

Expand Down Expand Up @@ -148,3 +148,17 @@ def test_unread_without_a_status_says_so_plainly(check):
verdict = _run(check, RewritingServer(get_status=503))
assert verdict["support"] == "unknown"
assert "None" not in verdict["behaviour"]


def test_x_parameter_kept_is_full_and_sent_on_summary():
sent = []
assert _run(CheckXParameter, RewritingServer(rewrite=lambda body: sent.append(body) or body))["support"] == "full"
assert all("\r\nSUMMARY;X-CALDAV-SERVER-TESTER=kept:" in body for body in sent)
assert len(sent) == 2, "an event and a task"


def test_x_parameter_dropped_is_unsupported():
"""Ox and Zimbra"""
verdict = _run(CheckXParameter, RewritingServer(rewrite=lambda b: b.replace(";X-CALDAV-SERVER-TESTER=kept", "")))
assert verdict["support"] == "unsupported"
assert "in an event" in verdict["behaviour"]
42 changes: 38 additions & 4 deletions tests/test_multiget.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

BASE = "http://example.com/cal/"
MISSING = "multiget.missing-href"
DELETED = "multiget.deleted"
LIMIT = "multiget.limit"
PROPFIND = "propfind.limit"
SEARCH = "search.limit"
Expand All @@ -45,7 +46,10 @@ def __init__(
missing_as=None,
propfind_status=None,
query_status=207,
keeps_deleted=False,
):
self.keeps_deleted = keeps_deleted
self.deleted = set()
self.query_status = query_status
self.propfind_status = propfind_status
self.missing_as = missing_as
Expand All @@ -67,6 +71,8 @@ def put(self, url, body, headers=None):
return Mock(status=201, headers={})

def delete(self, url, headers=None):
if self._name(url) in self.objects:
self.deleted.add(self._name(url))
self.objects.discard(self._name(url))
return Mock(status=204)

Expand All @@ -78,7 +84,8 @@ def report(self, url, body, depth=0):
if self.report_status != 207:
return Mock(status=self.report_status, tree=None, raw="")
names = [self._name(h) for h in re.findall(r"<D:href>(.*?)</D:href>", body)]
entries = [(n, None if n in self.objects else (self.missing_as or 404)) for n in names]
served = self.objects | (self.deleted if self.keeps_deleted else set())
entries = [(n, None if n in served else (self.missing_as or 404)) for n in names]
if self.omit_missing:
entries = [e for e in entries if e[1] is None]
return self._answer(entries)
Expand All @@ -92,6 +99,8 @@ def propfind(self, url, props=None, depth=0):

def request(self, url, method="GET", body="", headers=None):
"""The raw answer, left unparsed"""
if method == "GET":
return Mock(status=200 if self._name(url) in self.objects else 404, headers={})
assert method == "PROPFIND"
if self.propfind_raises:
raise self.propfind_raises
Expand Down Expand Up @@ -141,7 +150,7 @@ def _run(server, monkeypatch, objects=None):
checker.calendar.url = URL.objectify(BASE)
CheckMultiget(checker)._run_check()
fs = checker._features_checked
return {f: fs.is_supported(f, return_type=dict) for f in (MISSING, LIMIT, PROPFIND, SEARCH)}
return {f: fs.is_supported(f, return_type=dict) for f in (MISSING, DELETED, LIMIT, PROPFIND, SEARCH)}


def test_a_404_entry_for_the_missing_href_is_full(monkeypatch):
Expand Down Expand Up @@ -175,14 +184,27 @@ def test_a_missing_href_answered_otherwise_names_the_status(monkeypatch):
}


def test_a_deleted_object_answered_as_missing_is_full(monkeypatch):
server = MultigetServer()
assert _run(server, monkeypatch)[DELETED] == {"support": "full"}
assert not server.objects


def test_a_deleted_object_still_served_is_broken(monkeypatch):
"""Zimbra: the GET answers 404, the multiget the old data"""
verdict = _run(MultigetServer(keeps_deleted=True), monkeypatch)[DELETED]
assert verdict["support"] == "broken"
assert "404" in verdict["behaviour"]


def test_a_failing_multiget_is_ungraceful(monkeypatch):
assert _run(MultigetServer(report_status=400), monkeypatch)[MISSING]["support"] == "ungraceful"


def test_the_limits_are_not_probed_by_default(monkeypatch):
server = MultigetServer()
verdicts = _run(server, monkeypatch)
assert server.puts == 1
assert server.puts == 2, "the present object, and the one deleted"
for feature in (LIMIT, PROPFIND, SEARCH):
assert verdicts[feature]["support"] == "unknown"
assert ENV in verdicts[feature]["behaviour"]
Expand Down Expand Up @@ -229,7 +251,7 @@ def test_an_unusable_object_count_does_not_probe(monkeypatch, value):
checker.fixture_base_year = 2027
checker.calendar.url = URL.objectify(BASE)
CheckMultiget(checker)._run_check()
assert server.puts == 1
assert server.puts == 2, "the present object, and the one deleted"


def test_a_propfind_answered_507_as_a_whole_is_unsupported(monkeypatch):
Expand All @@ -255,3 +277,15 @@ def test_a_calendar_query_answered_507_as_a_whole_is_unsupported(monkeypatch):

def test_a_failing_calendar_query_is_ungraceful(monkeypatch):
assert _run(MultigetServer(query_status=500), monkeypatch, objects=12)[SEARCH]["support"] == "ungraceful"


def test_a_missing_href_answered_as_existing_leaves_deleted_unknown(monkeypatch):
"""Then a deleted object answered with properties says nothing of deletion"""
verdict = _run(MultigetServer(missing_as="propstat 200", keeps_deleted=True), monkeypatch)[DELETED]
assert verdict["support"] == "unknown"


def test_a_deleted_object_still_readable_is_unknown(monkeypatch):
server = MultigetServer()
server.delete = lambda url, headers=None: Mock(status=204) # nothing is deleted
assert _run(server, monkeypatch)[DELETED]["support"] == "unknown"
60 changes: 60 additions & 0 deletions tests/test_stable_url_probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def _make_checker(create_calendar_stable_url=None) -> Mock:
checker._client_obj = Mock()
checker._client_obj.features = FeatureSet()
checker.expected_features = FeatureSet()
checker.tasklist = None
return checker


Expand Down Expand Up @@ -344,3 +345,62 @@ def test_a_redirect_elsewhere_says_nothing(self) -> None:
def test_a_redirect_without_location_falls_back_to_the_lookup(self) -> None:
node, _ = _name_probe(NAME_PROBE_UID + ".ics", put_status=302)
assert node["forces_uid_ics"] is True


TASKS = "http://dav.example.com/caldav/tasks/"


def _task_probe(task_reported_as, create_calendar_stable_url=None) -> tuple[dict, Mock]:
"""Events keep their name; a task PUT under the probe's name is reported as ``task_reported_as``"""
calendar, client = _name_probe_calendar(NAME_PROBE_NAME)
tasklist = Mock()
tasklist.url = URL.objectify(TASKS)

def object_by_uid(uid):
obj = Mock()
obj.url = URL.objectify(TASKS + task_reported_as)
return obj

tasklist.object_by_uid = object_by_uid
checker = _make_checker(create_calendar_stable_url)
checker._client_obj = client
checker.tasklist = tasklist
PrepareCalendar(checker)._check_stable_url(calendar)
return checker.features_checked.is_supported("save-load.stable-url", dict), client


class TestATaskStoredUnderAnArbitraryName:
"""Ox keeps an event's name and names a task <uid>.ics."""

def test_a_task_named_uid_ics_is_unsupported_for_tasks_only(self) -> None:
node, client = _task_probe(NAME_PROBE_UID + ".ics")
assert node["support"] == "unsupported"
assert node["uid_ics_components"] == ["VTODO"]
assert "forces_uid_ics" not in node
assert "task" in node["behaviour"]
sent = [call.args[1] for call in client.put.call_args_list if str(call.args[0]).startswith(TASKS)]
assert sent and "BEGIN:VTODO" in sent[0]

def test_a_task_keeping_its_name_changes_nothing(self) -> None:
node, _ = _task_probe(NAME_PROBE_NAME)
assert node["support"] == "full"
assert "uid_ics_components" not in node

def test_a_relocated_collection_says_so_and_names_the_tasks(self) -> None:
"""Ox: both at once"""
relocated = {"support": "unsupported", "behaviour": "an opaque cal://0/NNN"}
node, _ = _task_probe(NAME_PROBE_UID + ".ics", create_calendar_stable_url=relocated)
assert node["uid_ics_components"] == ["VTODO"]
assert "create-calendar.stable-url" in node["behaviour"]
assert "task" in node["behaviour"]

def test_the_task_probe_is_removed(self) -> None:
_, client = _task_probe(NAME_PROBE_UID + ".ics")
deleted = {str(call.args[0]) for call in client.delete.call_args_list}
assert {TASKS + NAME_PROBE_NAME, TASKS + NAME_PROBE_UID + ".ics"} <= deleted

def test_a_task_renamed_to_another_name_is_unsupported_and_named(self) -> None:
node, _ = _task_probe("7f3a9c12-server-assigned.ics")
assert node["support"] == "unsupported"
assert "uid_ics_components" not in node
assert "7f3a9c12-server-assigned.ics" in node["behaviour"]
90 changes: 90 additions & 0 deletions tests/test_supported_task_modes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
"""Whether a server advertises RFC 10051 with CALDAV:supported-task-mode-set (section 13.1).

Neither Ox nor Zimbra has the property, on the calendar home or a calendar.
"""

from unittest.mock import Mock

from caldav.compatibility_hints import FeatureSet
from lxml import etree

from caldav_server_tester.checks import CheckSupportedTaskModes

HOME = "http://example.com/home/"
CAL = "http://example.com/home/tasks/"


def _answer(modes):
if modes is None:
prop, status = "<C:supported-task-mode-set/>", "404 Not Found"
else:
inner = "".join(f"<C:supported-task-mode>{m}</C:supported-task-mode>" for m in modes)
prop, status = f"<C:supported-task-mode-set>{inner}</C:supported-task-mode-set>", "200 OK"
xml = (
'<?xml version="1.0"?><D:multistatus xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">'
f"<D:response><D:href>/x/</D:href><D:propstat><D:prop>{prop}</D:prop>"
f"<D:status>HTTP/1.1 {status}</D:status></D:propstat></D:response></D:multistatus>"
)
return Mock(status=207, tree=etree.fromstring(xml.encode()), raw=xml)


def _run(home=None, calendar=None, fails=False, home_fails=False, tasklist=True):
"""``home`` and ``calendar``: the modes each lists, None where the property is absent"""
client = Mock()

def request(url, method="GET", body="", headers=None):
assert method == "PROPFIND" and "supported-task-mode-set" in body
if fails:
return Mock(status=500, tree=None, raw="")
return _answer(home if url == HOME else calendar)

client.request.side_effect = request
checker = Mock()
checker._features_checked = FeatureSet()
checker.debug_mode = None
checker._client_obj = client
if home_fails:
type(checker.principal).calendar_home_set = property(lambda self: (_ for _ in ()).throw(OSError("gone")))
else:
checker.principal.calendar_home_set.url = HOME
if tasklist:
checker.tasklist.url = CAL
else:
checker.tasklist = None
CheckSupportedTaskModes(checker)._run_check()
return checker._features_checked.is_supported("supported-task-modes", return_type=dict)


def test_absent_everywhere_is_unsupported():
"""Ox, Zimbra"""
verdict = _run()
assert verdict["support"] == "unsupported"
assert "supported-task-mode-set" in verdict["behaviour"]


def test_on_the_home_is_full_with_the_modes():
assert _run(home=["AUTOMATIC-COMPLETION", "AUTOMATIC-FAILURE"]) == {
"support": "full",
"values": ["AUTOMATIC-COMPLETION", "AUTOMATIC-FAILURE"],
}


def test_on_a_calendar_only_is_full():
assert _run(calendar=["AUTOMATIC-COMPLETION"])["support"] == "full"


def test_an_empty_set_is_unsupported():
"""No supported-task-mode inside: RFC 10051 says to assume no support"""
assert _run(home=[])["support"] == "unsupported"


def test_a_failing_propfind_is_unknown():
assert _run(fails=True)["support"] == "unknown"


def test_a_failing_home_lookup_asks_the_calendar_only():
assert _run(calendar=["AUTOMATIC-COMPLETION"], home_fails=True)["support"] == "full"


def test_without_a_task_calendar_the_home_is_asked():
assert _run(home=["AUTOMATIC-COMPLETION"], tasklist=False)["support"] == "full"
Loading
Loading